0

This is my first Raspberry Pi project. I’m a bit of a noob at the Pi, Python and other types of programming languages, as well as circuits and such. I’m trying to open my sliding gate to the entrance of our house with a Pi, utilising Python.

I have connected the Raspberry Pi3 to my PC via WI-Fi, using the command line over ssh. I have then used jumper wires to connect the Pi’s GPIO pins to the pins on a Arduino Compatible 4 Channel 12V Relay Module. From the Pi to the relay module, I have connected the ground to the ground, 5v to the VCC, and GPIO 17 (BCM) to IN2. On the relay module I have jumper wires connecting from the 2nd channel to the control board of the gate motor at TRG and COM, which I am quite certain are the correct inputs as when I stick the wires in, the gate opens/closes. When I run the code the gate doesn’t open. I am a Python code on the command line, which is to operate a GPIO pin to complete a circuit and open the circuit so that the gate can be opened and closed. I’ll take a picture of the Pi, relay module and gate motor, as well as a picture of the Python code that I am using. I am assuming the Python code is incorrect, or that the Pi cannot give the relay enough power.

Would anybody have any ideas as to how I could make this work?

enter image description here

enter image description here

#!/usr/bin/python

#import required python libraries
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

pinList = [17]

for i in pinList:
    GPIO.setup(i, GPIO.OUT)
    GPIO.output(i, GPIO.HIGH)

def trigger() :
        for i in pinList:
          GPIO.output(i, GPIO.LOW)
          time.sleep(0.5)
          GPIO.output(i, GPIO.HIGH)

try:
    trigger()

except KeyboardInterrupt:
  print " Quit"
GPIO.cleanup()
  • The relays are marked as 12V. Does that mean they need to be powered from 12V? – joan May 29 '18 at 9:12
  • Do you mean 12V of power that the Pi has to give to power the relays or 12V from the motor? – Rob May 29 '18 at 9:54
  • I mean the relays are marked 12V. That usually means the relays need to be powered from 12V to properly energise their coils. The AC/DC power you can switch on and off via the relay contacts is a different matter. – joan May 29 '18 at 10:11
  • I see what you're saying. Sorry for being so nooby, but so how does it receive that voltage? I'm assuming the Pi? Seems like a high voltage that a Pi has to give though, so probably not? – Rob May 29 '18 at 10:23
  • 2
    You worry me when you say connect 5V to 3V3. That is not correct. I meant to use a constant 3V3 source (the 3V3 rail) instead of a GPIO as an input to the relay logic. That would eliminate the Pi software as a problem if it doesn't switch the relay. Be careful what you connect to the Pi pins or GPIO. You can destroy the Pi if you connect the wrong voltage to the wrong point. Personally I think you have the wrong relays. You need ones which can be switched by 3V3 logic and can preferably be powered from 5V or less (so the Pi can supply the relay energiser coil power). – joan May 29 '18 at 11:23
0

The problem lies in a lack of diagnosis tools. Relays require current and voltage. Arduino relays switch on 5V. Raspberry Pi relays switch on 3V. Use a multimeter to measure current and voltage at the TRG input. Compare your successful measurements with the code-driven measurements.

Even if your circuit is nominally producing the right voltage, it could be requiring more current than your setup can supply. For example, if your Raspberry Pi is powered by a USB cable at 500mA, that may not enough to trigger all that circuitry. The fix in that case would be to use a powered USB hub or dedicated power supply for the Pi.

If the blue relays are not switching, then the fix is to replace them with a Raspberry Pi relay such as AdaFruit FeatherWing non-latching relay or Pimoroni Automation Hat. In general, Arduino relays don't work well with Raspberry Pi. When my code doesn't work, I double check with a multimeter.

1

Thanks for all the help. After investigating, it was indeed a problem with the voltages. I obtained a 5V Arduino single channel relay module instead of the 12V and maintained a very similar configuration of wires and it now works. Also the code did not seem to work, but now after changing it, it works perfectly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.