- Relay is an electrically operated switch.
- Relay is used to isolate electrical load.
- Two configuration
1.NO(normally open).
2.NC(normally close). - Relay have a coil that is energized by 12v , when coil energized switching action takes place.
BC548
- 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.
Hardware Required
- Relay.
- BC548 Transistor.
- Push-button.
- Raspberry pi.
- Breadboard
Circuit

Code
- Create a new text file “Relay.py” by typing the following
nano Relay.py
- 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.