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

Arduino Mega 2560 Controlled Ultrasonic Sensor with Servo, LCD Display, and Interactive Pushbutton

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Controlled Ultrasonic Sensor with Servo, LCD Display, and Interactive Pushbutton

Circuit Documentation

Summary

The circuit in question is designed to interface an HC-SR04 Ultrasonic Sensor, a Servo motor, a red LED, a Pushbutton, an LCD screen (16x2 with I2C interface), a Resistor, and a Buzzer with an Arduino Mega 2560 microcontroller. The circuit is likely intended for distance measurement, user input via a pushbutton, visual feedback through an LED and an LCD screen, and auditory signaling using a buzzer. The servo motor's position can be controlled, potentially in response to sensor readings or button presses.

Component List

HC-SR04 Ultrasonic Sensor

Servo

LED: Two Pin (red)

Pushbutton

LCD screen 16x2 I2C

Resistor

Arduino Mega 2560

Buzzer

Wiring Details

HC-SR04 Ultrasonic Sensor

Servo

LED: Two Pin (red)

Pushbutton

LCD screen 16x2 I2C

Resistor

Buzzer

Documented Code

Arduino Mega 2560 Code

// Define pin numbers
const int ledPin = 9;      // Pin for the LED
const int buttonPin = 2;   // Pin for the push button

// Variable to hold the button state
int buttonState = 0;

void setup() {
  // Initialize the LED pin as an output
  pinMode(ledPin, OUTPUT);
  
  // Initialize the button pin as an input with pull-up resistor
  pinMode(buttonPin, INPUT_PULLUP);
  
  // Start serial communication for debugging
  Serial.begin(9600);
}

void loop() {
  // Read the state of the button
  buttonState = digitalRead(buttonPin);
  
  // Check if the button is pressed
  if (buttonState == LOW) { // Button pressed (active LOW)
    // Turn on the LED
    digitalWrite(ledPin, HIGH);
    Serial.println("Button Pressed: LED ON");
  } else {
    // Turn off the LED
    digitalWrite(ledPin, LOW);
    Serial.println("Button Released: LED OFF");
  }
  
  // Small delay for stability
  delay(100);
}

HC-SR04 Ultrasonic Sensor Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

LCD screen 16x2 I2C Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

Buzzer Code

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

(Note: The code for the HC-SR04 Ultrasonic Sensor, LCD screen, and Buzzer is not provided with specific functionality and contains only the template structure. The actual implementation should be added based on the desired functionality of the circuit.)