90 second series - Quick and Easy Ultrasonic + Buzzer + LED project for Arduino

  Рет қаралды 338

Waiduino

Waiduino

Күн бұрын

Пікірлер
@Waiduino
@Waiduino Жыл бұрын
const int echo = 13; const int trig = 12; int LED1 = 2; int LED2 = 3; int LED3 = 4; int LED4 = 8; int LED5 = 9; int buzzer = 5; int duration = 0; int distance = 0; void setup() { pinMode(trig, OUTPUT); pinMode(echo, INPUT); pinMode(LED1, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED4, OUTPUT); pinMode(LED5, OUTPUT); pinMode(buzzer, OUTPUT); Serial.begin(9600); } void loop() { digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); duration = pulseIn(echo, HIGH); distance = (duration / 2) / 28.5; // Turn off all LEDs and the buzzer digitalWrite(LED1, LOW); digitalWrite(LED2, LOW); digitalWrite(LED3, LOW); digitalWrite(LED4, LOW); digitalWrite(LED5, LOW); noTone(buzzer); if (distance < 10) { digitalWrite(LED3, HIGH); tone(buzzer, 850); } else if (distance >= 10 && distance < 20) { digitalWrite(LED2, HIGH); tone(buzzer, 1000); } else if (distance >= 20 && distance < 30) { digitalWrite(LED1, HIGH); tone(buzzer, 1500); } else { // Distance is greater than or equal to 30, turn off the buzzer noTone(buzzer); for (int i = 0; i < 5; i++) { tone(buzzer, 1000); // High pitch digitalWrite(LED4, HIGH); digitalWrite(LED5, LOW); delay(100); noTone(buzzer); digitalWrite(LED4, LOW); digitalWrite(LED5, HIGH); delay(100); tone(buzzer, 500); // Low pitch } } Serial.println(distance); delay(1000); }
Stop Wasting Money on New Batteries! Restore Old AA Batteries Today!
18:17
VIP ACCESS
00:47
Natan por Aí
Рет қаралды 30 МЛН
Леон киллер и Оля Полякова 😹
00:42
Канал Смеха
Рет қаралды 4,7 МЛН
How to make a simple led traffic light circuit
3:56
Project AA
Рет қаралды 18 М.
Everything’s Gonna Be Fine!
7:59
TechLinked
Рет қаралды 265 М.
Announcing GeForce RTX 50 Series | CES 2025 Keynote from CEO Jensen Huang
11:57