My Pages Menu

My Upgraded Signaling Project Using Three Color LEDs

I decided to upgrade my signal system to use an Arduino MEGA as the controller. 

When I installed my current signal system I was going to use NJI signals but after waiting for over 6 months for them to become available I gave up and made the signals from K&S Brass.

I built the signals about 5 years ago, this is a recap.


My Type H-2 Search Light Signals

The Picture below shows the metal hole stamp, the K&S brass and a NJI Search Light head #525-4107 that I used as a go-by to make my own heads.

 

The 3/8" punch worked great for the signal back plates.  I used 5/32" K&S brass tubing for the Sun shield.

After I had made all 20 of the 3/8" back plates I found some brass washers that would have worked very well at Lowes.  OH Well, sometimes I win and sometimes I lose.  The toughest part was making the hole in the center.





The picture above shows several heads that I made using the NJI head on the left as the go-by. The head in the lower right is mounted on a 3/32" support tube.


I found that a #6S brass washer is very close to HO scale and will work for the signal head sun shield.




 

 



I will have a total of 16 signal heads for my mainline.  Eight of those will be on two Cantilever bridges over dual tracks the other eight will be mounted on eight single head mast for single tracks.  The signal bridges are kits from TrainCat Model Sales.



This is my first Southern Pacific H2 Search Light Signal.  The ladder is Oregon Rail Supply #142.  The Signal Cabinet is a casting that I made from an old Oregon Rail three light signal that they no longer have listed on their site.  I will install a 3mm three lead bi-color LED in it.




The signal head is one of my creations from K&S brass stock.  I made the 3/32" diameter brass tube support extend 1 1/4" from the bottom of signal cabinet.  I will use a 1/8" brass tube in the layout for the signal tube to slide into for easy removal.  I use that same scheme to mount my crossing signals and gates.

On to the upgrade of replacing the LEDs.
 
I had been using 3mm bi-color common cathode LEDs driven by a Rob Paisley circuit for about 15 years and it has worked very good.  

I have never liked the common cathode bi-color LEDs because of their poor yellow or my using only two wires and the brass signal pole for power thus my reason for my upgrade.  Having 16 powered brass tubes close to the tracks has been a tragedy waiting to happen.

Finding a good looking bi-color common anode LED proved to be impossible.  I tried several manufacturers of LEDs looking for the perfect common anode bi-color LEDs and all of them had a poor looking yellow as well as the red and green have hot spots so I gave up on bi-color LEDs.  

After many months of searching I finally found a perfect three color common anode LED in the Bivar SMTL4-RGY LED. 

This post is the process of up grading my signal system.  


Without actually sampling the SMTL4 Tri Color SMD LED I ordered 25 from Mouser.  The total cost per LED with shipping was $1.25 each.

This will be a good test for my new eyes after double cataract surgery. 



These little buggers most likely won't be easy to solder four #36 wires too. 
 









Actually I found out that the SMTL4-RGY is very easy to solder the wires to.   

I ruined the first one trying to hold it with a surgical clamp for soldering.  The LED housing collapsed under the pressure, that was unexpected.  Next I tried my long nose pliers with a rubber band around the handles to hold the LED with the pliers held in my Panavise. 

That worked but later I found it much easier to install the tiny LED in the signal head then hold the head with the surgical clamp with the clamp in my Panavise.



To get a handle on the size of the tiny LED the signal head back plate is .388" in diameter, the diameter of the housing that the LED is mounted to is .170".

The SMTL4-RGY doesn't have a lens, that bothered me at first but I soon found out that was much better.  At first tried chopping the lens of a 3mm (.117") Warm White LED and that worked out OK but the lens was a bit short in the signal head housing, too recessed.  I shortened a few heads by 1.5mm (.060") and that worked out OK.


Not happy with having to shorten the head body I ordered a 3mm diameter Acrylic rod to extend the length of LED lens.  I tried to make a .06" adapter to go between the 3mm LED lens and the SMTL4 and while that worked very good I found that I could round the end of the Acrylic rod by putting a short piece in the chuck of my drill and use some 200 grit sandpaper to form a lens was much easier.  

I found the illuminated look of the Mel lens better with the rough surface (200 grit in the picture) than a polished surface using 1000 grit sandpaper.



I now round off the Acrylic rod to make a lens then after cutting it to the correct length I attach it to the SMTL4 using Super Glue (CA) gluing it on to the signal head.  With that done its very easy to clamp the head with the surgical clamp then solder the four #36 wires to the the LED, super simple.

This is the way they appear attached to the LED with CA.




My photography isn't the best but here are the three perfect colors of the SMTL4-RGY LED.




This is a video of a single head SMTL4-RGY LED switching colors using a switch.






Signal Head problem solved

Next problem

After having continuous problems with current sensors for occupancy detection I made the decision to go with IR optical detection using a beam break scenario about three years ago.  Once installed and tweaked it has worked great, no problems at all.  

Current detection works OK but I have never liked having to install resistors on truck axles for the current detectors to sense occupancy.

I used an Arduino UNO to generate the modulated (38kHz/56kHz) 5 volt light source as well as for the IR detector receivers.  The IR beam type detection works great but it takes as many as five beams to cover a curve!   That requires a lot of problems hiding the Emitters and Receivers.

As I'm always researching for new ideas and in doing so I found a very slick IR detector module, the Arduino FC-51.  It is the reflective type so many are needed to obtain block occupation but the cost of the FC-1 is in the ballpark at 49¢ each, 50 for $20, 100 for $38 and no special circuits, no Arduino needed for detection or emitter modulation, simple switched ground output when active.





The FC-51 can be used for beam break detection but then the detector output is inverted and needs to be corrected for ground or switching a low.

The FC-51 has 5mm LEDs and by changing them to 3MM two will fit between the HO track ties.

