Blynk 2.0 and ESP8266 with DS18B20 &MQ9 LPG Gas Sensor
Table of Contents
Blynk 2.0 and ESP8266:
Blynk 2.0 and ESP8266 with DS18B20 & MQ9 LPG Gas Sensor-In this tutorial, you will learn how to use Blynk 2.0 with Nodemcu ESP8266 WiFi Module for monitoring Temperature and LPG Gas using DS18B20 One-wire waterproof digital temperature sensor and MQ9 LPG Gas Sensor.
I have already published a getting started tutorial on Blynk 2.0 and ESP32 WiFi + Bluetooth Module and in that article, I have explained why you guys need to migrate from Blynk 1.0 to Blynk 2.0. That tutorial is for the absolute beginners having no prior knowledge of Blynk Cloud Dashboard and Blynk Mobile App. So, if you are just getting started with the New Blynk V2.0; then I highly recommend you should read my previous article on the Blynk 2.0 and ESP32.
Anyway, Previously I used ESP32 with Blynk V2.0 for controlling an LED and for monitoring a Potentiometer. As this was a getting started tutorial; so my main focus was on how to setup the Blynk Cloud Dashboard and how to setup the Blynk Mobile App. So, I just used an LED as a device and a potentiometer as the Analog Sensor. Trust me as a beginner an LED and a Potentiometer are more than enough. Once you learn how to establish a two-way communication between the Blynk 2.0 and the WiFi controller board; then you can control any output device and of course you will be able to monitor any type of Analog or digital sensor.
In today’s tutorial, I am going to use NodeMCU ESP8266 WiFi module with Blynk 2.0 and since I have previously explained the most basic things so this time I decided to use some real sensors the DS18b20 and MQ9 Gas sensor.
So, before I am going to explain how to setup the Blynk Cloud Dashboard and Blynk Mobile App for the ESP8266; first, I am going to share with you the final test results and afterward I will explain everything else.
JLCPCB Sponsor:
Feel free to visit their website https://jlcpcb.com/SKL to not only find out what awesome PCB and Assembly services they offer, but also to easily upload your Gerber files and thus order affordable and high-quality PCBs quickly. You will only need to pay 2 dollars for 1- 4 layers PCBs, and 0 dollars for your PCB assembly. Besides this JLCPCB also offers industrial 3D printing services starting at only 1 dollar.
I have connected the DS18b20 Temperature Sensor and MQ9 LPG Gas sensor as per the circuit diagram which I will explain in a minute. Right now my Nodemcu ESP8266 Development board is connected with the WiFi. Now, using my cell phone I can monitor the temperature sensor and LPG Gas sensor from any part of the world provided if the internet connection is available. You can see, right now the temperature is 19.000 Celsius and the Gas value is 717, this slightly greater value is due to; I tested it with my lighter. Anyway, I am going to use my lighter to heat up the DS18B20 temperature sensor, and I will half press the lighter button to release the Gas.
The temperature value increased to 56.310 Celsius and the Gas value increased to 760. For the practical demonstration watch my video tutorial available on my YouTube channel Electronic Clinic.
I can also monitor both sensors using my designed Dashboard on the blynk.cloud.
The new Blynk 2.0 is the real game changer. Just like the Arduino IoT Cloud, Ubidots, Thingspeak, etc. You can now make cool dashboards for monitoring your sensors and for controlling your electrical devices. As you can see in the image above, I can monitor both sensors at the same time. Now, it’s totally up to the users whether he/she wants to monitor and control things using the Blynk.cloud dashboard or the Blynk IoT mobile application.
I am sure by now, you might have got an idea of how does this system work. So, without any further delay let’s get started!!!
Amazon Links:
DS18B20 waterproof one-wire digital Temperature Sensor
Disclosure: These are affiliate links. As an Amazon Associate I earn from qualifying purchases.
MQ9 sensor:
The MQ-9 Carbon Monoxide, Methane, and LPG Gas Sensor Module can be used to sense Carbon Monoxide and Methane Gas. Sensitive material of the MQ9 gas sensor is SnO2, which has lower conductivity in clean air.
It makes detection by the method of cycle high and low temperature, and detect CO when the low temperature (heated by 1.5V). The sensor’s conductivity is higher along with the gas concentration rising.
When a high temperature (heated by 5.0V), it detects Methane, Propane, etc. combustible gas and cleans the other gases adsorbed under low temperature.
Wire Connections
VCC – Positive pole (5V)
GND – Negative pole
DO – TTL switch signal output
AO – Analog signal output
Applications
- The domestic gas leakage detector
- Industrial gas detector
- Portable gas detector
Features:
- Good sensitivity to CO/Combustible Gas
- High sensitivity to Methane, Propane, and CO
- Long life and low cost
- Simple drive circuit
DS18b20 Temperature Sensor:
One-wire temperature sensors like the DS18B20 are devices that can measure temperature with a minimal amount of hardware and wiring. These sensors use a digital protocol to send accurate temperature readings directly to your development board without the need of an analog-to-digital converter or other extra hardware. You can get one-wire sensors in different form factors like waterproof and high-temperature probes–these are perfect for sensing temperature in many different projects and applications. And since these sensors use the one-wire protocol you can even have multiple of them connected to the same pin and read all their temperature values independently.
The DS18B20 Waterproof Temperature Sensor has three wires
- The red wire is the VCC wire: the operating voltage is 3 to 5 volts. In my case, I will use 3.3 volts.
- Yellow Wire is the Data wire: we usually connect a resistor between the data wire and VCC wire.
- The black wire is the Ground wire. This wire is connected with theNodemcu Esp8266 wifi module ground.
This temperature sensor is capable of measuring the temperature ranging from -55°C to 125°C
DS18b20 & Gas Sensor with ESP8266:
The VCC and GND pins of the MQ9 LPG Gas Sensor and the DS18b20 one-wire digital temperature sensor are connected with the Nodemcu ESP8266 WiFi module 3.3V and GND pins. While the Analog output pin of the MQ9 Gas sensor is connected with the A0 pin of the Nodemcu module and the Data wire of the DS18b20 is connected with the D4 Pin of the Nodemcu Module. Don’t forget to use a 4.7 Kilo ohm resistor between the VCC and data wire. You can also use a 10k resistor.
On the Left side is the regulated 5V power supply based on the LM7805 Voltage regulator. If you are planning to power up your Nodemcu ESP8266 WiFi module using a laptop or PC then there is no need for this power supply. But if you want to externally power up your project using a 12V adaptor or a 12V battery or a Solar panel, then you will need this 5V power supply.
These are the PCB boards which I received from the JLCPCB as you can see the quality is really great. The silkscreen is quite clear and the Black Solder mask looks amazing.
This is how my Nodemcu ESP8266 Development board looks after soldering all the components. I use this development board for testing all my ESP8266-based projects. You can watch my video on Nodemcu ESP8266 if you want to make the same development board.
Anyway, I connected the DS18b20 and MQ9 Gas sensor as per the circuit diagram. And now let’s start with the Blynk.
Blynk.Cloud Dashboard Setup:
In my previous tutorial, I have already explained how to register a free account. Anyway, login into your Blynk.cloudaccount. On the left side click on the Templates and then click on the New Template.
Enter the template name, select the Hardware type ESP8266, select Connection type, you can also write a description, and finally, click on the Done button.
Then info will appear which consists of the name of the template, hardware type, etc.
Go to Datastreams. On the Datasteams click on the New Datastream and select Virtual Pin.
Write the name, select virtual PIN, Data Type, you can also select units, and you can also set the Minimum and Maximum limits. After all the parameters are set then you can click on the Create button.
Now again click on the New Datastream button and follow the same exact steps for the Potentiometer. The virtual PIN is automatically incremented. After you have defined all the parameters then you can click on the Create button. Anyway, you can see our two datastreams are ready and now we can click on the Save button.
Now go to Web Dashboard and click on the Edit Button. On the left side, under the Widgets Box, you will different widgets, search for the Gauge and add it.
Then click on the Gauge setting.
Select the Datastream “Temperature(V0)”, activate the Show on/off labels, If you want you can also change the color, and finally, click on the Save button.
Now, I am going to add a Gauge for monitoring the Gas. The same way you can click on the gauge settings button and select the datastream and do other settings. Once you have added all the widgets then click on the Save button.
Click on the Search, then click on New Device.
Click on From template to create a new device.
Select the template we just created, write the device name, and finally click on the Create button.
My Dashboard is ready and now we have to use the Template ID, Device Name, and Authorization Token in the programming the same way as I explained in my previous tutorial.
Copy the TEMPLATE_ID and paste it next to the BLYNK_TEMPLATE_ID…repeat the same steps for the Device Name and Authorization Token.
You will also need to install ESP8266WiFi.h, WiFiClient.h, BlynkSimpleEsp8266.h, OneWire.h, and DallasTemperature.h libraries for this you can read my getting started articles on the Nodemcu ESP8266 WiFi Module and DS18b20.
Blynk 2.0 and ESP8266 Code:
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 |
// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud // See the Device Info tab, or Template settings #define BLYNK_TEMPLATE_ID "TMPLGckzgBDu" #define BLYNK_DEVICE_NAME "Temperature and gas monitoring" #define BLYNK_AUTH_TOKEN "InTQPNkMTPo_wK34c4j9pgBxszkqn89K" // Comment this out to disable prints and save space #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <BlynkSimpleEsp8266.h> #include <OneWire.h> #include <DallasTemperature.h> #define ONE_WIRE_BUS 2 // DS18B20 on arduino pin2 corresponds to D4 on physical board "D4 pin on the ndoemcu Module" OneWire oneWire(ONE_WIRE_BUS); DallasTemperature DS18B20(&oneWire); float temp; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "AndroidAP3DEC"; char pass[] = "electroniclinic"; BlynkTimer timer; char auth[] = BLYNK_AUTH_TOKEN; int gassensor=A0; void setup() { pinMode(gassensor,INPUT); // Debug console Serial.begin(115200); DS18B20.begin(); Blynk.begin(auth, ssid, pass); } void loop() { Blynk.run(); int gasvalue=analogRead(gassensor); DS18B20.requestTemperatures(); temp = DS18B20.getTempCByIndex(0); // Celcius Blynk.virtualWrite(V0,temp); Serial.println(temp); Blynk.virtualWrite(V1,gasvalue); } |
Using these steps you can migrate all your Blynk 1.0 projects to Blynk 2.0… Anyway, once the code is uploaded. Go back to your Blynk.Cloud dashboard and you should be able to see the temperature and Gas values on the Gauges.
You can see a rise in the temperature as I am holding the temperature sensor in my hand. You can also see a change in the Gas Sensor value as its detecting gas leakage from the lighter. Now, let’s start with the Blynk Iot Mobile App.
Blynk IoT App Mobile Setup:
If you also want to use your cell phone for controlling and monitoring different devices and sensors then you will need to install the Blynk IoT App. Go to the AppStore and search for the Blynk App make sure you install the Blynk IoT. Once the Blynk IoT App is installed then login with the same Gmail id and password.
Anyway, Open the Blynk application and click on the Developer Mode.
Then click on the temperature and gas monitoring.
Now, we will add a gauge for the temperature.
Once the Gauge is added, click on the gauge to open the settings.
Then select datastream for the gauge.
Then select the temperature and it will link with the Gauge.
Exactly the same way add another gauge for the Gas sensor, click on the gauge to open its settings, select a datastream, and do other settings as per your requirement.
My Blynk IoT App is ready and now let’s watch the Blynk 2.0 and ESP8266 WiFi module based temperature and Gas monitoring system in action.
ok,
Thank you