2 linked IR detection sensors

I am making a level crossing for my model railway and want one IR Object detection sensor to switch on the lights and another to switch them off, I have got sensor working with lights flashing but now want to go to the next stage but dont know ehere to start with the code.

wondered if anyone can help. Thanks.

Graham

To me (and I'm not a model rail guy, but I believe a number of members are so you will surely get specific help) that the key here is so-called state change detection. That means you don't simply sense the presence or absence of the train, but rather the arrival of it at (say) the left sensor (if train is going left to right) and its departure from the right hand one.

Arrival means the sensor reading went from no detection to detection; departure is the change from detection to no detection.

Arrival at the left would close the gates to cars, and prime the right-hand sensor so that if the gates are closed and the right hand sensor goes from train to not a train, the gates open.

But first, before getting to the details, I suggest looking at the state change detection example here, or a different (active low) version here.

Thanks yes that is exactly what I am tryingtodo but as I am a novice trying to do it in stages. I will look at those links thanks for your help

So you need to show us your circuit schematic, what parts you are using and your code so far.

And a photo or two of your setup. :grin:

Thanks for your reply I am going to try and take the problem a different if I can't I will come back to the forum
Thanks again sorry to trouble you

One thing just struck me- there's a risk of declaring the crossing safe when the exit sensor sees the end of the engine, or the gap between any carriages. We don't want that.... so I think you would need to add a short timer before declaring it's safe when the exit sensor says the train's gone, just in case it hasn't, to make sure we're not in a gap.

Hi thanks for that sorry about the delay in replying. That's a good pont but I was if there was any way of keeping the gate low until it crosses the next sensor.tobtrigger a return to its original positio.

Thanks for your interest in this it is much appreciated

Place the sensors obliquely across the track. :face_with_raised_eyebrow:

1 Like

Now that you mention it, I saw that in a paper I read on model railways quite some years ago. Didn't occur to me that there was a reason for it: now I know.

edit... Managed to track down the site where I saw the diagram below:

Source, which @GreyOwl you may find interesting.

Thanks for all your help on this it is all very useful

1 Like

You're welcome- how are you getting on?

Got the difficult part done lights sorted by making true and then linking sensors now got to link gates in can you tell me what "i" means can't find it anywhere thanks

Grahan

You'll need to give us some context :wink: ... is that in a line of code somewhere?

Maybe an array index, or a for loop counter, who knows; if it's in code please give an example.

OK will do thanks

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.