I found the best angle for the emitter and sensor to be 12° off track vertical center.  That makes the reflective focal point ½" above the rails.  The FC-51 IR beam catches anything from about ¼" to 2" above the tails, it even activates on a single axle rolling over the sensors.


Next I decided to make a "tool" for drilling the holes for the LEDs between the ties.

This was my first attempt, it worked on open track but not in turnouts.


At 82 I'm a shaky hands guy and need all the help I can get.  The tool works a lot better than I thought it would.  It makes drilling the two angled holes very easy even for old shaky hands Mel.  

This one is made out  of a scrap 1" x 2", before I really get into drilling a hundred or so holes I'll make a better tool from oak.
  
I left a stub of the brass tubing coming out of the bottom of the guide and filed the sides so that it would just fit between the ties. 
 
I drill one hole then turn the guide 180° and drill the second hole, both in perfect alignment.

I think after a bit of ballast retouching the holes will be almost invisible to the eye at a couple of feet.

The picture above was my first attempt, by the third try I wasn't dinging the ties at all.  When I did a couple of holes in difficult locations I did really ding a tie, I found it a very easy cosmetic fix by replacing the tie portion between the rails with a piece of a new tie.  Once the ballast is retouched the fix can't be seen.

This is my second attempt this time using Oak and Brass strips for rail guides.



The Oak was much easier to work with.  I also went with a smaller block, I found out that the first Pine block was too wide and some of my scenery interfered with the placement of the block.


 I used my Dremel Tool with a .02" cutting disk to cut the slots for the K&S Brass strips.


The 5/32" Brad Point Drill just touches the ties.  The sharp Brad Point Drill works much better than an ordinary drill bit.



The Brass strips fit snugly between the rails and work a lot better than my first tool.


Happy with the operation of the Arduino FC-51 Obstacle Avoidance Module it's time to move on to the Diode Matrix Board Interface. 

I don't like using delays in the Arduino programming, it slows down the operating program.  As the FC-51 is very fast I decided that an RC slow release circuit between the modules and the Arduino MEGA is a must have.  A simple 100K resistor with a 47ųfd capacitor equals 2 seconds hold time to the Arduino MEGA input.

I included an RC time delay on the Diode Matrix Board capable of up to 13 seconds or more and will make it possible to extend the FC-51 spacing if needed.  I still prefer close spacing with 2 to 7 seconds delay.

My blocks are 8' therefore each block will require 8 FC-51 modules at 12" spacing.  I designed a 16 block diode matrix allowing up to 10 modules per block.

As I am a visual guy and like LEDs to tell me when things are working I'm adding an activity indicator to each block matrix.  To prevent the LED indicator from altering the timing I'm driving the LED with a PNP transistor so it doesn't effect the delay, a 2N3906 or a MPSA64 works nicely. 



I bought a 9cm x 15cm perfboard to build up the diode matrix.  I'm using Arduino type 2.54mm/0.10" square pin connectors for both inputs and output.  A simple three wire extension cable between the FC-51 and the matrix board takes care of each detector.  It takes 16 wires between the matrix board and the Arduino MEGA Controller for the Arduino inputs but I went with a 20 pin connector for total compatibility with my other Arduinos, pins 17 to 20 for power.

Because I'm always changing or modifying my goodies I went with sockets for the delay capacitors, that way I can easily change the delay faster or longer.  The component sockets are 2.54mm/0.10" round pin header strips.


The Matrix Board is finished and it works great.  I can swap the hold time capacitors from 0 to 13 seconds (330ųfd) on each block.  I'm currently using 12" spacing on the FC-51 detectors and 7½ seconds (220ųfd) is working very good for slow and faster traffic.



Here the board has all the driver transistors and timing caps installed ready to go.




That was a tedious project, soldering 160 1N914 diodes without dinging one was very tedious!!!!  

I used sockets for both the transistors and capacitors, that way both can be easily changed to fit the output needed.

  47ųfd =   2 seconds (minimum must have)

100ųfd =   4 seconds

220ųfd =   7½ seconds

330ųfd = 13 seconds

The Arduino MEGA inputs turn on at 1.3 volts and off at 2.44 volts.





 





Arduino MEGA Signal Controller

The Arduino's are fascinating creatures!  This post is about using an Arduino MEGA 2560 as a Signal Controller.  The MEGA has 54 I/O ports and 16 analog input ports.  My Arduino sketch will drive 16 LED 3 color signal heads using 48 outputs.  The 16 analog inputs will handle the outputs from 16 occupancy detectors or block controls.

Its rather easy to drive a signal system by using a simple truth table for each signal head color.

Green = advance block high + signal block high = Green on
              else green off

Yellow = advance block low + signal block high = Yellow on
              else yellow off

Red= signal block low = Red on







The info above is for one direction (CCW), a separate code is required for reverse direction (CW) simply by reversing the order of the block numbers.  For my layout I used CCW (Counter Clock Wise) for West and CW (Clock Wise) for East.




=================================================

The resistors for driving the SMTL4-RGY from 5 volts are as follows: 

2ma for Red - 1KΩ

12.5ma for Yellow/Amber - 180Ω

4ma for Green - 560Ω

To my eye the three colors are well balanced for equal brightness at the above currents.
  =================================================



=================================================

Below is my Arduino MEGA 2560 Sketch for the controller.  The setup definitions are for a total of 16 blocks.  I only listed two CCW blocks for this post, additional blocks can be added with copy and paste and changing to block and signal head numbers for the proper sequence up to 16 blocks.


========================================================================

void setup()

{
int greenledPin1 = 1;    // Signal Head 1 Green
int yellowledPin2 = 2;   // Signal Head 1 Yellow
int redledPin3 = 3;      // Signal Head 1 Red
int greenledPin4 = 4;    // Signal Head 2 Green
int yellowledPin5 = 5;   // Signal Head 2 Yellow
int redledPin6 = 6;      // Signal Head 2 Red
int greenledPin7 = 7;    // Signal Head 3 Green
int yellowledPin8 = 8;   // Signal Head 3 Yellow
int redledPin9 = 9;      // Signal Head 3 Red
int greenledPin10 = 10;  // Signal Head 4 Green
int yellowledPin11 = 11; // Signal Head 4 Yellow
int redledPin12 = 12;    // Signal Head 4 Red
int greenledPin13 = 13;  // Signal Head 5 Green
int yellowledPin14 = 14; // Signal Head 5 Yellow
int redledPin15 = 15;    // Signal Head 5 Red
int greenledPin16 = 16;  // Signal Head 6 Green
int yellowledPin17 = 17; // Signal Head 6 Yellow
int redledPin18 = 18;    // Signal Head 6 Red
int greenledPin19 = 19;  // Signal Head 7 Green
int yellowledPin20 = 20; // Signal Head 7 Yellow
int redledPin21 = 21;    // Signal Head 7 Red
int greenledPin22 = 22;  // Signal Head 8 Green
int yellowledPin23 = 23; // Signal Head 8 Yellow
int redledPin24 = 24;    // Signal Head 8 Red
int greenledPin25 = 25;  // Signal Head 9 Green
int yellowledPin26 = 26; // Signal Head 9 Yellow
int redledPin27 = 27;    // Signal Head 9 Red
int greenledPin28 = 28;  // Signal Head 10 Green
int yellowledPin29 = 29; // Signal Head 10 Yellow
int redledPin30 = 30;    // Signal Head 10 Red
int greenledPin31 = 31;  // Signal Head 11 Green
int yellowledPin32 = 32; // Signal Head 11 Yellow
int redledPin33 = 33;    // Signal Head 11 Red
int greenledPin34 = 34;  // Signal Head 12 Green
int yellowledPin35 = 35; // Signal Head 12 Yellow
int redledPin36 = 36;    // Signal Head 12 Red
int greenledPin37 = 37;  // Signal Head 13 Green
int yellowledPin38 = 38; // Signal Head 13 Yellow
int redledPin39 = 39;    // Signal Head 13 Red
int greenledPin40 = 40;  // Signal Head 14 Green
int yellowledPin41 = 41; // Signal Head 14 Yellow
int redledPin42 = 42;    // Signal Head 14 Red

int blockdetector1Pin = A1;    // Block 1 Occupancy Detector
int blockdetector2Pin = A2;    // Block 2 Occupancy Detector
int blockdetector3Pin = A3;    // Block 3 Occupancy Detector
int blockdetector4Pin = A4;    // Block 4 Occupancy Detector
int blockdetector5Pin = A5;    // Block 5 Occupancy Detector
int blockdetector6Pin = A6;    // Block 6 Occupancy Detector
int blockdetector7Pin = A7;    // Block 7 Occupancy Detector
int blockdetector8Pin = A8;    // Block 8 Occupancy Detector
int blockdetector9Pin = A9;    // Block 9 Occupancy Detector
int blockdetector10Pin = A10;  // Block 10 Occupancy Detector
int blockdetector11Pin = A11;  // Block 11 Occupancy Detector
int blockdetector12Pin = A12;  // Block 12 Occupancy Detector
int blockdetector13Pin = A13;  // Block 13 Occupancy Detector
int blockdetector14Pin = A14;  // Block 14 Occupancy Detector




  pinMode(greenledPin1, OUTPUT);
  pinMode(yellowledPin2, OUTPUT);
  pinMode(redledPin3, OUTPUT);
  pinMode(greenledPin4, OUTPUT); 
  pinMode(yellowledPin5, OUTPUT);
  pinMode(redledPin6, OUTPUT); 
  pinMode(greenledPin7, OUTPUT);
  pinMode(yellowledPin8, OUTPUT);
  pinMode(redledPin9, OUTPUT);
  pinMode(greenledPin10, OUTPUT); 
  pinMode(yellowledPin11, OUTPUT);
  pinMode(redledPin12, OUTPUT);   
  pinMode(greenledPin13, OUTPUT);
  pinMode(yellowledPin14, OUTPUT);
  pinMode(redledPin15, OUTPUT);
  pinMode(greenledPin16, OUTPUT); 
  pinMode(yellowledPin17, OUTPUT);
  pinMode(redledPin18, OUTPUT); 
  pinMode(greenledPin19, OUTPUT);
  pinMode(yellowledPin20, OUTPUT);
  pinMode(redledPin21, OUTPUT);
  pinMode(greenledPin22, OUTPUT); 
  pinMode(yellowledPin23, OUTPUT);
  pinMode(redledPin24, OUTPUT); 
  pinMode(greenledPin25, OUTPUT);
  pinMode(yellowledPin26, OUTPUT);
  pinMode(redledPin27, OUTPUT);
  pinMode(greenledPin28, OUTPUT); 
  pinMode(yellowledPin29, OUTPUT);
  pinMode(redledPin30, OUTPUT); 
  pinMode(greenledPin31, OUTPUT);
  pinMode(yellowledPin32, OUTPUT);
  pinMode(redledPin33, OUTPUT);
  pinMode(greenledPin34, OUTPUT); 
  pinMode(yellowledPin35, OUTPUT);
  pinMode(redledPin36, OUTPUT); 
  pinMode(greenledPin37, OUTPUT);
  pinMode(yellowledPin38, OUTPUT);
  pinMode(redledPin39, OUTPUT);
  pinMode(greenledPin40, OUTPUT); 
  pinMode(yellowledPin41, OUTPUT);
  pinMode(redledPin42, OUTPUT); 
 
  pinMode(blockdetector1Pin,  INPUT_PULLUP);
  pinMode(blockdetector2Pin,  INPUT_PULLUP);
  pinMode(blockdetector3Pin,  INPUT_PULLUP);
  pinMode(blockdetector4Pin,  INPUT_PULLUP);
  pinMode(blockdetector5Pin,  INPUT_PULLUP);
  pinMode(blockdetector6Pin,  INPUT_PULLUP);
  pinMode(blockdetector7Pin,  INPUT_PULLUP);
  pinMode(blockdetector8Pin,  INPUT_PULLUP);
  pinMode(blockdetector9Pin,  INPUT_PULLUP);
  pinMode(blockdetector10Pin, INPUT_PULLUP);
  pinMode(blockdetector11Pin, INPUT_PULLUP);
  pinMode(blockdetector12Pin, INPUT_PULLUP);
  pinMode(blockdetector13Pin, INPUT_PULLUP);
  pinMode(blockdetector14Pin, INPUT_PULLUP);
}

void loop()
{
int greenledPin1 = 1;    // Signal Head 1 Green
int yellowledPin2 = 2;   // Signal Head 1 Yellow
int redledPin3 = 3;      // Signal Head 1 Red
int greenledPin4 = 4;    // Signal Head 2 Green
int yellowledPin5 = 5;   // Signal Head 2 Yellow
int redledPin6 = 6;      // Signal Head 2 Red
int greenledPin7 = 7;    // Signal Head 3 Green
int yellowledPin8 = 8;   // Signal Head 3 Yellow
int redledPin9 = 9;      // Signal Head 3 Red
int greenledPin10 = 10;  // Signal Head 4 Green
int yellowledPin11 = 11; // Signal Head 4 Yellow
int redledPin12 = 12;    // Signal Head 4 Red
int greenledPin13 = 13;  // Signal Head 5 Green
int yellowledPin14 = 14; // Signal Head 5 Yellow
int redledPin15 = 15;    // Signal Head 5 Red
int greenledPin16 = 16;  // Signal Head 6 Green
int yellowledPin17 = 17; // Signal Head 6 Yellow
int redledPin18 = 18;    // Signal Head 6 Red
int greenledPin19 = 19;  // Signal Head 7 Green
int yellowledPin20 = 20; // Signal Head 7 Yellow
int redledPin21 = 21;    // Signal Head 7 Red
int greenledPin22 = 22;  // Signal Head 8 Green
int yellowledPin23 = 23; // Signal Head 8 Yellow
int redledPin24 = 24;    // Signal Head 8 Red
int greenledPin25 = 25;  // Signal Head 9 Green
int yellowledPin26 = 26; // Signal Head 9 Yellow
int redledPin27 = 27;    // Signal Head 9 Red
int greenledPin28 = 28;  // Signal Head 10 Green
int yellowledPin29 = 29; // Signal Head 10 Yellow
int redledPin30 = 30;    // Signal Head 10 Red
int greenledPin31 = 31;  // Signal Head 11 Green
int yellowledPin32 = 32; // Signal Head 11 Yellow
int redledPin33 = 33;    // Signal Head 11 Red
int greenledPin34 = 34;  // Signal Head 12 Green
int yellowledPin35 = 35; // Signal Head 12 Yellow
int redledPin36 = 36;    // Signal Head 12 Red
int greenledPin37 = 37;  // Signal Head 13 Green
int yellowledPin38 = 38; // Signal Head 13 Yellow
int redledPin39 = 39;    // Signal Head 13 Red
int greenledPin40 = 40;  // Signal Head 14 Green
int yellowledPin41 = 41; // Signal Head 14 Yellow
int redledPin42 = 42;    // Signal Head 14 Red

int blockdetector1Pin = A1;    // Block 1 Occupancy Detector
int blockdetector2Pin = A2;    // Block 2 Occupancy Detector
int blockdetector3Pin = A3;    // Block 3 Occupancy Detector
int blockdetector4Pin = A4;    // Block 4 Occupancy Detector
int blockdetector5Pin = A5;    // Block 5 Occupancy Detector
int blockdetector6Pin = A6;    // Block 6 Occupancy Detector
int blockdetector7Pin = A7;    // Block 7 Occupancy Detector
int blockdetector8Pin = A8;    // Block 8 Occupancy Detector
int blockdetector9Pin = A9;    // Block 9 Occupancy Detector
int blockdetector10Pin = A10;  // Block 10 Occupancy Detector
int blockdetector11Pin = A11;  // Block 11 Occupancy Detector
int blockdetector12Pin = A12;  // Block 12 Occupancy Detector
int blockdetector13Pin = A13;  // Block 13 Occupancy Detector
int blockdetector14Pin = A14;  // Block 14 Occupancy Detector



{
  // CCW Block 1 Green
 
  // read from the button pin
      digitalRead(blockdetector1Pin);
      digitalRead(blockdetector2Pin);
          
 
  if (digitalRead(blockdetector1Pin) == HIGH  &&  digitalRead(blockdetector2Pin) == HIGH) // read two switches
  
      digitalWrite(greenledPin1,LOW);
  else
  {
      digitalWrite(greenledPin1, HIGH);
   }

  //CCW Block 1 Yellow
  // read from the button pin
     
      digitalRead(blockdetector1Pin);
      digitalRead(blockdetector2Pin);

  if (digitalRead(blockdetector1Pin) == HIGH  &&  digitalRead(blockdetector2Pin) == LOW)

      digitalWrite(yellowledPin2,LOW);

  else
  {
      digitalWrite(yellowledPin2, HIGH);
   }

    //CCW Block 1 Red
  // read from the button pin
      digitalRead(blockdetector1Pin);
    

  if (digitalRead(blockdetector1Pin) == LOW)

      digitalWrite(redledPin3,LOW);

  else
  {
      digitalWrite(redledPin3, HIGH);
       
 
   }

  // ==============================================================
  
   {
  // CCW Block 2 Green
 
  // read from the button pin
      digitalRead(blockdetector2Pin);
      digitalRead(blockdetector3Pin);
       
 
  if (digitalRead(blockdetector3Pin) == HIGH  &&  digitalRead(blockdetector3Pin) == HIGH) // read two switches
  
      digitalWrite(greenledPin4,LOW);
  else
  {
      digitalWrite(greenledPin4, HIGH);
   }

  //CCW Block 2 Yellow
  // read from the button pin
     
      digitalRead(blockdetector2Pin);
      digitalRead(blockdetector3Pin);

  if (digitalRead(blockdetector2Pin) == HIGH  &&  digitalRead(blockdetector3Pin) == LOW) //read two switches

      digitalWrite(yellowledPin5,LOW);

  else
  {
      digitalWrite(yellowledPin5, HIGH);
   }

    //CCW Block 2 Red
  // read from the button pin
      digitalRead(blockdetector2Pin);
    

  if (digitalRead(blockdetector2Pin) == LOW)

      digitalWrite(redledPin6,LOW);

  else
  {
      digitalWrite(redledPin6, HIGH);
       
  }

  
  
   }

  // ==================================================================




Updated November 26, 2017



The sketch below is a complete 14 block controller, it can be copied and pasted to the Arduino IDE.



void setup()



{

int greenledPin1 = 1;    // Signal Head 1 Green

int yellowledPin2 = 2;   // Signal Head 1 Yellow

int redledPin3 = 3;      // Signal Head 1 Red

int greenledPin4 = 4;    // Signal Head 2 Green

int yellowledPin5 = 5;   // Signal Head 2 Yellow

int redledPin6 = 6;      // Signal Head 2 Red

int greenledPin7 = 7;    // Signal Head 3 Green

int yellowledPin8 = 8;   // Signal Head 3 Yellow

int redledPin9 = 9;      // Signal Head 3 Red

int greenledPin10 = 10;  // Signal Head 4 Green

int yellowledPin11 = 11; // Signal Head 4 Yellow

int redledPin12 = 12;    // Signal Head 4 Red

int greenledPin13 = 13;  // Signal Head 5 Green

int yellowledPin14 = 14; // Signal Head 5 Yellow

int redledPin15 = 15;    // Signal Head 5 Red

int greenledPin16 = 16;  // Signal Head 6 Green

int yellowledPin17 = 17; // Signal Head 6 Yellow

int redledPin18 = 18;    // Signal Head 6 Red

int greenledPin19 = 19;  // Signal Head 7 Green

int yellowledPin20 = 20; // Signal Head 7 Yellow

int redledPin21 = 21;    // Signal Head 7 Red

int greenledPin22 = 22;  // Signal Head 8 Green

int yellowledPin23 = 23; // Signal Head 8 Yellow

int redledPin24 = 24;    // Signal Head 8 Red

int greenledPin25 = 25;  // Signal Head 9 Green

int yellowledPin26 = 26; // Signal Head 9 Yellow

int redledPin27 = 27;    // Signal Head 9 Red

int greenledPin28 = 28;  // Signal Head 10 Green

int yellowledPin29 = 29; // Signal Head 10 Yellow

int redledPin30 = 30;    // Signal Head 10 Red

int greenledPin31 = 31;  // Signal Head 11 Green

int yellowledPin32 = 32; // Signal Head 11 Yellow

int redledPin33 = 33;    // Signal Head 11 Red

int greenledPin34 = 34;  // Signal Head 12 Green

int yellowledPin35 = 35; // Signal Head 12 Yellow

int redledPin36 = 36;    // Signal Head 12 Red

int greenledPin37 = 37;  // Signal Head 13 Green

int yellowledPin38 = 38; // Signal Head 13 Yellow

int redledPin39 = 39;    // Signal Head 13 Red

int greenledPin40 = 40;  // Signal Head 14 Green

int yellowledPin41 = 41; // Signal Head 14 Yellow

int redledPin42 = 42;    // Signal Head 14 Red



int blockdetector1Pin = A1;    // Block 1 Occupancy Detector

int blockdetector2Pin = A2;    // Block 2 Occupancy Detector

int blockdetector3Pin = A3;    // Block 3 Occupancy Detector

int blockdetector4Pin = A4;    // Block 4 Occupancy Detector

int blockdetector5Pin = A5;    // Block 5 Occupancy Detector

int blockdetector6Pin = A6;    // Block 6 Occupancy Detector

int blockdetector7Pin = A7;    // Block 7 Occupancy Detector

int blockdetector8Pin = A8;    // Block 8 Occupancy Detector

int blockdetector9Pin = A9;    // Block 9 Occupancy Detector

int blockdetector10Pin = A10;  // Block 10 Occupancy Detector

int blockdetector11Pin = A11;  // Block 11 Occupancy Detector

int blockdetector12Pin = A12;  // Block 12 Occupancy Detector

int blockdetector13Pin = A13;  // Block 13 Occupancy Detector

int blockdetector14Pin = A14;  // Block 14 Occupancy Detector









  pinMode(greenledPin1, OUTPUT);

  pinMode(yellowledPin2, OUTPUT);

  pinMode(redledPin3, OUTPUT);

  pinMode(greenledPin4, OUTPUT); 

  pinMode(yellowledPin5, OUTPUT);

  pinMode(redledPin6, OUTPUT); 

  pinMode(greenledPin7, OUTPUT);

  pinMode(yellowledPin8, OUTPUT);

  pinMode(redledPin9, OUTPUT);

  pinMode(greenledPin10, OUTPUT); 

  pinMode(yellowledPin11, OUTPUT);

  pinMode(redledPin12, OUTPUT);   

  pinMode(greenledPin13, OUTPUT);

  pinMode(yellowledPin14, OUTPUT);

  pinMode(redledPin15, OUTPUT);

  pinMode(greenledPin16, OUTPUT); 

  pinMode(yellowledPin17, OUTPUT);

  pinMode(redledPin18, OUTPUT); 

  pinMode(greenledPin19, OUTPUT);

  pinMode(yellowledPin20, OUTPUT);

  pinMode(redledPin21, OUTPUT);

  pinMode(greenledPin22, OUTPUT); 

  pinMode(yellowledPin23, OUTPUT);

  pinMode(redledPin24, OUTPUT); 

  pinMode(greenledPin25, OUTPUT);

  pinMode(yellowledPin26, OUTPUT);

  pinMode(redledPin27, OUTPUT);

  pinMode(greenledPin28, OUTPUT); 

  pinMode(yellowledPin29, OUTPUT);

  pinMode(redledPin30, OUTPUT); 

  pinMode(greenledPin31, OUTPUT);

  pinMode(yellowledPin32, OUTPUT);

  pinMode(redledPin33, OUTPUT);

  pinMode(greenledPin34, OUTPUT); 

  pinMode(yellowledPin35, OUTPUT);

  pinMode(redledPin36, OUTPUT); 

  pinMode(greenledPin37, OUTPUT);

  pinMode(yellowledPin38, OUTPUT);

  pinMode(redledPin39, OUTPUT);

  pinMode(greenledPin40, OUTPUT); 

  pinMode(yellowledPin41, OUTPUT);

  pinMode(redledPin42, OUTPUT); 

 

  pinMode(blockdetector1Pin,  INPUT_PULLUP);

  pinMode(blockdetector2Pin,  INPUT_PULLUP);

  pinMode(blockdetector3Pin,  INPUT_PULLUP);

  pinMode(blockdetector4Pin,  INPUT_PULLUP);

  pinMode(blockdetector5Pin,  INPUT_PULLUP);

  pinMode(blockdetector6Pin,  INPUT_PULLUP);

  pinMode(blockdetector7Pin,  INPUT_PULLUP);

  pinMode(blockdetector8Pin,  INPUT_PULLUP);

  pinMode(blockdetector9Pin,  INPUT_PULLUP);

  pinMode(blockdetector10Pin, INPUT_PULLUP);

  pinMode(blockdetector11Pin, INPUT_PULLUP);

  pinMode(blockdetector12Pin, INPUT_PULLUP);

  pinMode(blockdetector13Pin, INPUT_PULLUP);

  pinMode(blockdetector14Pin, INPUT_PULLUP);

}



void loop()

{

int greenledPin1 = 1;    // Signal Head 1 Green

int yellowledPin2 = 2;   // Signal Head 1 Yellow

int redledPin3 = 3;      // Signal Head 1 Red

int greenledPin4 = 4;    // Signal Head 2 Green

int yellowledPin5 = 5;   // Signal Head 2 Yellow

int redledPin6 = 6;      // Signal Head 2 Red

int greenledPin7 = 7;    // Signal Head 3 Green

int yellowledPin8 = 8;   // Signal Head 3 Yellow

int redledPin9 = 9;      // Signal Head 3 Red

int greenledPin10 = 10;  // Signal Head 4 Green

int yellowledPin11 = 11; // Signal Head 4 Yellow

int redledPin12 = 12;    // Signal Head 4 Red

int greenledPin13 = 13;  // Signal Head 5 Green

int yellowledPin14 = 14; // Signal Head 5 Yellow

int redledPin15 = 15;    // Signal Head 5 Red

int greenledPin16 = 16;  // Signal Head 6 Green

int yellowledPin17 = 17; // Signal Head 6 Yellow

int redledPin18 = 18;    // Signal Head 6 Red

int greenledPin19 = 19;  // Signal Head 7 Green

int yellowledPin20 = 20; // Signal Head 7 Yellow

int redledPin21 = 21;    // Signal Head 7 Red

int greenledPin22 = 22;  // Signal Head 8 Green

int yellowledPin23 = 23; // Signal Head 8 Yellow

int redledPin24 = 24;    // Signal Head 8 Red

int greenledPin25 = 25;  // Signal Head 9 Green

int yellowledPin26 = 26; // Signal Head 9 Yellow

int redledPin27 = 27;    // Signal Head 9 Red

int greenledPin28 = 28;  // Signal Head 10 Green

int yellowledPin29 = 29; // Signal Head 10 Yellow

int redledPin30 = 30;    // Signal Head 10 Red

int greenledPin31 = 31;  // Signal Head 11 Green

int yellowledPin32 = 32; // Signal Head 11 Yellow

int redledPin33 = 33;    // Signal Head 11 Red

int greenledPin34 = 34;  // Signal Head 12 Green

int yellowledPin35 = 35; // Signal Head 12 Yellow

int redledPin36 = 36;    // Signal Head 12 Red

int greenledPin37 = 37;  // Signal Head 13 Green

int yellowledPin38 = 38; // Signal Head 13 Yellow

int redledPin39 = 39;    // Signal Head 13 Red

int greenledPin40 = 40;  // Signal Head 14 Green

int yellowledPin41 = 41; // Signal Head 14 Yellow

int redledPin42 = 42;    // Signal Head 14 Red



int blockdetector1Pin = A1;    // Block 1 Occupancy Detector

int blockdetector2Pin = A2;    // Block 2 Occupancy Detector

int blockdetector3Pin = A3;    // Block 3 Occupancy Detector

int blockdetector4Pin = A4;    // Block 4 Occupancy Detector

int blockdetector5Pin = A5;    // Block 5 Occupancy Detector

int blockdetector6Pin = A6;    // Block 6 Occupancy Detector

int blockdetector7Pin = A7;    // Block 7 Occupancy Detector

int blockdetector8Pin = A8;    // Block 8 Occupancy Detector

int blockdetector9Pin = A9;    // Block 9 Occupancy Detector

int blockdetector10Pin = A10;  // Block 10 Occupancy Detector

int blockdetector11Pin = A11;  // Block 11 Occupancy Detector

int blockdetector12Pin = A12;  // Block 12 Occupancy Detector

int blockdetector13Pin = A13;  // Block 13 Occupancy Detector

int blockdetector14Pin = A14;  // Block 14 Occupancy Detector







{

  // CCW Block 1 Green

 

  // read from the button pin

      digitalRead(blockdetector1Pin);

      digitalRead(blockdetector2Pin);

          

 

  if (digitalRead(blockdetector1Pin) == HIGH  &&  digitalRead(blockdetector2Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin1,LOW);

  else

  {

      digitalWrite(greenledPin1, HIGH);

   }



  //CCW Block 1 Yellow

  // read from the button pin

     

      digitalRead(blockdetector1Pin);

      digitalRead(blockdetector2Pin);



  if (digitalRead(blockdetector1Pin) == HIGH  &&  digitalRead(blockdetector2Pin) == LOW)



      digitalWrite(yellowledPin2,LOW);



  else

  {

      digitalWrite(yellowledPin2, HIGH);

   }



    //CCW Block 1 Red

  // read from the button pin

      digitalRead(blockdetector1Pin);

    



  if (digitalRead(blockdetector1Pin) == LOW)



      digitalWrite(redledPin3,LOW);



  else

  {

      digitalWrite(redledPin3, HIGH);

       

 

   }



  // ==============================================================

  

   {

  // CCW Block 2 Green

 

  // read from the button pin

      digitalRead(blockdetector2Pin);

      digitalRead(blockdetector3Pin);

       

 

  if (digitalRead(blockdetector3Pin) == HIGH  &&  digitalRead(blockdetector3Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin4,LOW);

  else

  {

      digitalWrite(greenledPin4, HIGH);

   }



  //CCW Block 2 Yellow

  // read from the button pin

     

      digitalRead(blockdetector2Pin);

      digitalRead(blockdetector3Pin);



  if (digitalRead(blockdetector2Pin) == HIGH  &&  digitalRead(blockdetector3Pin) == LOW) //read two switches



      digitalWrite(yellowledPin5,LOW);



  else

  {

      digitalWrite(yellowledPin5, HIGH);

   }



    //CCW Block 2 Red

  // read from the button pin

      digitalRead(blockdetector2Pin);

    



  if (digitalRead(blockdetector2Pin) == LOW)



      digitalWrite(redledPin6,LOW);



  else

  {

      digitalWrite(redledPin6, HIGH);

       

  }



  

  

   }



  // ==================================================================



  {

  // CCW Block 4 Green

 

  // read from the button pin

      digitalRead(blockdetector4Pin);

      digitalRead(blockdetector5Pin);

       

 

  if (digitalRead(blockdetector4Pin) == HIGH  &&  digitalRead(blockdetector5Pin) == HIGH) //read two switches

  

      digitalWrite(greenledPin7,LOW);

  else

  {

      digitalWrite(greenledPin7, HIGH);

   }



  //CCW Block 4 Yellow

  // read from the button pin

     

      digitalRead(blockdetector4Pin);

      digitalRead(blockdetector4Pin);



  if (digitalRead(blockdetector4Pin) == HIGH  &&  digitalRead(blockdetector5Pin) == LOW)



      digitalWrite(yellowledPin8,LOW);



  else

  {

      digitalWrite(yellowledPin8, HIGH);

   }



    //CCW Block 4 Red

  // read from the button pin

      digitalRead(blockdetector4Pin);

     



  if (digitalRead(blockdetector4Pin) == LOW)



      digitalWrite(redledPin9,LOW);



  else

  {

      digitalWrite(redledPin9, HIGH);

       

  }

 

  }}

  // ================================================================



{

  // CCW Block 5 Green

 

  // read from the button pin

      digitalRead(blockdetector5Pin);

      digitalRead(blockdetector6Pin);

       

 

  if (digitalRead(blockdetector5Pin) == HIGH  &&  digitalRead(blockdetector6Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin10,LOW);

  else

  {

      digitalWrite(greenledPin10, HIGH);

   }



  //CCW Block 5 Yellow

  // read from the button pin

     

      digitalRead(blockdetector5Pin);

      digitalRead(blockdetector6Pin);



  if (digitalRead(blockdetector5Pin) == HIGH  &&  digitalRead(blockdetector6Pin) == LOW)



      digitalWrite(yellowledPin11,LOW);



  else

  {

      digitalWrite(yellowledPin11, HIGH);

   }



    //CCW Block 5 Red

  // read from the button pin

      digitalRead(blockdetector5Pin);

    



  if (digitalRead(blockdetector5Pin) == LOW)



      digitalWrite(redledPin12,LOW);



  else

  {

      digitalWrite(redledPin12, HIGH);

       

  }





 



  //==================================================================



  {

  // CCW Block 7 Green

 

  // read from the button pin

      digitalRead(blockdetector7Pin);

      digitalRead(blockdetector8Pin);

       

 

  if (digitalRead(blockdetector7Pin) == HIGH  &&  digitalRead(blockdetector8Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin13,LOW);

  else

  {

      digitalWrite(greenledPin13, HIGH);

   }



  //CCW Block 7 Yellow

  // read from the button pin

     

      digitalRead(blockdetector7Pin);

      digitalRead(blockdetector8Pin);



  if (digitalRead(blockdetector7Pin) == HIGH  &&  digitalRead(blockdetector8Pin) == LOW)



      digitalWrite(yellowledPin14,LOW);



  else

  {

      digitalWrite(yellowledPin14, HIGH);

   }



    //CCW Block 7 Red

  // read from the button pin

      digitalRead(blockdetector7Pin);

    



  if (digitalRead(blockdetector7Pin) == LOW)



      digitalWrite(redledPin15,LOW);



  else

  {

      digitalWrite(redledPin15, HIGH);

       

  }





  } 



  // =============================================================



{

  // CCW Block 8 Green



  // read from the button pin

      digitalRead(blockdetector8Pin);

      digitalRead(blockdetector9Pin);

       

 

  if (digitalRead(blockdetector8Pin) == HIGH  &&  digitalRead(blockdetector9Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin16,LOW);

  else

  {

      digitalWrite(greenledPin16, HIGH);

   }



  //CCW Block 8 Yellow

  // read from the button pin

    { 

      digitalRead(blockdetector8Pin);

      digitalRead(blockdetector9Pin);



  if (digitalRead(blockdetector8Pin) == HIGH  &&  digitalRead(blockdetector9Pin) == LOW)



      digitalWrite(yellowledPin17,LOW);



  else

  {

      digitalWrite(yellowledPin17, HIGH);

   }

{

    //CCW Block 8 Red

  // read from the button pin

      digitalRead(blockdetector8Pin);

    



  if (digitalRead(blockdetector8Pin) == LOW)



      digitalWrite(redledPin18,LOW);



  else

  {

      digitalWrite(redledPin18, HIGH);

       

  }



  // =============================================================================

  // CW

  // =============================================================================

 

  {

  // CW Block 1 Green

 

  // read from the button pin

      digitalRead(blockdetector1Pin);

      digitalRead(blockdetector12Pin);

          

 

  if (digitalRead(blockdetector1Pin) == HIGH  &&  digitalRead(blockdetector12Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin25,LOW);

  else

  {

      digitalWrite(greenledPin25, HIGH);

   }



  //CCW Block 1 Yellow

  // read from the button pin

     

      digitalRead(blockdetector1Pin);

      digitalRead(blockdetector12Pin);



  if (digitalRead(blockdetector1Pin) == HIGH  &&  digitalRead(blockdetector12Pin) == LOW)



      digitalWrite(yellowledPin26,LOW);



  else

  {

      digitalWrite(yellowledPin26, HIGH);

   }



    //CCW Block 1 Red

  // read from the button pin

      digitalRead(blockdetector12Pin);

    



  if (digitalRead(blockdetector12Pin) == LOW)



      digitalWrite(redledPin27,LOW);



  else

  {

      digitalWrite(redledPin27, HIGH);

       

 

   }



  // ==============================================================

  

   {

  // CCW Block 12 Green

 

  // read from the button pin

      digitalRead(blockdetector12Pin);

      digitalRead(blockdetector11Pin);

       

 

  if (digitalRead(blockdetector12Pin) == HIGH  &&  digitalRead(blockdetector11Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin28,LOW);

  else

  {

      digitalWrite(greenledPin28, HIGH);

   }



  //CCW Block 12 Yellow

  // read from the button pin

     

      digitalRead(blockdetector12Pin);

      digitalRead(blockdetector11Pin);



  if (digitalRead(blockdetector12Pin) == HIGH  &&  digitalRead(blockdetector11Pin) == LOW) //read two switches



      digitalWrite(yellowledPin29,LOW);



  else

  {

      digitalWrite(yellowledPin29, HIGH);

   }



    //CCW Block 12 Red

  // read from the button pin

      digitalRead(blockdetector12Pin);

    



  if (digitalRead(blockdetector12Pin) == LOW)



      digitalWrite(redledPin30,LOW);



  else

  {

      digitalWrite(redledPin30, HIGH);

       

  }



  

  

   }



  // ==================================================================



  {

  // CCW Block 7 Signal 8 Green

 

  // read from the button pin

      digitalRead(blockdetector7Pin);

      digitalRead(blockdetector6Pin);

       

 

  if (digitalRead(blockdetector7Pin) == HIGH  &&  digitalRead(blockdetector6Pin) == HIGH) //read two switches

  

      digitalWrite(greenledPin31,LOW);

  else

  {

      digitalWrite(greenledPin31, HIGH);

   }



  //CCW Block 7 Signal 8 Yellow

  // read from the button pin

     

      digitalRead(blockdetector7Pin);

      digitalRead(blockdetector6Pin);



  if (digitalRead(blockdetector7Pin) == HIGH  &&  digitalRead(blockdetector6Pin) == LOW)



      digitalWrite(yellowledPin32,LOW);



  else

  {

      digitalWrite(yellowledPin32, HIGH);

   }



    //CCW Block 7 Signal 8 Red

  // read from the button pin

      digitalRead(blockdetector7Pin);

     



  if (digitalRead(blockdetector7Pin) == LOW)



      digitalWrite(redledPin33,LOW);



  else

  {

      digitalWrite(redledPin33, HIGH);

       

  }

 

  }}

  // ================================================================



{

  // CCW Block 6 Signal 7 Green

 

  // read from the button pin

      digitalRead(blockdetector6Pin);

      digitalRead(blockdetector5Pin);

       

 

  if (digitalRead(blockdetector6Pin) == HIGH  &&  digitalRead(blockdetector7Pin) == HIGH) // read two switches

  

      digitalWrite(greenledPin34,LOW);

  else

  {

      digitalWrite(greenledPin34, HIGH);

   }



  //CCW Block 6 Signal 7 Yellow

  // read from the button pin

     

      digitalRead(blockdetector6Pin);

      digitalRead(blockdetector5Pin);



  if (digitalRead(blockdetector6Pin) == HIGH  &&  digitalRead(blockdetector5Pin) == LOW)



      digitalWrite(yellowledPin35,LOW);



  else

  {

      digitalWrite(yellowledPin35, HIGH);

   }



    //CCW Block 6 Signal Red

  // read from the button pin

      digitalRead(blockdetector6Pin);

    



  if (digitalRead(blockdetector6Pin) == LOW)



      digitalWrite(redledPin36,LOW);



  else

  {

      digitalWrite(redledPin36, HIGH);

       

  }





  }}}}}}
 
 
 


 

No comments:

Post a Comment