Forums » Electronics

List of newest posts

    • August 2, 2018 7:28 PM EDT
    • I've recently communicated with Dennis Drury with questions about his ABS code for the Arduino. He was nice enough to send me the latest version of the code.

      Are there many out there using this code for simple signals? Or some other Arduino-based code for operating signals?

      David

       

      /*

        ABS Signal circuit using the Arduino microcontroller.

        This code implements a single section of bi-directional ABS signals using either the Uno, Leonardo, or ProMini boards.

        Version 1.2 by Dennis Drury

        Version history

        V1.0 Initial Release

        V1.1 Added approach lighting

        V1.2 Changed pin assignments to better match up with the Pro Mini board.

        V1.3 Changed pin assignments to better match up with the Nano board.

        This code is in the public domain and may be freely copied or modified.

        

                            Sig_1

                                 0-| 

        ------|-------|-------|----------|-------|-------

        Blk_1   Blk_2   Blk_3 |-0  Blk_4   Blk_5   Blk_6

                            Sig_2

        

        The Flashing Yellow section includes modified code from the Arduino.cc website that is in the public domain

        http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay

        

      */

       

      // There are six detected blocks

      // Blk_1 to Blk_6

      int Blk_1 = A1;

      int Blk_2 = A2;

      int Blk_3 = A3;

      int Blk_4 = A4;

      int Blk_5 = A5;

      int Blk_6 = A6;

       

      // There are six signal outputs

      // Sig_1r, Sig_1y, Sig_1g, Sig_2r, Sig_2y and Sig_2g

      const int Sig_1r = 4;

      const int Sig_1y = 5;

      const int Sig_1g = 6;

      const int Sig_2r = 7;

      const int Sig_2y = 8;

      const int Sig_2g = 9;

       

      // There are four internal variables that will change.  These are only used for the flashing yellow aspects.

      int Sig_1y_f = LOW;

      int Sig_2y_f = LOW;

      long previousMillis1 = 0;

      long previousMillis2 = 0;

       

      // The following variables are the flash rates for the signals.

      // Note these values may need to change depending on the size of your final code and the clock speed of your processor.

      // The numbers are slightly different because in my experience no two prototype flashing relays ever flashed at the exact same rate.

      long interval1 = 800;

      long interval2 = 810;

       

      // The setup routine runs once on bootup or pressing the reset button

      void setup() {

        // Set up the blocks as inputs

        pinMode(Blk_1, INPUT_PULLUP);

        pinMode(Blk_2, INPUT_PULLUP);

        pinMode(Blk_3, INPUT_PULLUP);

        pinMode(Blk_4, INPUT_PULLUP);

        pinMode(Blk_5, INPUT_PULLUP);

        pinMode(Blk_6, INPUT_PULLUP);

          

        // Set up the signals as outputs

        pinMode(Sig_1r, OUTPUT);

        pinMode(Sig_1y, OUTPUT);

        pinMode(Sig_1g, OUTPUT);

        pinMode(Sig_2r, OUTPUT);

        pinMode(Sig_2y, OUTPUT);

        pinMode(Sig_2g, OUTPUT);

      }

      // This loop runs continously

      void loop() 

      {

       

        // Read block occupancy

        Blk_1 = digitalRead(A1);

        Blk_2 = digitalRead(A2);

        Blk_3 = digitalRead(A3);

        Blk_4 = digitalRead(A4);

        Blk_5 = digitalRead(A5);

        Blk_6 = digitalRead(A6);

       

        // Set signal 1 Green

        if (Blk_3 == HIGH && Blk_2 == HIGH && Blk_1 == HIGH) //If approach lighting add "&& Blk_4 == LOW" to if statement

         {

         digitalWrite(Sig_1r, HIGH); digitalWrite(Sig_1y, HIGH); digitalWrite(Sig_1g, LOW);

         }

         

        // Set signal 1 Flashing Yellow

        if (Blk_3 == HIGH && Blk_2 == HIGH && Blk_1 == LOW) //If approach lighting add "&& Blk_4 == LOW" to if statement

          {

           digitalWrite(Sig_1r, HIGH); digitalWrite(Sig_1g, HIGH);

           unsigned long currentMillis1 = millis();

          

        if(currentMillis1 - previousMillis1 > interval1)

          {

          // save the last time you blinked the LED

          previousMillis1 = currentMillis1;  

       

          // if the LED is off turn it on and vice-versa:

          if (Sig_1y_f == LOW)

            Sig_1y_f = HIGH;

          else

            Sig_1y_f = LOW;

       

          // set the LED with the state of the variable:

          digitalWrite(Sig_1y, Sig_1y_f);

          } 

          }

         // Set signal 1 Yellow

        if (Blk_3 == HIGH && Blk_2 == LOW) //If approach lighting add "&& Blk_4 == LOW" to if statement

         {

         digitalWrite(Sig_1r, HIGH); digitalWrite(Sig_1y, LOW); digitalWrite(Sig_1g, HIGH);

         }

        

        // Set signal 1 Red

        if (Blk_3 == LOW) //If approach lighting add "&& Blk_4 == LOW" to if statement

         {

         digitalWrite(Sig_1r, LOW); digitalWrite(Sig_1y, HIGH); digitalWrite(Sig_1g, HIGH);

         }

        

        /*

        Uncomment the /* pair to enable approach lighting

        // Set signal 1 to Off

        if (Blk_4 == HIGH)

          {

          digitalWrite(Sig_1r, HIGH); digitalWrite(Sig_1y, HIGH); digitalWrite(Sig_1g, HIGH);

          }

        */  

       

      // Set signal 2 Green

        if (Blk_4 == HIGH && Blk_5 == HIGH && Blk_6 == HIGH) //If approach lighting add "&& Blk_3 == LOW" to if statement

           {

           digitalWrite(Sig_2r, HIGH); digitalWrite(Sig_2y, HIGH); digitalWrite(Sig_2g, LOW);

           }

           

        // Set signal 2 Flashing Yellow

        if (Blk_4 == HIGH && Blk_5 == HIGH && Blk_6 == LOW) //If approach lighting add "&& Blk_3 == LOW" to if statement

          {

          digitalWrite(Sig_2r, HIGH); digitalWrite(Sig_2g, HIGH);

          unsigned long currentMillis2 = millis();

       

        if(currentMillis2 - previousMillis2 > interval2)

          {

          // save the last time you blinked the LED

          previousMillis2 = currentMillis2;  

          // if the LED is off turn it on and vice-versa:

          if (Sig_2y_f == LOW)

            Sig_2y_f = HIGH;

          else

            Sig_2y_f = LOW;

        

          // set the LED with the ledState of the variable:

          digitalWrite(Sig_2y, Sig_2y_f);

          }

          }

        // Set signal 2 Yellow

        if (Blk_4 == HIGH && Blk_5 == LOW) //If approach lighting add "&& Blk_3 == LOW" to if statement

           {

           digitalWrite(Sig_2r, HIGH); digitalWrite(Sig_2y, LOW); digitalWrite(Sig_2g, HIGH);

           }

        

        // Set signal 2 Red

        if (Blk_4 == LOW) //If approach lighting add "&& Blk_3 == LOW" to if statement

         {

         digitalWrite(Sig_2r, LOW); digitalWrite(Sig_2y, HIGH); digitalWrite(Sig_2g, HIGH);

         }

         

         /*

         Uncomment the /* pair to enable approach lighting

         // Set signal 2 to Off

         if (Blk_3 == HIGH)

         {

         digitalWrite(Sig_2r, HIGH); digitalWrite(Sig_2y, HIGH); digitalWrite(Sig_2g, HIGH);

         }

         */

      }

       

    • June 23, 2018 9:45 AM EDT
    • Bob, maybe you need to brush up on your boolean algebra.

    • June 23, 2018 8:51 AM EDT
    • Bob McCown said:
      Al Pomeroy said:

      Bob,

      sounds like we will be under signal rules for trainopps?

      Al P.

      Not this year, but 'eventually'.  There's still lots to do, but this year I'll be collecting some data behind the scenes to get a feel for how the system will work.  Last year we had some signals at Burke, and I discovered a couple of oddities. 

      Odditiy?   So that's what I am now???  Sheesh.

       

    • June 23, 2018 8:46 AM EDT
    • Al Pomeroy said:

      Bob,

       

      sounds like we will be under signal rules for trainopps?

       

      Al P.

       

      Not this year, but 'eventually'.  There's still lots to do, but this year I'll be collecting some data behind the scenes to get a feel for how the system will work.  Last year we had some signals at Burke, and I discovered a couple of oddities. 

    • June 23, 2018 8:14 AM EDT
    • David Maynard said:

      Ah, those who can, do. Those who can't, teach. And those who cant teach, teach gym.

      I gotcha.

      When I was an instructor, we had folks come in and "teach" us how to become better instructors.    So, our version was: "those who can, do; those who can't, teach; and those who cant teach, teach the teachers."

    • June 23, 2018 7:47 AM EDT
    • Ah, those who can, do. Those who can't, teach. And those who cant teach, teach gym.

      I gotcha.

    • June 22, 2018 9:12 PM EDT
    • David Maynard said:

      Great! And what about the poor folks who are colour blind, or extremely myopic?

      They become instructors.

    • June 22, 2018 6:55 PM EDT
    • Great! And what about the poor folks who are colour blind, or extremely myopic?

    • June 22, 2018 6:01 PM EDT
    • Bob,

       

      sounds like we will be under signal rules for trainopps?

       

      Al P.

    • June 22, 2018 12:32 PM EDT
    • 90 percent of my signals wont be facing direct sun;  I havent seen an issue yet, at least with the ones out on the layout already.  And if it becomes an issue, there are high-intensity LEDs available.

    • June 21, 2018 7:38 PM EDT
    • While very cool, I don't believe that semaphores would be reliable, long term, in the garden setting nor do most lay-people really pay attention to that sort of thing.

    • June 20, 2018 10:09 PM EDT
    • Todd, so maybe you need to use semaphores.

    • June 20, 2018 9:46 PM EDT
    • Problem I have is that you can't really see the green and the red is really hard to see during the day in the sunlight.

    • June 20, 2018 9:37 PM EDT
    • Another small update.  Signal ready for installation, protecting the entry to Burke yard from Williamsport.  The base will get painted, and buried under the ballast.

       

    • June 20, 2018 12:25 PM EDT
    • David Palmeter said:

      Back to square one. I want the battery box, wiring and lights all self contained for easy removal for battery charging so an external magnetic off-on capability would be a plus. Has anyone been able to find a source for reasonably priced and readily available latching reed switches lately?

      I did find THESE but no retail source. Anyone?

      David - I once sold such latching reed switches on eBay - I had a good source but it has since dried up - I still have 50 or 60 left- how many do you need?

      There are some notes and a short video here

      http://www.trainelectronics.com/LED_Articles_2007/LED_103/index.htm

      Drop me an email dave@davebodnar.com

      dave

    • June 20, 2018 5:51 AM EDT
    • Dave Bodner demonstrated such a set up at out club once. I would see if he knows.

    • June 19, 2018 9:19 PM EDT
    • I did get magnets and batteries and the tests have proven successful. However, when a mechanical engineer messes with electronics, generally some big chunk of metal ends up in the circuit. I really like the 'wave a magnetic wand' method of switching the passenger car lights on and off, and since latching reed switches are mostly unavailable, I came up with this genius solution. This is part of the battery box inside the roof so I can use a magnet outside the roof to move the ball bearing between the wired and unwired boxes. Mechanically it works a treat but electrically, when shaken around as if travelling on my branch line level of track maintenance, it reintroduces the dreaded blinkys. I even applied dielectric grease to damp the oscillations - no luck. 

      Back to square one. I want the battery box, wiring and lights all self contained for easy removal for battery charging so an external magnetic off-on capability would be a plus. Has anyone been able to find a source for reasonably priced and readily available latching reed switches lately?

      I did find THESE but no retail source. Anyone?

    • June 18, 2018 12:28 AM EDT
    • Nowadays, web sites are cheap to the point of being free.

       

      The domain has a private registration, i.e. someone pays extra to not reveal who owns it... interesting... so they have the money to pay extra on the registration but not the money to have a working website?

       

       

    • June 17, 2018 10:20 PM EDT
    • I got the "Forbidden" message too. I guess they do not want my business.

      Tom