Interfacing HC05 Bluetooth Module with Raspberry pi pico



Controlling 5 Relays via bluetooth module HC05 in micropyhon programming

Download Android APK file for the Application from the Given link

https://drive.google.com/file/d/1qr3WY5u5K4XytKopU8D0akamqsebhGX0/view?usp=sharing

 https://drive.google.com/file/d/1qr3WY5u5K4XytKopU8D0akamqsebhGX0/view?usp=sharing 

Micropython Code

from machine import Pin# importng machine module

from machine import UART# importng UART(Universal Asynchronous Receiver) module

from time import sleep#importing sleep from time module

HC05=UART(0,9600)#creating an object HC05 and declaring UART communication channel,boud rate

relay_1=Pin(28,Pin.OUT)#creating an Object relay_1 and assign Pin 28 as an OUTPUT

relay_2=Pin(20,Pin.OUT)#creating an Object relay_2 and assign Pin 20 as an OUTPUT

relay_3=Pin(18,Pin.OUT)#creating an Object relay_3 and assign Pin 18 as an OUTPUT

relay_4=Pin(19,Pin.OUT)#creating an Object relay_4 and assign Pin 19 as an OUTPUT

led=Pin(25,Pin.OUT)#Onboard led of Raspbetty pi pico

while True:# creating an infinite loop to checking is there is any data availabel?

    if HC05.any()>0:

        data=HC05.read(1)#creating a variable(data)and saving the availabel data from Hc05.

        if "0" in data:#condition checking-if available data is (0)

            relay_1.on()#command for relay_1 ON

            #relay_1.value(1)#command for relay_1 ON

        if "1" in data:#condition checking-if available data is (1)

            relay_1.off()#command for relay_1 OFF

            #relay_1.value(0)#command relay_1 OFF

        if "2" in data:#condition checking-if available data is (2)

            relay_2.on()#command for relay_2 ON

            #relay_2.value(1)#command relay_2 ON

        if "3" in data:#condition checking-if available data is (3)

            relay_2.off()#command for relay_2 OFF

            #relay_2.value(0)#command for relay_2 OFF

        if "4" in data:#condition checking-if available data is (4)

            relay_3.on()#command for relay_3 ON

            #relay_3.value(1)#command for relay_3 ON

        if "5" in data:#condition checking-if available data is (5)

            relay_3.off()#command for relay_3 OFF

            #relay_3.value(0)#command for relay_3 OFF

        if "6" in data:#condition checking-if available data is (6)

            relay_4.on()#command for relay_4 ON

            #relay_4.value(1)#command for relay_4 ON

        if "7" in data:#condition checking-if available data is (7)

            relay_4.off()#command for relay_4 OFF

            #relay_4.value(0)#command for relay_4 OFF    

        if "8" in data:#condition checking-if available data is (8)

            led.on()#command for led ON

            #led.value(1)#command for led ON

        if "9" in data:#condition checking-if available data is (9)

            led.off()#command for led OFF

            #led.value(0)#command for led OFF   

            

            

            

Comments

Popular posts from this blog

4 Stage Timer With DS3231RTC Module.

Interfacing KY038 sound sensor with Raspberry pi Pico

Interfacing MQ2 Gas & Smoke Sensor With Raspberry Pi Pico