Arduino SIM800L Blynk, Arduino publish data to Blynk, Arduino Blynk
Table of Contents
Arduino SIM800L Blynk:
Arduino SIM800L Blynk, Arduino publish data to Blynk, Arduino Blynk- In today’s article, we are going to use the versatile SIM800L GSM/GPRS module with the Arduino. Our project centers around controlling not one, but four relays connected to bulbs, and closely monitoring temperature changes using the DS18b20, a robust one-wire waterproof digital temperature sensor.
But that’s not all! We’re taking control and monitoring to the next level with the Blynk Application.
This powerful application will be our command center, allowing us to keep an eye on the temperature readings and manage the lighting setup right from our smartphones.
Amazon Links:
Arduino Nano USB-C Type (Recommended)
*Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
Next, what I am going to explain, you need to listen carefully and then you have to decide whether you want to use the SIM800L GSM/GPRS module or not.
About SIM800L:
Network Compatibility:
The SIM800L operates on quad-band GSM/GPRS frequencies (850/900/1800/1900 MHz), making it compatible with GSM network standards worldwide.
Features:
It supports voice calls, SMS messages, and data transmission via GPRS. Its small size and low power consumption make it suitable for mobile applications and IoT projects.
Applications:
Common uses include vehicle tracking, remote control systems, small-scale IoT applications, and any scenario where a basic cellular connection is needed.
Usage in Different Countries:
Developing Countries:
In developing countries like Pakistan and India, where 2G networks are still widely used, the SIM800L is highly relevant. These regions often maintain robust 2G infrastructure due to the widespread use of basic mobile phones and the slower adoption of more advanced network technologies.
In the place where I live, modern cellular networks like 3G and 4G are operational and accessible. However, despite the availability of these newer, faster networks, the infrastructure for 2G services is still supported. This means that the spectrum (the range of electromagnetic radio frequencies used for communication) is still allocated for 2G services, allowing devices and technologies that rely on 2G networks, such as the SIM800L GSM/GPRS module, to function. This scenario is common in many regions where there’s a gradual transition to advanced network technologies while maintaining support for older ones.
Developed Countries:
In contrast, developed countries like the USA, Canada, and many in Europe, are phasing out 2G networks in favor of more advanced 3G, 4G, and 5G networks. As 2G networks are being decommissioned in many developed countries, devices that rely solely on these networks, like the SIM800L, lose their functionality. In some cases, regulatory bodies in certain countries might decide to repurpose the spectrum used for 2G services for more advanced network technologies, leading to a phase-out of 2G.
I’m not sure about your location and whether 2G services are still operational there. If your area does support 2G network infrastructure, then you can effectively use a 2G SIM card in your SIM800L module. This will allow you to connect to the network and create amazing IoT projects.
Anyway, in my experience, when I tried using 3G and 4G SIM cards with the SIM800L module, it wouldn’t connect to the network. However, when I switched to an older 2G Ufone SIM card, the connection was successful almost immediately. This shows that the SIM800L module works best with 2G networks. So, if you’re planning to use this module, I recommend using a 2G SIM card. While 2G might seem outdated, many countries still offer these SIM cards, so you should be able to find one for your project.
As you can see in my setup, once the SIM800L module is connected to the internet, it’s fully functional. I can monitor temperature changes – watch as I apply some heat and notice the temperature rise.
Now, let’s move on to controlling these four bulbs.
Remember, safety first: When the 110/220Vac supply is connected, never touch the relay contacts as it can be extremely dangerous. It is important to note that when working with mains voltage, proper safety precautions should always be taken, and it is advisable to consult relevant electrical codes and standards.
As demonstrated, I can control all four bulbs with ease.
If the SIM800L module isn’t suitable for your area due to network compatibility, don’t worry. In my next video, I’ll introduce the SIM7600G LTE module, which is compatible with 2G, 3G, and 4G networks.
This module offers greater flexibility for different network environments. So, consider subscribing, if you don’t want to miss any of my upcoming tutorials using this module. Anyway, let’s take a look at the wiring.
SIM800L Module interfacing with Arduino:
As usual I am using my designed Arduino Nano Development board but you can also use Arduino Uno. The reason I am using this development board is because on this board I have a 5V and 3A power supply which is more than enough to power up the Arduino, GSM SIM800L module, and all the other electronics. I have talked about the SIM800L module technical specifications, power supply requirements, and related issues in detail in my getting started article on the SIM800L module.
Connect the VCC and GND pins of the SIM800L module to the 5V and 3A power supply. Connect the TXD pin to the Arduino D9 and connect the RXD pin to the Arduino D10.
The 5V SPDT type relays and are connected to the Arduino pins D4, D5, D6, and D7.
Connect the VCC and GND wires of the DS18B20 temperature sensor to the Arduino 3.3V and GND. Connect the Data pin to the Arduino Pin D3. And don’t forget to add a 10K resistor between the VCC and Data wire.
You can see the Vin and GND wires in the circuit diagram. Simply, connect these wires to a 5V and 3A power supply.
You can follow this circuit diagram; if you want to make your own 5V and 3A power supply. Now, let’s start with the Blynk Web Dashboard setup.
Blynk Web Dashboard Setup:
While you are logged-in into your Blynk account. Click on the New Template.
Write the Template Name, select the Hardware, and select the connection type as GSM. Finally, click on the Done button.
Then click on the Datastreams and click on the new Datastream and select the virtual pin.
Write name of the virtual Pin “Temperature”, select the PIN V0, select the DATA TYPE, select the UNITS, and define the MIN and MAX values. Finally, click on the Create button.
Now again click on the new Datastream and select the virtual pin. Write name of the virtual Pin “Relay1”, Select the PIN “V1”, Select the DATA TYPE “Integer”, set the UNITS to “None”, and select the MIN and MAX values as 0 and 1.
Following the same exact steps, create three more virtual pins for the remaining 3 relays and assign Virtual Pins V2, V3, and V4; as you can see in the image below.
Then click on the web Dashboard.
Double click on the Gauge or drag and drop the gauge from the Widget Box. Then click on the settings “Gear Icon”.
Select the Datastream Temperature(V0).
Next, add 4 switches the way we added the Gauge widget and assign the corresponding Datastreams; as you can see in the image below.
All the 5 widgets have been added to the Web Dashboard. We will be using the Gauge for the temperature monitoring and all the other switches for controlling the output loads. Anyway, make sure you click on the save button.
Click on the Devices on the left side, under the Developer Zone.
Click the + New Device and then click on the “From template”.
Select the DS18B20 template and click on the create button.
Then copy the credentials.
When the dashboard is ready, simply copy these credentials, open the program and paste the credentials as you can see in the prom given below.
Arduino SIM800L Blynk, Programming:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
//----------------------------------------------------------------------- /* Comment this out to disable prints and save space */ #define BLYNK_PRINT Serial //----------------------------------------------------------------------- #define BLYNK_TEMPLATE_ID "TMPL6gW5tkaBt" #define BLYNK_TEMPLATE_NAME "DS18B20 sensor with Arduino using SIM800" #define BLYNK_AUTH_TOKEN "_do7cL1tmYPbkfunT3rZYCv790AIUElX" //----------------------------------------------------------------------- // Select your modem: #define TINY_GSM_MODEM_SIM800 //#define TINY_GSM_MODEM_SIM900 //#define TINY_GSM_MODEM_M590 //#define TINY_GSM_MODEM_A6 //#define TINY_GSM_MODEM_A7 //#define TINY_GSM_MODEM_BG96 //#define TINY_GSM_MODEM_XBEE //----------------------------------------------------------------------- // Default heartbeat interval for GSM is 60 // If you want override this value, uncomment and set this option: //#define BLYNK_HEARTBEAT 30 //----------------------------------------------------------------------- #include <TinyGsmClient.h> #include <BlynkSimpleTinyGSM.h> //----------------------------------------------------------------------- // You should get Auth Token in the Blynk App. // Go to the Project Settings (nut icon). char auth[] = BLYNK_AUTH_TOKEN; //----------------------------------------------------------------------- // Your GPRS credentials // Leave empty, if missing user or pass char apn[] = "ufone.pinternet"; char user[] = ""; char pass[] = ""; //----------------------------------------------------------------------- // or Software Serial on Uno, Nano #include <SoftwareSerial.h> SoftwareSerial SerialAT(9, 10); // TXpin=9 RXpin=10 TinyGsm modem(SerialAT); //----------------------------------------------------------------------- #include <OneWire.h> #include <DallasTemperature.h> // Setup a oneWire instance to communicate with any OneWire devices #define ONE_WIRE_BUS 3 OneWire oneWire(ONE_WIRE_BUS); // Pass our oneWire reference to Dallas Temperature sensor DallasTemperature sensors(&oneWire); float temp; int Relay1 = 4; int Relay2 = 5; int Relay3 = 6; int Relay4 = 7; //----------------------------------------------------------------------- BlynkTimer timer; #define INTERVAL 1000L //----------------------------------------------------------------------- void SendData() { // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus sensors.requestTemperatures(); temp=sensors.getTempCByIndex(0); Blynk.virtualWrite(V0,temp); } /************************************************************************************ * setup() function **********************************************************************************/ void setup() { //----------------------------------------------------------- // Debug console Serial.begin(115200); pinMode(Relay1,OUTPUT); pinMode(Relay2,OUTPUT); pinMode(Relay3,OUTPUT); pinMode(Relay4,OUTPUT); delay(10); //----------------------------------------------------------- // Set GSM module baud rate SerialAT.begin(9600); //SerialAT.begin(9600,SWSERIAL_8N1,D3,D4); delay(3000); //----------------------------------------------------------- sensors.begin(); //----------------------------------------------------------- // Restart takes quite some time // To skip it, call init() instead of restart() Serial.println("Initializing modem..."); modem.restart(); //----------------------------------------------------------- Blynk.begin(auth, modem, apn, user, pass); //----------------------------------------------------------- // Setup a function to be called every second timer.setInterval(INTERVAL, SendData); //----------------------------------------------------------- } /************************************************************************************ * loop() function **********************************************************************************/ void loop() { Blynk.run(); timer.run(); } BLYNK_WRITE(V1) // From Blynk to the ESP32, to control a Relay { int pinValue1 = param.asInt(); digitalWrite(Relay1 , pinValue1); } BLYNK_WRITE(V2) // From Blynk to the ESP32, to control a Relay { int pinValue2 = param.asInt(); digitalWrite(Relay2 , pinValue2); } BLYNK_WRITE(V3) // From Blynk to the ESP32, to control a Relay { int pinValue3 = param.asInt(); digitalWrite(Relay3 , pinValue3); } BLYNK_WRITE(V4) // From Blynk to the ESP32, to control a Relay { int pinValue4 = param.asInt(); digitalWrite(Relay4 , pinValue4); } |
Don’t forget to change the GPRS Credentials.
Before, you upload the program, make sure you have installed the required libraries. Simply copy the library name, then go to the Sketch menu, then to Include Library, and click on the Manage Libraries. Paste the library name in the search box, as you can see I have already installed this library.
Next, you will also need to install the entire Blynk library package, for this simply type Blynk in the search box.
You can see I have also installed this library. It works with over 400 boards.
Finally, you can upload the program, in my case I have already uploaded this program. Anyway, go back to the Blynk web dashboard and check if you can monitor the sensor and control the relays.
If it’s working then congrats you have done it. Next, you can start with the Blynk IoT Application setup on your Smartphone.
Blynk IoT App setup on Smartphone:
Open the Blynk IoT App and click on the DS18B20 sensor with Arduino using SIM800 template.
Click on the settings icon to enter in the developer mode. Then rest of the process is pretty straightforward. Simply, add a Gauge and 4 switches, and assign the corresponding Datastreams. Your Application should look something like this.
If you face any issues then watch the video tutorial on my YouTube channel “Electronic Clinic”.
So, that’s all for now.
Hi my two points:
1. I’m afraid that there is a major flaw in the circuit, SIM800 module can accept max 4.2V, internal voltage monitor will trigger over-voltage protection most probably above that level or close to 4.4V at 5V module will not survive very long.
2. In the transfer mode SIM800 will use at max 2A so 3A power supply is not really needed, a big capacitor at around 2200uf between the VIN and GND will help to stabilise the power supply.
Other than this it’s a nice concept 🙂