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

Arduino UNO-Based Ultrasonic Distance Detection with Servo Control and TFT Display Feedback

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Ultrasonic Distance Detection with Servo Control and TFT Display Feedback

Circuit Documentation

Summary

This circuit integrates various components to perform a range of functions including logic level conversion, distance measurement, magnetic field detection, and visual display. The core of the circuit is an Arduino UNO microcontroller, which interfaces with an HC-SR04 Ultrasonic Sensor for distance measurement, a QMC5883L Magnetometer for magnetic field detection, an ili9341 TFT display for visual output, and a Servomotor SG90 for actuation. A logic level converter (Adafruit TXB0108) is used to safely interface devices with different voltage levels.

Component List

Adafruit TXB0108 8-channel Bi-directional Logic Level Converter

Arduino UNO

ili9341 TFT Display

QMC5883L Magnetometer

HC-SR04 Ultrasonic Sensor

Servomotor SG90

Wiring Details

Adafruit TXB0108 8-channel Bi-directional Logic Level Converter

Arduino UNO

ili9341 TFT Display

QMC5883L Magnetometer

HC-SR04 Ultrasonic Sensor

Servomotor SG90

Documented Code

/*
 * This Arduino Sketch uses an HC-SR04 Ultrasonic Sensor to measure distance.
 * If an object is detected within 10 cm, a buzzer sounds and an LED lights up.
 */

#define TRIG_PIN 9
#define ECHO_PIN 10
#define BUZZER_PIN 11
#define LED_PIN 11
#define DISTANCE_THRESHOLD 10 // Distance threshold in cm

void setup() {
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  long duration, distance;
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  duration = pulseIn(ECHO_PIN, HIGH);
  distance = (duration / 2) / 29.1;
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println(" cm");
  if (distance < DISTANCE_THRESHOLD) {
    digitalWrite(BUZZER_PIN, HIGH);
    digitalWrite(LED_PIN, HIGH);
  } else {
    digitalWrite(BUZZER_PIN, LOW);
    digitalWrite(LED_PIN, LOW);
  }
  delay(500);
}

Note: The code provided has a minor issue with pin definitions. BUZZER_PIN and LED_PIN are both defined as pin 11, which may not be the intended behavior. This should be reviewed and corrected as necessary.