HOME Automation using Arduino
Discussion in "AVR Discussion Forum" started by gaurav Apr 11, 2013.
Thu Apr 11 2013, 05:19 pm
here is the code for my project ..the problem is that when i uplode it in arduino uno...
it and when i sens a string LOAD1ON there should be a resopnce LOAD1=ON
but i wont recive this response on terminal
it and when i sens a string LOAD1ON there should be a resopnce LOAD1=ON
but i wont recive this response on terminal
#include <LiquidCrystal.h> #include <Servo.h> LiquidCrystal lcd( 12, 11, 5, 4, 3, 2); Servo SERVO ; void setup() { Serial.begin(9600); analogReference(EXTERNAL); lcd.begin(16, 2); SERVO.attach(10); Serial.println("AT\r"); //To check if GSM module is working delay(2000); Serial.println("AT+CMGF=1\r"); // set the SMS mode to text delay(1500); pinMode(6,OUTPUT); pinMode(7,OUTPUT); pinMode(8,OUTPUT); pinMode(9,OUTPUT); pinMode(13,OUTPUT); } void loop() { int TEMP_read = analogRead(1); float temp = ((4.68 * TEMP_read * 100.0) / 1024); lcd.clear(); lcd.setCursor(0,0); lcd.print("TempC:"); lcd.println(temp); int GAS_read = analogRead(2); if(GAS_read > = 600) { lcd.setCursor(0,1); lcd.print("Gas Detected"); delay(500); } if(GAS_read <= 600) { lcd.setCursor(0,1); lcd.print("Gas Not Detected"); delay(500); } if(digitalRead(13) == HIGH) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Motion Detected"); Serial.println("Motion Detected"); delay(500); } //Serial.print("AT+CMGR=1\r"); //delay(1000); //RUN2(); if (Serial.available() > 0) { //RUN(); RUN2(); } } /*void RUN() { char S= Serial.read(); switch(S) { case 'A': LOAD1_ON(); Serial.print("AT+CMGD=1\r"); break; case 'B': LOAD1_OFF(); Serial.print("AT+CMGD=1\r"); break; case 'C': LOAD2_ON(); Serial.print("AT+CMGD=1\r"); break; case 'D': LOAD2_OFF(); Serial.print("AT+CMGD=1\r"); break; case 'E': LOAD3_ON(); Serial.print("AT+CMGD=1\r"); break; case 'F': LOAD3_OFF(); Serial.print("AT+CMGD=1\r"); break; case 'G': LOAD4_ON(); Serial.print("AT+CMGD=1\r"); break; case 'H': LOAD4_OFF(); Serial.print("AT+CMGD=1\r"); break; case 'I': SERVO_ON(); Serial.print("AT+CMGD=1\r"); break; case 'J': SERVO_OFF(); Serial.print("AT+CMGD=1\r"); break; case 'a': Serial.print("AT+CMGS=\"+919220635426\"\r"); delay(1000); TEMPERATURE(); GAS_Sensor(); PIR_Sensor(); LOADS_status(); delay(1000); Serial.write(0x1A); delay(1000); Serial.print("AT+CMGD=1\r"); //LDR_Sensor(); break; } } */ void RUN2() { char c[10]={Serial.read()}; if(c == "LOAD1ON") { LOAD1_ON(); } if(c == "LOAD1OFF") { LOAD1_OFF(); } if(c == "LOAD2ON") { LOAD2_ON(); } if(c == "LOAD2OFF") { LOAD2_OFF(); } if(c == "LOAD3ON") { LOAD3_ON(); } if(c == "LOAD3OFF") { LOAD3_OFF(); } if(c == "LOAD4ON") { LOAD4_ON(); } if(c == "LOAD4OFF") { LOAD4_OFF(); } return; } //} //subroutines void LOAD1_ON() { digitalWrite(6,HIGH); Serial.println("LOAD1=ON"); return; } void LOAD1_OFF() { digitalWrite(6,LOW); Serial.println("LOAD1=OFF"); return; } void LOAD2_ON() { Serial.println("LOAD2=ON"); digitalWrite(7,HIGH); return; } void LOAD2_OFF() { digitalWrite(7,LOW); Serial.println("LOAD2=OFF"); return; } void LOAD3_ON() { digitalWrite(8,HIGH); Serial.println("LOAD3=ON"); return; } void LOAD3_OFF() { digitalWrite(8,LOW); Serial.println("LOAD3=OFF"); return; } void LOAD4_ON() { digitalWrite(9,HIGH); Serial.println("LOAD4=ON"); return; } void LOAD4_OFF() { Serial.println("LOAD4=OFF"); digitalWrite(9,LOW); return; } void SERVO_ON() { SERVO.write(90); Serial.println("DOOR Closed"); delay(500); return; } void SERVO_OFF() { SERVO.write(0); Serial.println("Door open"); delay(500); return; } void TEMPERATURE() { int TEMP_read = analogRead(1); float temp = ((4.68 * TEMP_read * 100.0) / 1024); Serial.print("TempC:"); Serial.println(temp); delay(500); return; } void GAS_Sensor() { int GAS_read = analogRead(2); if(GAS_read > = 600) { Serial.println("Gas Detected"); //lcd.setCursor(0,1); //lcd.print("Gas Detected"); //delay(500); } if(GAS_read <= 600) { Serial.println("Gas Not Detected"); //lcd.setCursor(0,1); //lcd.print("Gas Not Detected"); //delay(500); } delay(500); return; } void PIR_Sensor() { if(digitalRead(13) == HIGH) { Serial.println("Motion Detected"); } else { Serial.println("NO Motion"); } return; } void LOADS_status() { if(digitalRead(6) == HIGH) { Serial.println("Load1=NO"); } else { Serial.println("Load1=OFF"); } if(digitalRead(7) == HIGH) { Serial.println("Load2=ON"); } else { Serial.println("Load2=OFF"); } if(digitalRead(8) == HIGH) { Serial.println("Load3=ON"); } else { Serial.println("Load3=OFF"); } if(digitalRead(9) == HIGH) { Serial.println("Load4=ON"); } else { Serial.println("Load4=OFF"); } return; } // void GSM_READ() // { // Serial.print("AT+CMGR=1\r"); //RUN(); //}
Mon Apr 15 2013, 05:30 pm
I am not sure if arduino works this way.. or I am thinking how will it work. maybe the below statement waits for 10 bytes to be recevied?
I feel reading should be somewhat like this:
char c[10]={Serial.read()};
I feel reading should be somewhat like this:
for (i = 0; i < 10; i++) { while(!Serial.available()); c[i] = Serial.read; }
Wed Apr 17 2013, 05:56 pm
I am not sure if arduino works this way.. or I am thinking how will it work. maybe the below statement waits for 10 bytes to be recevied?char c[10]={Serial.read()};
I feel reading should be somewhat like this:for (i = 0; i < 10; i++) { while(!Serial.available()); c[i] = Serial.read; }Ajay Bhargav
the logic is ....seems to be simple and correct...
but not tested........
because....unfortunately....a..late....reply.....
i have completed the..code...with another logics..in arduino..n workes fine......
will try to use u r logic in another program.......
Thank u......for the reply.....
Thu Apr 18 2013, 02:37 pm
the logic is ....seems to be simple and correct...
Well I doubt the correctness of the same. even if compiler create code for such statement. either it will end after reading 10 bytes compulsorily in order to fill the buffer or it will read just one byte. In either case if your command will not match with expected.
e.g. you give LOAD1ON = 7 bytes, arduino might wait for 3 more bytes before start processing.
Fri Apr 19 2013, 06:29 am
I agree Ajay
According to this page
http://arduino.cc/en/Serial/Read
Serial.read() only reads one byte.
There is a
Serial.readBytes() function which may be what was intended.
According to this page
http://arduino.cc/en/Serial/Read
Serial.read() only reads one byte.
There is a
Serial.readBytes() function which may be what was intended.
Sun Dec 29 2013, 12:42 am
m about to complet this project but stuck in a GSM AT command
when we send a
AT+CMGR=1 the modem send the first sms that is recived with the time, date, caller ic ...etc then at last the required sms
but any AT command that will only send the required sms to konw
or
first sms to deisplay then other all details of sms...
when we send a
AT+CMGR=1 the modem send the first sms that is recived with the time, date, caller ic ...etc then at last the required sms
but any AT command that will only send the required sms to konw
or
first sms to deisplay then other all details of sms...
Sun Jan 12 2014, 05:04 pm
At command CMGR will give all the data that's how it's designed. There is no way to get just the SMS text. However you can add a start and end character to recognise the desired text from SMS response.
Mon Jan 13 2014, 11:54 pm
ok...so what modification ..
or what type of instruction ..have to write..in embedded c or arduino
or what type of instruction ..have to write..in embedded c or arduino
Fri Jan 17 2014, 10:10 am
@gaurav, sorry for delayed response festive season.
You can add special characters to your sms as I mentioned, e.g.
$LIGHT1=ON#
wait till you get $ after sending CMGR command and then to find end of message look for #. I think you can easily do it in C something like:
easy enough
You can add special characters to your sms as I mentioned, e.g.
$LIGHT1=ON#
wait till you get $ after sending CMGR command and then to find end of message look for #. I think you can easily do it in C something like:
while (uart_read() != '$'); do { ch = uart_read(); } while(ch != '#');
easy enough
Powered by e107 Forum System