I am building a race timer and tree for slot car drag racing. I am using optocoupler modules to read when the car is blocking the sensors at the start of the race. Once the car is staged and blocking the sensor I have separate nano that operates a drag racing tree that shows that the car is staged with led lights and drops through three yellow bulbs and then a green one. Each yellow bulb has a 500 millisecond delay and when the bottom yellow bulb lights it has a 500 millisecond delay then it sends a signal to my uno that the race has started. The cars leave and run through three optocouplers then an final one at the finish line.
THE PROBLEM : I need to get a time stamp at the exact time the cars leave the staging sensor and when the first block the three sensors along the track and finally the exact time they block the finish sensor.
Being new to arduino I’ve tried everything I can to get this to work but nothing is accurate enough. Need to find millis when stage sensor has a falling edge and a rising edge on the rest of the sensors to be able to do some math and display time intervals from the start to the finish and from start to sensors on the other three sensors.
Any help would be awesome and thanks in advance.
I have changed the code so much to try and get this to work. Really need a way to capture the millis when a sensor first reads high then I can get a good code. I’ve tried if statements and from what I can tell with my ociliscope depending on where the arduino is in the code I get a trigger to read from 5 to 20 milliseconds. Some kind of interrupt where I can read the millis or micros seamed to be the ticket but I can’t figure it out. I’d like to have an accuracy of around .001 to .003. Thank you.
How do you determine that the time you are getting from the Arduino is not accurate? How do you measure the actual time that you compare to the reported time?
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
Post a schematic.
Post an image of your project.
Which Micro Controller are you using?
Is this simulator code?
Please describe the problem better then you just did.
I am using 2 Chanel’s on the oscilloscope one is triggered when sensor goes from low to high and one is is triggered on an output pin that digitalWrites high when that event is true. I am new to this forum. But when I figure out how to post a picture I will post a picture of my fastest times and my slowest times.
Yellow is sensor trigger and blue is D/O pin trigger. This has about 3 ms delay. My readings range from half a ms to around 20 ms between both. I would think this is because of where in the loop the arduino is when the event occurs. It seems like the form is only going to let me post one picture at a time.
I have tried the pin change interrupts but my problem is when the cars pass through the optocouplers the car breaks the beam and an interrupt occurs then the car leaves the beam and a second interrupt occurs. I just need the micros at the exact time that the first interrupt goes from high to low on that edge and I don’t need the second interrupt on that sensor at all. Then the car goes down the track to another sensor and the procedure repeats on that sensor. Five sensors total and then I can do some math and display a reaction time and elapsed times from start to each sensor.