ESP32IOT Projects

ESP32 with GSM Sim900A, GSM WIFI, IOT GSM, ESP32 and GSM

ESP32 with GSM, Project Description:

 

ESP32 with GSM Sim900A Module- I have been using GSM and ESP32 Wifi + Bluetooth Modules for quite a long time in different types of Arduino based and IOT related projects. In my previous tutorial, I used the same GSM SIM900A module with the Nodemcu ESP8266 Wifi Module; I highly recommend you should read this article, because you will learn a lot of new things Nodemcu ESP8266 and GSM SIM900A”. In this tutorial, you will learn how to use EPS32 Wifi + Bluetooth Module with GSM Sim900A module. ESP32 and GSM module together can be used in different advanced level projects.


About the Sponsor “PCBWay”:

ESP32 with GSM

High quality & Only 24 Hours Build time

This ESP32 Power Supply PCB board is sponsored and manufactured by the PCBway Company, which is one of the most experienced PCB and PCB assembly manufacturer. They create high-quality PCBs at reasonable prices, Only 5 dollars for 10 PCBs and 30 dollars in total for 20 PCBs assembly; besides this the new members also get a 5 Dollars bonus. As you can see the quality is really great, the silkscreen is quite clear and the black solder mask looks amazing. I am 100% satisfied with their work.

Download Gerber files:

The main advantage of using the ESP32 with the GSM Module is that, if you have the internet connection and the ESP32 module is connected with the Wifi, then you can monitor the sensor data in real time from anywhere around the world using the Blynk application or any other IOT Platform and you will also be able to receive the alert messages via GSM network.

There are situations when the internet is not available, in a situation like this you won’t be able to monitor the data in real time, but you will get the alert messages via GSM network each time the sensor crosses a threshold value.

For the demonstration purposes I have connected a variable resistor with the ESP32. You can use any type of analog and digital sensors.

In this tutorial, we will cover;

  1. Complete circuit diagram explanation.
  2. Blynk application designing
  3. ESP32 with GSM code explanation and finally
  4. Testing

Without any further delay, let’s get started!!!

The components and tools used in this project can be purchased from Amazon, the components Purchase links are given below:

ESP32 WiFi + Bluetooth Module(Recommended)

Sim900A GSM Module:

DC 5V 2A Adaptor

Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!



GSM Sim900A Module:

ESP32 with GSM

This is the GSM Sim900A mini Module. The first thing that you will notice about this GSM module is that, it has no onboard voltage regulator, so be very careful while applying the voltage; Because voltages greater than 5 volts can easily damage this module. Ideal voltage for this GSM module is 4.7v but you can easily power up this GSM Sim900A module using a 5v adaptor. If you don’t have a 5v adaptor then you can make your power supply using lm317t adjustable variable voltage regulator, I have a very detailed tutorial on lm317t explaining everything.

There are a few things that I really like about the GSM sim900A module which are

  1. This is the cheapest GSM module available on the Market.
  2. Another cool thing is, it can be easily interfaced with 5V supported controller boards like Arduino Uno, Arduino mega, Arduino Nano etc and also with 3.3v controller boards like Nodemcu ESP8266 Wifi Module and ESP32 etc.

GSM Sim900A specifications:

GSM Sim900A Power Supply:

As I said earlier the GSM Sim900A Module has no onboard voltage regulator. Although it has a power supply pin which can be connected with the Arduino’s 5 volts. When no sensors are connected with the Arduino then you can run this GSM module without any problem. But the time you start connecting different sensors with the Arduino, then Arduino cannot provide enough current to the Sim900A Module due to which the Arduino keeps resetting.

So, my recommendation is use an external regulated 5v power supply for the GSM module.

GSM Sim900A pin configuration:

ESP32 with GSM

