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!