In this Instructables, I am going to make an home automation project to control my home appliances with my smart phone(android phone) via Bluetooth. Here In my study room there are four electrical appliance's (Bulb, Tube light, Fan and Cooler). I normally turns on and off these appliances with the help of mechanical switches. For controlling these appliances with my smart phone I am going to use 4 Electromechanical switches( Relay's). I am controlling there relays with an RP2040 Microcontroller. The reason behind selecting this microcontroller is that it can be programmed using either Python(Micropython or Circuit Python) or C/C++. The maximum operating frequency of RP2040 is 133MHz. It has 2MB(Mega Bites)of external Flash memory. It supports SPI, I2C and UART Communication Protocols.
For communicating with smart phone's Bluetooth I am using HC-05 Bluetooth module. It uses UART communication protocol for communicating with a microcontroller or microprocessor.
I have downloaded Bluetooth Serial Terminal app to on or off the appliances. Now Let's get started.
Hardware RequirementsElectronic parts
Raspberry Pi Pico
https://quartzcomponents.com/products/raspberry-pi-pico?_pos=1&_sid=a395bdb06&_ss=r
- 4-Channel Relay
- HC-5 Bluetooth
https://quartzcomponents.com/products/hc-05-bluetooth-module?_pos=1&_sid=d10607bd6&_ss=r
- Breadboard
- Jumper wires
https://quartzcomponents.com/products/65pcs-breadboard-jumper-cable?_pos=7&_sid=3ac700a32&_ss=r
- Micro-USB cable
https://quartzcomponents.com/products/raspberry-pi-cable-for-charging?_pos=5&_sid=a2ea2a3ea&_ss=r
- 5V/2A SMPS adapter
https://quartzcomponents.com/products/5v-2a-adapter?_pos=1&_sid=6b3bdea7d&_ss=r
- 16x2 LCD Display
https://quartzcomponents.com/products/16x2-lcd-display-module-blue?_pos=4&_sid=bea989263&_ss=r
- I2C module
- Wires
https://quartzcomponents.com/search?type=product&q=copper+wire+cable
Tools
- Screw Driver
- Soldering Iron
https://quartzcomponents.com/products/analog-soldering-iron-60w?_pos=5&_sid=29c8e1c9c&_ss=r
- Soldering Flux
https://quartzcomponents.com/products/rma-223-solder-flux-paste?_pos=2&_sid=9ff3e5613&_ss=r
- Electrical Tape
- Thonny(Python IDE for beginners)
- MIT App Inventor
- MicroPython Firmware For Raspberry Pi Pico
https://micropython.org/download/rp2-pico/
ProcessStep 1: Making a Prototype Circuit on Breadboard
Before soldering all hardware on a printed circuit board(PCB). I always prefer to test the circuit by prototyping it on a breadboard. Follow given instruction to make your own prototype circuit on a bread board.
- Fix the Raspberry Pi Pico microcontroller board on the bread board as shown in the Fig-1.
- Connect the 4 Channel relay module to Raspberry Pi Pico according to given wiring scheme.
Relay module...........................................Raspberry Pi Pico
VCC----------------------------------------------------->VBUS
GND----------------------------------------------------->GND
IN1------------------------------------------------------->GPIO-2
IN2------------------------------------------------------->GPIO-3
IN3------------------------------------------------------->GPIO-4
IN4------------------------------------------------------->GPIO-5
- Fix the HC-05 Bluetooth module on the breadboard as shown in the Fig-2.
- Connect the HC-05 Bluetooth module to Raspberry Pi Pico according to given wiring scheme.
HC-05........................................ Raspberry Pi Pico
VCC---------------------------------------->VBUS
GND---------------------------------------->GND
Tx------------------------------------------->Rx
Rx------------------------------------------->Tx
- Connect the LCD module and I2C module together with the help of soldering.
- Connect the I2C module to Raspberry Pi Pico according to given wiring scheme.
I2C Module.......................................... Raspberry Pi Pico
VCC------------------------------------------------->VBUS
GND------------------------------------------------->GND
SDA-------------------------------------------------->GPIO-14
SCL--------------------------------------------------->GPIO-15
- Connect the VBUS and GND pins of Raspberry pi pico to +Ve(Red) and -Ve(Blue) rails of the breadboard.
Step2: Programming(Writing the main.py MicroPython script)
For programming the raspberry pi pico, I am using my raspberry pi computer system.
Open a new script in thonny and write the following lines of program;
from machine import Pin, I2C, UART
from lcd_api import LcdApi
from i2c_lcd import I2cLcd
import time
relay_1 = Pin(2, Pin.OUT)
relay_2 = Pin(3, Pin.OUT)
relay_3 = Pin(4, Pin.OUT)
relay_4 = Pin(5, Pin.OUT)
relay_1.value(1)
relay_2.value(1)
relay_3.value(1)
relay_4.value(1)
I2C_ADDR = 0x3E
Row_no = 2
Column_no = 16
i2c = I2C(id = 1, sda = Pin(14), scl = Pin(15), freq = 400000)
lcd = I2cLcd(i2c, I2C_ADDR, Row_no, Column_no)
uart = UART(0, 9600, tx = Pin(0), rx = Pin(1))
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("FAN:")
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")
while True:
if uart.any() > 1:
data = uart.readline(1)
print(data)
if 'B' in data:
relay_1.value(False)
lcd.move_to(5, 0)
lcd.putstr("on ")
if 'b' in data:
relay_1.value(True)
lcd.move_to(5, 0)
lcd.putstr("off")
if 'T' in data:
relay_2.value(False)
lcd.move_to(5, 1)
lcd.putstr("on ")
if 't'in data:
relay_2.value(True)
lcd.move_to(5, 1)
lcd.putstr("off")
if 'F' in data:
relay_3.value(False)
lcd.move_to(13, 0)
lcd.putstr("on ")
if 'f' in data:
relay_3.value(True)
lcd.move_to(13, 0)
lcd.putstr("off")
if 'C' in data:
relay_4.value(False)
lcd.move_to(13, 1)
lcd.putstr("on ")
if 'c' in data:
relay_4.value(True)
lcd.move_to(13, 1)
lcd.putstr("off")
Save this script with name as main.py on Raspberry Pi Pico. We further need two more python modules (lcd_api.py & i2c_lcd.py) for controlling the I2C LCD. You can download these micropython modules from my GitHub repository. The link has been given below;
https://github.com/ramjipatel041/Home-Automation
Step-3: Connecting the Relays and Mains board using Cables
For controlling my room appliances with my smartphone through Bluetooth, I am going to use Bluetooth serial terminal android app. This app is available on the play store. You can download it by free. The link has given below:
Pictures of my Work
Comments