Hello everyone,
As I'm using a SIM900 GSM/GPRS board build to use with Arduino UNO with a CH340 USB driver, so the boards are connected through quick install pins (male SIM board/female Arduino UNO).
I saw before people still has issues to get the GSM board working.
Be aware to use a 2G SIM card and not a new 4G/5G one, because it will not work as the SIM900 uses 2G.
This is the code I'm using:
#include <SoftwareSerial.h>
// Wiring
/*
GSM/GPRS shield only works on 2G, only with an old 2G sim card it will work and only as long 2G will be available.
12 Vdc comes from a transformator to power on RY1.
5V comes from a 12V battery and a 5 Vdc converter 3A.
Battery + goes to the COM on RY1 and NC goes to the 12 Vdc + input on the DC converter.
Battery GND goes to the DC converter GND input.
5Vdc from the converter: GND goes to the Arduino UNO and GSM shield power supply GND.
5Vdc + goes to RY2 coil pin.
RY2 coil pin GND supply comes from Arduino pin 13.
Place jumpers on J1 and J2 (sometimes J11 and J12).
Only RY1 and the DC-DC converter will be powered with 12V!
The GSM shield will send a sms on power failure, battery will start up the Arduino and gsm shield.
* GSM shield Arduino RY2:5V RY1 12Vdc Battery + Conv
* 5V from DCconv VINN 5V
* GND GND COIL-
*
* J1 7
* J2 8
* 13 COIL+
* PWRKey COM
* PWRKey NC
* 12 Vdc RY1 coil
* BAT RY1 COM
* Conv RY1 NC
*
*/
int pinStartUp = 13; // Used to start up the GSM shield
int i = 0;
//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(19200);
//Begin serial communication with Arduino and SIM900
SIM900.begin(19200);
//Begin serial communication with Arduino and SIM900
if (i == 0)
{
SIM900power();
i++;
}
delay(500);
Serial.println("Initializing...");
SIM900.println("AT"); //Handshaking with SIM900
updateSerial();
SIM900.println("AT+CMGF=1"); // Configuring TEXT mode
updateSerial();
SIM900.println("AT+CMGS=\"+ZZxxxxxxxxx\"");//change ZZ with country code and xxxxxxxxxxx with phone number used to receive sms
updateSerial();
SIM900.print("Power failure\r"); //text content
updateSerial();
SIM900.write(26);
}
void loop()
{
updateSerial();
}
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
}
}
void SIM900power()
{
// Start up the SIM900 via the PWR key
pinMode(pinStartUp, OUTPUT);
digitalWrite(pinStartUp, HIGH);
Serial.println("Start up SIM900");
digitalWrite(pinStartUp, LOW);
delay(2000);
Serial.println("Done starting up SIM900");
delay(15000);
}
Later as everyone knows 2G won't work in the future, so I bought a SIM7080 telecom hat, so I will have to code again.
When it works, I will share it too.