Sunday, October 21, 2018

Arduino : Intermediate - Control Relay with Push Button

Description
Demonstrates the use of relay and control via push button. The relay will turn ON when push button is push and OFF after push button release.

List Item
  1. Arduino Uno 
  2. Push Button
  3. Relay
  4. Wire Jumper

Wiring Diagram


Coding

const int pushButton = 7;
const int relay = 8;


void setup()
{
  pinMode(pushButton,INPUT_PULLUP);
  pinMode(relay, OUTPUT);
}

void loop()
{
  int reading = digitalRead(pushButton);

  if(reading == HIGH)
  {
    digitalWrite(relay, HIGH);
  }

  else
  {
    digitalWrite(relay, LOW);
  }
}

No comments:

Post a Comment