Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Controlled Relay with Pushbutton Activation

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled Relay with Pushbutton Activation

Circuit Documentation

Summary of the Circuit

This circuit is designed to control a relay module using an Arduino UNO based on the state of a pushbutton. The relay can be used to switch higher power devices on and off. The Arduino UNO reads the state of the pushbutton and toggles the relay accordingly. The power supply provides the necessary voltage to the Arduino and the relay module. The circuit includes debouncing for the pushbutton to prevent false triggering due to contact bounce.

Component List

Arduino UNO

Pushbutton

RELAY MODULE

Power Supply

Wiring Details

Arduino UNO

Pushbutton

RELAY MODULE

Power Supply

Documented Code

// sketch.ino
const int buttonPin = 2;    // the number of the pushbutton pin
const int relayPin = 8;     // the number of the relay pin

int buttonState = 0;        // variable for reading the pushbutton status
int relayState = LOW;       // variable for relay state

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, relayState);
}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    relayState = !relayState;
    digitalWrite(relayPin, relayState);
    delay(300); // Debounce delay
  }
}

File Name: sketch.ino

Description: This code sets up the Arduino UNO to read the state of a pushbutton and control a relay. The relay's state is toggled each time the pushbutton is pressed. A debounce delay is included to prevent false triggering.