Devices & Components
Arduino Uno Rev3
Male/Female Jumper Wires
IR proximity sensor
USB-A to Mini-USB Cable
RGB Diffused Common Cathode
Software & Tools
Arduino IDE
Project description
Code
speed_detection101
arduino
here's the code for the speed detector.just upload to arduino after doing the circuitry. sen1 is the first sensors .sen2 is the second.led pin is the pin to the RGB led.The seperation between my sensors was 7.5 cms. you can adjust the speedconst variable for the same.
1//code by YaSh. 2 3int sen1=A0; 4int sen2=A3; 5int ledPin=9; 6unsigned long t1=0; 7unsigned long t2=0; 8float velocity; 9float velocity_real; 10float timeFirst; 11float timeScnd; 12float diff; 13float speedConst=7.5; //in cm. 14void setup() 15{ 16 Serial.begin(9600); 17 pinMode(sen1,INPUT); 18 pinMode(sen2,INPUT); 19 analogWrite(11,LOW); 20 analogWrite(10,HIGH); 21} 22 void loop() 23 { 24 if (analogRead(sen1)<500 && analogRead(sen2)>500) 25 { 26 timeFirst = millis(); 27 digitalWrite(ledPin, LOW); 28 delay(30); 29 } 30 31 if (analogRead(sen2)>500 && analogRead(sen1)<500) 32 { 33 timeScnd = millis(); 34 diff = timeScnd - timeFirst; 35 velocity = speedConst / diff; 36 velocity_real = (velocity*360)/100; //milliseconds to hours and centimetres to kilometeres. 37 delay(30); 38 digitalWrite(ledPin, HIGH); 39 Serial.print("\ 40 the velocity is : "); 41 Serial.println(velocity_real); 42 Serial.print(" km/hr. "); 43 delay(500); 44 digitalWrite(ledPin,LOW); 45 delay(500); 46 } 47 /*else if(analogRead(sen2)<500 && analogRead(sen1)<500) //uncomment if you want to write it. 48 { 49 Serial.print("\ 50 Error:404/ the object is tooo big."); 51 }*/ 52 /* else{Serial.print("\ 53 error:404/no object detected ");} //uncomment if you want to write it.*/ 54 }
speed_detection101
arduino
here's the code for the speed detector.just upload to arduino after doing the circuitry. sen1 is the first sensors .sen2 is the second.led pin is the pin to the RGB led.The seperation between my sensors was 7.5 cms. you can adjust the speedconst variable for the same.
1//code by YaSh. 2 3int sen1=A0; 4int sen2=A3; 5int ledPin=9; 6unsigned long t1=0; 7unsigned long t2=0; 8float velocity; 9float velocity_real; 10float timeFirst; 11float timeScnd; 12float diff; 13float speedConst=7.5; //in cm. 14void setup() 15{ 16 Serial.begin(9600); 17 pinMode(sen1,INPUT); 18 pinMode(sen2,INPUT); 19 analogWrite(11,LOW); 20 analogWrite(10,HIGH); 21} 22 void loop() 23 { 24 if (analogRead(sen1)<500 && analogRead(sen2)>500) 25 { 26 timeFirst = millis(); 27 digitalWrite(ledPin, LOW); 28 delay(30); 29 } 30 31 if (analogRead(sen2)>500 && analogRead(sen1)<500) 32 { 33 timeScnd = millis(); 34 diff = timeScnd - timeFirst; 35 velocity = speedConst / diff; 36 velocity_real = (velocity*360)/100; //milliseconds to hours and centimetres to kilometeres. 37 delay(30); 38 digitalWrite(ledPin, HIGH); 39 Serial.print("\ 40 the velocity is : "); 41 Serial.println(velocity_real); 42 Serial.print(" km/hr. "); 43 delay(500); 44 digitalWrite(ledPin,LOW); 45 delay(500); 46 } 47 /*else if(analogRead(sen2)<500 && analogRead(sen1)<500) //uncomment if you want to write it. 48 { 49 Serial.print("\ 50 Error:404/ the object is tooo big."); 51 }*/ 52 /* else{Serial.print("\ 53 error:404/no object detected ");} //uncomment if you want to write it.*/ 54 }
Downloadable files
Test_Video
A Video showcasing a test run of the project. the speed gets printed in the serial monitor.
Test_Video
Test_Video
A Video showcasing a test run of the project. the speed gets printed in the serial monitor.
Test_Video
here is the circuit schematic
the wires are a bit jumbled. And use the IR sensors whose link is given in the components section and not the one in the CAD.
here is the circuit schematic
Comments
Only logged in users can leave comments