I have a SIM900 board which has a serial interface. I'm trying to control it using Arduino Uno. I've tried using SoftwareSerial on pins 10 (RX) and 11 (TX) to talk to my board. It works OK with different baud rates (SIM900 has auto-bauding). I'm connecting pin 10 directly to my board, but pin 11 is connected through a voltage divider in order to lower voltage from 5 V to 2.8 V (SIM900 uses 2.8 V CMOS logic levels).
But now I want to use Arduino's hardware UART to talk to SIM900. I'm using pins 0 and 1 with similar design as above (also using voltage divider). I just can't get it to work. No matter what I do I can't see any communication. I've tried different baud rates, but it just doesn't work. Here is my code:
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
delay(10000);
Serial.write("AT\r");
delay(1000);
if (Serial.available())
{
digitalWrite(13, HIGH);
}
}
void loop()
{
}
So I should see a LED light up but nothing happens (SIM900 responds with "\r\nOK\r\n" to "AT\r"). What am I doing wrong?
2 Answers 2
2.8V is not high enough to register as a high on an AVR input. You will need to use a level converter to raise the TX line of the SIM900 from 2.8V to 5V.
-
So why it does work with software serial without any problems?rubix_addict– rubix_addict2014年12月06日 17:18:46 +00:00Commented Dec 6, 2014 at 17:18
-
It is very marginal. The additional loading from the USB communication chip destroys this margin.Ignacio Vazquez-Abrams– Ignacio Vazquez-Abrams2014年12月06日 17:20:12 +00:00Commented Dec 6, 2014 at 17:20
-
I see. Thank you for help. I'll use a level shifter as you suggested.rubix_addict– rubix_addict2014年12月06日 17:39:42 +00:00Commented Dec 6, 2014 at 17:39
-
One would think that an idle USB serial chip would actually be pulling the line up thought its series resistor, rather than loading it down.Chris Stratton– Chris Stratton2017年03月14日 06:02:10 +00:00Commented Mar 14, 2017 at 6:02
Arduino with sim900 module is disabled after a day or course sim900 module is completely safe and always receives sms but the Arduino module led after one or more days is no longer able to enable or disable.
#include <SoftwareSerial.h>
SoftwareSerial SIM900 (7, 8);
char incoming_char = 0; // Will hold the incoming character from the Serial Port.
int led_status = 0;
int led1 = 10;
int led2 = 13;
void setup () {
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
SIM900power ();
Serial.begin (19200); // Set the baud rate
SIM900.begin (19200); // For GSM shield
delay (20000); // Give time to log on to network.
SIM900.print ( "AT + CMGF = 1 \ r"); // Set SMS mode to text
delay (100);
SIM900.println ( "AT + CNMI = 2,2,0,0,0 \ r");
//SIM900.print("AT+CLIP=1\r "); // Turn on caller ID notification
digitalWrite (led1, LOW); // Set led to LOW
digitalWrite (led2, LOW);
// Serial.println ( "AT + CMGD = 1,4"); // Delete all SMS in box
}
void sendSMS (char led_status) {// SEND SMS
SIM900.print ( "AT + CMGF = 1 \ r"); // AT command to send SMS message
delay (1000);
SIM900.println ( "AT + CMGS = \" + 9xxxxxxxx \ "\ r"); // Recipient's mobile number, in international format
delay (1000);
if (led_status == 0)
{
SIM900.println ( "ALARM ON");
}
else
{
SIM900.println ( "ALARM OFF");
}
delay (1000);
SIM900.println ();
delay (5000); // Give module time to send SMS
}
void SIM900power ()
// Software equivalent of pressing the GSM shield "power" button
{
digitalWrite (9, HIGH);
delay (1000);
digitalWrite (9, LOW);
delay (7000);
}
void loop () {
// # A1s on & # a0s off
if (SIM900.available ()> 0)
{
incoming_char = SIM900.read ();
if (incoming_char == '#')
{
delay (10);
incoming_char = SIM900.read ();
if (incoming_char == 'a')
{
delay (10);
incoming_char = SIM900.read ();
if (incoming_char == '0')
{
digitalWrite (led1, LOW);
digitalWrite (led2, LOW);
}
else if (incoming_char == '1')
{
digitalWrite (led1, HIGH);
digitalWrite (led2, HIGH);
}
else if (incoming_char == 'S')
{
digitalRead (led1);
led_status = digitalRead (led1);
led_status = digitalRead (led2);
Serial.print (led_status); // Prints status on serial terminal
sendSMS (led_status);
}
delay (10);
}
// End AT command with a ^ Z, ASCII code 26
delay (5000);
led_status = digitalRead (led1);
led_status = digitalRead (led2);
Serial.print (led_status); // Prints status on serial terminal
sendSMS (led_status);
SIM900.println ((char) 26);
}
}
}