The white connector labeled with 4.7 – 5V, This is where we connect the external 5volt regulated power supply. It has a total of 9 male headers. The three male headers on the right side are not connected.

  • Pin number 1 is the VCC which can be connected with the In my case as I will power up this module using the external power supply so I will leave this pin unconnected.
  • Pin number 2 is the ground, which will be connected with the Arduino’s ground.
  • Pin number 3 is the 5v TXD,
  • Pin number 4 is the 5v RXD,
  • Pin number 5 is the 3.3v TXD, and
  • Pin number 6 is the 3.3v RXD.

As the Nodemcu ESP8266 Wifi Module is based on the 3.3v controller board so, we will be using the 3.3v TXD and 3.3v RXD pins of the GSM Sim900A module.

If you want to study more about the GSM Sim900A module, then read my article GSM Sim900A with Arduino Complete Guide with GSM based Projects Examples,


Nodemcu with GSM Circuit Diagram:

ESP32 with GSM

Let’s first of all, start with the 5v regulated Power supply which is used to power up the ESP32 module.  This Power Supply is based on the famous LM7805 voltage regulator. J1 is the female power jack and this is where we connect a 12v adaptor, battery or a solar panel. Two 470uf decoupling capacitors are connected at the input and output sides of the voltage regulator. A 330 ohm resistor is connected in series with a 2.5v led. This is a current limiting resistor. The output of the voltage regulator is connected with the Vin pin of the ESP32 module and the ground is connected with the ground.

The GSM Sim900A module 5V RXD pin is connected with the ESP32 TX pin, while the ground pin of the GSM Sim900A module is connected with the ground pin of the ESP32 WiFi + Bluetooth Module. As I explained earlier the recommend voltage for this GSM module is 4.7 to 5 volts.

Note:

While performing the experiments I connected the 3.3V RXD pin of the GSM SIM900A module with the TX pin of the ESP32 but it didn’t work. This was supposed to work, because I used the same 3.3V pins with the Nodemcu ESP8266 Wifi Module and it worked. While in the case of ESP32 module it failed. But when I connected the 5V RXD pin of the GSM module with the TX pin of the ESP32 Module it worked.

The middle leg of the potentiometer or variable resistor is connected with the Analog pin A0 which is the GPIO PIN 36 of the ESP32 Module. While the other two legs are connected with the 3.3v and ground pins of the ESP32 Module.

Finally, I designed a PCB for the ESP32 board, so that I can easily use it as the development board.

ESP32 with GSM

After, checking all the connections, I generated the Gerber files and placed an online order on the PCBWay official website.


About the ESP32 Power Supply PCB Board:

ESP32 with GSM

This is the ESP32 power supply board Manufactured by the PCBWay Company. I have already explained the designing and making of this board. Finally, I connected everything as per the circuit diagram already explained. Now, this board can be easily interfaced with the GSM Sim900A Module and other sensors.

ESP32 with GSM

Finally, I connected the GSM Module and Potentiometer with the ESP32 Module as per the circuit diagram already explained. Let me remind you once again, connect the 5V RXD pin of the GSM SIM900A module with the TX pin of the ESP32. Now, let’s make the Blynk application.

Note: this old version of the Blynk app is no more functional. For the blynk mobile App setup and Blynk.cloud dashboard setup ready my article on the New Blynk V2.0. In this article I have explained how to migrate your projects from Blynk 1.0 to the new Blynk V2.0. You can also watch the video.

Blynk application designing for ESP32 and GSM:

I always first start with the Blynk application designing, this way I know which digital and virtual pins I have to use in the programming. Moreover this also helps me in checking my code, as I keep testing my project. Make sure you have downloaded and installed the Blynk application.

  • First of all, open the blynk
  • Click on the new project and enter the project name as “ESP32 with GSM”. If you want you can select any other name. Later you can also modify the name.
  • Click on the choose device and select ESP32 Dev Board.
  • Make sure the connection type is set to WIFI.
  • Finally, click on the create button, an authentication token will be sent on your email id, which later will be used in the ESP32 programming.
  • Now, click anywhere on the screen and search for the Gauge Widget and add it. Now click on the Gauge, enter the name if you want, then click on the pin and select virtual pin V2. Finally, you can click on the font and select the larger or smaller type, in the end click on the push and select 1 second.
  • Again click on the Screen and this time search for the notification widget and add.

