Skip to main content

Automatic Station Lights

 Following on from the station lights blog I published awhile ago I have now have the lights coming on automatic when a train comes into any of the four tracks using a Arduino Nano

As I have some spare Ezybus boards I used one of these to do all my connections to the Nano, it also has a 12 Volt input to power the Nano

As my layout is DCC I am using a MERG PMP7 for train detecting, which uses a opto-isolator, to control the LED on the control panel.

One side has a voltage on, in my case 5 Volts with a dropper resistor which brings it down to about 3.5 Volts, the other side is connected to ground 0 Volts.

One of the Nano pins reads this voltage, if it is 3.5 volts it does nothing but if it at 0 volts it switches on another pin on the Nano.

I have used 4 PMP7's for the 4 tracks and used 4 pins on the Nano ( one for each track ) if any of the pins goes to 0 Volts it will switch on the output pin, this in turn switches on a replay to power the LED's ( I have not used the output pin to power the LED's as the currant draw may be too much for the output pin to handle. 

Also I wrote  into the sketch is a 2 second delay for when the last train leaves the station.


Code for Nano ( I hope this is the right one, Keith)
int track71=A3;                                    //read pin:
int track72=A2;
int track81=A1;
int track82=A0;
int readVal1;                                     //readVal:
int readVal2;
int readVal3;
int readVal4;
float V1;
float V2;
float V3;
float V4;
int dt=5;                                             //delay time: 
int dt1=2000;                                          // delay time after train leaves
int stationLights=2;                                    //output Pin:


void setup()
{
  // put your setup code here, to run once:
  Serial.begin (9600);
  pinMode (track71,INPUT);                         //read pin:
  pinMode (track72,INPUT);
  pinMode (track81,INPUT);
  pinMode (track82,INPUT);
pinMode (stationLights,OUTPUT);                        //output pin:

}

void loop() {
  // put your main code here, to run repeatedly:
  readVal1=analogRead(track71);
  readVal2=analogRead(track72);
  
  readVal3=analogRead(track81);
  readVal4=analogRead(track82);
  V1=(5./1023.) *readVal1;
  V2=(5./1023.) *readVal2;
  V3=(5./1023.)*readVal3;
  V4=(5./1023.)*readVal4;
  Serial.println (readVal1);
  Serial.println (readVal2);
  Serial.println (readVal3);
  Serial.println (readVal4);
  

  if (V1<=1||V2<=1||V3<=1||V4<=1)
  {
  digitalWrite (stationLights,HIGH);
  delay (dt1);

  }

  if  (V1>=1.1&&V2>=1.1&&V3>=1.1&&V4>=1.1) 
  {
    digitalWrite (stationLights,LOW);
    
  }
  
delay(dt);

 

}






Comments

Popular posts from this blog

3D Printing Presentation

Sunday's Zoom meeting had our largest audience so far with 19 members attending from various parts of the country. Alan Geekie gave us an excellent and well received presentation on 3D printing that included FDM (Fused Deposition Modeling) and SLA (Stereolithography apparatus) types He first showed how we can source "things to print" using sites like Thingiverse. His own filament printer was the Prusa i3 Mk 3S which is available either as a kit (£699) or pre-assembled (£899) and features a self leveling bed. It also benefited from an additional multi material upgrade kit and he demonstrated the start up sequence of leveling, homing, clearing remaining filament from the hot end and then beginning the print.  The process of slicing where a 3d object drawing file (.stl) is broken up into the x,y,z drawing coordinates for each individual layer was also explained. Alan then moved on to resin printers using another Prusa model, the SL1 and its associated curing and washing mach

Arduino Book Recommendation

Welcome to the site which has been set up for all members of the Scottish Borders Group of MERG.  As you know, I have been working on various Arduino projects recently including the station and cafe displays.  There are many resources available online when you come across a problem but a good reference book which explains how things work is essential.  I have tried a few and found the following book the best so far. It is well written and laid out logically for the beginner to be able to develop new skills. The structure of the Chapters makes it easy to find the relevant section.   By clicking on the link below you will be able to look inside and see for yourself. https://amzn.to /38HfrWW If you decide to purchase through this link  you should be aware that I will receive a small commission on any sales generated which will help to finance further projects Andy R

Train sequence / timetable using Arduino

                              Following discussions in a MERG Zoom meeting about potential projects for the Cumbria virtual area group I have started this blog to share my ideas for building a train sequence / timetable system based on an Arduino UNO. The trigger for this project was Andy Robb's article in the MERG journal (June 2020 edition). In it Andy describes using an UNO with a OLED display to produce an electronic station display board.  Having tried out Andy's version I started thinking about expanding the idea and have come up the following list of possibilities: 1. Replace my card index train sequence with an electronic version. 2. Have the train sequence synchronised with the on platform displays. 3. Display an analogue clock on the station display and have it display the train times. 4. Store the position reached in the sequence so that it starts where it left off on power up.  To make the project of greater potential interest to other modellers the following