Timer Prototype Finished
Primary tabs
February 19, 2014 - OK, I first posted on this project a couple of days ago. I've got a short window to get this working. Liam's science expo is on March 7th, and I need to complete the track (with attached timer) in time so Liam and I can run a set of experiments. So late last night, I managed to finish the prototype of the Arduino timer I plan to mount to the side of the test track. It's all breadboarded now, and I'll probably just use the prototype to run the timing for Liam. After we get some results on paper, I'll worry about turning this into a sturdy version permanently attached to the side of the track.
The hardware work was basically done last week. I just needed to figure out the update to the sketch to figure out how to trigger the timing code using the inputs from the two photo-resistor sensors. The picture here shows the prototype board, as it's currently working. Click the image to enlarge it.
I'm using the following inputs and outputs on the Arduino:
LCD I/O:
RS: Pin 2
EN: Pin 3
D4: Pin 4
D5: Pin 5
D6: Pin 6
D7: Pin 7
Other I/O:
Start/stop button input: digital pin 8
Timing indicator LED: digital pin 13
Start line sensor input: analog pin 0
Finish line sensor input: analog pin 1
I made a short video last night showing how it functions in operation. (This also happens to be my first video uploaded to Youtube. . . hard to believe. What can I say, I'm shy. ;-) )
The power needs of the sensors was a concern during the process. Running the LCD, both sensor inputs and both source LEDs off of the Arduino power wasn't going to work, with a limit of around 50mA for all outputs (realistically, it seemed to tank at about 100mA). So I'm running the two 'lightbeam' LEDs off of an external 350mA, 5V wall wart I had laying around. When I convert this to a boxed project, I'll probably run everything off of it. The other key parameter, as it operates now, is the way I detected the light beam being broken. Since the photoresistors output is highly dependent on the ambient light in the room, I decided to go full range on the analog inputs (so, a range from 0-1023) and then opted to calculate the detection range each time the board is powered up or reset. But what light drop would cause the detection. After playing with the system in a dark room and then in a room in full daylight from nearby windows, the best option was a drop of about 8%. This way the system automatically adjusts to ambient light conditions, at least when I restart the board, and it successfully detects the beam being broken whether the room is in full light or complete darkness. In sketch #30, I added these calculated threshold sensor values to the right end of the second row on the LCD screen. (I removed the secondary indicator of the 'blinking' variable that had been displayed in the bottom right corner of the display, since the timing "+" sign on the first row took care of that feedback.) Take a look at the video; you should be able to see what I mean. |
This is the code I used in the prototype, which I called 'Sketch 30' //Twin Lightbeam Timer with LCD Output, by Jay Oyster /* //Include the LCD Library //Constants for button pin input, LED counting pin output, light sensor threshold value, and the sketch build number //Initialize an LCD object //Variables for the read and display of photoresistor values, to track the state of a button input and and LED output, and to store timing values void setup() //Print my name //Initialize start button //Calculate the optical sensor trigger levels for the counter void loop() //Clear the line if (((buttonState == LOW && lastButtonState == HIGH) || (lightLevel1 <= threshold1)) && blinking == false){ // check for a high to low transition startTime = millis(); // store the start time //Turn on timing indicator else if (((buttonState == LOW && lastButtonState == HIGH) || (lightLevel2 <= threshold2)) && blinking == true){ // check for a high to low transition elapsedTime = millis() - startTime; // store elapsed time //Clear previous time // use modulo operator to get fractional part of time // pad in leading zeros - wouldn't it be nice if lcd.print(fractional); // print fractional part of time } else{ // blink routine - blink the LED while timing if ( (millis() - previousMillis > interval) ) { if (blinking == true){ |