8 Relays Module - EN
8 Relays Module - EN
Have fun!
Relays are used to control AC circuits, switching them ON or OFF. The
relay is one of the most important control elements. It is an electrical switch
that responds to a signal received from the microcontroller (like in
Atmega328P or Raspberry Pi). Relays are widely used in remote control,
communications, mechatronics devices, power electronic devices, etc. They
also can be used to separate powerful voltage/current electronics (like AC
or DC motors, or any AC device, etc.), from microelectronics (like
microcontrollers, sensors, etc.).
Inside relay, there is one mechanical switch (three yellow metal rods, with
one in the middle that is bent to one side, and is movable), which is
controlled by the second element of the electromagnet (yellow cylinder), as
shown on the image below:
In the non active state, the switch is in the OFF state, NC pin is connected
with common pin, and NO is unconnected. When the power is being
connected to the electromagnet (via transistor and rectifier diode), this
moves the switch to the active state, thus connecting the common pin to NO
pin.
The 8 relays module consists of eight relays capable of handling up to 5A
50V AC and 5A 30V DC. For every relay, there are aslo a LED, two
resistors, a NPN transistor, a rectifier diode and optocoupler.
On the DC side of the board there are ten pins, eight input pins for eight
relays, one for power supply (VCC) and one for ground (GND). There is
also a three pin jumper for selecting power supply (external or VCC power
supply). On the AC side there is three pin screw terminal header, where
pins are labeled as: Normally Closed - NC pin, Common pin and Normally
Open - NO pin.
Specifications:
Maximum AC: 5A 50V
Maximum DC: 5A 30V
Contact Type: Both: Normally Closed – NC, Normally Opened - NO
Dimensions: 50 x 140mm [1.97 x 5.5in]
The pinout
External power supply jumper is used for selecting the power supply input. If
it is left unconnected, the relays will not be powered up at all, but the LEDs
on-board the module will still blink. If you connect the JD-VCC pin and VCC
pin together (with two pin jumper), the the module will be powered up from
the VCC pin.
If you want to use external power supply, remove two pin jumper, and
connect the positive side of external power supply to JD-VCC pin, and
ground pin of external power supply with ground pin of the module.
If you did not install Arduino IDE already, this is how to do it. Go to the link:
https://www.arduino.cc/en/Main/Software and download installation file for
your operating system platform.
For
After installation of the first script, run the second called "install.sh" script. In
terminal, run the following command:
sh install.sh
After the installation of these scripts, go to the All Apps to find the Arduino
IDE installed.
Next thing is to check if your PC can detect the microcontroller board. Open
freshly installed Arduino IDE, and go to:
Tools > Board > {your board name here}
{your board name here} should be the Arduino/Genuino Uno, as you can
see on the image below:
After this you need to select the port on which the microcontroller board is
connected. Go to: Tools > Port > {port name goes here}
If you connected the microcontroller board on the usb port, there should be
several port names. Because we are using Arduino IDE on Windows, port
names are like on image below.
For Linux users, port name is “/dev/ttyUSBx” for example, where “x”
represents integer number between 0 and 9, for instance.
Connecting the module with Atmega328P Board
Connect the 8 relays module with the microcontroller board with as shown
on the following connection diagram:
Sketch example:
void loop() {
for (uint8_t i = 0; i < 8; i++) {
digitalWrite(relays[i], HIGH); // Turn ON
}
delay(1000);
for (uint8_t i = 0; i < 8; i++) {
digitalWrite(relays[i], LOW); // Turn OFF
}
delay(1000);
}
When you upload the sketch to the microcontroller board, you should hear
clicks from relays. When the relay changes state from active to rest and vice
versa, you can hear switching clicks.
First you have to install operating system on the Raspberry Pi, then to set it
up so that you can use it in the “headless” mode. Headless mode enables
you to remotely connect to the Raspberry Pi, without the need for PC
screen Monitor, mouse and keyboard. You can find detailed explanation in
the free eBook "Raspberry Pi Quick Startup Guide", which can be found on
our site:
https://www.az-delivery.de/products/raspberry-pi-kostenfreies-e-book?ls=en
NOTE 2: As you can see in the red rectangle on the connection diagram,
external power supply jumper is connected, connecting JD-VCC pin with
VCC pin. This means that the 8 relays module will be powered up from
Raspberry Pi board via VCC pin.
Python script:
import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
Relays = (14, 15, 18, 23, 24, 25, 8, 7)
for i in range(8):
GPIO.setup(Relays[i], GPIO.OUT)
print('[press ctrl+c to end the script]')
try: # Main program loop
while True:
for i in range(8):
GPIO.output(Relays[i], GPIO.HIGH)
print('Normally opened pin is HIGH')
sleep(1) # Waitmode for 1 second
for i in range(8):
GPIO.output(Relays[i], GPIO.LOW)
print('Normally opened pin is LOW')
sleep(1) # Waitmode for 1 second
# Scavenging work after the end of the program
except KeyboardInterrupt:
print('Script end!')
finally:
GPIO.cleanup()
Save the script by the name "Relays.py" into default script directory. To run
the script open terminal in the directory where you saved the script and run
the following command:
python3 Relays.py
The output should look like the output on the image below:
https://az-delivery.de
Have Fun!
Impressum
https://az-delivery.de/pages/about-us