Wiring all same previous blog just add relay module
VDO
Connect 4 Relays module to Arduino Board
Wiring
4 Relays module to Board Arduino
Vcc 5 Volt
IN1 Pin 4
IN2 Pin 5
IN3 Pin 6
IN4 Pin 7
GND GND
I2C LCD
Connect
LCD >>> Arduino
GND >>> GND
VCC >>> 5Vcc
SDA >>> A4
SCL >>> A5
Temperature
Sig >>> A0 (Arduino)
Concept
Idea for control relay if you want to control something immedaitly
example pump lighting .
Send sms
a1 relay IN1 on
a? relay IN1 off
b1 relay IN2 on
b? relay IN2 off
c1 relay IN3 on
c? relay IN3 off
d1 relay IN4 on
d? relay IN4 off
x1 All relay on
x? All relay off
Library
Code
#include "SIM900.h"
#include <SoftwareSerial.h>
//If not used, is better to exclude the HTTP library,
//for RAM saving.
//If your sketch reboots itself proprably you have finished,
//your memory available.
//#include "inetGSM.h"
//If you want to use the Arduino functions to manage SMS, uncomment the lines below.
#include "sms.h"
SMSGSM sms;
//To change pins for Software Serial, use the two lines in GSM.cpp.
//GSM Shield for Arduino
//www.open-electronics.org
//this code is based on the example of Arduino Labs.
//Simple sketch to send and receive SMS.
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
//LCD
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
//temp
float tempC;
int reading;
int tempPin = 0;
void setup()
{
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
//stup lcd
lcd.init();
//setup temp
analogReference(INTERNAL);
//Serial connection.
Serial.begin(9600);
Serial.println("GSM Shield testing.");
//Start configuration of shield with baudrate.
//For http uses is raccomanded to use 4800 or slower.
if (gsm.begin(2400)) {
Serial.println("\nstatus=READY");
started=true;
} else Serial.println("\nstatus=IDLE");
if(started) {
//Enable this two lines if you want to send an SMS.
if (sms.SendSMS("08*******", "GSM SmartHome"))
Serial.println("\nSMS sent OK");
}
};
void loop()
{
temp();
if(started) {
//Read if there are messages on SIM card and print them.
if(gsm.readSMS(smsbuffer, 160, n, 20)) {
Serial.println(n); //Print out phone number
Serial.println(smsbuffer); // Text
char* ptr = smsbuffer;
while ( strlen(ptr) >= 2 ) {
if ( ptr[0] == 'a' ) {
if ( ptr[1] == '1' )
digitalWrite(4, LOW);
else
digitalWrite(4, HIGH);
}
if ( ptr[0] == 'b' ) {
if ( ptr[1] == '1' )
digitalWrite(5, LOW);
else
digitalWrite(5, HIGH);
}
if ( ptr[0] == 'c' ) {
if ( ptr[1] == '1' )
digitalWrite(6, LOW);
else
digitalWrite(6, HIGH);
}
if ( ptr[0] == 'd' ) {
if ( ptr[1] == '1' )
digitalWrite(7, LOW );
else
digitalWrite(7, HIGH);
}
if ( ptr[0] == 'x') {
if ( ptr[1] == '1'){
digitalWrite(4,LOW);
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);}
else
{
digitalWrite(4,HIGH);
digitalWrite(5,HIGH);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
}
}
ptr += 2;
}
}
delay(1000);
}
};
void temp()
{
reading = analogRead(tempPin);
tempC = reading / 10;
//Serial.println(tempC);
// Print a message to the LCD.
lcd.backlight();
lcd.setCursor(3,0);
lcd.print("Temperature");
lcd.setCursor(2,1);
lcd.print(tempC);
if(tempC > 23 )
{
sms.SendSMS("084*******", "Temp over 23 C");
}
delay(1000);
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น