Interrupts and fast analog reading.

Hello:

I am involved in make a train control, the team chose arduino UNO because is easy buy one and the local store gives you one with a introductory course, we have troubles in two aspects.

  1. We chose send a stop signal when a laser beam is interrupted, using a LDR and analogRead, we can stop the train but when the train is so fast, analogRead can’t detect the voltage change, I need improve the analogRead or need alternative, I believe digitalRead is faster, but I don’t now how fast is it and I don’t now how convert the analog signal of LDR in a digital signal using transistors or similar methods.

2)We need a emergency stop, I think using interrupts can make faster an better stop, using the library PciManager, anyone has experience with this library?

Thanks

train is so fast

What speeds do you need? Look at direct port manipulation. You can take about 100 analog readings in .011 seconds with the Arduino as you buy it.

RedCrow: Hello:

I am involved in make a train control, the team chose arduino UNO because is easy buy one and the local store gives you one with a introductory course, we have troubles in two aspects.

1) We chose send a stop signal when a laser beam is interrupted, using a LDR and analogRead, we can stop the train but when the train is so fast, analogRead can't detect the voltage change, I need improve the analogRead or need alternative, I believe digitalRead is faster, but I don't now how fast is it and I don't now how convert the analog signal of LDR in a digital signal using transistors or similar methods.

2)We need a emergency stop, I think using interrupts can make faster an better stop, using the library PciManager, anyone has experience with this library?

Thanks

The main issue here is more likely the LDR itself. LDR's are slow devices and need quite some time (say in the 5ms to 100ms range) to respond to changes in light. Rather you should be looking at phototransistors for this type of application.

  1. Use a phototransistor, not an LDR, as Ben says.

  2. Each analogRead takes about 110us on the Uno, although you can speed it up by increasing the ADC clock frequency, at the expense of reduced resolution. For faster response, you could use the analog comparator. Google “arduino analog comparator library” to find out more.

the train but when the train is so fast, analogRead can't detect the voltage change

This is a problem in the design of your code! Post your code!

Mark

Why use the analogRead anyway. If I read it correct, the laser beam is only used for detecting an interruption. And you are using an phot transistor any. Why not make sure the phototransistor saturates (big enough collector resistor) and connect the pin to an interrupt? Then you should easily be able to detect 10K pulses per second. The rest is up to your code.