This project combines two simpler projects – Sonic Distance Sensor and LED Status Lights to create a parking guide you could use in your garage. The status LEDs change from Green to Yellow and then to Red as the car pulls in closer to the Sonic Distance Sensor on the wall.
TODO: Change to LED 3 color that comes with 17-in-1 kit.
Test!
Clean up code
Create component page for sonic distance sensor
3 component version has dial indicator to be tunable
// Sketch for Parking Guide - 2 component
// Components: https://www.iotprojectkit.com/
// https://www.iotprojectkit.com/
// Tutorial: https://www.iotprojectkit.com/
// Sketch for HC-SR01 Sonic Distance Sensor
// Component: TBD
// Tutorial: TBD
// 10 is really close, 80 is someone walking up
// PWM for brightness?
// NOT YET TESTED
// Change to the pin numbers to the pin on the Traffic Light for the color
#define GREEN_PIN 13
#define YELLOW_PIN 12
#define RED_PIN 11
#define TRIGGER_PIN 9
#define ECHO_PIN 10
#define RED_PIN 13
float duration;
float distance;
float green_threshold = 40;
float yellow_threshold = 30;
float red_threshold = 10;
// The setup() section runs once when the Arduino starts up
void setup() {
pinMode(RED_PIN, OUTPUT);
pinMode(YELLOW_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = (duration*.0343)/2;
Serial.print("Distance Detected: ");
Serial.println(distance);
if (distance < red_threshold) {
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(YELLOW_PIN, HIGH);
digitalWrite(RED_PIN, HIGH);
} else if (distance < yellow_threshold ) {
digitalWrite(GREEN_PIN, LOW);
digitalWrite(YELLOW_PIN, HIGH);
digitalWrite(RED_PIN, HIGH);
} else if (distance < green_threshold) {
digitalWrite(GREEN_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(RED_PIN, HIGH);
} else {
digitalWrite(GREEN_PIN, LOW);
digitalWrite(YELLOW_PIN, LOW);
digitalWrite(RED_PIN, LOW);
}
delay(200);
}
