Relay problem notes

Viewed 18 times

I’m working on my first python/hardware project and I want to create a simple (or at least I thought it was simple) cabinet lock, which will lock/unlock when certain RFID tags are approached to the RFID reader. I have the RFID side of code working, however I’m struggling with the lock part. I have a solenoid lock (this) powered by a 12V/1A power supply and I want to control the solenoid lock with RPI GPIO pins via a single channel relay. I have the following code:

#!/usr/bin/env python3
#GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM)
import time
import RPi.GPIO as GPIO
pin = 13

print "Unlocking"
GPIO.setup(pin, GPIO.OUT)
print "Locking"

Now, when I run this code, the LED on the relay blinks, however, the solenoid lock does not move at all. It’s not a problem of the power supply – when I power the lock directly from the PSU, it “unlocks”. Please see the picture of the wiring, maybe it is wrong, but I was following one of the guides on the Internet and it should be fine. My guess is that the code is wrong, because when I manually wire GND wire (from RPi) to the IN1 pin on the relay, the solenoid activates and lock gets unlocked. Any help would be appreciated, I’m a newbie and I’ve never worked with electronics before…

Many thanks!


 New contributor
  • 3
    We need a link to the specs of the “single channel relay” and a clear photo of the wiring. – joan 8 hours ago
  • At a first glance the relay module seems to have an opto-isolator, like the dozens of others who have asked similar questions these are unsuitable for use with the Pi. See raspberrypi.stackexchange.com/a/100014/8697 – Milliways 3 hours ago
  • Hello @jnko, Welcome and nice to meet you. Ah, let me. Your relay seems to be an Arduino compatible “High level trigger” relay. For this kind of relay, a Low level signal is used to switch off, a High signal (for Arduino, High means higher than roughly 4.2V) to switch on. Now, if you are using Rpi to switch off this Arduino relay, you have a problem, because Rpi’s GPIO High signal is at most 3.3V, therefore CANNOT switch off the relay. In other words, Rpi GPIO High is not high enough to switch of this relay. There are a couple of workarounds, including the following: / to continue, … – tlfong01 11 mins ago
  • Rpi 5V relay problem and solution references: (1) raspberrypi.stackexchange.com/questions/99988/… (2) raspberrypi.stackexchange.com/questions/83494/…. If you do not have a spec of the relay, you might like to do trial and errors. Good luck. Best Regards, Yours sincerely, Ta and cheers, 🙂 – tlfong01 6 mins ago

Categories: Uncategorized

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: