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

Arduino UNO Controlled LED with Pushbutton and Servo Motor

View and Edit Project In Cirkit DesignerImage of Arduino UNO Controlled LED with Pushbutton and Servo Motor

Circuit Documentation

Summary

This circuit consists of an Arduino UNO microcontroller, a pushbutton, a red LED, and three resistors. The Arduino UNO controls the LED and a servo motor based on the state of the pushbutton. When the pushbutton is pressed, the servo motor moves to 90 degrees, and when released, it returns to 0 degrees. The LED is connected to the Arduino and is controlled via a digital pin.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Resistor (200 Ohms)

    • Description: A resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2
  3. Resistor (200 Ohms)

    • Description: A resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2
  4. Resistor (200 Ohms)

    • Description: A resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2
  5. LED: Two Pin (red)

    • Description: A red LED with two pins.
    • Pins: cathode, anode
  6. Pushbutton

    • Description: A pushbutton with four pins.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)

Wiring Details

Arduino UNO

Resistor (200 Ohms)

LED: Two Pin (red)

Pushbutton

Code Documentation

Code Summary

The provided code controls a servo motor and reads the state of a pushbutton. When the pushbutton is pressed, the servo motor moves to 90 degrees. When the pushbutton is released, the servo motor returns to 0 degrees.

Code

#include <Servo.h>

Servo myServo;  // Create a servo object
const int buttonPin = 2;  // Push button pin
const int servoPin = 9;   // Servo control pin
int buttonState = 0;      // Variable to store the button state

void setup() {
  pinMode(buttonPin, INPUT);  // Initialize the push button pin as an input
  myServo.attach(servoPin);   // Attach the servo to the control pin
  myServo.write(0);           // Initialize the servo position to 0 degrees
}

void loop() {
  buttonState = digitalRead(buttonPin);  // Read the state of the push button

  if (buttonState == HIGH) {
    myServo.write(90);  // Move the servo to 90 degrees when the button is pressed
  } else {
    myServo.write(0);   // Move the servo back to 0 degrees when the button is released
  }
}

Code File