Hi all!
--------------------------------------------------------------------------------------------------------------------------------------
Speedometer:
The idea was to be familiar with the game and start KISS. So, before decide where to place in the Layout, I plan for a "portable" one ( so it can be used also on a modular layout during meetings ?)
The Micro used is the little and cheap Nano, more than enough for this simple application:
http://www.ebay.com/itm/5PCS-USB-Nano-V3-0-ATmega328-16M-5V-Micro-controller-CH340G-board-For-Arduino-A-/201152975734?ssPageName=ADME:L:OU:IT:3160
Mechanically will be based on a plastic bar that holds two of this IR sensor at the ends :
http://www.ebay.com/itm/Infrared-reflective-Photoelectric-Switch-IR-Barrier-Line-Track-sensor-TCRT5000L-/310536079942?ssPageName=ADME:L:OU:IT:3160
I've order also some spare TCRT5000 sensors (in case it works) to install somewhere along the tracks in future.
If these sensors demonstrate not enough sensible at reasonable distance ... I've order also a couple of :
http://www.ebay.com/itm/Smart-car-Obstacle-avoidance-Infrared-Sensor-module-Reflective-photoelectric-/400494756580?ssPageName=ADME:L:OU:IT:3160
The "brain" can be positioned on fascia (cab or cards holders?) and I plan a little LCD display and an audio board to generate voice pre-recorded messages.
Project parts and cost (more or less! ) :are :
- 1 x Arduino Nano = $4.
- 2 x IR sensors boards = $3.
- 1 x LCD display 2lines x 20 char= $5
- 1 Audio board ( option) = $3
---------------------------------------------------
TOTAL = $15
http://www.ebay.com/itm/IIC-I2C-TWI-SP-I-Serial-Interface1602-16X2-Character-LCD-Module-Display-Blue-/310565065847?ssPageName=ADME:L:OU:IT:3160
Sound voice generator card as option .... to warn the operators !
http://www.ebay.com/itm/ISD1820-Sound-Voice-Recording-Playback-Module-With-Mic-Sound-Audio-Loudspeaker-/200958077647?ssPageName=ADME:L:OU:IT:3160
Project
To clock the interrupt pin D2 ( interrupt 0) , as the Arduino's internal timer is not totally reliable, I try the PWM analog output D3 wired directly to the interrupt pin D2.
The analog PWM outputs did have a very steady square wave of 490Hz. The duty cycle is determined by the value written to the analog pin. (i.e. - 0 is zero volts, 127 is a 50% duty cycle, 255 is a logic high/5V).
Also I will limit max time measurement between 2 sensors to max 60 seconds and sensors distance is "hardware configured" to measure the train’s speed over 1/50 or 1/100 ( jumper selectable or just wired on software ) of a scale mile (or Km) both displayed on LCD.
Means you need to install the 2 IR sensor at a specific distance (depending on Scale and resolution wanted)
The sensor spacing for N and HO is listed here:
Scale - Scale mile (inch) - 1/50 mile(inch) - 1/100 mile(inch)
N 396.000 7.920 3.960
HO 728.276 14.566 7.283
scale - Scale Km(cm) - 1/50 km (cm) - 1/100 Km (cm)
N 625.00 12.50 6.25
HO 1149.43 22.99 11.49
For example, in N scale if you use the 1/100 scale mile interval, you need to place the sensors 3.96 inches apart.
If your particular scale is not listed you need to calculate the proper interval by dividing 63360 (the number of inches in a mile) by your scale’s ratio, and then dividing that result by the interval chosen (50, 100).
The accuracy of the unit depends upon how precisely the sensors are spaced!
Sensor spacing errors can be minimized by choosing the longest spacing that is practical for your layout and scale
Also, IR sensors use available ambient light. Mounting them in tunnels or dark corners of the layout is not working. It is best to pick a well lit section of the layout where the light source comes from above and ‘inside’ the layout. If the light source is ‘outside’ the layout a person walking by may trigger the unit. (these info are from TCS TrainSpeed page)
Speed calculation is very simple. For example:
- if sensors are installed at 1/100 scale miles:
10 / (time in 1/10secs ) ) x 3,6 = Km/h ; Km/h x 1,6093 = Miles / h - If sensors are at 1/50 of scale miles:
- 5 / (time in 1/10secs ) ) x 3,6 = Km/h ; Km/h x 1,6093 = Miles / h
Note: To have a better speed resolution display my interrupt routine counts 1/10 of second in place of seconds.
At the end I've finally find some time to write some software (well, not really nice, I admit, but at least seems working well)
As a first test, I've connected two buttons in place of the two IR sensors.
And software take care for now just of a left_right direction (from sensor 1 to sensor 2)
Next step will be complete the sketch with a possibility to detect a run in reverse direction on same track.
And ... make a better SW "status machine" !
Also I've connected a LED to display 1/10 sec clock during measurement, and for the moment use the Serial Monitor in place of the final LCD Library ...
Well, lot of more free time to find to complete, but... I've fun for now, and this was the primary scope!
See attached the sketch listing at present stage of evolution ... (download the PDF file)
Later a ... second section... but no promise about schedule!
Enzo Fortuna
Modeling the friendly Espee in Italy
http://enzofortuna.altervista.org/ http://valleybeforesilicon.blogspot.com/
http://sp-layouts.blogspot.com/