My task this week is to Design and program a smart device that performs a certain function or solve a problem using Arduino UNO and coding on IDE Arduino software to read signals from multiple input components to control multiple action components using Arduino C (Text Code)
I will design a Smart weather station using Arduino UNO to sense temperature and Humidity, and rain, then display it on LCD screen and the LED will be indicated when it is raining.
To know how I did it, follow me to the next few steps.
This project will require the following components
LCD Screen 2x16 ( Action device )
Digital Humidity & Temperature Sensor Module DHT11 ( input device )
LDR Photosensitive Resistor Sensor ( Input device )
LED ( Action device )
Rain Water Level Detection Sensor Module " As it is not available on the provided kit I'll use the LDR instead of"
Installing Libraries and Testing
In this stage we going to install libraries for sensors and the liquid crystal screen to make sure that they are working smoothly and test every device separately
The first sensor is the temperature and humidity sensor "DHT11" and it will be used as an input device
It has 3 pins for
VCC connected to 5 Volt and connected to voltage
GND connected to the ground and connected to the ground
DATA connected to any Arduino digital input and connected to pin 2
Go to the library section on Arduino IDE
search and install the following library
DHT sensor library by Adafruit
from the file menu, choose examples, DHT sensor library, DHT Tester
Then connect your DHT11 Sensor to your Arduino
connect VCC, GND, and the DATA pin to pin 2, and make sure you modify it at the code and the DHT type is DHT11 as shown above
Now click upload at the top left, then click on the serial monitor
If you have done everything right, your sensor should read the humidity and temperature as shown in the picture.
The LCD 2x16 " I2C " Has 4 pins and it will be used as an action device
VCC connected to 5 Volt
GND connected to the ground
SDA Serial Data Line
SCL Serial Clock Line
Go to the library section on Arduino IDE
search and install the following library
LiquidCrystal 12C by Frank de
Brabander
from the file menu, choose examples, Liquid crystal i2c, Hello world
Modify the code as shown" The address is 0x27, and the screen size 16 char with 2 lines
connect VCC, GND, then connect SDA to pin A4, and SCL to pin A5
The LDR sensor that will be used as the input device has 4 pins
VCC, connected to the voltage pin
GND, connected to the ground pin
DO, digital pin, and connected to digital input
AO, Analog pin, and connected to the analog input pin
we will use the digital pin DO in our device and will be connected to pin 5
You can modify the code that you want to display on the LCD from the code
By setting the cursor to the block ( Block no, and Line ) and then printing the word on it
so you can understand it from the code 😉
Upload the code If you have done everything right, you should see it on your LCD 😎
Merging and modifying the code
In this stage we going to merge the two libraries' code and modify it to complete my project
But first, we need to wire the component to modify the code, as shown in the picture " wiring simulation using Tinkercad" 🧑💻
As you can see,
I used the temperature sensor as a simulation of DHT 11
The soil moisture sensor to simulate the LDR sensor
The first thing to edit at the "void setup "is adding the device name " smart weather station " as we did before
then wait for 2 seconds, clear the LCD
after that type my name in two lines
After that, we need to display the humidity and temperature on the screen.
so at the " void loop," we will add the phrases and parameters at the right places using the lcd.setCursor command, each one at a separate line as we can see in the code
Now for the rain sensor, As I do not have a rain sensor in my provided kit, I'll use my LDR sensor to do this challenge, As they have the same pins and the same code can apply to them , add pinMode for the right pins.
as you can see from the code, I add " if, else" statement to make the LED blinking if there is rain
Now let's add some challenges to the code
I will make the LCD screen type " Rain" and plink with the LED when it rains outside to make the user pay attention
So I connected an LED to Arduino pin 5 to blink when it rains.
as you can see in the code 👈🏽
👾Note: You do not need to edit anything else in the code " just merge the two codes from libraries that we mentioned before together.
Finally, you can download the code from here 👇🏽
Now we going to test the device after wiring and uploading the code
as you can see the device is working perfectly,
displaying the splash screen
showing temperature and humidity
on rain simulation with the LDR
the LED pinking " the second action device "
display "Rain" on the screen and plinking
Making Device enclosure with cardboard
Creating a cool cardboard enclosure with places for the LCD and Arduino
Working as before with the enclosure
but I don't have a rain sensor, so I used the LDR sensor to simulate it, as they have the same pins and I do not need to make any changes to the code