Using Light-sensitive Resistors (LDRs) for detecting occupancy of short blocks on a model railway

I needed something that would act as a detector on a double slip, which is a comparatively short length of track and ended up looking at light dependent resistors (LDRs), also known as photoresistors, or photocell resistors.
The ESP32 LDR tutorial referenced in the video esp32io.com/tutorials/esp32-l...
The LDR class and sample sketch used in the video github.com/Vintage80sModelRai...
I've created a repo for all of my current live node sketches across the Arduinos, ESP32s and Galileos. All of them are written in the Arduino IDE.
github.com/Vintage80sModelRai...
The LDRs I bought (no affiliate links) www.ebay.co.uk/itm/404362187416
#modelrailways #modeltrains

Пікірлер: 28

  • @henrybest4057
    @henrybest405710 ай бұрын

    Two suggestions:- 1) For IR sensors, swap the 5mm IR emitter and detector for 3mm IR emitter and detector. They will then fit between two sleepers. Also keep their leads long so that they can be bent to allow the circuit board to be flat against the underside of the baseboard. 2) If you have a unobstructed LDR to measure the ambient light (day or night running) you can use its output value to set the threshold value for all the other LDRs on the layout, with a little bit of programming. Also, your Arduino Uno has 6 analogue to digital inputs.

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Thank you - both very valid siggestions. I did put wire between the emitters and the board on one IR sensor but I'm not a great solderer and it took me a while, seemed a bit too labour intensive for the amount of sensors I use. 2 - it took me a couple of reads to get what you meant, but that's a great idea! I'll definitely do that, thank you! Regards, Chris

  • @ebjamville
    @ebjamville2 ай бұрын

    As to the LDRs and 'night' ops. I remember seeing an example in HO Primer with a street lamp.

  • @chrissharp6845
    @chrissharp68457 ай бұрын

    Hi Chris, Sorry for the lateness of the comment, I've been catching up on your channel today. Couple of thoughts. You could attach another LDR to the ESP32 and use that to measure the ambient light level in the area. That could then be used to adjust the detection threshold. My initial thoughts at the start of this video was that you could have stuck with the DTC2. When the double slip's DTC2 channel goes LOW your ESP2 could change to occupied. However, it would stay occupied while both blocks either side of the double slip were occupied. It would only switch to unoccupied once the double slip's channel is HIGH and one of the blocks either side of it was also HIGH. Put another way, it can only clear once the previous block has cleared. This suggestion is several months too late, sorry. Hope to see you at and Area Group meeting soon. Cheers Chris

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    7 ай бұрын

    Hi Chris! Good to hear from you and thank you - the LDR measure is an excellent idea and I'll get one up there! You're right re the DTC2 - the issue I had was that if a train was waiting on the track to the left to go down the incline, while one came up, then it would also occupy the double slip, which would mean that the train coming up wouldn't be able to cross it and they'd block each other. So I think the double slip needed to be its own block so that it didn't.... block.... anything! You wouldn't believe how many of those meetings I pencil myself in for then have to drop out - there was one very close to me recently - was it Goole? I'd read all of the joining instructions, park further back as it's a narrow road approaching the hall etc. but something came up at the last minute and I couldn't go. I do read them though and always plan to go. I have my daughter every other weekend so that limits my time a little. Regards, Chris

  • @Mapplewell_Park
    @Mapplewell_Park10 ай бұрын

    Watching your videos always make me realise how simple and not technical my layout is 😂🫣

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Ha, well there's nothing wrong with that. At least your layout is reliable and works all the time! Regards, Chris

  • @trbancroft
    @trbancroft9 ай бұрын

    An option that i have looked at / used with slips, is using Logix in JMRI, using this you can use the "occcupied" event of the crossing / slip detector to activate the section, but the off / unoccupied event does nothing. You can then use the off event of the block before, to also change the slip section to "unoccupied" This way you can keep with just purely eletrical detection and do the additional work in JMRI. (this assums the front and rear of the train has resistive wwheelsets)

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    9 ай бұрын

    Thank you - and yes, logic is always a fallback. I did look into it a long time ago now but just had that many unknowns and apparent bugs in what I was doing already, I wasn't keen to add more! Maybe it's something I will look back into at some point. Regards, Chris

  • @anfieldroadlayoutintheloft5204
    @anfieldroadlayoutintheloft520410 ай бұрын

    GOOD UPDATE ON LAYOUTV THANKS LEE

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Thanks Lee!

  • @joedoe6471
    @joedoe647110 ай бұрын

    Your deadpan delivery of the "that was very unsuccessful." line when you derailed that hopper car had me crying!! 🤣😂🤣.

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Ha, I'd forgotten about that! It was a bad idea though, wasn't it?! And a poor attempt too! One of those 'that's never going in a video... pah, leave it in it doesn't matter' moments! Chris

  • @joedoe6471

    @joedoe6471

    10 ай бұрын

    That part literally made the video at least 10x better! 😂@@WirenwoodModelRailway

  • @JohnHill-qo3hb
    @JohnHill-qo3hb10 ай бұрын

    Great video, I use the same IR sensor. I drill two 0.25 inch holes between parallel sleepers, I slip a length of 0.25 inch black heat shrink tubing (don't shrink it, snug fit as is) to keep the sensor's field of view narrow/eliminate false triggers, the length is from the top of the LED to the rim of the LED plus the thickness of the baseboard. I cut small blocks of wood to mount the sensor board to via small wood screws and glued the wooden block in place under the baseboard.

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Thanks John - some really useful ideas there. Regards, Chris

  • @56NeilWatson
    @56NeilWatson10 ай бұрын

    You can can get 3mm diameter IR sensors. I replaced some for my N gauge

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Thanks Neil - yeah, it's definitely a neat and tidy option, I'm just not sure I'm keen on all the labour involved for 40+ IR sensors! Regards, Chris

  • @aleopardstail
    @aleopardstail10 ай бұрын

    one to watch with LDR stuff is you need a reasonably constant level of ambient light for any given sensor (so once its set it will work) - issue if you want "night mode" to see train and background lights. I've had a think on this as the layout I want to build will also need some short blocks (slips included), was thinking of a current sensor, but combined with a bit of custom arduino code to provide for a longer hold on delay than the basic sensors provide (or maybe fiddle with components on the block sensor for a longer delay). the idea however of routing the sensor directly to a reasonably nearby micro controller with a nice software set threshold works. also could cover the "night mode" issue if you use a LDR that also works with some IR light sources, have some IR LEDs above the general area (or provide visible light "yard lights" nearby and away you go I have tried a small (my layout is N guage) IR solution, a custom PCB with a surface mount phototransistor and IR LED to go between adjacent sleepers so no track cutting - also had a second "ambient light" phototransistor to sit a few mm outside the rails - idea was to look at the difference between the two sensors. it didn't work very well

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Thanks Dale! Yeah, first of all the loft has absolutely no ambient light - no windows etc, so I'm totally in control. I'm definitely thinking of placing some strategic scenic LEDs though as I do intend to run in the dark too. It'll be easy enough to code a secondary light threshold and I thought if those strategic LEDs are controlled by JMRI, through MQTT, then the devices that control the sensors will know if we're running in full or low light (assuming the LEDs are switched off in full light) so will know what threshold to use. While I was thinking about that, I also thought about putting those threshold values in JMRI memory variables and broadcasting those to MQTT too, so that I don't have to hardcode them into skwtches and change / upload each time I want to tweak the values. Regards, Chris

  • @aleopardstail

    @aleopardstail

    10 ай бұрын

    @@WirenwoodModelRailway I really need to look more into this MQTT stuff, especially if its easy to broadcast values back out like that, not just for thresholds but to have devices listen in. Have done that over RS-485 with my own comms protocol for other projects, not compatible with JMRI though, here its good, as you note have the devices know day/night mode, actual data values out makes sense too. pondering possibilities say for a memory location broadcast with train ID of whats going into a fiddle yard and allow an ESP32 or whatever to actually manage the yard entirely

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    It's definitely worth a look, being able to send messages, string values over CMRI's binary values definitely increases what I can do. That sounds like an interesting project, are you considering RFID? Chris

  • @joedoe6471
    @joedoe647110 ай бұрын

    Another great video Chris! 👍

  • @davidtwist3659
    @davidtwist365910 ай бұрын

    Great video and just the job to detect a small area. I am looking at sensors for my station area and was thinking of using opto sensors connected to Wemos D1 mini's communicating with MQTT. But seeing your video LDR's maybe easier to fit. I have been following your progress for some time and enjoy your content. I am not a software person so find it difficult with the code and have to see what is available on the web. Maybe it would be good if you went through your code. On a side note the link to the LDR class and sample sketch is not functioning. Keep up the great work.

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    10 ай бұрын

    Thanks David! I've done the odd code walkthrough video, I should do more really! They don't get many views but then that doesn't really matter as I try to just make this channel about what I'm doing and not about me, or trying to gain anything from it. I'll try to get a few more out there, please let me know if there's anything particular you'd like me to walk through. Thanks for letting me know about the links - they should work now. Regards, Chris

  • @hctreintje
    @hctreintje9 ай бұрын

    You can not include a crossing in a blok !!

  • @WirenwoodModelRailway

    @WirenwoodModelRailway

    9 ай бұрын

    Hi, thanks for this. I think it's ok if the crossing IS the block. It's worked for me anyway! Regards, Chris