rhyperion
Posts: 3
Joined: Sat Dec 14, 2013 1:33 am

python 8 channel relay

Sat Dec 14, 2013 1:38 am

hello can some help to get a script to start learning how to us a 8 channel relay board i lock alle over the internet but i cant vind it can some help me

User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: python 8 channel relay

Sat Dec 14, 2013 8:56 am

The software/hardware needed to control a relay board depends on the exact model you plan to use.

Do you have a relay board in mind?


User avatar
joan
Posts: 15949
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: python 8 channel relay

Sat Dec 14, 2013 2:32 pm

To confirm the operation please do the following (at your own risk!)

Leave the green jumper in place.

See http://elinux.org/RPi_Low-level_peripherals for pin numbering.

Connect 5V (Pi pin P1-2) to the left-most pin marked VCC.
Connect ground (Pi pin P1-6) to the pin next to VCC labelled GND.

A LED should light on the board.

Connect 3V3 (Pi pin P1-1) to a wire.

Connect the other end of the wire to IN1 to IN8 in turn. Each relay should operate in turn.

rhyperion
Posts: 3
Joined: Sat Dec 14, 2013 1:33 am

Re: python 8 channel relay

Sun Dec 15, 2013 1:06 am

alle te relays are working but i still need a script to let it work wat is the best script code i can us to learn to make them my self

gordon77
Posts: 6391
Joined: Sun Aug 05, 2012 3:12 pm

Re: python 8 channel relay

Sun Dec 15, 2013 6:29 am

Connect one relay input wire, eg from IN1, to pin P1-24, as well as the 5v and ground you already have connected

Try this in python, started from the gui by
startx
Double click on LXterminal
Type in sudo idle and the press Enter
when the Python Shell window appears
Choose File
Choose New Window
when the new window appears
Type in the code below
Choose run
Choose run module
Save it when it asks

import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(24,GPIO.OUT)
GPIO.output(24,GPIO.HIGH)
time.sleep(2)
GPIO.output(24,GPIO.LOW)

The relay should switch for 2 seconds

Return to “Beginners”