Project Control Relay 12V with Shield SIM 900A : Arduino – Schematic Diagram
Bonjour Sarah et Rui,
Je suis en train d’essayer le tuto de RNT pour contrôler en France par le réseau GSM / GPRS un relais 12v à partir d’une carte SIM de l’opérateur Orange.
1 / La carte SIM900A fonctionne uniquement en 9600 bauds et non pas en 19200 bauds, pouvez-vous me dire pourquoi?
2 / Les commandes ON et OFF fonctionnent parfaitement, c’est Ok.
3 / La commande STATE répond bien de l’état ON ou OFF, mais uniquement sur le moniteur série, je pensais recevoir l’information aussi sur le smartphone; les codes préfixes pour la France sont au format international: + 336XXXXXXXX. Pouvez vous m’aidez sur ce point ?
4/ L’envoi d’un message SMS depuis le Smartphone vers la carte SIM est bien reçue sur le moniteur série.
5/ L’envoi d’un message SMS depuis le programme RNT téléchargé dans la carte Uno n’est pas reçu sur le Smartphone …
Je pense que le tutoriel n’est pas assez explicite avec les fonctionnalités AT utilisées pour cette applications.
Pouvez vous SVP m’aider à essayer de régler ces difficultés. Par avance merci
Bien Cordialement
Dominique
Bonjour Sarah et Rui,
Je suis en train d’essayer le tuto de RNT pour contrôler en France par le réseau GSM / GPRS un relais 12v à partir d’une carte SIM de l’opérateur Orange.
1 / La carte SIM900A fonctionne uniquement en 9600 bauds et non pas en 19200 bauds, pouvez-vous me dire pourquoi?
2 / Les commandes ON et OFF fonctionnent parfaitement, c’est Ok.
3 / La commande STATE répond bien de l’état ON ou OFF, mais uniquement sur le moniteur série, je pensais recevoir l’information aussi sur le smartphone; les codes préfixes pour la France sont au format international: + 336XXXXXXXX. Pouvez vous m’aidez sur ce point ?
4/ L’envoi d’un message SMS depuis le Smartphone vers la carte SIM est bien reçue sur le moniteur série.
5/ L’envoi d’un message SMS depuis le programme RNT téléchargé dans la carte Uno n’est pas reçu sur le Smartphone …
Je pense que le tutoriel n’est pas assez explicite avec les fonctionnalités AT utilisées pour cette applications.
Pouvez vous SVP m’aider à essayer de régler ces difficultés. Par avance merci
Bien Cordialement
Dominique
Je ne parle pas français donc j’ai utilisé Google Translate
1. À partir de https://www.instructables.com/GSM-SIM900A-With-Arduino/, la carte SIM900A est réglée par défaut sur 9600 bauds. Vous pouvez utiliser les commandes de base
sur https://www.pantechsolutions.net/blog/basic-at-commands-for-sim900a-gsmgprs-module/ pour définir le débit en bauds.
3. Je crois comprendre que vous ne pouvez pas simplement utiliser le symbole ‘+’ dans le code. Le ‘+’ signifie utiliser votre code de numérotation international local. Par exemple, aux États-Unis,
le code est 0011. Je ne sais pas ce que c’est en France ni si vous avez même besoin de l’utiliser pour les appels locaux. Vous pouvez directement connecter la carte et
essayez les commandes AT du site Web ci-dessus pour essayer d’envoyer un message SMS.
Une fois que vous avez envoyé un message de test, il devrait être simple de modifier le code pour utiliser ce que vous avez appris.
Hi Steve,
Firstly many thanks for your answer and sorry for my last French message, but i sure no that if you have very well understood my question.
I’try to use RNT course “Control a 12v Lamp via SMS Arduino’ with Shield SIM 900 A and Arduino Uno.
Please see the describe code https://github.com/RuiSantosdotme/Random-Nerd-Tutorials/raw/master/Projects/Arduino_Control_a_12V_Lamp_via_SMS.ino
When i send message with my smartphone “ON”, “OFF” or “STATE “ message shield SIM 900A, the uno card receive perfectly the order and the 12v relay was actived and also the serial monitor received all datas normaly on the serial monitor.
The only question is why there no return “Lamp State Message “ from the Arduino to the Smartphone, (following the schematic diagram see after) ?Thank you very much for your help
Thank you very much for your help.
Dominique
Sorry but it’s no possible to annexed Shematic Diagram inside last the message.
Regards
Dominique
Sara says “To share an image, I recommend sharing a link to Google Drive, Dropbox, imgur or any other image server that suits you.”.
The code you linked to has no error checking and just writes data to the serial port. You need to know the actual error. Add “AT+CMEE=2\r”
SIM900.print("AT+CMEE=2\r"); // Enable +CME ERROR: <err> result code and use verbose <err> values
at the beginning of the sendSMS function. After sending the SMS see if there are any characters available on the serial port (Hint: Look at the very first if statement in the loop) and print those out (This should be any error message or OK). You may have to add a delay to get the output.
Hello Steve and Sara, and also Rui.
Thank you for your message and recommendations. Regarding your message you don’t answer about line code to do and to send a text message SMS to a Smartphone when “STATE” is enabled.
About the operating diagram, I use exactly the same one that is included inside the RNT tutorial “Control a 12V lamp via SMS with Smartphone” page 3, and the command “STATE” which confirms on the screen of the serial monitor and also on the Smartphone the status of the lamp with an SMS message.
The code used is strictly identical to the RNT code on page 10 of the tutorial. (code here after)
The question is why there is no reception and sending of message on the Smartphone, and confirm me if this is possible.
Please see attached my code used and please tell me if I need to change lines of code to make it work.
Best Regards
Dominique
/*
* Complete Project Details https://randomnerdtutorials.com
*/
// Include Software Serial library to communicate with SIM900
#include <SoftwareSerial.h>
// Configure software serial port
SoftwareSerial SIM900(7, 8);
// Variable to store text message
String textMessage;
// Create a variable to store Lamp state
String lampState = “HIGH”;
// Relay connected to pin 12
const int relay = 12;
void setup() {
// Automatically turn on the shield
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
// Set relay as OUTPUT
pinMode(relay, OUTPUT);
// By default the relay is off
digitalWrite(relay, HIGH);
// Initializing serial commmunication
Serial.begin(9600);
SIM900.begin(9600);
// Give time to your GSM shield log on to network
delay(20000);
Serial.print(“SIM900 ready…”);
// AT command to set SIM900 to SMS mode
SIM900.print(“AT+CMGF=1\r”);
delay(100);
// Set module to send SMS data to serial out upon receipt
SIM900.print(“AT+CNMI=2,2,0,0,0\r”);
delay(100);
}
void loop(){
if(SIM900.available()>0){
textMessage = SIM900.readString();
Serial.print(textMessage);
delay(10);
}
if(textMessage.indexOf(“ON”)>=0){
// Turn on relay and save current state
digitalWrite(relay, LOW);
lampState = “on”;
Serial.println(“Relay set to ON”);
textMessage = “”;
}
if(textMessage.indexOf(“OFF”)>=0){
// Turn off relay and save current state
digitalWrite(relay, HIGH);
lampState = “off”;
Serial.println(“Relay set to OFF”);
textMessage = “”;
}
if(textMessage.indexOf(“STATE”)>=0){
String message = “Lamp is ” + lampState;
sendSMS(message);
Serial.println(“Lamp state resquest”);
textMessage = “”;
}
}
// Function that sends SMS
void sendSMS(String message){ // AT command to set SIM900 to SMS mode
SIM900.print(“AT+CMGF=1\r”);
delay(100);
// REPLACE THE X’s WITH THE RECIPIENT’S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
// Send the SMS
SIM900.println(“AT + CMGS =\”+33XXXXXXXXX\””);
delay(100);
//Send theSMS
SIM900.println(message);
// End AT command with a ^Z, ASCII code 26
SIM900.println((char)26);
delay(100);
SIM900.println();
// Give module time to send SMS
delay(5000);
}
Hi.
Have you tried an example that simply sends an SMS to your smartphone?
Check this tutorial: https://randomnerdtutorials.com/sim900-gsm-gprs-shield-arduino/
Go to the section “sending an SMS” and try that sketch: https://raw.githubusercontent.com/RuiSantosdotme/Random-Nerd-Tutorials/master/Projects/GSM/sendSMS.ino
If that doesn’t work, it means that your shield is not sending SMS to your smartphone. So, we need to start working from that basic example.
Regards,
Sara
My guess is that it’s probably the string used for the mobile number. Check with the manual for your SIM900 board and your service provider on what the string should be.
As for my troubleshooting message, locate the “sendSMS” function and add the debug code at the very beginning. Then add code to check the response (Look at the hint I provided) after the line that sends the SMS (Note that the “SMS” variable is just a serial port so “sending the SMS” is just a matter of sending text via the serial port). There is already code to receive text via the serial port which you report as working.
The whole idea behind this forum and the ebooks is to teach you how to program boards yourself. In my case I will point you in the right direction so you will learn rather than writing the code for you.
Hi Sara and Steve, and also Rui,
Thank you for your messages and your responsiveness in technical support for the mastery of the SIM900A Shield.
To introduce myself, I am a retired engineer after more than 40 years of career in the sector of large hydroelectric projects and the transport of strong currents around the world, including in Brazil, China and also micro-power plants in Portugal…
He is 3 years old and to take care of the pleasure of retirement, I became interested in the “IOT” and I had the pleasure of discovering on @ the company RNT and the remarkable work of Rui Santos with the micro controllers EP8266 and ESP32, which I put into practice successfully for small applications in Station or Access Point mode with the books purchased from RNT.
Today I am preparing a project to remotely control by the GSM network some relays from an Arduino Uno card and a SIM900A card to send ON or OFF commands, check the STATES and receive error alarm messages by SMS on a Smartphone
While looking at the various RNT tutorials about SIM900A shields, I studied and tried the code proposed by RNT for the command and control of a 12Vrelay. The code using the AT s function worked perfectly by sending the ON, OFF and STATE commands from the Smartphone.
I do not understand how the triggering of the function sending an SMS that is integrated into this code works?
My sketch, is identical to the RNT code, I adjusted the communication to 9600 bds and connected pins 6 and 7 of the Uno card to the SIM900A card by positioning the jumpers.
I did not pair the cards together and preferred to leave them flat, because I think it is easier to replace the SIM card of the GSM/GPRS network access provider if necessary.
there is no triggering of message and receipt of SMS on the Smartphone.
I found on @ and tested another code similar to the SMS code offered by Sara and this one work perfectly, but it launches the SMS instantly when the SIM 900A goes live. I would like the triggering of the SMS to be done only if there is an identified alarm or a defect.
I will communicate to you tomorrow this code, which you must have met on other forums…. I’m going to keep experimenting… but I don’t know how I can diagnose the points or do a Self-test with the serial monitor.
Thank you for your help and to answer Steve, for my part I am not looking standard project and not to make a copy -paste, but to assemble functional blocks that have already been tested and can be integrated into my sketch projects. I don’t have time to do too complex studies on all the programming languages available, I think I’m starting to be too old now.
I have not found any books or books that explain the chronological organization of the structures of implementation of the different functions.
Do you have any articles in RNT’s course books?
Best regards to RNT team.
Dominique
Hi Sara,
Please see attached one other code to send SMS by SIM900A to smarphone.
I found on @ and tested another code similar to the SMS code offered by you on RNT tuttorial but this one work perfectly, but it launches the SMS instantly when the SIM 900A goes live.
Best regards
Dominique
Code : send SMS by SIM900A to Smarphone
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
//Begin serial communication with Arduino and SIM900
mySerial.begin(9600);
Serial.println(“Initializing…”);
delay(1000);
mySerial.println(“AT”); //Handshaking with SIM900
updateSerial();
mySerial.println(“AT+CMGF=1”); // Configuring TEXT mode
updateSerial();
mySerial.println(“AT+CNMI=1,2,0,0,0”); // Decides how newly arrived SMS messages should be handled
updateSerial();
}
void loop()
{
updateSerial();
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(mySerial.available())
{
Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
}
}
Hi SARA,
I’m very sorry for this mistake, the code send before is not applicable for Send an SMS by the SIM900A
According my last message, please see after the new code.
What do you think ?
#include <SoftwareSerial.h> // Create software serial object to communicate with SIM900 SoftwareSerial mySerial (7, 8); // SIM900 Tx & Rx is connected to Arduino # 7 & # 8 void setup (){ // Begin serial communication with Arduino and Arduino IDE (Serial Monitor) Serial.begin (9600); // Begin serial communication with Arduino and SIM900 mySerial.begin (9600); Serial.println ("Initializing…"); delay (1000); mySerial.println ("AT"); // Handshaking with SIM900 updateSerial (); mySerial.println ("AT + CMGF = 1"); // Configuring TEXT mode updateSerial (); mySerial.println ("AT + CMGS = \" + ZZxxxxxxxxxx \ ""); // change ZZ with country code and xxxxxxxxxxx with phone number to sms updateSerial (); mySerial.print ("SMS Message"); // text content updateSerial (); mySerial.write (26); } void loop (){ } void updateSerial (){ delay (500); while (Serial.available ()) { mySerial.write (Serial.read ()); // Forward what Serial received to Software Serial Port } while (mySerial.available ()){ Serial.write (mySerial.read ()); // Forward what Software Serial received to Serial Port } }
Best regards
Dominique
Hi.
It seems to me that the code is the same as ours, but with different names for variables. And it uses the println() function instead of print() with the /r carriage return.
However, if that code works for you, you just need to adjust the sendSMS() function in your first sketch to be similar to that one as shown below.
// Function that sends SMS
void sendSMS(String message){ // AT command to set SIM900 to SMS mode
SIM900.println(“AT + CMGF = 1”);
delay(100);
// REPLACE THE X’s WITH THE RECIPIENT’S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
// Send the SMS
SIM900.println(“AT + CMGS = \” + 33XXXXXXXXX \ ””);
delay(100);
//Send theSMS
SIM900.print(message);
// End AT command with a ^Z, ASCII code 26
SIM900.write(26);
delay(100);
SIM900.println();
// Give module time to send SMS
delay(5000);
}
I hope this helps.
Regards,
Sara
Hi Sara,
Many thanks for your best effort, but unfortunately it is not possible to verify and check your code and also upload or it may be it is incomplete.
I would like prefer to use the RNT tutorial, because i have confidence in your seriousness and the high quality of your technical documentation.
I send to you see after lhe code that i am going to use and that i have tested. It work perfectly and i don’understand why there are few users of the shield SIM 900. The document published by Rui are perfectly complete..
Sara, can you explain to me, how it is possible to send an SMS after the presence of a fault or sensor alarm ? i need to add this fonction inside my project.
I think there’s no such thing in your RNT books ….
Thanks you in advance
Best regards
Dominique
Code : Sketch Send SMS with SIM900 to Smartphone
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM900
SoftwareSerial SIM900(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
SIM900.begin(9600);
Serial.println(“Initializing…”);
delay(1000);
SIM900.println(“AT”); //Handshaking with SIM900
updateSerial();
SIM900.println(“AT+CMGF=1”); // Configuring TEXT mode
updateSerial();
SIM900.println(“AT+CMGS=\”+336XXXXXXXX\””);//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
SIM900.print(“Your Welcome”); //text content
updateSerial();
SIM900.write(26);
}
void loop()
{
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
SIM900.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(SIM900.available())
{
Serial.write(SIM900.read());//Forward what Software Serial received to Serial Port
}
}
The reason there are few users of SIM900 series boards is that they use 2G. Whilst some countries (Obviously yours) still have 2G networks available, most other countries have moved on to 3G (Also being phased out) and then to LTE CAT-M1 NB-IOT.
You would need to check with your local carriers (And, possibly, Government) about their plans for 2G.
Most other people are using the SIM7000 series boards.
Hi.
The code that I send is just a function. You need to integrate it into your code to make it work. You need to copy it to your code before the setup(). And then, you need to call the function when you want to send an SMS. As an argument to the function, you should pass the message you want to send. For example:
sendSMS("Hello");
If the code you have is working fine, you should use that code.
The easiest way to do what you want is to create a function to send an SMS based on the code that you have or my code if it is working for you. Then, add an if statement to your code that checks if the alarm was triggered. If it was, send an SMS.
Regards,
Sara
Hi Sara,
I’m very sorry for my to late answer today, but no to mutch time for Arduino project.and my project is not solved.
According your recommandation, I tried to test my SIM900A with Uno Card but unfortunaly no SMS was send to my Smarphone.
For this project, I want only use your course for Home automation by GSM SIM 900 A and Arduino Uno.
The sketch RNT to control light with Relay is only operate for function ON, OFF and State.
But there are no return to confirm the position ON or OFF whit the fuction State by SMS on the Smartphone.
How to check it step by step, because i turn around and no result today.
What do you want to send for analize this probleme together or your check list to solve this very soon.
Many thanks and best regards.
Dominique
Hi.
I’m not sure that I understood your question.
Isn’t the STATE command working?
Regards,
Sara
Hi again.
As I mentioned in one of my previous answers, did you test the sendSMS() function?
Regards,
Sara
Sara,
Sorry, but i’m little lost with my old age ….and not easy to get a good level alone ….
i prefer used your RNT Course and i think is better for solve trouble …
1/ I use the RNT raw code inside Github that you suggest to check if sendSMS works ….https://raw.githubusercontent.com/RuiSantosdotme/Random-Nerd-Tutorials/master/Projects/GSM/sendSMS.ino
2/ After upload this code and tried that dosen’t work and i d’nt know what i do
The only trouble is to send an SMS
Questions
What the best way to check, if sofware. problem or maybe hardware
How to check ( AT+CMGS =\”+XXXXXX…\””) or SIM900 card if any ….
Regards
Dominique
Hi.
I don’t know why it doesn’t work.
Let’s try to understand what is going on.
Can you test the code suggested in this discussion: https://forum.arduino.cc/t/sim900a-not-sending-sms/896352/19
I will help understand the issue.
Tell me what you get on the Serial Monitor.
Regards,
Sara
Sara many thanks,
See attached the Serial Monitor screen ….
How to send file copy or picture … ?
regards
Dominique
Hi.
You can copy the content from the Serial Monitor and paste it here. No need for a printscreen in this case.
Regards,
Sara
Sorry SARA,
I say,
But i dn’t understand why for paste the sketch is’t ok, and is impossible to do the same with the datas on serial monitor.
I try again with another PC .
Regards
Hi again.
To share a picture, upload it to your google drive account, or dropbox or imgur, and then, share the link.
Regards,
Sara
Hi.
I received your email with the results.
Clearly, something is wrong with your setup. The problem is not the code.
There should be a problem with your SIM card or with your network provider.
What is the SIM card that you’re using?
The SIM900 only supports 2G networks. Does your location support 2G?
Additionally, does your SIM card have a plan? I mean, it needs to be charged or prepaid to be able to send SMS.
If you put that card on a smartphone, are you able to send messages?
Regards,
Sara
Hi Sara,
Thanks for your help. My target is to get result asap for this project.
First i have choice a SIM card prepaid for SMS from Orange. I buy yesterday a new charge with this operator for only 2 months of validity for a price 25€.
Secondly I have use the RNT sketch to operate a relay 12v with my smartphone, ON, OFF and STATE. The result was OK when I ask ON or OFF and the relay turn ON or OFF.
For the STATE opération the serial monitor write the state position of the relay, but there no send message to confirm relay position on the smartphone. That is the problem.
Thirtly I tried another sketch from tutorial of Las Minut Engineer about SIM900A card and AT Command to check only send SMS function with my platform project.
The smartphone and the serial monitor receive together normally all SMS Message.
I dont check with another smartphone and these same SIM card inside, but I’m sure that send SMS is operate.
Best regards
Dominique
Hi.
So, you can combine their sketch with yours to send SMS.
Do you need help with that?
Show the sketch that sends SMS that works for you.
Regards,
Sara
Hi Sara,
Yes it’s my idea, but need you to help me, to ad function for a relay control.
I was send to you my code few months ago. It is in our blog
This the codeCode : Sketch Send SMS with SIM900 to Smartphone
#include <SoftwareSerial.h>
//Create software serial object to communicate with SIM900
SoftwareSerial SIM900(7, 8); //SIM900 Tx & Rx is connected to Arduino #7 & #8
void setup()
{
//Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
Serial.begin(9600);
SIM900.begin(9600);
Serial.println(“Initializing…”);
delay(1000);
SIM900.println(“AT”); //Handshaking with SIM900
updateSerial();
SIM900.println(“AT+CMGF=1”); // Configuring TEXT mode
updateSerial();
SIM900.println(“AT+CMGS=\”+336XXXXXXXX\””);//change ZZ with country code and xxxxxxxxxxx with phone number to sms
updateSerial();
SIM900.print(“Your Welcome”); //text content
updateSerial();
SIM900.write(26);
}
void loop()
{
}
void updateSerial()
{
delay(500);
while (Serial.available())
{
SIM900.write(Serial.read());//Forward what Serial received to Software Serial Port
}
while(SIM900.available())
{
Serial.write(SIM900.read());//Forward what Software Serial received to Serial Port
}
}
Good receipt
Regards
Dominique
Hi Sara,
My idea is to replace tnside the code see after, the function to operate the Sending SMS , (was unfortunatly no effect with STATE order), by the code that send to you few minutes ago. But I think is not to easy for me, with my C++ acknowledge.
Thanks for your help?
Best regards
Dominique
// 1 – Code RNT to control Relay 12V with Smartphone
#include <SoftwareSerial.h> // Library for using software serial communication
SoftwareSerial SIM900(7, 8); // Pins 7, 8 are used as used as software serial pins
String incomingData; // for storing incoming serial data
String message = “”; // A String for storing the message
int relay_pin = 2; // Initialized a pin for relay module
void setup()
{
Serial.begin(115200); // baudrate for serial monitor
SIM900.begin(19200); // baudrate for GSM shield
pinMode(relay_pin, OUTPUT); // Setting erlay pin as output pin
digitalWrite(relay_pin, LOW); // Making relay pin initailly low
// set SMS mode to text mode
SIM900.print(“AT+CMGF=1\r”);
delay(100);
// set gsm module to tp show the output on serial out
SIM900.print(“AT+CNMI=2,2,0,0,0\r”);
delay(100);
}
void loop()
{
//Function for receiving sms
receive_message();
// if received command is to turn on relay
if(incomingData.indexOf(“A.light_On”)>=0)
{
digitalWrite(relay_pin, HIGH);
message = “Light is ON”;
// Send a sms back to confirm that the relay is turned on
send_message(message);
}
// if received command is to turn off relay
if(incomingData.indexOf(“A.light_Off”)>=0)
{
digitalWrite(relay_pin, LOW);
message = “Light is OFF”;
// Send a sms back to confirm that the relay is turned off
send_message(message);
}
}
void receive_message()
{
if (SIM900.available() > 0)
{
incomingData = SIM900.readString(); // Get the data from the serial port.
Serial.print(incomingData);
delay(10);
}
}
void send_message(String message)
{
SIM900.println(“AT+CMGF=1”); //Set the GSM Module in Text Mode
delay(100);
SIM900.println(“AT+CMGS=\”+37165738579\””); // Replace it with your mobile number
delay(100);
SIM900.println(message); // The SMS text you want to send
delay(100);
SIM900.println((char)26); // ASCII code of CTRL+Z
delay(100);
SIM900.println();
delay(1000);
}
Sara again,
I’m very very sorry for my mistake for the wrong file send to you.
This see after is the right “Master code ” that I use and to be modified only for the part function SendSMS and to be all right for receipt “STATE ” message of relay, and to be replace by all or portion code to be send before.
I think you can understand that i want to do it.
Regards
Dominique
/*
* Complete Project Details https://randomnerdtutorials.com
*/
// Include Software Serial library to communicate with SIM900
#include <SoftwareSerial.h>
// Configure software serial port
SoftwareSerial SIM900(7, 8);
// Variable to store text message
String textMessage;
// Create a variable to store Lamp state
String lampState = “HIGH”;
// Relay connected to pin 12
const int relay = 12;
void setup() {
// Automatically turn on the shield
digitalWrite(9, HIGH);
delay(1000);
digitalWrite(9, LOW);
delay(5000);
// Set relay as OUTPUT
pinMode(relay, OUTPUT);
// By default the relay is off
digitalWrite(relay, HIGH);
// Initializing serial commmunication
Serial.begin(9600);
SIM900.begin(9600);
// Give time to your GSM shield log on to network
delay(20000);
Serial.print(“SIM900 ready…”);
// AT command to set SIM900 to SMS mode
SIM900.print(“AT+CMGF=1\r”);
delay(100);
// Set module to send SMS data to serial out upon receipt
SIM900.print(“AT+CNMI=2,2,0,0,0\r”);
delay(100);
}
void loop(){
if(SIM900.available()>0){
textMessage = SIM900.readString();
Serial.print(textMessage);
delay(10);
}
if(textMessage.indexOf(“ON”)>=0){
// Turn on relay and save current state
digitalWrite(relay, LOW);
lampState = “on”;
Serial.println(“Relay set to ON”);
textMessage = “”;
}
if(textMessage.indexOf(“OFF”)>=0){
// Turn off relay and save current state
digitalWrite(relay, HIGH);
lampState = “off”;
Serial.println(“Relay set to OFF”);
textMessage = “”;
}
if(textMessage.indexOf(“STATE”)>=0){
String message = “Lamp is ” + lampState;
sendSMS(message);
Serial.println(“Lamp state resquest”);
textMessage = “”;
}
}
// Function that sends SMS
void sendSMS(String message){ // AT command to set SIM900 to SMS mode
SIM900.print(“AT+CMGF=1\r”);
delay(100);
// REPLACE THE X’s WITH THE RECIPIENT’S MOBILE NUMBER
// USE INTERNATIONAL FORMAT CODE FOR MOBILE NUMBERS
// Send the SMS
SIM900.println(“AT + CMGS = \”+33616234297\””);
delay(100);
//Send theSMS
SIM900.println(message);
// End AT command with a ^Z, ASCII code 26
SIM900.println((char)26);
delay(100);
SIM900.println();
// Give module time to send SMS
delay(5000);
Hi.
This is the code modified with the function you said was working: https://gist.github.com/sarasantos/23c0a883d0302b5f344e72f7406504b6
Tell me if it works.
Regards,
Sara
Hi Sara,
Please see after the screen view of the test with your last code sended on 31/10/2021 (send by email today)
All functions ON, Off and STATE work normally and also the relay.
But unfortunately there are no messages received on the smartphone to confirm the STATE position of the relay.
I have also tested the sim card with the SIM900 for sending SMS, and the connection was done and the smarphong ring immediately.
This is very strange, are you very sure of the code and do you have the possibility to test it on your workshop platform.?
Maybe Rui has an idea to solve this problem ?
I was very surprised that there was not much forum discussion or feedback about this subject.Many thanks for your help.
Best regards,
Dominique
Hi.
That is so weird.
Especially because you said it works if the code only has the function to send SMS?
I have no idea what might be wrong.
Have you tried to post your issue in the Arduino forum? Maybe you’ll find more people that can help you there.
Regards,
Sara
I made a little modification to the code.
Can you try it again?
https://gist.github.com/sarasantos/23c0a883d0302b5f344e72f7406504b6
Regards,
Sara