Reverse Parking Indicator
This project is a replication of modern day car parking sensors. This project will display the inches the nearest object is, will change beeps depending on how far the object is and will change lights depending on how far the object is.
Supplies
the supplies needed to create this project is
Switch
Red, green and yellow lights
Buzzer
7 segment display
Switch
Distance sensor
Audrino
Breadboard
4 330 resistors
Jumper cables
CIrcuit
Code
int a = 4;
int b = 5; int c = 6; int d = 7; int e = 8; int f = 3; int g = 2; const int trig = 10; const int echo = A2; int led3 = 13; int led2 = 12; int led1 = 9; int buzz = 11;
void setup() { Serial.begin(9600); pinMode(trig, OUTPUT); pinMode(echo, INPUT); pinMode(a, OUTPUT); pinMode(b, OUTPUT); pinMode(c, OUTPUT); pinMode(d, OUTPUT); pinMode(e, OUTPUT); pinMode(f, OUTPUT); pinMode(g, OUTPUT); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(buzz, OUTPUT); } void zero() { digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, HIGH); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(1000); }
void one() { digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(buzz, HIGH); digitalWrite(led3, HIGH); digitalWrite(led2, HIGH); digitalWrite(led1, HIGH); delay(1000); }
void two() { digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, HIGH); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, HIGH); digitalWrite(g, LOW); digitalWrite(buzz, HIGH); delay(100); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(100); digitalWrite(buzz, HIGH); digitalWrite(led3, HIGH); digitalWrite(led2, HIGH); digitalWrite(led1, HIGH); delay(100); }
void three() { digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, LOW); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(300); digitalWrite(buzz, HIGH); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, HIGH); delay(300); }
void four() { digitalWrite(a, HIGH); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(500); digitalWrite(buzz, HIGH); digitalWrite(led3, LOW); digitalWrite(led2, HIGH); digitalWrite(led1, HIGH); delay(500); }
void five() { digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(700); digitalWrite(buzz, HIGH); digitalWrite(led3, LOW); digitalWrite(led2, HIGH); digitalWrite(led1, LOW); delay(700); }
void six() { digitalWrite(a, LOW); digitalWrite(b, HIGH); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(900); digitalWrite(buzz, HIGH); digitalWrite(led3, HIGH); digitalWrite(led2, HIGH); digitalWrite(led1, LOW); delay(900); }
void seven() { digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, HIGH); digitalWrite(g, HIGH); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(1100); digitalWrite(buzz, HIGH); digitalWrite(led3, HIGH); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(1100); }
void eight() { digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, LOW); digitalWrite(e, LOW); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(buzz, LOW); digitalWrite(led3, LOW); digitalWrite(led2, HIGH); digitalWrite(led1, LOW); delay(1300); }
void nine() { digitalWrite(a, LOW); digitalWrite(b, LOW); digitalWrite(c, LOW); digitalWrite(d, HIGH); digitalWrite(e, HIGH); digitalWrite(f, LOW); digitalWrite(g, LOW); digitalWrite(buzz, LOW); digitalWrite(led3, HIGH); digitalWrite(led2, LOW); digitalWrite(led1, LOW); delay(1500); }
void loop(){ long duration, distance; digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); duration = pulseIn(echo, HIGH); distance = (duration/74)/2; Serial.println(distance); if (distance<1) zero(); else if (distance>= 1 && distance<2 ) one(); else if (distance>=2 && distance <3) two(); else if (distance>=3 && distance <4) three(); else if (distance>=4 && distance <5) four(); else if (distance>= 5 && distance <6) five(); else if (distance>=6 && distance <7) six(); else if (distance>=7 && distance <8) seven(); else if (distance>= 8 && distance <9) eight(); else if (distance>=9 ) nine(); }