I connected a protective relay to raspberry pi +5V (to relay VCC), GND (to relay GND) and pin 17 ports (to relay IN) . This relay controls a DC motor. The DC motor has a separate power supply connected to it. This power supply goes over the relay thus by opening and closing the relay I will be able to control the motor actually.
When I start raspberry I can run the motor continuously. I wrote a code like below to control the power going to relay but it didn't work. Similar code was working for different pins to control a led component.
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(2 , GPIO.OUT) while True: GPIO.output(2, True) time.sleep(10) GPIO.output(2, False) time.sleep(10)
Is there another way to control the relay without manually disconnecting it from the board?
Edit2: I changed the pin 17 to pin 11 then relay started to working properly. I can now control it by the code
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11 , GPIO.OUT) while True: GPIO.output(11, True) time.sleep(10) GPIO.output(11, False) time.sleep(10)