I am a Python noob, and recently purchased a 2 channel relay module from sunfounder. I wired it up to my Pi, and the relay turned on and stays on. I am wondering if any one can provide my with the simplest Python code to flip the relay on and off.

Extra Info: I am connected to pins 2 (5V), 6 (Ground), and 9 (Ground) on a Raspberry Pi Model B.

I followed the instructions


1 Answer 1


First off, your pins are messed up - so you need to connect the Vcc to a 5V pin and the GND to a ground pin. Then you connect your two relays to a GPIO pin. For instance, I connected my two to GPIO 2 and 3. Then use the python scripts supplied by "skiwithpete" on YouTube, see this video Raspberry Pi: 16 Channel Relay how to with example software for automation projects.

  • I have taken the liberty of adding the links to which I believe you are referring to. Please correct me if I am wrong. Feb 1, 2016 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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