Karmbir 19 ML (2) (1) - Merged
Karmbir 19 ML (2) (1) - Merged
Department
Of
Computer Science and Engineering
2023-24
Nodemcu board x 1 —
DHT11 sensor x 1 —
BMP180 sensor x 1 —
Rain sensor x 1 —
Breadboard x 1 —
Jumper wires —
First, go to the Thingspeak website and create a new account using your email
address. Then, click the “New channel” button.
Next, enter your project name as you like. Then, activate the four fields and
name them Temperature, Humidity, Pressure, and Rainfall respectively. After,
click the “Save channel” button.
code
#include <SFE_BMP180.h>
#include <Wire.h>
#include <ESP8266WiFi.h>
#include "DHT.h"
void setup() {
Serial.begin(115200);
delay(10);
bmp.begin();
Wire.begin();
dht.begin();
WiFi.begin(ssid, pass);
void loop() {
//BMP180 sensor
status = bmp.startTemperature();
if (status != 0) {
delay(status);
status = bmp.getTemperature(T);
status = bmp.startPressure(3);// 0 to 3
if (status != 0) {
delay(status);
status = bmp.getPressure(P, T);
if (status != 0) {
}
}
}
//DHT11 sensor
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
//Rain sensor
int r = analogRead(A0);
r = map(r, 0, 1024, 0, 100);
if (client.connect(server, 80)) {
String postStr = apiKey;
postStr += "&field1=";
postStr += String(t);
postStr += "&field2=";
postStr += String(h);
postStr += "&field3=";
postStr += String(P, 2);
postStr += "&field4=";
postStr += String(r);
postStr += "\r\n\r\n\r\n\r\n";
Serial.print("Temperature: ");
Serial.println(t);
Serial.print("Humidity: ");
Serial.println(h);
Serial.print("absolute pressure: ");
Serial.print(P, 2);
Serial.println("mb");
Serial.print("Rain");
Serial.println(r);
}
client.stop();
delay(1000);
}
Next, select board and port. After, upload this code to the Nodemcu board.
Now, go back to the Thingspeak app and click the private view tab.
Now we can see the monitered Tempersture,Humidity,Pressure and can detect
Rain by this project.
thankyou