Devices & Components
Arduino Uno Rev3
IR sensor (Receive) 3 leg.
Breadboard (generic)
IR LED
5 mm LED: Green
Male/Male Jumper Wires
LCD 20x4 with I2C module
Software & Tools
Arduino IDE
Project description
Code
Speed Test - Speeduino!
arduino
Get the speed of toy die-cast cars!
1/* Speed Test for Hot Wheels(R) die cast toy cars. 2 3 IR LEDs with 220ohms resistors. IR sensor without any resistor. 4 5 This project works ok at the bench when you throw the car smoothly. 6 But in the "real world" of a Hot Wheels tracks the sensors are not fast reading enough. Please share your 7 improvements if you find a more precise and fast reading sensors! 8 9 Project creator Fabio Coelho - Rio de Janeiro - Brazil Dec2018. 10 11 Some improvements were made following inputs from fellow members at Arduino Project hub. Thank You! 12 13 14 */ 15 16#include <LiquidCrystal_I2C.h> 17//We use a LCD 20x4 with an I2C module. It really keeps wiring simple... 18#include <Wire.h> 19 20LiquidCrystal_I2C lcd(0x27,20,4);// I2C adress 21 22const int ledPin = 12; 23byte irPinA = 4; 24byte irPinB = 5; 25byte irValA; 26byte irValB; 27float diff; // store timeScnd minus timeFirst 28float vel; // calculated speed 29unsigned long timeFirst;// IR sensor at irPinA 30unsigned long timeScnd;// IR sensor at irPinB 31float speedConst = 453.6; // ((distance between IR sensors in mm) x 3600)/1000)to convert mm/millis to km/h) 32 // In This project we have 126mm between IR sensors 33 34 35byte customChar0[8] = { //some art for the LCD screen 36B01000, 37B01100, 38B01110, 39B01111, 40B01110, 41B01100, 42B01000, 43B00000 44}; 45 46void configLCD(){ //function to config the LCD display 47 48lcd.createChar(0, customChar0); 49lcd.setCursor(0,0); 50lcd.write(0); 51lcd.write(0); 52lcd.write(0); 53lcd.write(0); 54lcd.write(0); 55lcd.setCursor(5,0); 56lcd.print("SPEED TEST"); 57lcd.setCursor(15,0); 58lcd.write(0); 59lcd.write(0); 60lcd.write(0); 61lcd.write(0); 62lcd.write(0); 63lcd.setCursor(0,1); 64lcd.print("P1:"); 65lcd.setCursor(0,2); 66lcd.print("P2:"); 67lcd.setCursor(0,3); 68lcd.print("Speed:"); 69 70} 71 72void setup() 73{ 74pinMode(irPinA, INPUT); 75pinMode(irPinB, INPUT); 76pinMode(ledPin, OUTPUT); 77//Serial.begin(9600);noneededt 78lcd.init(); 79lcd.backlight(); 80configLCD(); 81digitalWrite(ledPin, HIGH); //Green LED HIGH: ok to next ride. 82 83}//end setup 84 85 86void loop() 87{ 88 irValA = digitalRead(irPinA); 89 irValB = digitalRead(irPinB); 90 91 if (irValA == LOW){ 92 timeFirst = millis(); 93 digitalWrite(ledPin, LOW); 94 delay(30); 95 } 96 97 if (irValB == LOW){ 98 timeScnd = millis(); 99 diff = timeScnd - timeFirst; 100 vel = speedConst / diff;//get the Speed converted from mm/millis to km/h. 101 /* 102 use only if you want 103 Serial.print("T1: "); 104 Serial.println(timeFirst); 105 Serial.print("T2: "); 106 Serial.println(timeScnd); 107 Serial.print("Diff: "); 108 Serial.println(diff); 109 Serial.print("Speed: "); 110 Serial.println(vel); 111 */ 112 113 lcd.setCursor(6, 1); 114 lcd.print(timeFirst); 115 lcd.setCursor(6, 2); 116 lcd.print(timeScnd); 117 lcd.setCursor(6,3); 118 lcd.print(vel); 119 lcd.print("km/h"); 120 delay(5000); 121 lcd.clear(); 122 configLCD(); 123 digitalWrite(ledPin, HIGH); 124 } 125 126}//end Loop
Downloadable files
Speed Tracker - Speeduino.
Project Schematics
Speed Tracker - Speeduino.

Speed Tracker - Speeduino.
Project Schematics
Speed Tracker - Speeduino.

Comments
Only logged in users can leave comments