weather forecasting smart device
To measuring weather condition
I'm teaching my student about weather tools .That's how I got inspired to create a smart weather forecasting tool.
it will be abole to detect temperature and humidity through DHT sensor and air pressure through BMP280 sensor and finally it could predect rain through air drop sensor
Autodesk fusion 360
RDworks
at first i started with the front side
i made its dimensions 25x15cm
i started to take the measurement of the DHT sensor and LCD and the LED and i draw each on the front side then i draw the t slots with the standerd measurments
i extruded the side with 3mm because the plywood thickness i going to use is 3mm
i started to do the back side with same measurements and steps of the front side but i made a hole 5cm to be air champers to allow air to pass inside the encluser
then i made the right side with dimensions 15x15cm and i added slot for wires and t slots and on off switch hole its diameter 22.8mm
then i made the left side with dimensions 15x15cm and i made a hole for rain sensor slot
i started to do the top and base side with dimensions 15x25cm with the T slots
in another file i made the rain sensor holder its a rectangle with T slot with the common measurements and the distance betwens screws holes is 50 x35 mm
i started to do the assembly for all sides
ARDUINO MOUNTING
LCD MOUNTING
DHT SENSOR MOUNTING
I used laser cutter machine to fabricate my design
the parameters i used speed 40 and power 45
the design took around 5min to be fabricated
the outputs of my project are LCD and LEDs
the microcontroller i used is Arduino
to detect the rains
DHT 11 sensor wiring diagram
used to detect the temprature and humidity
graund on graund
Analog on pin AO
Digetal on pin 2
graund on graund
signal on pin 7
used to detect the air pressure
Vcc on 5v
graund on graound
vx and tx on arduino
used to display the out put
vcc on 5v
ground on graund
SDA on A4
SCL on 5v
used to worn the user if weather is normal or danger
the Anode connected to pins 8,9,10 ,11,12,3 and4
AT FIRST I STARTED TO TEST EACH SENSOR ON SERIAL MONITIR AFTER I MADE SURE THAT THEY ALL ARE WORKING I STARTED TO SEARCH FOR REFRENCES OF EACH SENSOR WITH LCD
#include "DHT.h"
#define DHTPIN 7 // what pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(2000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// Compute heat index
// Must send in temp in Fahrenheit!
float hi = dht.computeHeatIndex(f, h);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
source of code
https://www.instructables.com/DHT11-Temperature-Humidity-Sensor-With-Arduino/
source of code Autodesk intractable
https://www.instructables.com/Instructions-for-Using-the-BMP180-Air-Pressure-Sen/
const int sensorMin = 0; // sensor minimum
const int sensorMax = 1024; // sensor maximum
void setup() {
}
void loop() {
// read the sensor on analog A0:
int sensorReading = analogRead(A0);
// map the sensor range (four options):
// ex: 'long int map(long int, long int, long int, long int, long int)'
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);
// range value:
switch (range) {
case 0: // Sensor getting wet
Serial.println("Rain Warning");
break;
case 1: // Sensor dry
Serial.println("Not Raining");
break;
}
delay(1000); // delay between reads
}
source of code ardumotive
https://www.ardumotive.com/how-to-use-the-raindrops-sensor-moduleen.html
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27 and size 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <DHT.h>
#define DHTPIN 7 // Define the pin where the DHT sensor is connected
#define DHTTYPE DHT11 // Change to DHT22 if using that sensor
void setup() {
Serial.begin(9600); // Start serial communication
dht.begin(); // Initialize the DHT sensor
lcd.init();
lcd.backlight();
}
void loop() {
float humidity = dht.readHumidity(); // Read humidity
float temperature = dht.readTemperature(); // Read temperature in Celsius
lcd.setCursor(0, 1);
lcd.print("Temp: ");
lcd.print (temperature);
delay(3000); // Update every second
lcd.clear();
lcd.setCursor(0, 1);
lcd.print("Humidity: ");
lcd.print (humidity);
delay(2000);
i started by identifying the necessary components: an LCD display and a DHT11 sensor. Then, i set up the libraries needed for communication. After that, i initialized the hardware, making sure the LCD and sensor were ready for data processing. In the main loop, you structured the data retrieval process, ensuring the sensor readings were displayed clearly and updated every few seconds. Finally, i managed the LCD display flow, switching between temperature and humidity to provide a clear and organized output.
the code logic
LCD display the temperature and humidity value that the DHT11 sensor detect
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27 and size 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP180 sensor, check wiring!");
while (1)
;
}
lcd.init();
lcd.backlight();
}
void loop() {
lcd.print("Pressure= ");
lcd.setCursor(9, 0);
lcd.print(bmp.readPressure());
delay(2000); // Update every second
}
I first include the necessary libraries for the LCD and the BMP180 sensor. I initialize the LCD with an I2C address of 0x27 and dimensions of 16x2. Then, I create an instance of the BMP180 sensor. In the setup() function, I start serial communication and check if the BMP180 sensor is detected; if not, the program halts with an error message. I initialize the LCD and turn on its backlight. In the loop(), I display the text "Pressure=" on the LCD, set the cursor position, and print the atmospheric pressure reading from the BMP180 sensor. The display updates every two seconds to provide real-time pressure data.
the code logic
LCD display the air pressure value that the BMB180 sensor detect
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define RAIN_SENSOR_PIN 2
/ Initialize the LCD with I2C address 0x27 and size 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
void setup() {
lcd.init();
lcd.backlight();
}
void loop() {
int sensorState = digitalRead(RAIN_SENSOR_PIN); // Read the sensor state
int sensorValue = analogRead(RAIN_SENSOR_PIN);
if (sensorValue < THRESHOLD) {
lcd.setCursor(0, 0);
lcd.print("It's Raining");
} else {
lcd.setCursor(0, 0);
lcd.print("No Rain");
}
delay(3000); // Update every second
}
the refrence
https://lastminuteengineers.com/rain-sensor-arduino-tutorial/
I started by including the necessary libraries, Wire.h and LiquidCrystal_I2C.h, to interface with the I2C-based LCD. I then defined RAIN_SENSOR_PIN as pin 2, where my rain sensor is connected. Next, I initialized the LCD with the I2C address 0x27 and specified its size as 16x2. In the setup() function, I initialized the LCD and turned on its backlight. In the loop(), I read the sensor state using digitalRead(RAIN_SENSOR_PIN) and then attempted to read an analog value from the same pin using analogRead(RAIN_SENSOR_PIN). Based on the sensor value, I compared it with a threshold (though I forgot to define THRESHOLD). If the value is below the threshold, the LCD displays "It's Raining"; otherwise, it shows "No Rain." Finally, I included a delay(3000) to update the display every three seconds. However, I need to fix a few issues: defining THRESHOLD, ensuring I use the correct pin type (digital or analog), and setting up pinMode() in setup().
the code logic
LCD display its raining when the rain drop sensor sense rain and display no rain when rain drop sensor sense no rain
#include <Wire.h>
#include <Adafruit_BMP085.h>
#include <DHT.h>
// Sensor Setup
Adafruit_BMP085 bmp;
#define DHTPIN 7
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
// LED Pins
#define LED_PRESSURE_RED 8
#define LED_PRESSURE_GREEN 9
#define LED_HUMIDITY_GREEN 10
#define LED_HUMIDITY_RED 11
#define LED_TEMP_GREEN 12
#define LED_TEMP_RED 13
#define LED_RAIN_GREEN 4
#define LED_RAIN_RED 3
// Rain Sensor Pin
#define RAIN_SENSOR A0
void setup() {
pinMode(LED_PRESSURE_RED, OUTPUT);
pinMode(LED_PRESSURE_GREEN, OUTPUT);
pinMode(LED_HUMIDITY_GREEN, OUTPUT);
pinMode(LED_HUMIDITY_RED, OUTPUT);
pinMode(LED_TEMP_GREEN, OUTPUT);
pinMode(LED_TEMP_RED, OUTPUT);
pinMode(LED_RAIN_GREEN, OUTPUT);
pinMode(LED_RAIN_RED, OUTPUT);
dht.begin();
if (!bmp.begin()) {
while (1); // If BMP180 fails, halt the program
}
}
void loop() {
float pressure = bmp.readPressure() / 100.0; // Convert Pa to hPa
float humidity = dht.readHumidity();
float temperature = dht.readTemperature();
int rainValue = analogRead(RAIN_SENSOR);
// Air Pressure Condition
if (pressure > 1030) {
digitalWrite(LED_PRESSURE_RED, HIGH);
digitalWrite(LED_PRESSURE_GREEN, LOW);
} else {
digitalWrite(LED_PRESSURE_RED, LOW);
digitalWrite(LED_PRESSURE_GREEN, HIGH);
}
// Humidity Condition
if (humidity < 50) {
digitalWrite(LED_HUMIDITY_GREEN, HIGH);
digitalWrite(LED_HUMIDITY_RED, LOW);
} else {
digitalWrite(LED_HUMIDITY_GREEN, LOW);
digitalWrite(LED_HUMIDITY_RED, HIGH);
}
// Temperature Condition
if (temperature < 37) {
digitalWrite(LED_TEMP_GREEN, HIGH);
digitalWrite(LED_TEMP_RED, LOW);
} else {
digitalWrite(LED_TEMP_GREEN, LOW);
digitalWrite(LED_TEMP_RED, HIGH);
}
// Rain Prediction
if (rainValue <500) { // Adjust threshold based on calibration
digitalWrite(LED_RAIN_GREEN, LOW);
digitalWrite(LED_RAIN_RED,HIGH);
} else {
digitalWrite(LED_RAIN_GREEN, HIGH);
digitalWrite(LED_RAIN_RED, LOW);
}
delay(1000); // Update every second
}
First, I included the necessary libraries to interface with the BMP180 pressure sensor and the DHT11 temperature and humidity sensor. Then, I defined the sensor pins and assigned digital pins for the LEDs, ensuring each environmental factor (pressure, humidity, temperature, and rain) had both a green (normal) and red (warning) LED. In the setup(), I initialized the sensors and set the LED pins as outputs, making sure the BMP180 was functioning correctly before proceeding. In the loop(), I read pressure, humidity, temperature, and rain sensor values, then applied conditions to determine which LEDs should turn on. If the pressure was too high, the red LED activated; if humidity was below 50%, the green LED stayed on; if the temperature was below 37°C, it was considered safe, and for rain detection, values below 500 triggered a red LED warning. Finally, I added a delay of one second to refresh the readings continuously, ensuring real-time monitoring of environmental conditions.
the code logic
when humidity above 50 the red led turn on (danger )
if humidity below 50 the green led turn on (normal)
when temperature above 37the red led turn on (danger )
if temperature below 37 the green led turn on (normal)
when air pressure above 10030 the red led turn on (danger )
if air pressure below 10030 the green led turn on (normal)
when its running the red led turn on (danger )
when its not running the green led turn on (normal)
I had a challenge the air pressure sensor was not abele to display the value on the LCD screen as both are working on SDL and SDA I though that was the problem and after many trayels with wiring but its still not working by the help of my instructors Hala ❤️ its become abele to display the result on the screen the problem was in my code logic and here is the right code
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize the LCD with I2C address 0x27 and size 16x2
LiquidCrystal_I2C lcd(0x27, 16, 2);
#include <Adafruit_BMP085.h>
Adafruit_BMP085 bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin()) {
Serial.println("Could not find a valid BMP180 sensor, check wiring!");
while (1)
;
}
lcd.init();
lcd.backlight();
}
void loop() {
lcd.print("Pressure= ");
lcd.setCursor(9, 0);
lcd.print(bmp.readPressure());
delay(2000); // Update every second
}
if I had more time I would add a Bluetooth module to display the weather conditions on mobile screen and l would improve the design to have nicer appearance and I would also add more features like measuring wind speed