SMS controlled relays and sensors. Need some help...

Hi guys,

I have just found Arduino and begin to be really into those many opportunitys what this all can give.

My trouble is coding. I’m quite technical guy and able to build many things, but now I have faced something what I really dont manage.

So, My project is to control and communicate some relays and sensors by sms.

I have Arduino Uno and A6 gsm pro serial module.

Relay is Basic arduino fitted 5v/230v.

Sensors are humidity and temperature.

Program should be:

Relay controlling by sms example “Relay 1 On” “Relay 2 Off”.

Sensor reading by sms example: “Read Sensor 1” “Read Sensor 2”.

Also i need alarmmode for sensors example: " Temperature too high" (alarm should come by sms).

And what I’m doing…

It’s the orchidea plant garden. Birthday present to my lovely wife. :smiley:

I want to control Water pump and want to know what kind of circumstances is In the plant box.

I can only do some simply codes. Just to get the Led blinking. Its not enough to do this.

Anyone want To help me A bit?

This is the code what i found and trying to get it works.

What should i change to get this work with A6 serial pro module.

What is real differences between sim900 and A6?

Pinouts ofcourse but what Else?

This code was made to control aquarium, but it seems to be possible to my project as Wells.

#include <SoftwareSerial.h>

char inchar; // Will hold the incoming character from the GSM shield

#include <OneWire.h>

SoftwareSerial SIM900(7, 8);

OneWire ds(2); // on pin 2 (a 4.7K resistor is necessary)

int led1 = 10;

int led2 = 11;

int led3 = 12;

int led4 = 13;

void setup()

{

Serial.begin(19200);

// set up the digital pins to control

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);

pinMode(led4, OUTPUT);

digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

digitalWrite(led4, LOW);

SIM900.begin(19200);

SIM900power();

delay(20000); // give time to log on to network.

SIM900.print(“AT+CMGF=1\r”); // set SMS mode to text

delay(100);

SIM900.print(“AT+CNMI=2,2,0,0,0\r”);

// blurt out contents of new SMS upon receipt to the GSM shield’s serial out

delay(100);

Serial.println(“Ready…”);

}

void SIM900power()

// software equivalent of pressing the GSM shield “power” button

{

digitalWrite(9, HIGH);

delay(1000);

digitalWrite(9, LOW);

delay(7000);

}

void sendSMS()

{

SIM900.print(“AT+CMGF=1\r”); // AT command to send SMS message

delay(100);

SIM900.println(“AT + CMGS = "+49xxxxxxxxxxx"”); // recipient’s mobile number, in international format

delay(100);

SIM900.println(" hello."); // message to send

delay(100);

SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26

delay(100);

SIM900.println();

delay(5000); // give module time to send SMS

SIM900power(); // turn off module

}

void loop()

{

//If a character comes in from the cellular module…

if(SIM900.available() >0)

{

inchar=SIM900.read();

if (inchar==‘#’)

{

delay(10);

inchar=SIM900.read();

if (inchar==‘a’)

{

delay(10);

inchar=SIM900.read();

if (inchar==‘0’)

{

digitalWrite(led1, LOW);

}

else if (inchar==‘1’)

{

digitalWrite(led1, HIGH);

}

delay(10);

inchar=SIM900.read();

if (inchar==‘b’)

{

inchar=SIM900.read();

if (inchar==‘0’)

{

digitalWrite(led2, LOW);

}

else if (inchar==‘1’)

{

digitalWrite(led2, HIGH);

}

delay(10);

inchar=SIM900.read();

if (inchar==‘c’)

{

inchar=SIM900.read();

if (inchar==‘0’)

{

digitalWrite(led3, LOW);

}

else if (inchar==‘1’)

{

digitalWrite(led3, HIGH);

}

delay(10);

inchar=SIM900.read();

if (inchar==‘d’)

{

delay(10);

inchar=SIM900.read();

if (inchar==‘0’)

{

digitalWrite(led4, LOW);

}

else if (inchar==‘1’)

{

digitalWrite(led4, HIGH);

}

delay(10);

}

}

SIM900.println(“AT+CMGD=1,4”); // delete all SMS

}

}

}

}

byte i;

byte present = 0;

byte type_s;

byte data[12];

byte addr[8];

float celsius, fahrenheit;

if ( !ds.search(addr)) {

SIM900.print(“AT+CMGF=1\r”); // AT command to send SMS message

delay(100);

SIM900.println(“AT + CMGS = "+49xxxxxxxxxxxxx"”); // recipient’s mobile number, in international format

delay(100);

SIM900.println(" Thank You "); // message to send

delay(100);

SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26

delay(100);

SIM900.println();

delay(5000); // give module time to send SMS

SIM900power(); // turn off module

ds.reset_search();

delay(10000);

return;

}

switch (addr[0]) {

case 0x28:

SIM900.print(“AT+CMGF=1\r”); // AT command to send SMS message

delay(100);

SIM900.println(“AT + CMGS = "+49xxxxxxxxxxx"”); // recipient’s mobile number, in international format

delay(100);

SIM900.println(" Temperature report"); // message to send

delay(100);

SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26

delay(100);

SIM900.println();

delay(5000); // give module time to send SMS

SIM900power(); // turn off mod

type_s = 0;

break;

return;

}

ds.reset();

ds.select(addr);

ds.write(0x44); // start conversion, use ds.write(0x44,1) with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not

// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();

ds.select(addr);

ds.write(0xBE); // Read Scratchpad

for ( i = 0; i < 9; i++) { // we need 9 bytes

data = ds.read();
}
int16_t raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// “count remain” gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
// at lower res, the low bits are undefined, so let’s zero them
if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
//// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;

SIM900.print(“AT+CMGF=1\r”); // AT command to send SMS message
delay(100);
SIM900.println(“AT + CMGS = "+49xxxxxxxxxxx."”); // recipient’s mobile number, in international format
delay(100);
SIM900.println(" Temp= "); // message to send
SIM900.println(celsius);
SIM900.println(" Cel, "); // message to send
SIM900.println(fahrenheit);
SIM900.println(" Fah");
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(10000); // give module time to send SMS
SIM900power();

}