- Relay is an electrically operated switch.
- Relay is used to isolate electrical load.
- Two configuration
- Relay have a coil that is energized by 12v , when coil energized switching action takes place.
- BC548 is general purpose NPN bipolar junction transistor.
- This transistor act as a driver to pull the relay ON.
- The base is connected with a micro-controller in series with the resistor.
- Emitter to ground.
- Collector to relay.
- BC548 Transistor.
- Raspberry pi.
- Create a new text file “Relay.py” by typing the following
- Now type the following code
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO. BCM) //BCM is broadcom which specifies the actual pin number considered by broadcom chip GPIO.setwarnings(False) //Ignore warnings GPIO.setup(23, GPIO.IN) //Set pin 23 to be an input pin for push button. GPIO.setup(24,GPIO.OUT) //set pin 24 as output for relay. if GPIO.input(23) == GPIO.LOW: GPIO.output(24,GPIO.HIGH) print ("Relay pulled On")//This line prints the status on to the terminal. time.sleep(3) //delay function pauses the program for 3 secs else: GPIO.output(24,GPIO.LOW) print ("Relay pulled Off") time.sleep(3) GPIO.cleanup() //To reset the pin status
- To run type python Relay.py in the terminal.