I’m writing this tutorial to highlight the advantages of using the
DQ10rly I2C-HAT, a relay board specifically designed as an add-on for Raspberry Pi, rather than using a generic relay board.
- easy install, just mount
DQ10rly I2C-HATon top of Raspberry Pi using the
mounting kit, no wires required
- stackable up to 16x, use the
mounting kit extensionto stack more
DQ10rly'son the same Raspberry Pi, just like in this
- the only GPIOs that are used are the I2C bus pins(GPIO02 and GPIO03), all the other GPIOs are free to use for other purposes.
STEP1: Install relay board
STEP2: Enable I2C bus
Enable I2C bus on your Raspberry Pi using ‘raspi-config’ command. Open a terminal and type:
Then go to Interfacing Options->Advanced Options->I2C and select YES when asked ‘Would you like the ARM I2C interface to be enabled?’ and also select YES when asked ‘Would you like the I2C kernel module to be enabled by default?’
STEP3: Install software packages
sudo apt-get install python-smbus
sudo apt-get install python-pip
sudo pip install raspihats
STEP4: Write a python control script
This is a simple script that will toggle relay channel 0 (2s on, 2s off):
from raspihats.i2c_hats import DQ10rly from time import sleep b = DQ10rly(0x50) print("Use 'Ctrl+C' to stop program.") try: while True: b.dq.channels = True sleep(2) b.dq.channels = False sleep(2) except KeyboardInterrupt: pass finally: b.dq.channels = False
STEP5: Control a led strip
Materials needed besides Raspberry Pi with relay board DQ10rly mounted on top:
- Led strip 12V/24W
- Power supply 12V/25W
- Power cable
Danger high voltage!!! Make sure you know what you are doing when connecting the power cable to the power supply.
DQ10rly can handle up to 5A of current per relay channel, in this case the led strip required current vis 24W/12V=2A. Be careful that your led strip current consumption does not surpass 5A and that your led strip power supply can handle it.
Connect led strip to relay channel 0: