Video:
Pics:
I had wanted to drive a relay ( an electronic component that can be used as a electro-mechanical switch to control AC mains) ever since I realised the potential of the GPIO pins on the RPi. The led on/off through the gpio was baby steps towards achieving this.
I stumbled on to a blog by Kevin, with detailed schematic and more ( http://www.susa.net/wordpress/2012/06/raspberry-pi-relay-using-gpio/ ). It should have been dead simple to do what I wanted following the instructions in his blog. I had slightly different components ( transistor was BC547B, diode was 1N4007), but Kevin had in reply to other comments mentioned that any similar transitor/diode should work.
Since yesterday, I had been trying to get it to work. It wouldnt.
To debug I did:
1.Check that the relay itself was working fine by connecting the 5V pin and GND to the relay – and could hear the click of the switch working.
2. Check that the circuit was wired up correct – I was able to light up an LED ( in series with a 470 ohm resistor) with the 5V pin grounding through the transistor.
I went and bought a multi-meter today ( I was trying to avoid it, because I dont want to get too deep) to do more debugging. Couldnt. Posted a comment on Kevin’s blog, asking for help – he replied immediately suggesting I try with another transistor or with decreased resistance connecting the 3V3 pin to the base.
As I was pullnig out the only other transistor that came in the kit I bought on ebay ( a BC557 ) and looked up the pin arrangement for the EBC – I realised that I had previously swapped the E & C pins on the circuit.
I turned the transistor around on the breadboard – and heard the reassuring click of the relay engaging. Moved the 3v3 lead to GPIO and turned on/off realy from webiopi.
Possibilities of this are immense – home automation being key – and I already have a couple of real world needs.
1.Turning on my washing machine – I have a 6 year old washing machine that takes about 2 hours for a quick wash. My wife Janani and I, are only able to wash clothes on weekends – as other days, it takes too long to finish up before we have to rush to the office. So setting up the machine the previous night ( stuff the clothes, detergent ), and through RPi-Relay turn it on at say 5am in the morning – will enable us to wash weekdays too.
2. A friend of mine wants to be able to turn/off lights in his independent house when he and his family are not in town. For security reasons. RPi to the rescue.