Pages: [1] 2   Go Down
Author Topic: I HAVE ARDUINO UNO AND SIM900 GSM MODEM.... THIS IS THE CODE... I WANT TO LED ON  (Read 1542 times)
0 Members and 1 Guest are viewing this topic.
chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
#include <SoftwareSerial.h>  //Include the NewSoftSerial library to send serial commands to the cellular module.

char inchar;                //Will hold the incoming character from the Serial Port.

SoftwareSerial cell(2,3);    //Create a 'fake' serial port. Pin 2 is the Rx pin, pin 3 is the Tx pin.

int led1 = 11;

int led2 = 12;

int led3 = 13;



void setup()

{    // prepare the digital output pins

pinMode(led1, OUTPUT);

pinMode(led2, OUTPUT);

pinMode(led3, OUTPUT);



digitalWrite(led1, LOW);

digitalWrite(led2, LOW);

digitalWrite(led3, LOW);

   //Initialize GSM module serial port for communication.

Serial.begin(9600);

delay(3000); // give time for GSM module to register on network etc.

Serial.println("AT+CMGF=1"); // set SMS mode to text

delay(200);

Serial.println("AT+CNMI=3,3,0,0"); // set module to send SMS data to serial out upon receipt

delay(200);
}

void loop()

{    //If a character comes in from the cellular module...

if(Serial.available() >0)

{

inchar=Serial.read();

if (inchar=='#') // OK - the start of our command

{

delay(10);

inchar=Serial.read();

if (inchar=='a')

{

delay(10);

inchar=Serial.read();

if (inchar=='0')

{

digitalWrite(led1, LOW);

}

else if (inchar=='1')

{

digitalWrite(led1, HIGH);

}

delay(10);

inchar=Serial.read();

if (inchar=='b')

{

inchar=Serial.read();

if (inchar=='0')

{

digitalWrite(led2, LOW);

}

else if (inchar=='1')

{

digitalWrite(led2, HIGH);

}

delay(10);

inchar=Serial.read();

if (inchar=='c')

{

inchar=Serial.read();

if (inchar=='0')

{

digitalWrite(led3, LOW);

}

else if (inchar=='1')

{

digitalWrite(led3, HIGH);

}

delay(10);



}

}

Serial.println("AT+CMGD=1,4"); // delete all SMS

}

}

}

}


Moderator edit: CODE TAGS ADDED.

« Last Edit: January 21, 2013, 10:45:16 am by AWOL » Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11176
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
WHERE IS T MISTAKE

Please don't shout.

Please post code in [ code ] [ /code ] tags so it displays correctly, and make sure your code is complete.

Also please tell us what the code is supposed to do, what it actually does, and what you're tried so far to find the problem.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11176
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

PLEASE DON'T SHOUT.

You have a sketch that includes statements to turn the LEDs on and off. Does it compile? Does it do what you want? If not, what do you want it to do, what does it actually do, and what circuits do you have connected to it?
Logged

I only provide help via the forum - please do not contact me for private consultancy.

chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i want to turn on / off led using sms from my mobile
Logged

chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

j have arduino uno and sim900 modem, i need to turn on/off led using sms from mobile... this is the code i tried... but through sms is nt wrking... if we give code in serial monitor it works.... but not wrking in sms
#a1b1c1 is the code to turn on the 3 led connected to pin 11,12,13.....
Logged

chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

where is t mistake ????
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46111
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If there is at least one character available to read, read a while bunch of them. Nope. That won't work.

The proper way to read, store, and compare serial data comes up nearly daily. Time for you to do some research.
Logged

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 25
Posts: 1143
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The program you have shown only does I/O on the hardware Serial port (ie the one connected to the USB). I do not see any calls to the softwareserial"cell" you have opened...?

Also look at http://www.arduino.cc/en/Reference/SoftwareSerialExample which shows a sort of "echo" between the hardware port and the softwareserial - you should do something similar to see what you actually receive on the modem.

Lastly (in other words there is more than one error) whilst you wait correctly for the first character (Serial.available()>0) you simply assume the other 6 characters have arrived. They may or may not have arrived (I noticed the delay(10) - probably a workaround you found worked, sort of) . Either do a  (Serial.available()>0) before each Serial.read OR do a  (Serial.available()>=6) which means at least 6 characters have arrived.
Logged

chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i tried it also not working... i want to know how gsm reads t message in serial monitor?????
Logged

chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sms is not recieving serial window
Logged

UK
Offline Offline
Shannon Member
****
Karma: 184
Posts: 11176
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

where is t mistake ????

You are sending your modem commands to the hardware serial port instead of the SoftwareSerial port 'cell' that you have created, which presumably is connected to the modem. You would presumably also need to read the responses from the cell SoftwareSerial port.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

so, what i need to do?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to stop opening new threads on the same topic.

Do NOT cross-post, it makes me very CROSS.
Also, please start using code tags when posting code.
And stop SHOUTING.

Clear?
« Last Edit: January 21, 2013, 12:08:12 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

chennai
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok sir, give me example coding to turn on/off leg using gsm
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 239
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
give me example coding to turn on/off leg using gsm
Nice attitude.

I've just merged cross-posted threads and given you an example of how to add CODE TAGS to your posts.
Now look, you've made me shout too.
« Last Edit: January 21, 2013, 01:11:03 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: [1] 2   Go Up
Jump to: