Intro: 2 Way Switching Using Raspberry PI and Berry IO
My very first instructable..
I posted a video on youtube on a project I did during my holidays, here's a link:
After much mails and questions from people asking about the details to this 2 way switching, I decided to draft this instructable, to contribute to the community. My first of many..
I'm drafting this after 10 months the video was made. I'm not on site, so I don't have the pictures of the boards, and I might be a bit vague on the parts, schematics, apologies for this, but please do raise your questions, I'll be happy to assist.
Danger: You'll be working with 230vac! BE CAREFUL!
Basically, the bigger picture, wanting to dust off my theory in electronics, I planned to add a bit of convenience to my house. This ranges from controlling my lights, garage, entertainment system, remotely. To brush up on my electronic literature, I wanted to do all this from scratch, component by component..
For the sake of this instructable, I scaled down the contents of this tutorial to addressing only how I made 2 way switching possible via RPI.
There's a valid reason why I went the two way route. Firstly, I don't want to be cuffed down to just technology, without a manual override option. When the internet goes, and I don't have a connection to the RPI, I still want to switch on/off my lights from the wall. Especially seeing that my line is not always solid, especially in peak times.
What you'll need:
ULN2803 darlington array
NT73-2C-S12-DC5V Relay 5v
2 way rocker switch
Light bulb (230vac)
Page on for the 2 way tutorial..
Step 1: 2 Way Switching Basics
(pardon for my challenges with manipulating images in this site..)
(Image courtesy of http://cubus-adsl.dk/eng/multiway_switching.php) - with a bit of editting..
The idea behind 2 way switching is, once you toggle any of the switches, the light will toggle state logically. If the light is on, then it will switch off once any of the switches are toggled. This allows us to control one light from 2 switches, which in our case will be from a wall switch, and our RPI pin.
The image has a light bulb, and 2 switches (S1 and S2). The switches have 2 positions, marked with 0, and 1, respectively.
Walla, that's your simplistic view of a 2 way switch layout.
If the light is off, and you toggle S1, the light will switch on. And if you toggle S2 immediately after that, the light will switch off.
Refer to attached sheet for the ladder logic.
Page on for the RPI notes..
Step 2: RPI Switching
Berry IO (https://github.com/NeonHorizon/berryio) is a RPI software that fas-tracks you to control your pins.
It comes equipped with pin controlling and reading code, an interface for the pin statuses, and more.
Essentially, all you need is a way to control your pins. I started off with Berry IO, and eventually ended up writing my own code using Python. Others have written their code in php, preferences really. Oh, decided to write my own, because, I don't know what BerryIO exposes to the net, and how secure it is. And I wanted granular control on what BerryIO exposes, without missing any fine prints. The best way around that for me was, pick up a python book and write my own. But as a startup, BerryIO is great! Bigups to the developers..
Using BerryIO (skip this if you have an alternative), choose a random GPIO, say, GPIO 3 (I think this pin has the built in LED), set to Output mode, and test, by connecting a LED to GPIO 3, you should be able to switch the LED on/off through BerryIO, with visual feedback.
Once you're able to to toggle the LED, you're ready for the big stuff.
We're planning to control a 5v relay (NT73-2C-S12-DC5V) through our pin. The problem here is, the switching voltage required to toggle this 5v relay is 3.8v+-, and the RPI pins only outputs 3.3v max.
To counter this, I used a Darlington Array ULN2803 to step up the voltage. The tutorial for this is by an instructable user RU4Realz (https://www.instructables.com/id/Controlling-High-P.... He gives schematics on how to step up your voltage using ULN2803. Connect your GPIO3 to the ULN2803.
Connect the output of your ULN2803 to your relay. Page on..
Step 3: Relay Connection
By using the relay, you have isolated the voltage running your RPI (5VDC), to the voltage running your bulb (230VAC).
Connect the output of you Darlington array to your relay, to control the electromagnet, and then ground the relay to the RPI.
If you test the RPI again, the relay should give a "click" sound when you toggle GPIO 3. If this is the case, you're almost there.
Connect your wall plug (AC voltage) to the Common Terminal of your relay. Run the Normally Open (NO) wire from the relay across to one end of your 2 way rocker switch, and run the Normally Closed (NC) wire from the relay to the other end of your 2 way rocker switch.
Connect the rocker switch to your bulb, and bulb to wall (AC).
The diagrams above illustrates how this should be connected.
Switch on the wall power, and test your RPI again.
Walla, there you have it.. Have as much fun as I did in the video.. Toggle the RPI pin, and toggle the 2 way switch, just, go crazy with it..
Notes: Connect a diode between the relay.