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.
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.
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
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:
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