Relay Control


Description

The applications of embedded systems range from controlling small DC motors to use in industrial automation. When it comes to controlling high voltage devices, microcontrollers often depend on Relays to drive them. Relays act as a bridge between the low power microcontrollers and high voltage devices. In this project, we are going to control a Relay using Arduino UNO to drive a high current load like a motor. Although the project is explained to drive a simple motor. Okay let's see how it works.

Components Required

 1. Arduino UNO    * 1
 2. Relay   * 1
 3. 1N4007 PN Junction Diode    * 1
 4. 2N2222 NPN Transistor    * 1
 5. Push Button   * 1
 6. Power Supply(12V)    * 1
 7. Bread Board    * 1
 8. Jumper Wires   * 1

 Circuit Diagram



Program

const int buttonPin = 12;
const int transistorPin = 7;

int buttonState = 0;

void setup() 
{
 
 pinMode(buttonPin, INPUT_PULLUP);
 pinMode(transistorPin, OUTPUT);
 
}

void loop() 
{
 
 buttonState = digitalRead(buttonPin);
 
 if (buttonState == LOW) 
  {
  
   digitalWrite (transistorPin, HIGH); 
    
  }
 
 else 
  {
   
   digitalWrite (transistorPin, LOW);  

  }
  
}