Circuit Documentation
Summary
This circuit utilizes an Arduino UNO microcontroller to control an HC-SR04 Ultrasonic Sensor and an Adafruit LED Sequin. The ultrasonic sensor measures distance, and based on the measured distance, the LED's brightness is adjusted. If an object is detected within 15 cm, the LED is set to full brightness. If the object is between 15 cm and 30 cm, the LED is set to half brightness. If the object is farther than 30 cm, the LED is turned off.
Component List
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
HC-SR04 Ultrasonic Sensor
- Description: A sensor used to measure distance by using ultrasonic waves.
- Pins: VCC, TRIG, ECHO, GND
Adafruit LED Sequin - Emerald Green
- Description: A small, bright LED.
- Pins: +, -
Wiring Details
Arduino UNO
- 5V: Connected to VCC of HC-SR04 Ultrasonic Sensor
- GND: Connected to GND of HC-SR04 Ultrasonic Sensor
- D7: Connected to + of Adafruit LED Sequin
- D10: Connected to TRIG of HC-SR04 Ultrasonic Sensor
- D11: Connected to ECHO of HC-SR04 Ultrasonic Sensor
HC-SR04 Ultrasonic Sensor
- VCC: Connected to 5V of Arduino UNO
- GND: Connected to GND of Arduino UNO
- TRIG: Connected to D10 of Arduino UNO
- ECHO: Connected to D11 of Arduino UNO
Adafruit LED Sequin - Emerald Green
- +: Connected to D7 of Arduino UNO
- -: Not connected (assumed to be connected to GND internally)
Code
#define TRIG_PIN 10
#define ECHO_PIN 11
#define LED_PIN 7
void setup() {
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
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;
if (distance < 15) {
analogWrite(LED_PIN, 255); // Full brightness
} else if (distance < 30) {
analogWrite(LED_PIN, 128); // 50% brightness
} else {
analogWrite(LED_PIN, 0); // LED off
}
delay(100);
}
This code initializes the pins for the ultrasonic sensor and the LED. In the loop function, it measures the distance using the ultrasonic sensor and adjusts the LED brightness based on the measured distance.
