Components and supplies
Arduino UNO
Male/Female Jumper Wires
Arduino Parking Sensor
Ultrasonic Sensor - HC-SR04 (Generic)
Apps and platforms
Arduino IDE
Project description
Code
Arduino Parking Sensor Codes
c_cpp
1#define trigpin 12 //We need trig and echo pin for use HC-SR04 Sensor. 2#define echopin 11 3#define clock 10 //Clock, latch and data pins are about 74HC595 shift register 4#define latch 9 // We need to use this pins for our LED's 5#define data 8 //More details at: https://www.arduino.cc/en/tutorial/ShiftOut 6#define buzzer 5 //We are using 1 buzzer for voice to get feedback betwwen obstacles and us 7 8static int range; //We need this variables for use our Ultrasonic Sensor 9static int Time; 10 11byte leds[]={0b10000000, 120b11000000, 130b11100000, 140b11110000, 150b11111000, 160b11111100, 170b11111110, 180b11111111, 190b00000000 }; 20//We need to assign our leds for how many from them will be working in the range for between obstacles and us 21 22void setup() 23{ 24 pinMode(trigpin, OUTPUT); //This code is about what our pins are will be output or input 25 pinMode(echopin, INPUT); 26 pinMode(buzzer, OUTPUT); 27 pinMode(latch, OUTPUT); 28 pinMode(clock, OUTPUT); 29 pinMode(data, OUTPUT); 30} 31 32void loop() 33{ 34 digitalWrite(trigpin, HIGH); //This area about our sensor codes 35 delayMicroseconds(1000); //More details at https://howtomechatronics.com/tutorials/arduino/ultrasonic-sensor-hc-sr04/ 36 digitalWrite(trigpin, LOW); 37 Time = pulseIn(echopin, HIGH); 38 range = (Time/2) / 29.1; 39//After from here we are setting which leds and buzzer will be active at which range, you can change the ranges as you wish 40 if(range>=141){ 41 digitalWrite(latch,LOW); 42 shiftOut(data,clock,MSBFIRST,leds[8]); 43 digitalWrite(latch,HIGH); 44 //We are setting our leds off at over 141cm range 45 } 46 if(range>=121&&range<=140){ 47 digitalWrite(latch,LOW); 48 shiftOut(data,clock,MSBFIRST,leds[0]); //Which led scnerio will be work in this range 49 digitalWrite(latch,HIGH); 50 bzzr(1000); //our buzzer intensity in this range 51 } 52 if(range>=101&&range<=120){ 53 digitalWrite(latch,LOW); 54 shiftOut(data,clock,MSBFIRST,leds[1]); 55 digitalWrite(latch,HIGH); 56 bzzr(700); 57} 58 if(range>=81&&range<=100){ 59 digitalWrite(latch,LOW); 60 shiftOut(data,clock,MSBFIRST,leds[2]); 61 digitalWrite(latch,HIGH); 62 bzzr(500); 63} 64 if(range>=61&&range<=80){ 65 digitalWrite(latch,LOW); 66 shiftOut(data,clock,MSBFIRST,leds[3]); 67 digitalWrite(latch,HIGH); 68 bzzr(300); 69 } 70 if(range>=41&&range<=60){ 71 digitalWrite(latch,LOW); 72 shiftOut(data,clock,MSBFIRST,leds[4]); 73 digitalWrite(latch,HIGH); 74 bzzr(200); 75 } 76 if(range>=21&&range<=40){ 77 digitalWrite(latch,LOW); 78 shiftOut(data,clock,MSBFIRST,leds[5]); 79 digitalWrite(latch,HIGH); 80 bzzr(100); 81 } 82 if(range>=11&&range<=20){ 83 digitalWrite(latch,LOW); 84 shiftOut(data,clock,MSBFIRST,leds[6]); 85 digitalWrite(latch,HIGH); 86 bzzr(50); 87 } 88 if(range>=0&&range<=10){ 89 digitalWrite(latch,LOW); 90 shiftOut(data,clock,MSBFIRST,leds[7]); 91 digitalWrite(latch,HIGH); 92 bzzr(1); 93 } 94 } 95 96void bzzr(int speed){ 97 digitalWrite(buzzer, LOW); 98 static unsigned long time=millis(); 99 if(millis()-time >=speed){ 100 time=millis(); 101 digitalWrite(buzzer, HIGH); 102 } 103 } //This is buzzer function. You dont need to know this for use the parking sensor. 104
Downloadable files
Parking Sensor Schematic
Parking Sensor Schematic
Parking Sensor Schematic
Parking Sensor Schematic
Comments
Only logged in users can leave comments
circleelectronic
0 Followers
•0 Projects
Table of contents
Intro
1
0