Here In this project we are going to make an IOT based Home Automation system for our home to control the AC Electrical Appliances(In my case, one Cooler, one Tube Light, LED Bulb and one extension). So let's get started.
Requirements For The Project1. Hardware Requirements
Electronic Parts
Raspberry Pi Pico W
https://quartzcomponents.com/products/raspberry-pi-pico-w?_pos=1&_sid=4867388e7&_ss=r
4-Channel Relay Module
Micro-USB Cable
https://quartzcomponents.com/products/raspberry-pi-cable-for-charging?_pos=2&_sid=2eff98b8b&_ss=r
Breadboard(MB102)
Jumper Wires(M-T-M & M-T-F)
DHT11 Temperature & Humidity Sensor
16x2 LCD
https://quartzcomponents.com/products/16x2-lcd-display-module-blue?_pos=2&_sid=de26eb6f3&_ss=r
I2C Module
Tools
Screw Driver
Card board box
Cutter
https://robu.in/product/freemans-clh-18-utility-cutters/
Vernier Calipers
2. Software Requirements
- Thonny(Python IDE for Beginners)
- MicroPython Firmware for Raspberry Pi Pico W(Latest)
https://micropython.org/download/RPI_PICO_W/
- Blynk IOT Application
Step-1; Making a Test setup on the bread board
To create a prototype of the project on a breadboard you can take the help of the schematic diagram. Also make proper wiring connections with the help of schematic diagram and given images.
Step-2;Programming
Raspberry pi pico w board can be programmed in various programming languages but I am a big fan of MicroPython programming so I am using this language to program the Raspberry pi pico w microcontroller board.
If you have purchased a new Raspberry pi pico w board from the market then first of all you need to flash the latest micropython firmware on Raspberry pi pico w. If you don't know how to do that then please visit my article on Getting started with Raspberry pi pico w. The link of the Article is given below;
https://www.hackster.io/Ramji_Patel/getting-started-with-raspberry-pi-pico-w-e3df24
the main.py micropython script is given below;
from machine import Pin, I2C
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import network
import BlynkLib
import dht
import time
relay1 = Pin(2, Pin.OUT)
relay2 = Pin(3, Pin.OUT)
relay3 = Pin(4, Pin.OUT)
relay4 = Pin(5, Pin.OUT)
sensor = dht.DHT11(Pin(13))
sensor.measure()
temperature = sensor.temperature()
print(temperature)
relay1.value(1)
relay2.value(1)
relay3.value(1)
relay4.value(1)
I2C_ADDR = 0x3E
Row_no = 2
Column_no = 16
i2c = I2C(id = 0, sda = Pin(0), scl = Pin(1), freq = 400000)
lcd = I2cLcd(i2c, I2C_ADDR, Row_no, Column_no)
lcd.move_to(0, 0)
lcd.putstr("Hello world!")
time.sleep(1)
lcd.clear()
lcd.move_to(0 , 0)
lcd.putstr("BULB:")
lcd.putstr("off")
lcd.move_to(9, 0)
lcd.putstr("CHR:")
lcd.putstr("off")
lcd.move_to(0, 1)
lcd.putstr("Tube:")
lcd.putstr("off")
lcd.move_to(9, 1)
lcd.putstr("Col:")
lcd.putstr("off")
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("Zebronics_5g","RaspberrypiB+")
BLYNK_AUTH = "bHMxkODGws3HcMeC3gaG34h2rvvyf9fV"
# connect the network
wait = 10
while wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
wait -= 1
print('waiting for connection...')
time.sleep(1)
# Handle connection error
if wlan.status() != 3:
raise RuntimeError('network connection failed')
else:
print('connected')
ip=wlan.ifconfig()[0]
print('IP: ', ip)
"Connection to Blynk"
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
# Register virtual pin handler
@blynk.on("V0") #virtual pin V0
def v0_write_handler(value): #read the value
if int(value[0]) == 1:
relay1.value(0) #turn the led on
lcd.move_to(5, 0)
lcd.putstr('on ')
else:
relay1.value(1) #turn the led off
lcd.move_to(5, 0)
lcd.putstr('off')
@blynk.on("V1") #virtual pin V0
def v1_write_handler(value): #read the value
if int(value[0]) == 1:
relay2.value(0) #turn the led on
lcd.move_to(5, 1)
lcd.putstr('on ')
else:
relay2.value(1) #turn the led off
lcd.move_to(5, 1)
lcd.putstr('off')
@blynk.on("V2") #virtual pin V0
def v2_write_handler(value): #read the value
if int(value[0]) == 1:
relay3.value(0) #turn the led on
lcd.move_to(13, 1)
lcd.putstr('on ')
else:
relay3.value(1) #turn the led off
lcd.move_to(13, 1)
lcd.putstr('off')
@blynk.on("V3") #virtual pin V0
def v3_write_handler(value): #read the value
if int(value[0]) == 1:
relay4.value(0) #turn the led on
lcd.move_to(13, 0)
lcd.putstr('on ')
else:
relay4.value(1) #turn the led off
lcd.move_to(13, 0)
lcd.putstr('off')
while True:
blynk.virtual_write(5, temperature)
time.sleep(0.1)
blynk.run()
Other necessary micropython module are given in code section.
Step-3;Cut the Card board box
To cut the cardboard box first I need to measure the dimensions of LCD and DHT11 sensor. So I measured the dimensions of these parts with the help of my vernier calipers as shown in the given images.
After measuring the dimensions with my digital calipers, I make the cutting drawing of LCD and sensor on the front side of the box and then I cut the card-board with help of cutter.
I also make the holes on the front side on the box to hold the LCD and DHT sensor using M3 nuts and bolts.
Step-4;Fix all electronic parts inside the cardboard box and make all wiring connections
You can take the help of given images to understand how I placed all the electronic parts inside the box and how to make wiring connections inside the box.
Step-5:Log in to Blynk IOT Platform
To control my home appliances by an smart phone or a laptop/computer I am using Blynk IOT platform. To use the Blynk application first create a new user account by logging in through your email-id and also create a new password for your account as shown in the Image-1.
After logging in create a new Blynk project. First of all you need to create a new template. click on new template option to create a new template as shown in the given image;
After creating the template, Create a new device by clicking on new device option. Give a name to your device as I am giving Raspberry pi pico W name to my project as shown below;
After creating the device we are ready to create new datastreams. Here I am controlling 4 appliances and displaying the temperature readings of DHT11 on Blynk IOT platform so I have created total 5 data streams. To create a new data stream click on new Datastreams.
After creating the datastreams create a new Web Dashboard by clicking on Web Dashboard option.
Now add new Widgets. I drag four switches and one gauge widget. Then I change the settings of all the widgets.
Step-6:FinalTesting
After making all wiring connections we are ready to test the project again. If it does not work then check again all the wiring connections that you made inside the cardboard box.
Comments