Monday, November 18, 2013

My Opto-coupled Relay Board

First I did the simplest possible test -- wired as shown:

Here's my Python test program:

import time
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

RelaySw1 = 8 # Pi pin 24

GPIO.setup(RelaySw1, GPIO.OUT)

for x in range(4): # tries
GPIO.output(RelaySw1,GPIO.HIGH) # SW on
time.sleep(2)
GPIO.output(RelaySw1,GPIO.LOW) # SW off
time.sleep(2)

GPIO.cleanup()

And running it makes the first relay click on and off 4 times. Big deal. Before testing the relay with house current I wanted to take advantage of the current isolation that the board provides. After a few dim attempts I finally found this at an Arduino site:

 If you want complete optical isolation, connect "Vcc" to Arduino +5 volts but do NOT connect Arduino Ground.  Remove the Vcc to JD-Vcc jumper. Connect a separate +5 supply to "JD-Vcc" and board Gnd. This will supply power to the transistor drivers and relay coils. 
NOTE: Each relay draws about .08A (80 Ma) when on, so if all 8 relays are actuated the board needs about 8*80 or 640 Ma (.64 amps). In this case a separate power supply for the relay board is required. Connect as in preceeding paragraph. A 5 Volt 1 A supply such as THIS  would be good.

Here's the rewired image (that works):


Next, I tried controlling it from my 8-port I2C chip (I don't have 8 spare GPIO pins). But as soon as I plugged jumper into the inactive I2C pin, the relay closed. Oops! this board is "active low." I.e., LOW (ground) turns them ON. This is apparently not a "bug" but a "feature." Ok, I can work it backwards but I'm left with a start-up problem. Let's say my 8 relays control 8 irrigation valves. And I never want them all ON at the same time. So: my very first bit of start-up code has to set all 8 pins HIGH.

Tricky (see http://arduino-info.wikispaces.com/ArduinoPower)! 

BTW: My Python program above is all wrong. The "SW on", "SW off" comments are backwards!

I2C -- another day.

No comments:

Post a Comment