Now we are going to prepare RPi to control smart bulb when a user make 2
changes in the state of the switch at dashboard application. 3
As you know we can not control 4
can not glow a bulb using RPi beacuse it can output a maximum of 5v. right? So we need a relay driving circuit. 5
I gave you a brief explanation of this circuit in the basic electronics section. that when a 5v 6
5v signal of a digital high signal is applied at this control point. 7
the appliance connected to relay switches on. and when the signal at control pin is 0v or digital low. 8
than appliance will turn off. 9
so this is the connection that you need to make, now understand the python code for this application 10
it so this is our pyhton code and 11
I have imported the required librarires here 12
the 13
pin mode is set to BCM 14
I have setted it to digital output pin 15
are now in the infinite loop am printing some debug messages 16
then I'm making this GET request here so as in the last lesson we saw that 17
when we make this GET request it return 1 or 0 based on the state of 18
dashboard button. So am reading 19
it in a variable 'responce' 20
and if the response I got there is one 21
so if the response return is one than turn on the light and if it is 0 than turn off the bulb 22
now copy this code 23
go to your folder 24
and create a new file here 25
say 'smartbulb.py' 26
now paste that code here 27
Ctrl+X >> Save it run it>> sudo python smartbulb.py 28
there we go 29
now you can see the present status of the bulb 30
of the bulb 31
now go to your dashboard and 32
make changes in the buttons state and see the bulb 33
following your commands!