For the Charleston Area Model Railroad Club, We have combined our train detector circuit from the scale speedometer project with a LED Crossing Light to make it simple to indicate a train is coming to a crossing. The next step is to add a servo operated crossing bar, and bell sounds, but I’m getting ahead of myself.
Get the IR sensor board at http://arduinotronics.blogspot.com/2017/06/6-channel-infra-red-transceiver-sensor.html
The Circuit:
The detection circuit is the same as the scale speedometer. A TCRT5000 IR LED / Phototransistor pair, with two resistors, connected to an Arduino input (D8). You can lower the value of the Phototransistor pullup resistor to 10k-50k ohm (instead of 80k-100k ohm) to reduce it’s sensitivity to ambient light. Increase the value of the IR LED resistor (68 Ohm) to reduce range. Never drop IR resistor below 68 Ohms.
Become the Maker you were born to be. Try Arduino Academy for FREE!
The output is a off the shelf LED crossbuck with 2 red LED’s and a common anode. I put a 300 ohm resistor on the common and connected to 5v, and connected the two cathodes directly to arduino outputs D11 and D12. Add a second LED Crossbuck (with resistor) to the same outputs for the other side of the crossing. See the video below the code.
The code checks to see if the phototransistor is lit (a 0 or LOW), and activates the lights (LOW is lit, HIGH is off)) as long as it is.
//int sensor1 = 1;
void setup() {
Serial.begin(9600);
pinMode(8, INPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
int sensor1 = digitalRead(8);
Serial.println(sensor1);
if (sensor1 == LOW){
digitalWrite(12, HIGH);
digitalWrite(11, LOW);
delay(1000);
digitalWrite(12, LOW);
digitalWrite(11, HIGH);
delay(1000);
}
}
Nice project. I’m sure the finished product will be very realistic. One suggestion regarding filming. Check the focus on the close ups. Watching the video full screen was hard on the eyes.
I misspoke in the video, the LED's have a common anode, connected to +5vdc through a 300 Ohm resistor, and the two cathodes are connected to Arduino pins 11 & 12, respectively.
Interesting project. Why don't you use a simpler circuit by taking the arduino out completely?
http://www.electroschematics.com/5789/led-flashing-circuit/
Duplicate the TCRT5000 circuit for the sensor on the other side of the level crossing, and duplicate the associated code.
Because the Arduino is running the lights, the servo for the crossing gates, the crossing sounds, and block detection. I prefer code over circuits.
Just finished the board (see above) with the dual track sensor circuitry. Will update the code soon.
Have you added block detection code? I currently use 2 sensors one and the entrance and exit of the block. I am having issues though running 2 trains and keeping each block separate. are you able to assist? Thanks
I'm building a module at the club which will show the full set of block detection, level crossing, and speed detection. Stay tuned ..
How is this project coming along?
In this case would not it be better to combine the two (electronic circuits and arduino)?
Let the arduino do what he does best. Check the sensors, turn the lights and sound on and off and start the servo.