Components and supplies
IR sensor (Receive) 3 leg.
Breadboard (generic)
IR LED
5 mm LED: Green
Arduino UNO
Male/Male Jumper Wires
LCD 20x4 with I2C module
Apps and platforms
Arduino IDE
Project description
Code
Speed Test - Speeduino!
arduino
Get the speed of toy die-cast cars!
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
NerdFatherRJ
2 years ago
Video already published! Hope you enjoy.
Anonymous user
2 years ago
Hey I love the project! Just wondering where you got your sensors or where is a good place to get IR sensors/LEDs
HANGOVER101
2 years ago
if i use IR ( transmitter and receiver) with this code is it still work?
NerdFatherRJ
2 years ago
Hello! it is a simple and cheap 3 leg IR receiver. I think you will find in any eletronic stuff shop.
Anonymous user
2 years ago
Hello! I'm trying to build this project for my final project in my robotics and electronics class. My setup looks correct and I copied your code. Everything seems to work except that the speed from my sensors are not popping up on the LCD 20x4 with I2C module. Does anyone have any tips on how I can solve this issue?
magicChristian
2 years ago
Hello Fleary, the first question is: did you ever get something on your display? if not, than the initialization is probably not correct: it needs a lot of waiting and the correct line number. if yes, than the line to write is never executed. This is my best to help you without having your code. Christian Am 06.02.2019 um 23:48 schrieb Hackster.io:
magicChristian
2 years ago
Fleary, if wiring and supply is stable than try to add some delays into your code. <the LCD controller specially the old HD448.. are rather slow and Arduino library do not check the busy signal. Some commands, like clear display, need quite a time to get it daone internal. If you add a delay of 2 ms before next write it may help.
Anonymous user
2 years ago
Christian, I did get something to display. I'm using the code that was given by Fabio. It occasionally works, but not consistently.
Anonymous user
2 years ago
When I take the IR sensors out it displays random speeds. When the IR sensors are in, no speed is displayed.
NerdFatherRJ
2 years ago
Hello! Did You load into program code the correct Display Library "LiquidCrystal_I2C.h" and its setup? It is not the one already included on Arduino Ide software. You need to download and install this other one. #include <LiquidCrystal_I2C.h> //We use a LCD 20x4 with an I2C module. It really keeps wiring simple... #include <Wire.h> LiquidCrystal_I2C lcd(0x27,20,4); // I2C adress
Anonymous user
2 years ago
i'm getting an error code when i put in the code the exact way that it was shown the error code is stating : Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno" sketch_sep27a:28:4: error: expected constructor, destructor, or type conversion before '(' token lcd(0x27,20,4);// I2C adress ^ \\\\ORION\\Students\\Electronics\\\\Documents\\Arduino\\sketch_sep27a\\sketch_sep27a.ino: In function 'void configLCD()': sketch_sep27a:56:1: error: 'lcd' was not declared in this scope lcd.createChar(0, customChar0); ^ \\\\ORION\\Students\\Electronics\\22bgarrett\\Documents\\Arduino\\sketch_sep27a\\sketch_sep27a.ino: In function 'void setup()': sketch_sep27a:86:1: error: 'lcd' was not declared in this scope lcd.init(); ^ \\\\ORION\\Students\\Electronics\\22bgarrett\\Documents\\Arduino\\sketch_sep27a\\sketch_sep27a.ino: In function 'void loop()': sketch_sep27a:121:5: error: 'lcd' was not declared in this scope lcd.setCursor(6, 1); ^ exit status 1 expected constructor, destructor, or type conversion before '(' token
Anonymous user
2 years ago
Hola Fabio, I'm new to arduino and I would like to make this speedometer for my car circuit. I put all together but I have problems with the code, it gives error for the I2C adress, I can't understand if it's somethng that i have to import (if yes how) or something that I have to insert from the circuits codes. The error say that there is no such file or directory. Help me ermano.... Best wishes and thank you.
Anonymous user
2 years ago
Hello, Fabio. I find your project very interesting. You've mentioned something about missing fast cars. I believe the code of the *loop* function should be changed to improve the project. For example, the last line of the first *if* block is a *delay*, which stops the program for 50 milliseconds. Also there are some other lines of code doing some serial and lcd output. Could it be that the fast cars are leaving the track before the second sensor can be read? What I would suggest is to let all output related code after the capture is finished. Of course, this would not solve the problem if its source is infrared sensor response time. The code follows my text. Of course, the code still can be improved to avoid being stuck in the second *while* loop. I have not mounted the circuitry, nor have compiled the code to check for correctness. So please forgive any mistake. Cheers. void loop() { // Wait for the first pin to become LOW while (digitalRead(irPinA) != LOW) ; timeFirst = millis(); digitalWrite(ledPin, LOW); // Wait for the second pin to become LOW while (digitalRead(irPinB) != LOW) ; timeScnd = millis(); // Do the output stuff Serial.print("T1: "); Serial.println(timeFirst); lcd.setCursor(6, 1); lcd.print(timeFirst); diff = timeScnd - timeFirst; vel = speedConst / diff;//get the Speed converted from mm/millis to km/h. Serial.print("T2: "); Serial.println(timeScnd); Serial.print("Diff: "); Serial.println(diff); Serial.print("Speed: "); Serial.println(vel); lcd.setCursor(6, 2); lcd.print(marcaB); lcd.setCursor(6,3); lcd.print(vel); lcd.print("km/h"); delay(5000); cleanResultsLCD(); digitalWrite(ledPin, HIGH); }
NerdFatherRJ
2 years ago
Thanks for the inputs. I will try this later.
javidambra
2 years ago
Hi: very nice project, I love this kind of thing, when adults and kids both learn a lot. I'm pretty sure that the problem with fast cars are all those serial and LCD prints in the if's. try once you detect the first sensor trig, do nothing until you detect the second (put a timeout just in case) the do all the math...
NerdFatherRJ
2 years ago
Thank again for all of you! I certanly will work on inputs You brought.
Anonymous user
2 years ago
This looks so fun and I can't wait to try with my daughter's speed tube cars.
Anonymous user
2 years ago
Hello Mr. Formula Kids, If you use a loop to get the edges of the both light gates this cant be very fast. You have to use an interrupt if one of the light gates ist detecting the car and if you use the Timer of microseconds it should work also with superfast cars. Simple calculation 20 km/h = 20000m/3600s = 5,5 m/s = for a distance of 20cm = 1/5m we get about 1 second !! A simpler approach without interrupt: shortest possible lopp to wait for first light gate, getting actual time 1, than shortest loop waiting for second light gate and getting time 2 . And after this do all calculating and drive the display
Anonymous user
2 years ago
Hey, i'm planning to do this project but I don't have a lcd display with 12C module, how would i do this with a regular lcd display? also, what code do i use? THANK YOU!
NerdFatherRJ
2 years ago
Hello! I Think you can do it. The wiring scheme you can find easy on internet but I do really recommend You to get a Display with I2C because it uses only four wires to connect. The display without the module is a mess of wiring! (and you loose many digital ports only to mange it).
Anonymous user
2 years ago
Hi NerdFatherRJ ! I agree with lcbarcellos. You should try to avoid processing as much as possible between the two pulses. Also you should consider using Interruptions. On the Uno, you have two pins which can be used in this special mode. Interruptions are not refreshed the same way as the regular IO. It's used when you need fast acquisition and when you want to be sure not to loose an external signal. See https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/ And if you have some furious Hotwheel driver in the house, you might consider a doppler sensor. Some are cheap and Arduino compatible. It's the technology used for "grownup" cars so surely fast enough but you'll have to dig a bit more into code Enjoy and Nice project :)
NerdFatherRJ
2 years ago
Thanks for the input. So many things I need to learn.
laurebayfield
2 years ago
Very good project, maybee you could uppload it with lasers or press sensors by puting them on the track?? Otherwise, continue like that it's very good!!!
Anonymous user
2 years ago
Nice project! I wish I had this when I was a kid (and my kids are too old now -- *sigh*). One idea to improve the response time is to use lasers. I'm thinking of something like these laser diodes: https://www.amazon.com/DTOL-Laser-Diode-Module-650nm/dp/B00R73MC1S or: https://www.amazon.com/KY-008-Copper-Sensor-Module-Arduino/dp/B01CG52K1S/ And then a fast photodiode or such for the sensor. I'm also wondering if something like an old computer mouse (with a thumbwheel) would work... I believe they react pretty quickly as the thumbwheel is spun. Just some ideas. Hope this helps! :-)
Anonymous user
2 years ago
I understand your concern. The little laser diodes I was referring to are less than 5 milliwatt -- the same as a consumer grade laser pointer -- so they shouldn't be a problem. But I understand your desire to err on the safe side. :-) I was also going to post about using interrupts to trigger the timer, but I see RaphaelM beat me to the punch. I'd look at using lasers AND interrupts to make a nice system. Hey, please keep us posted as to who the project evolves! Good luck!
NerdFatherRJ
2 years ago
Thanks for this comment. I am thinking about using lasers but I feel little worried to let my kid play with laser light, lied on the floor and looking the cars from its perspective...kkk Anyway this seems to be a more accurate solution and it is on the table for future experience.
Anonymous user
4 years ago
Hola Fabio, I'm new to arduino and I would like to make this speedometer for my car circuit. I put all together but I have problems with the code, it gives error for the I2C adress, I can't understand if it's somethng that i have to import (if yes how) or something that I have to insert from the circuits codes. The error say that there is no such file or directory. Help me ermano.... Best wishes and thank you.
laurebayfield
5 years ago
Very good project, maybee you could uppload it with lasers or press sensors by puting them on the track?? Otherwise, continue like that it's very good!!!
Anonymous user
5 years ago
i'm getting an error code when i put in the code the exact way that it was shown the error code is stating : Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno" sketch_sep27a:28:4: error: expected constructor, destructor, or type conversion before '(' token lcd(0x27,20,4);// I2C adress ^ \\\\ORION\\Students\\Electronics\\\\Documents\\Arduino\\sketch_sep27a\\sketch_sep27a.ino: In function 'void configLCD()': sketch_sep27a:56:1: error: 'lcd' was not declared in this scope lcd.createChar(0, customChar0); ^ \\\\ORION\\Students\\Electronics\\22bgarrett\\Documents\\Arduino\\sketch_sep27a\\sketch_sep27a.ino: In function 'void setup()': sketch_sep27a:86:1: error: 'lcd' was not declared in this scope lcd.init(); ^ \\\\ORION\\Students\\Electronics\\22bgarrett\\Documents\\Arduino\\sketch_sep27a\\sketch_sep27a.ino: In function 'void loop()': sketch_sep27a:121:5: error: 'lcd' was not declared in this scope lcd.setCursor(6, 1); ^ exit status 1 expected constructor, destructor, or type conversion before '(' token
Anonymous user
6 years ago
Hello! I'm trying to build this project for my final project in my robotics and electronics class. My setup looks correct and I copied your code. Everything seems to work except that the speed from my sensors are not popping up on the LCD 20x4 with I2C module. Does anyone have any tips on how I can solve this issue?
Anonymous user
2 years ago
Christian, I did get something to display. I'm using the code that was given by Fabio. It occasionally works, but not consistently.
Anonymous user
2 years ago
Hello Fleary, the first question is: did you ever get something on your display? if not, than the initialization is probably not correct: it needs a lot of waiting and the correct line number. if yes, than the line to write is never executed. This is my best to help you without having your code. Christian Am 06.02.2019 um 23:48 schrieb Hackster.io:
Anonymous user
2 years ago
Fleary, if wiring and supply is stable than try to add some delays into your code. <the LCD controller specially the old HD448.. are rather slow and Arduino library do not check the busy signal. Some commands, like clear display, need quite a time to get it daone internal. If you add a delay of 2 ms before next write it may help.
NerdFatherRJ
2 years ago
Hello! Did You load into program code the correct Display Library "LiquidCrystal_I2C.h" and its setup? It is not the one already included on Arduino Ide software. You need to download and install this other one. #include <LiquidCrystal_I2C.h> //We use a LCD 20x4 with an I2C module. It really keeps wiring simple... #include <Wire.h> LiquidCrystal_I2C lcd(0x27,20,4); // I2C adress
Anonymous user
6 years ago
Hey, i'm planning to do this project but I don't have a lcd display with 12C module, how would i do this with a regular lcd display? also, what code do i use? THANK YOU!
NerdFatherRJ
2 years ago
Hello! I Think you can do it. The wiring scheme you can find easy on internet but I do really recommend You to get a Display with I2C because it uses only four wires to connect. The display without the module is a mess of wiring! (and you loose many digital ports only to mange it).
deppeler
6 years ago
This looks so fun and I can't wait to try with my daughter's speed tube cars.
NerdFatherRJ
6 years ago
Hello, I did some improvements on Code, following Lcbarcellos and RaphaelM inputs. I Let de Serial and LCD printing being displayed only after the main instructions and the program work better. I also tried substitute "If" statements for "while" statements as suggested. After doing some tests I feel the "ifs" more consistent. I do not know why due to my total dumbness in the deep realms of programming and eletronics...:/ Here is the code with "while" statements for comparison: void setup() { pinMode(irPinA, INPUT); pinMode(irPinB, INPUT); pinMode(ledPin, OUTPUT); //Serial.begin(9600); Keep off if not needed //Inicializa o LCD e o backlight lcd.init(); lcd.backlight(); configLCD(); digitalWrite(ledPin, HIGH); }//end setup void loop() { //Wait first pin to become low while (digitalRead(irPinA) != LOW); timeA = millis(); digitalWrite(ledPin, LOW); delay(50); while (digitalRead(irPinB) != LOW); timeB = millis(); diff = timeB-timeA; vel = 453.6 / diff;//calcula a velocidade em km/h 126mm /* use only for debugging Serial.print("TimeA: "); Serial.println(timeA); Serial.print("TimeB: "); Serial.println(timeB); Serial.print("Diff: "); Serial.println(diff); Serial.print("Vel: "); Serial.println(vel); */ lcd.setCursor(6, 1); lcd.print(timeA); lcd.setCursor(6, 2); lcd.print(timeB); lcd.setCursor(6,3); lcd.print(vel); lcd.print("km/h"); delay(5000); lcd.clear(); configLCD(); digitalWrite(ledPin, HIGH); }//end Loop So, thanks again for the inputs.
NerdFatherRJ
6 years ago
Thank again for all of you! I certanly will work on inputs You brought.
javidambra
6 years ago
Hi: very nice project, I love this kind of thing, when adults and kids both learn a lot. I'm pretty sure that the problem with fast cars are all those serial and LCD prints in the if's. try once you detect the first sensor trig, do nothing until you detect the second (put a timeout just in case) the do all the math...
magicChristian
6 years ago
Hello Mr. Formula Kids, If you use a loop to get the edges of the both light gates this cant be very fast. You have to use an interrupt if one of the light gates ist detecting the car and if you use the Timer of microseconds it should work also with superfast cars. Simple calculation 20 km/h = 20000m/3600s = 5,5 m/s = for a distance of 20cm = 1/5m we get about 1 second !! A simpler approach without interrupt: shortest possible lopp to wait for first light gate, getting actual time 1, than shortest loop waiting for second light gate and getting time 2 . And after this do all calculating and drive the display
Anonymous user
6 years ago
Hey I love the project! Just wondering where you got your sensors or where is a good place to get IR sensors/LEDs
Anonymous user
2 years ago
if i use IR ( transmitter and receiver) with this code is it still work?
NerdFatherRJ
2 years ago
Hello! it is a simple and cheap 3 leg IR receiver. I think you will find in any eletronic stuff shop.
Anonymous user
6 years ago
Hi NerdFatherRJ ! I agree with lcbarcellos. You should try to avoid processing as much as possible between the two pulses. Also you should consider using Interruptions. On the Uno, you have two pins which can be used in this special mode. Interruptions are not refreshed the same way as the regular IO. It's used when you need fast acquisition and when you want to be sure not to loose an external signal. See https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/ And if you have some furious Hotwheel driver in the house, you might consider a doppler sensor. Some are cheap and Arduino compatible. It's the technology used for "grownup" cars so surely fast enough but you'll have to dig a bit more into code Enjoy and Nice project :)
NerdFatherRJ
2 years ago
Thanks for the input. So many things I need to learn.
Anonymous user
6 years ago
Hello, Fabio. I find your project very interesting. You've mentioned something about missing fast cars. I believe the code of the *loop* function should be changed to improve the project. For example, the last line of the first *if* block is a *delay*, which stops the program for 50 milliseconds. Also there are some other lines of code doing some serial and lcd output. Could it be that the fast cars are leaving the track before the second sensor can be read? What I would suggest is to let all output related code after the capture is finished. Of course, this would not solve the problem if its source is infrared sensor response time. The code follows my text. Of course, the code still can be improved to avoid being stuck in the second *while* loop. I have not mounted the circuitry, nor have compiled the code to check for correctness. So please forgive any mistake. Cheers. void loop() { // Wait for the first pin to become LOW while (digitalRead(irPinA) != LOW) ; timeFirst = millis(); digitalWrite(ledPin, LOW); // Wait for the second pin to become LOW while (digitalRead(irPinB) != LOW) ; timeScnd = millis(); // Do the output stuff Serial.print("T1: "); Serial.println(timeFirst); lcd.setCursor(6, 1); lcd.print(timeFirst); diff = timeScnd - timeFirst; vel = speedConst / diff;//get the Speed converted from mm/millis to km/h. Serial.print("T2: "); Serial.println(timeScnd); Serial.print("Diff: "); Serial.println(diff); Serial.print("Speed: "); Serial.println(vel); lcd.setCursor(6, 2); lcd.print(marcaB); lcd.setCursor(6,3); lcd.print(vel); lcd.print("km/h"); delay(5000); cleanResultsLCD(); digitalWrite(ledPin, HIGH); }
NerdFatherRJ
2 years ago
Thanks for the inputs. I will try this later.
JonS99
6 years ago
Nice project! I wish I had this when I was a kid (and my kids are too old now -- *sigh*). One idea to improve the response time is to use lasers. I'm thinking of something like these laser diodes: https://www.amazon.com/DTOL-Laser-Diode-Module-650nm/dp/B00R73MC1S or: https://www.amazon.com/KY-008-Copper-Sensor-Module-Arduino/dp/B01CG52K1S/ And then a fast photodiode or such for the sensor. I'm also wondering if something like an old computer mouse (with a thumbwheel) would work... I believe they react pretty quickly as the thumbwheel is spun. Just some ideas. Hope this helps! :-)
NerdFatherRJ
2 years ago
Thanks for this comment. I am thinking about using lasers but I feel little worried to let my kid play with laser light, lied on the floor and looking the cars from its perspective...kkk Anyway this seems to be a more accurate solution and it is on the table for future experience.
JonS99
2 years ago
I understand your concern. The little laser diodes I was referring to are less than 5 milliwatt -- the same as a consumer grade laser pointer -- so they shouldn't be a problem. But I understand your desire to err on the safe side. :-) I was also going to post about using interrupts to trigger the timer, but I see RaphaelM beat me to the punch. I'd look at using lasers AND interrupts to make a nice system. Hey, please keep us posted as to who the project evolves! Good luck!
NerdFatherRJ
6 years ago
Video already published! Hope you enjoy.
NerdFatherRJ
2 years ago
Hello, I did some improvements on Code, following Lcbarcellos and RaphaelM inputs. I Let de Serial and LCD printing being displayed only after the main instructions and the program work better. I also tried substitute "If" statements for "while" statements as suggested. After doing some tests I feel the "ifs" more consistent. I do not know why due to my total dumbness in the deep realms of programming and eletronics...:/ Here is the code with "while" statements for comparison: void setup() { pinMode(irPinA, INPUT); pinMode(irPinB, INPUT); pinMode(ledPin, OUTPUT); //Serial.begin(9600); Keep off if not needed //Inicializa o LCD e o backlight lcd.init(); lcd.backlight(); configLCD(); digitalWrite(ledPin, HIGH); }//end setup void loop() { //Wait first pin to become low while (digitalRead(irPinA) != LOW); timeA = millis(); digitalWrite(ledPin, LOW); delay(50); while (digitalRead(irPinB) != LOW); timeB = millis(); diff = timeB-timeA; vel = 453.6 / diff;//calcula a velocidade em km/h 126mm /* use only for debugging Serial.print("TimeA: "); Serial.println(timeA); Serial.print("TimeB: "); Serial.println(timeB); Serial.print("Diff: "); Serial.println(diff); Serial.print("Vel: "); Serial.println(vel); */ lcd.setCursor(6, 1); lcd.print(timeA); lcd.setCursor(6, 2); lcd.print(timeB); lcd.setCursor(6,3); lcd.print(vel); lcd.print("km/h"); delay(5000); lcd.clear(); configLCD(); digitalWrite(ledPin, HIGH); }//end Loop So, thanks again for the inputs.