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.
- Arduino Uno
- Push Button
- Relay
- Wire Jumper
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