Hello,
I am trying to control remotely a led with my Arduino Uno by sending sms text but the code i am using doesn't seem to work. I am new to arduino so can anyone help me???
The code:
#include <SoftwareSerial.h>
char inchar; // Will hold the incoming character from the GSM shield
SoftwareSerial SIM900(3, 2);
int led = 10;
void setup()
{
Serial.begin(19200);
// set up the digital pins to control
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
// wake up the GSM shield
SIM900.begin(19200);
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 loop()
{
//If a character comes in from the cellular module...
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar=='#')
{
delay(100);
inchar=SIM900.read();
if (inchar=='a')
{
delay(100);
inchar=SIM900.read();
if (inchar=='0')
{
digitalWrite(led, LOW);
}
else if (inchar=='1')
{
digitalWrite(led, HIGH);
}
delay(100);
SIM900.println("AT+CMGD=1,4"); // delete all SMS
}
}
}
}
Which SIM900 based device are you trying to use?
Hello,
I am using SIM900 Quad-band GSM/GPRS Shield for Arduino UNO.
sim900
Try the primer in my signature, but adjust to use pins D2 & D3, rather than D7 & D8.
Assuming you have set the jumpers appropriately, shouldn't it be
SoftwareSerial SIM900(2, 3);
I have tried that also but nothing happened. Now at the SIM900 board i use D3-GRx and D2-GTx. When i used SoftwareSerial SIM900(2, 3) it was D2-GRx and D3-GTx.
So when i send for example #a1 in order to led on nothing happens.
Seeing as there is no software power control in your code, you are turning it on aren't you?
When you send #a1 it makes led: digital port 10 high. So it sends 5V. When you send #a0 makes led:digital port 10 0. So it sends 0V. Isn't that correct.
Does AT command need (ctrl z) also in order to work? And if yes how i do it?
Thank u!!
That is what it looks like it is supposed to do.
Have you tried the SerialRelay test as in my signature? No point trying to get leds to light until you know the board is working.
No the truth is i haven't tried that. So i do that and i will come back with feedback.
Until you can get it to respond to a basic 'AT' command you are wasting your time. That will tell you that you have in configured correctly.
In case that it doesn't respond what would be the reason? If the code is correct and the jumpers for softwareserial are correct?
What should i check after that?
Right, assuming that GRx is jumpered to D3, and GTx to D2, load and run:
// Untested!
#include <SoftwareSerial.h>
SoftwareSerial GPRS(2, 3);
const byte POWER_PIN = 7;
void setup()
{
// Configure software power control
pinMode(POWER_PIN, OUTPUT);
digitalWrite(POWER_PIN,LOW);
delay(1000);
powerUp();
GPRS.begin(19200); // the GPRS baud rate
Serial.begin(19200);
}
void loop()
{
if (GPRS.available())
{
while(GPRS.available())
{
Serial.write(GPRS.read());
}
}
if (Serial.available())
{
while(Serial.available())
{
GPRS.write(Serial.read());
}
}
}
void powerUp()
{
digitalWrite(POWER_PIN,HIGH);
delay(2000);
digitalWrite(POWER_PIN,LOW);
delay(3000);
}
Open up Serial Monitor (you made need to do this twice as opening it resets the Arduino, first time will turn the shield off...) and type AT. You should get a response.
Also, try here for some common problems and hints.
Dannable thank you very much for your help. I will tell you how it went when i run the code.
Also i have a question.
When we use for example SoftwareSerial(2, 3) is it SoftwareSerial(Rx, Tx)???So it has to be 2 as Rx and 3 as Tx or it doesn't matter the order. I mean if the jumpers are Rx:2, Tx: 3 it is the same (2, 3) and (3, 2)???
You configure SoftwareSerial from the Arduino perspective. So you are using Arduino D2(Rx) to listen to shield D2(Tx), and Arduino D3(Tx) to talk to shield D3(Rx).
I run the Serial Relay code but nothing happened. But after i run the other code that you send me when i was sending the AT command the led went on for a few mseconds but after that i had to reset the GPRS shield because the NET led stopped blinking. The GPRS shield that i use as i attached in the reply#2, has a a position for an RTC battery but i haven't inserted any. Maybe is that the reason that it doesn't respond?
Thank u!!
The most likely reason that the net light will stop blinking is if there isn't enough power available - the voltage drops below a specific value and the SIM900 will shut down.
The battery is only for keeping the RTC running when the main power supply is unavailable. You aren't using the RTC?
So i don't need the battery for now. What else should i do for this to work??? I have tried everything!!!! When i run the Serial Relay an d i open the Serial port of Arduino to send "AT" as you said not only i don't see a OK response but i don't see the "AT" command that i have sent? Should i use some how the ctrl z???
No, you do not need a battery. What are you using to power the SIM900?