Nodemcu and BMP180 “temperature, pressure & Altitude” internet of things project “iot”
Table of Contents
Nodemcu And BMP180 Project Description:
In this tutorial, you will learn how to use the BMP180 sensor with Nodemcu esp8266 wifi module, with the help of this project you can monitor the temperature, pressure, and Altitude values using Blynk application from anywhere around the world. This project is based on two-way communication; we will be monitoring and controlling both at the same time. This project is based on my previous two tutorials.
In this tutorial you will learn how to use the BMP180 sensor, this tutorial explains the datasheet and basic circuit diagram.
While this tutorial explains the two-way communication between the Nodemcu esp8266 wifi module and Arduino using the Blynk application.
I recommend you should first watch these two tutorials for the best understanding.
Amazon Links:
Other Tools and Components:
Super Starter kit for Beginners
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!
Arduino Nodemcu and BMP180 Circuit Diagram:
This is the complete circuit diagram. This schematic is designed in the Cadsoft eagle 9.1.0 version. If you want to learn how to make a schematic and PCB then watch my tutorial.
Let’s start with the power supply. 7805 voltage regulator is used to regulate the input voltage at 5 volts. These 5 volts can be used to power up the Nodemcu module if in case you want to use it alone. You can simply connect the output of the voltage regulator with the VIN pin of the Nodemcu and make sure you connect the ground as well. This power supply can also be used to power up the Arduino, by connecting its output with the VIN pin of the Arduino and removing the wire which is connected with the 5v.
You can also power up Arduino using a 12v adaptor, and then you can disconnect this power supply. And you can power the Nodemcu using the Arduino 5 volts. But my recommendation is to use the external power supply for the Nodemcu esp8266 wifi module.
The TX and RX pin’s of the Nodemcu are connected with pin2 and pin3 of the Arduino. So the Nodemcu will communicate serially with Arduino Uno through pin2 and pin3. Pin2 is RX and pin3 is TX, which will be defined in the programming using the software serial library.
The VIN pin of the bmp180 sensor is connected with 3.3v of the Arduino, SCL is connected with A5 and SDA is connected with A4 and the ground is connected with the Arduino’s ground.
A led is connected with pin number 13 and a 330-ohm resistor is connected in series. I will use the Arduino’s onboard led for the demonstration purposes.
I soldered all the components as per the circuit diagram. If you want to learn how to make a power supply for the Nodemcu so that it can be easily powered up using a 12v adaptor or battery then you should watch my tutorial on Nodemcu power supply.
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.
Mobile Application Designing:
For the Blynk application designing and Setup watch video Tutorial given at the end of this Article.
Programming:
Arduino Programming:
Nodemcu and BMP180-
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 |
#include <SoftwareSerial.h> #include <Wire.h> #include <Adafruit_BMP085.h> SoftwareSerial nodemcu(2,3); // Connect VCC of the BMP180 / BMP085 sensor to 3.3V // Connect GND to Ground Adafruit_BMP085 bmp; long int data; int relay1 = 13; int relay2 = 12; int sdata1 = 0; // temperature data long int sdata2 = 0; // pressure data int sdata3 = 0; // altitude data String cdata; // complete data void setup() { Serial.begin(9600); nodemcu.begin(9600); pinMode(relay1, OUTPUT); pinMode(relay2, OUTPUT); if (!bmp.begin()) { Serial.println("Could not find a valid BMP180 sensor, check wiring!"); while (1) {} } } void loop() { if(nodemcu.available() == 0 ) { Serial.print("Temperature = "); Serial.print(bmp.readTemperature()); sdata1 = bmp.readTemperature(); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(bmp.readPressure()); sdata2 = bmp.readPressure(); Serial.println(" Pa"); // Calculate altitude assuming 'standard' barometric // pressure of 1013.25 millibar = 101325 Pascal Serial.print("Altitude = "); Serial.print(bmp.readAltitude()); sdata3 = bmp.readAltitude(); Serial.println(" meters"); cdata = cdata + sdata1+","+sdata2+","+sdata3; Serial.println(cdata); nodemcu.println(cdata); delay(1000); // 100 milli seconds cdata = ""; } if ( nodemcu.available() > 0 ) { data = nodemcu.parseInt(); delay(100); Serial.println(data); if ( data == 10 ) { digitalWrite(relay1, LOW); } if ( data == 11 ) { digitalWrite(relay1, HIGH); } // relay2 if ( data == 12 ) { digitalWrite(relay2, LOW); } if ( data == 13 ) { digitalWrite(relay2, HIGH); } } } |
Nodemcu esp8266 wifi module 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 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
#define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> #include <SoftwareSerial.h> #include <SimpleTimer.h> int pinValue1; int pinValue2; int pinValue3; int pinValue4; char auth[] = "80a57c58dde24141834e87f459881ac3"; // Your WiFi credentials. // Set password to "" for open networks. char ssid[] = "ZONG MBB-E8231-6E63"; char pass[] = "08659650"; SimpleTimer timer; String myString; // complete message from arduino, which consistors of snesors data char rdata; // received charactors //for temperature , pressure and altitude int firstVal, secondVal,thirdVal; // // This function sends Arduino's up time every second to Virtual Pin (1). // In the app, Widget's reading frequency should be set to PUSH. This means // that you define how often to send data to Blynk App. void myTimerEvent() { // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V1, millis() / 1000); } void setup() { // Debug console Serial.begin(9600); Blynk.begin(auth, ssid, pass); timer.setInterval(1000L,sensorvalue1); timer.setInterval(1000L,sensorvalue2); timer.setInterval(1000L,sensorvalue3); } void loop() { if (Serial.available() == 0 ) { Blynk.run(); timer.run(); // Initiates BlynkTimer } if (Serial.available() > 0 ) { rdata = Serial.read(); myString = myString+ rdata; // Serial.print(rdata); if( rdata == '\n') { // Serial.println(myString); // Serial.println("fahad"); // new code String l = getValue(myString, ',', 0); String m = getValue(myString, ',', 1); String n = getValue(myString, ',', 2); firstVal = l.toInt(); secondVal = m.toInt(); thirdVal = n.toInt(); myString = ""; // end new code } } } void sensorvalue1() { int sdata = firstVal; // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V2, sdata); } void sensorvalue2() { int sdata = secondVal; // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V3, sdata); } void sensorvalue3() { int sdata = thirdVal; // You can send any value at any time. // Please don't send more that 10 values per second. Blynk.virtualWrite(V4, sdata); } String getValue(String data, char separator, int index) { int found = 0; int strIndex[] = { 0, -1 }; int maxIndex = data.length() - 1; for (int i = 0; i <= maxIndex && found <= index; i++) { if (data.charAt(i) == separator || i == maxIndex) { found++; strIndex[0] = strIndex[1] + 1; strIndex[1] = (i == maxIndex) ? i+1 : i; } } return found > index ? data.substring(strIndex[0], strIndex[1]) : ""; } // in Blynk app writes values to the Virtual Pin 10 BLYNK_WRITE(V10) { pinValue1 = param.asInt(); // assigning incoming value from pin V10 to a variable Serial.print(pinValue1); } // in Blynk app writes values to the Virtual Pin 11 BLYNK_WRITE(V11) { pinValue2 = param.asInt(); // assigning incoming value from pin V10 to a variable Serial.print(pinValue2); } |