How Too Peripherals Python Tutorials

Testing Raspberry PI JBtek 8 Channel DC 5V Relay Module

Post Reply
raspberrypi / howtoo     Views: 3300Prev .. Next
Testing Raspberry PI JBtek 8 Channel DC 5V Relay ModulePosted: Tuesday, May 8, 2018 [15:33:54] - 1
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
Connecting and testing JBtek 8 Channel DC 5V Relay Module.

Post 25808034 Image 1

Running a test program remotely VIA login-less SSH.

Post 25808034 Image 2


https://youtu.be/-EQ2_xwX3fY



Frame is 3D printed.There's no place like ~
JBtek 8 Channel DC 5V Relay Module software and connectionPosted: Tuesday, May 8, 2018 [18:20:00] - 2
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
Connecting a module is quite easy:

Post 25818000 Image 1
Based on connection writing a Python script:
View Code#!/usr/bin/python
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

# initialized pins

pinList = [2, 3, 4, 17, 27, 22, 10, 9]

# loop through pins and set GPIOs accordingly

for i in pinList:
GPIO.setup(i, GPIO.OUT)
GPIO.output(i, GPIO.HIGH)

# sleep between turning on in the main loop

SleepTimeL = 1
try:
GPIO.output(2, GPIO.LOW)
print "One"
time.sleep(SleepTimeL);
GPIO.output(3, GPIO.LOW)
print "Two"
time.sleep(SleepTimeL);
GPIO.output(4, GPIO.LOW)
print "Three"
time.sleep(SleepTimeL);
GPIO.output(17, GPIO.LOW)
print "Four"
time.sleep(SleepTimeL);
GPIO.output(27, GPIO.LOW)
print "Five"
time.sleep(SleepTimeL);
GPIO.output(22, GPIO.LOW)
print "Six"
time.sleep(SleepTimeL);
GPIO.output(10, GPIO.LOW)
print "Seven"
time.sleep(SleepTimeL);
GPIO.output(9, GPIO.LOW)
print "Eight"
time.sleep(SleepTimeL);
GPIO.cleanup()
print "End of program"

# End program cleanly with keyboard
except KeyboardInterrupt:
print " Quit"

# Clean-up
GPIO.cleanup()

script will lid-up all lights and on exit turn them off.

Now write individual scripts for every relay:
View Code#!/usr/bin/python
# turn relay 1 "ON"
import RPi.GPIO as GPIO
GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)
pinList = [2]

for i in pinList:
GPIO.setup(i, GPIO.OUT)

try:
GPIO.output(2, GPIO.LOW)
print "turned on"

except KeyboardInterrupt:
print "Quit"
GPIO.cleanup()


View Code#!/usr/bin/python
# turn relay 1 "OFF"
import RPi.GPIO as GPIO
GPIO.setwarnings(False)

GPIO.setmode(GPIO.BCM)
pinList = [2]

for i in pinList:
GPIO.setup(i, GPIO.OUT)

try:
GPIO.output(2, GPIO.HIGH)
print "turned off"

except KeyboardInterrupt:
print "Quit"

GPIO.cleanup()


Create ON/OFF scripts for every relay and check them with simple Perl script:
View Code#!/usr/bin/perl
@a = (1..8);
foreach $i (@a) {
print "Relay $i\n";
print "On\n";
`python /home/pi/Desktop/relay/$i.on.py`;
sleep(1);
print "Off\n";
`python /home/pi/Desktop/relay/$i.off.py`;
sleep(1);
} ## FOREACH END

on video above this Perl script ran remotely.There's no place like ~
Raspberry Pi and relay module frame 3D model file.Posted: Tuesday, May 8, 2018 [18:30:13] - 3
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
This post is part of the Smart Garden project at:
www.codemacs.com/raspberr..
Here is a link to STL file for the Raspberry Pi and relay module frame:
www.codemacs.com/download..
Enjoy!There's no place like ~
RE: Testing Raspberry PI JBtek 8 Channel DC 5V Relay ModulePosted: Wednesday, May 9, 2018 [21:42:58] - 4
Posted by:ItweetForStuffPosts: 1
Any chance you could make a stl that would fit a RPI Zero? Or could you make the original file available?
Thanks
RE: Testing Raspberry PI JBtek 8 Channel DC 5V Relay ModulePosted: Wednesday, May 9, 2018 [21:45:31] - 5
rootPosted by:rootMember Since:
June 16 2010
Posts: 357
Sure, when I'll get a RPi zero - I'll make one.
CheersThere's no place like ~
raspberrypi / howtooPrev .. Next
 
Post Reply
Home - Raspberrypi: How Too Peripherals Python Tutorials
Our Telegram Group