1

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

GPIO.setmode(GPIO.BCM)
print "Unlocking"
GPIO.setup(pin, GPIO.OUT)
GPIO.output(pin,GPIO.HIGH)
time.sleep(4)
print "Locking"
GPIO.output(pin,GPIO.LOW)
GPIO.cleanup(pin)

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!

wiring

jnko
  • 11
  • 2
  • 3
    We need a link to the specs of the "single channel relay" and a clear photo of the wiring. – joan Feb 27 '20 at 17:39
  • 1
    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 https://raspberrypi.stackexchange.com/a/100014/8697 – Milliways Feb 27 '20 at 22:33
  • 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 Feb 28 '20 at 02:07
  • Rpi 5V relay problem and solution references: (1) https://raspberrypi.stackexchange.com/questions/99988/rpi-gpio-controlling-5v-relay-problem (2) https://raspberrypi.stackexchange.com/questions/83494/gpio-pin-low-not-low-enough-aka-how-to-zero-the-tension-on-a-low-pin/83512. 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 Feb 28 '20 at 02:11
  • 1
    The code may or may not be wrong. We need 2 things to help you: A simple [schematic](https://raspberrypi.meta.stackexchange.com/questions/2074/how-do-i-add-a-schematic-to-my-question), and specifications on your relay - even a link to the vendor's page or a model number may suffice. – Seamus Feb 28 '20 at 03:11
  • I skimmed your program and guess you might have fallen into a common newbie trap, ie. "CLEAN UP GPIO OR EXIT PROGRAM TOO SOON". The trap is that all GPIO output pins would reset to input mode, therefore not driving any thing any more. There are many troubleshooting tricks: (1) Use a while loop to repeatedly switch on, then sleep, then off forever. (2) Do NOT exit program, just test the one off switch on step, and later test the switch off step. I have some demo solenoid lock posts your might like to read: / to continue, ... – tlfong01 Feb 28 '20 at 05:47
  • "Solenoid/Lock/Value Tests - rpi.org.forum discussions": (1) https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=230325&start=25#p1413583 (2) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=230984&start=25#p1417740 (3) https://www.raspberrypi.org/forums/viewtopic.php?f=37&t=231541&p=1418054#p1418054 (4) https://www.raspberrypi.org/forums/viewtopic.php?f=91&t=230325&start=25#p1414587. – tlfong01 Feb 28 '20 at 05:48

0 Answers0