You Blynk application should look something like this,

ESP32 with GSM


Before you start the programming first of all make sure that you have installed the ESP32 board. If you want to know more about the ESP32 module like its pinout and specification, then consider reading my article on ESP32 WROOM 32D Pinout, Features, and specifications.

ESP32 with GSM Code/Programming:

/*
 * ESP32 and GSM SIM900A module together for monitoring an Analog Sensor
 * When the value is exceeded a message is sent along with the Sensor value, 
 * This also sends the notification message to the Blynk application. 
 * The Sensor value can also be monitored in real-time using a Gauge widget. 
 * 
 * Download Libraries:
 * https://www.electroniclinic.com/arduino-libraries-download-and-projects-they-are-used-in-project-codes/
 */
#define BLYNK_PRINT Serial
/* ESP32 & Blynk */
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>
int VResistor = A0; // GPIO36
int vrdata = 0;  
int VRFlag = 0; 
 
String textForSMS;


char auth[] = "1FRxywOEJWaF0-WJWPec4YbwxR83pNAt";
/* WiFi credentials */
char ssid[] = "AndroidAP7DF8";
char pass[] = "jamshaid";

SimpleTimer timer;


void setup() {


 randomSeed(analogRead(0));
 Serial.begin(9600); // original 19200. while enter 9600 for SerialA

delay(5000); // wait for 5 seconds
 Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, Sensors);
  
}

void loop() {

  timer.run(); // Initiates SimpleTimer
  Blynk.run(); 


}


void sendSMS(String message)
{
  Serial.print("AT+CMGF=1\r");                     // AT command to send SMS message
  delay(200);
 Serial.println("AT + CMGS = \"+923339218213\"");  // recipient's mobile number, in international format
 
  delay(200);
  Serial.println(message);                         // message to send
  delay(200);
  Serial.println((char)26);                        // End AT command with a ^Z, ASCII code 26
  delay(200); 
  Serial.println();
  delay(100);                                     // give module time to send SMS
  Blynk.begin(auth, ssid, pass);
}

void Sensors()
{
   vrdata = analogRead(VResistor);
   vrdata = map(vrdata,0,4000,0,1023);
    Blynk.virtualWrite(V2, vrdata);
    
  if ((vrdata > 500) && (VRFlag == 0)) 
{
textForSMS =  "\nValue Exceeded!!!\n"; 
textForSMS = textForSMS + " Sensor Value: "; 
textForSMS = textForSMS + vrdata; 
textForSMS = textForSMS + "\n"; 
Blynk.notify("Exceeded!!!");
 
sendSMS(textForSMS);
//Serial.println(textForSMS);
//Serial.println("message sent."); 
textForSMS = ""; 
delay(200);
VRFlag = 1; 
}

if ((vrdata < 500) && (VRFlag == 1)) 
{
textForSMS =  "\nValue Got Normal\n"; 
textForSMS = textForSMS + " Sensor Value: "; 
textForSMS = textForSMS + vrdata; 
textForSMS = textForSMS + "\n"; 
Blynk.notify("Got normal :)"); 
sendSMS(textForSMS);
//Serial.println(textForSMS);
textForSMS = "";
delay(200);
VRFlag = 0; 
}



}

Before, you start the programming, first of all, make sure that you download all the necessary libraries. A variable resistor is connected with the analog pin A0 which is the GPIO Pin 36 on the ESP32 Board.

Then I defined a variable vrdata of the type integer for storing the data coming from the Variable Resistor or Potentiometer.

int vrdata = 0;

Next, I defined a variable VRFlag of the type integer, this will be used as the flag, to stop the unnecessary repetition of code.

int VRFlag = 0;

then, I defined a variable textForSMS of the type String, this variable will be used to store the message which will be send when the sensor value increases or decreases below a pre-defined value.

String textForSMS;

While making the Blynk application, Authentication code was mailed which is given below. This authentication token will be mailed on your registered email id.



char auth[] = “1FRxywOEJWaF0-WJWPec4YbwxR83pNAt”;

/* WiFi credentials */

char ssid[] = “AndroidAP7DF8”; // WiFi router name

char pass[] = “Eclinic”; // password

SimpleTimer timer;

Inside the setup() function, I activated the serial communication using Serial.begin() and selected 9600 as the baud rate, next, I used a delay of 5 seconds, then the Blynk.begin() which takes three arguments as the input authorization, ssid, and password.

void setup() {

 randomSeed(analogRead(0));

 Serial.begin(9600); // original 19200. while enter 9600 for SerialA

delay(5000); // wait for 5 seconds

 Blynk.begin(auth, ssid, pass);

timer.setInterval(1000L, Sensors);

}

The loop() function has only two functions timer.run() and Blynk.run(). Don’t write any code inside the Loop() function, otherwise your blynk application will keep resetting.

void loop() {

  timer.run(); // Initiates SimpleTimer

  Blynk.run();

}

SendSMS() is a user defined function which takes only one argument as the input which is of the type string. Inside this function we have some AT commands and the recipient cell phone number.

void sendSMS(String message)

{

  Serial.print(“AT+CMGF=1\r”);                     // AT command to send SMS message

  delay(200);

 Serial.println(“AT + CMGS = \”+923339218213\””);  // recipient’s mobile number, in international format

  delay(200);

  Serial.println(message);                         // message to send

  delay(200);

  Serial.println((char)26);                        // End AT command with a ^Z, ASCII code 26

  delay(200);

  Serial.println();

  delay(100);                                     // give module time to send SMS

  Blynk.begin(auth, ssid, pass);

}



Sensors() function is a user-defined function, inside this function we have the code for reading the Variable resistor and some conditions to check if the value is increased or decreased below the pre-defined value.

void Sensors()

{

   vrdata = analogRead(VResistor);

   vrdata = map(vrdata,0,4000,0,1023);

    Blynk.virtualWrite(V2, vrdata);

  if ((vrdata > 500) && (VRFlag == 0))

{

textForSMS =  “\nValue Exceeded!!!\n”;

textForSMS = textForSMS + ” Sensor Value: “;

textForSMS = textForSMS + vrdata;

textForSMS = textForSMS + “\n”;

Blynk.notify(“Exceeded!!!”);

sendSMS(textForSMS);

//Serial.println(textForSMS);

//Serial.println(“message sent.”);

textForSMS = “”;

delay(200);

VRFlag = 1;

}

if ((vrdata < 500) && (VRFlag == 1))

{

textForSMS =  “\nValue Got Normal\n”;

textForSMS = textForSMS + ” Sensor Value: “;

textForSMS = textForSMS + vrdata;

textForSMS = textForSMS + “\n”;

Blynk.notify(“Got normal :)”);

sendSMS(textForSMS);

//Serial.println(textForSMS);

textForSMS = “”;

delay(200);

VRFlag = 0;

}

}

The rest of the instructions are exactly the same as used in my previous IOT Projects and GSM projects.


Finally, I was ready for the testing. I started off by uploading the code. I powered up the GSM Module using a 5V adaptor and powered up the ESP32 board using a 12V adaptor.

ESP32 with GSM

Next, I opened my Blynk application, and started rotating the knob of the Potentiometer. I was able to monitor the value in real time.

ESP32 with GSM

I was able to receive notifications on the Blynk application and was also able to receive text message on my cell phone.

ESP32 with GSM

I tested this project many times, and each time I received the notification messages on the Blynk and on the cell phone through text messages.

ESP32 with GSMWith this my tutorial on the ESP32 with GSM comes to an end. This project can be easily modified, the potentiometer can be replaced with other analog sensors, you can also add digital sensors. I hope you have learned something from this tutorial. Don’t forget to subscribe to my website and YouTube channel “Electronic Clinic”.


Watch Video Tutorial:

 

 

 

 

 

 

 

 

 

 

 

 

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button