51 Replies Latest reply on Oct 5, 2019 12:46 PM by commanderkelly

    Flashing Led's

    commanderkelly

      Hello, I am new to this site and loving it. I did a bit of Electronics in 1995 where I made a flashing led circuit with 2 led's and it was cool. My other hobby is model trains and I would like to put 2 small led's in buffer stops and make them flash and run it off a DC train controller. Does anyone have a simple circuit that would do the job for this? I am basically a noob at electronics but I can follow a simple circuit.

       

      Thank you.

       

      Gary.

        • Re: Flashing Led's
          14rhb

          Hi Gary,

           

          Welcome to Element 14 Community. Although a long time ago, you have already completed the first step on the world of modern electronics - the famous 'blinky' experiment .

           

          I'm assuming you want your LEDs to alternate. There are many ways of doing this from relays, microcontrollers, 555 timers etc but what will be easiest is probably to search for "Astable Multivibrator + transistor". One good link I have just found is this https://www.build-electronic-circuits.com/blinking-led-circuit/  (however I apologise to other E14 members as in my own comments I have stated that I don't like posting links off site). A little way down that linked-page is a circuit titled Astable Multivibrator using transistors.

           

          If you are in the UK you can get the parts from somewhere like CPC Farnell (nice and low cost delivery), Farnell UK or in America use Newark. The transistors are nothing special, so 2N3904 would be fine; there are many other suitable ones. Again a quick Google and you will likely find a full parts list. You need to adjust the values of R1 and R4 to suit the Power Supply you are using - for 12v I would increase them to something like 750 ohms.

           

          Keep asking if you are unsure of anything, and I'd really like to know how you get on (eg a photo of the finished buffer stop lights in action )

           

          Rod

          9 of 9 people found this helpful
            • Re: Flashing Led's
              commanderkelly

              Thank you for the info you have given me, I will do a photo for sure and let you know how it went. I will have to wait 2 weeks to get the stuff as I do not work so not got money right now. I do live in the UK so I will check the places you have told me to check.

               

              Gary.

              2 of 2 people found this helpful
              • Re: Flashing Led's
                fmilburn

                Hi Rod and Gary,

                I am more of a digital guy but I saw this and had to build it.  The circuit is close to the first link that Rod gave above.  The voltage source is 4 AAA, R1 and R4 are 330 ohm, R2 and R3 are 47k, the caps are 22 uF, and the transistors are 2N3904.

                 

                6 of 6 people found this helpful
                  • Re: Flashing Led's
                    commanderkelly

                    Thank you for the video and for the info given, I will be using a DC train controller for the power. The output power of the controller I am using is 14.2V now I did try a led on it hooked up to a 1k resistor as that is all I got at the moment are 100x 1K Ohm and it worked great did not get to bright.

                     

                    Gary.

                      • Re: Flashing Led's
                        14rhb

                        If you have loads of 1k resistors and don't mind using several of them up you could parallel two to get 500 ohms. Put three in parallel to get 330 ohms. Then put the double bundle in series with the triple bundle to get 830 ohms....probably about right for your 14v supply.

                         

                        If you are buying a resistor for R1 and R4 I would choose something around 680 ohms for a 14.2v supply (14.2 v - 0.2 v drop in transistor, 20mA design current for LED ) and they should be a good brightness. That assumes a fairly standard LED current, if you know the part numbers of the LEDs you have then you could look up the If (the forward current they recommend). Again, if you are unsure, just ask.

                         

                        Rod

                         

                        [editted: see calculation below that included the voltage drop of the LED]

                        4 of 4 people found this helpful
                      • Re: Flashing Led's
                        14rhb

                        Hi Frank,

                         

                        That is really great to see, well done, I'm sure it has really helped commanderkelly to see what the finished project will look like before spending any money

                         

                        Ro

                    • Re: Flashing Led's
                      beacon_dave

                      Probably can't get much simpler than a flashing LED: 

                      https://uk.farnell.com/c/optoelectronics-displays/led-products/flashing-blinking-leds

                      Size may be an issue however. 3mm is the smallest listed.

                      7 of 7 people found this helpful
                      • Re: Flashing Led's
                        commanderkelly

                        Hello Rod,

                         

                        I have no clue what the part number is sorry I only have a pic I just took.

                        Leds

                         

                        not sure if that helps.

                         

                        Gary.

                        1 of 1 people found this helpful
                          • Re: Flashing Led's
                            14rhb

                            If you have no other information on them you can usually just work out the resistance for 20mA @2.2v drop.

                             

                            Actually in my calculation above I forgot the voltage drop of the LED: so 14.2v -0.2 - 2 = 12v to drop across the R1/R4

                             

                            12v / 20mA = 600 ohms => 620 ohms typically

                             

                            Rod

                            4 of 4 people found this helpful
                              • Re: Flashing Led's
                                commanderkelly

                                Hello Rod,

                                 

                                I will do that, I seen a resistor pack on Amazon I will get to do the job as it should have what I need in it.

                                 

                                Gary.

                                • Re: Flashing Led's
                                  commanderkelly

                                  Hello Rod,

                                   

                                  I made the Flashing led circuit but got a prob, I made a video for you to check.

                                   

                                  https://www.youtube.com/watch?v=G2GYehn22DU&list=PL-kfiq8mHqQ2-8B3Lid3TlONV2XteJgby

                                  1 of 1 people found this helpful
                                    • Re: Flashing Led's
                                      fmilburn

                                      Hi Gary,

                                       

                                      As you noted, it appears it is flashing so rapidly at 14V that it almost appears constantly lit.  So, the circuit is charging and discharging too rapidly with the higher voltage.  A solution might be to use a resistor in line with the voltage source to reduce it down to 9V or possibly lower.  Using Ohms Law and assuming a 5 V reduction and current on average 20 mA we get a resistor or 5V / .02 = 250 ohms.  You could use a 1000 ohm potentiometer set up as a rheostat to control the blink rate.  Alternatively you could swap out resistors R1 and R4 for higher resistance in the circuit.  Rod will correct me if I am wrong :-)

                                       

                                      Frank

                                        • Re: Flashing Led's
                                          commanderkelly

                                          Hello Frank,

                                           

                                          I will try what you have said and let you know.

                                           

                                          Gary.

                                          • Re: Flashing Led's
                                            commanderkelly

                                            Hello Frank,

                                             

                                            I try what you said and there was no change so I change the caps from 10uf to 100uf. It did seem to slow it just a bit so maybe adding a adding a high value ones will help.

                                             

                                            Gary.

                                              • Re: Flashing Led's
                                                fmilburn

                                                I will try breadboarding the circuit when I get back home...

                                                • Re: Flashing Led's
                                                  fmilburn

                                                  OK, disregard everything I said above.  Should have thought this through and looked closer before posting...

                                                   

                                                  R1 and R4 control current through the LEDs and serve to make them brighter or dimmer.  R2 and R3 (along with the capacitors) control timing.  In the video below increasing R2 and R3 by a factor of 20 demonstrates the concept.  Do a search for RC time constant to learn more.

                                                   

                                                  If you use a potentiometer as a voltage divider it will also change the rate (and the LED brightness).  This is demonstrated in video as well ( the probes on the multimeter are backwards which is why it shows negative voltage ).

                                                   

                                                   

                                                  Forget the potentiometer and try playing with R2,R3 resistance and capacitance.  Thanks to Rod for pointing out this simple but humbling little circuit.

                                                  1 of 1 people found this helpful
                                                    • Re: Flashing Led's
                                                      14rhb

                                                      I thought this circuit's timing was proportional to the C and R only and not supply voltage dependant?

                                                      but thanks to Frank taking the time to experiment, we see timing does vary with supply voltage.

                                                       

                                                      Rod

                                                        • Re: Flashing Led's
                                                          fmilburn

                                                          Hi Rod,

                                                           

                                                          I have been playing with it a bit more.  In my experiment it gets faster and dims as the voltage decreases.  Gary's observation is it gets faster as the voltage increases. Does the lower supply voltage in my experiment mean it does not take as much time to charge the capacitor to circuit required capacity and also discharges faster and so speeds things up?  That kind of makes sense (to a mechanical engineer least :-).  I ran it again just now all the way up to 14 V on my bench power supply.  It does not speed up but appears to continue to slow a bit.  So something else appears to be going on for Gary.

                                                           

                                                          Frank

                                                           

                                                          EDIT:  The rapid blinking only occurs at very low voltages in my experiment - the rate does not change so much between 6V and 14V.  Time to break out the simulator...

                                                    • Re: Flashing Led's
                                                      14rhb

                                                      As you noted, it appears it is flashing so rapidly at 14V that it almost appears constantly lit.  So, the circuit is charging and discharging too rapidly with the higher voltage.

                                                      Yes, it does appear so. I'm not quite so sure about the reason though - I thought this circuit's timing was proportional to the C and R only and not supply voltage dependant?

                                                       

                                                      I'm having a think....

                                                       

                                                      Rod

                                              • Re: Flashing Led's
                                                e14phil

                                                I'm a big fan of "flashing LEDS", you can buy them off the shelf and they flash without a timer circuit.

                                                The only drawback is that you don't have control over the speed they flash.

                                                • Re: Flashing Led's
                                                  14rhb

                                                  To everyone following commanderkelly initial blog, I must admit there are some strange goings on for such a simple circuit

                                                   

                                                  Like fmilburn I also breadboarded this to see how supply voltage affected the flash rate. I used 2N3804 transistors, 68k + 10uF/25v capacitors, plain old technology LEDs + 560 ohm current limiting resistors. These component values give a decent 1.22 Hz flash rate at 14v DC.

                                                   

                                                  The flash rate did vary, and it increased as the voltage dropped to around that required by the LEDs...as expected. Mid-voltages I saw a flash rate as expected, as seen in the blue plot below. This was based on the following equation:

                                                  frequency      = 1 / (0.38 * R * C)

                                                                        = 1.06Hz Frequency of standard astable multivibrator increases at higher supply voltages. Modifying the circuit by adding a base diode stops this happening.

                                                  But at higher voltages the flash rate started to increase again and I wasn't sure why. I don't think it is to do with the capacitors: for some types of capacitor the capacitance value changes significantly with applied voltage, but that isn't the case for electrolytics. I ran the circuit without the LEDs and measured the frequency on an oscilloscope and it still exhibited this variance in frequency. That leaves the effect down to the transistors.

                                                   

                                                  Focusing on the voltages on the transistor, and specifically the base voltage (which goes negative during switching and the capacitor voltage is maintained but inverts) this reverse biased the base-emitter junction of the transistor....there is a rated value in the specification sheets for that of 6v minimum. I suspect when that is overcome the junction behaves like a Zener diode, something we did not expect. Now the timing will start to vary as we see in the blue plots above. There is a solution though. Adding a simple diode like the 1N4148 in series with the base of both transistors prevents this effect occuring as these diodes now increase that breakdown voltage significantly to approx. 75v.

                                                   

                                                  Plotting the frequency now gives the orange graph above. We can see the circuit behaves poorly at low voltages as it now has to overcome the forward bias of the new diode to start working. But at higher voltages it definately looks much better.

                                                   

                                                  Rod

                                                  2 of 2 people found this helpful
                                                    • Re: Flashing Led's
                                                      14rhb

                                                      ps: there is always an advantage to being awake at 4am

                                                      • Re: Flashing Led's
                                                        jc2048

                                                        Although datasheets always show it as either 5V or 6V, in reality reverse breakdown of the base-emitter junction can be a good bit higher than that - more like 7 or 8V. It's exactly the same effect as a 'zener' diode of more than 3 or 4 volts, merely the reverse breakdown of a pn junction by avalanching. The difference is that with an actual zener it's designed to cope with a certain power level and is properly characterised for voltage. With the transistor, it will start to do damage that will probably affect the transistor properties.

                                                         

                                                        On a 9V battery you can usually get away with it without problems, although technically you are outside the datasheet. With higher voltages, traditionally people used to put diodes in series with the emitters like this

                                                         

                                                         

                                                        That's from Transistor Circuit Design published by the engineering staff of Texas Instruments in 1963.

                                                         

                                                        I'm not sure why that's better than having the diode in series with the base where you'd preserve the output swing. The effect on the timing would be the same. Perhaps there's a snag with doing that that I can't see.

                                                        3 of 3 people found this helpful
                                                        • Re: Flashing Led's
                                                          fmilburn

                                                          Great detective work Rod!  Good on you for for actually measuring frequency at higher voltage as I missed that. 

                                                          • Re: Flashing Led's
                                                            commanderkelly

                                                            I will try this when I get some more stuff thanks.

                                                             

                                                            Gary.

                                                          • Re: Flashing Led's
                                                            commanderkelly

                                                            I want to thank everyone who is helping me with this.

                                                             

                                                            Gary.

                                                            • Re: Flashing Led's
                                                              commanderkelly

                                                              I have not been well for a bit but have not forgot about this project. I have now got one of them Ardunio Uno and was thinking of powering the flashing leds with it in the buffer stops. Now as I said before I am a noob at all this and I have no clue how to use an Arduino, Can anyone help me out here. I would like to power say like 10 flashing leds on differant buffer stops around the train track. Would this be possible on 1 Arduino and does anyone have a circuit that would help me do this.

                                                               

                                                              Thank you Gary.

                                                                • Re: Flashing Led's
                                                                  shabaz

                                                                  Hi Gary,

                                                                   

                                                                  It can do that, there's an example for a single LED here:

                                                                  https://www.arduino.cc/en/tutorial/blink

                                                                   

                                                                  Once you've tried that, then you'll have confirmed the software and hardware is functioning, and then you can extend it to more LEDs to achieve your aim. Extending to flash two LEDs alternatively is easy by slightly modifying this code.

                                                                  However, it wasn't clear what behaviour you were looking for. If it is to flash all LEDs identically or flash all LEDs in alternate pairs, then the code doesn't need to change further, you can connect many LEDs to the same connections on the Arduino, although you'll need to use some small additional circuit to provide the current for all the LEDs. Is this what you're aiming to do?

                                                                  Otherwise, if your aim is to make them flash at different rates, or alternately, or under control of individual switches or sensors, then that will need more code changes.

                                                                  The easiest way is to start with the blink example mentioned, and then try a few more examples, to get familiar with the capabilities of the Arduino. Then you'll feel confident to want to do more complex behaviour for the LEDs (e.g. controlled by switches as mentioned).

                                                                   

                                                                  The tutorials here: https://www.arduino.cc/en/Tutorial/BuiltInExamples   will give you a feel for the capabilities of the Arduino (not all need to be tried, just a few that interest you).

                                                                  4 of 4 people found this helpful
                                                                    • Re: Flashing Led's
                                                                      commanderkelly

                                                                      Hello and thank you I just want them to flash at the smae rate so for now this will do, thanks for your help.

                                                                       

                                                                      Gary

                                                                      1 of 1 people found this helpful
                                                                        • Re: Flashing Led's
                                                                          fmilburn

                                                                          Hi Gary,

                                                                           

                                                                          If you are OK with them flashing at the same rate and more or less synchronized then it is fairly straightforward  with an Arduino and will work just as Shabaz has described.  The circuit will be simple. There can be 10 output pins connected to the LEDs with current controlling resistors of say 330 ohms.  There could be 10 input pins for switching the behavior of the LEDs.  When a switch signals the start a timer can be used to determine how long the blinking occurs.  It is an interesting project.  Once you get things working as Shabaz describes then report back if it is not clear on how to proceed.

                                                                          3 of 3 people found this helpful
                                                                          • Re: Flashing Led's
                                                                            fmilburn

                                                                            PS:  it should be much easier with an Arduino than all the mucking about we did above :-)

                                                                              • Re: Flashing Led's
                                                                                commanderkelly

                                                                                The Arduino UNO did it for me, just what I want. 1. tryed with 1 Led flashing2. added another led where both was flassing at same time. I want to Thank everyone who as helped me with this project really nice people, I am sure I will play with this to make them flash at different times.

                                                                                5 of 5 people found this helpful
                                                                          • Re: Flashing Led's
                                                                            14rhb

                                                                            Hi commanderkelly

                                                                             

                                                                            Sorry to hear you were unwell - hopefully you are OK now.

                                                                             

                                                                            Thank you for keeping us informed of your project progress. It is always nice to know someone's goals are progressing and it sounds like yours are with extra LEDs around the model. You've got some great replies already and I'm so pleased to see your Arduino progress. Personally I too like the Arduino as you can very easily and accurately adjust the timings. In time you may also like to add a switch input - perhaps a microswitch that the train brushes against or better still a non-contact sensor....we can discuss that when you are ready. You would then be able to modify your Arduino code to perform an action based on that switch or to undertake an action (the buffer LEDs toggling) for a certain amount of time before turning off again.

                                                                             

                                                                            I see you have suggestion of using the 555 timer IC - always a staple device for such projects in the past and I think most of us have a fond spot for it. However it cannot be configured quite as easily - great if you are happy with the exact blink times and the 50:50 split between two LED but less so when the timing division is asymmetrical or hard to set. Setting up switches would then be more complex as well....not  extremely, but just a bit awkward IMO.

                                                                            1 of 1 people found this helpful
                                                                              • Re: Flashing Led's
                                                                                commanderkelly

                                                                                Hello 14rhb,

                                                                                 

                                                                                I like what you are talking about here, I was thinking about a sensor also. Where the train say like driving up to the buffer stop and the sensor picks it up and the buffer spot LED starts to flash and when the trian get right up close the LED then stops flashing and stays on to let the train know to stop. I am not sure if that could be done or not and you might have other ideas.

                                                                                 

                                                                                Gary.

                                                                                 

                                                                                I have also ordered some 555 timers.

                                                                                1 of 1 people found this helpful
                                                                                  • Re: Flashing Led's
                                                                                    14rhb

                                                                                    You should be able to do all that with your Arduino. Currently you are using some pins as outputs to the LEDs, as well as that you can set pins up as inputs.

                                                                                     

                                                                                    Mechanical Switch

                                                                                    The simple circuit below shows such a switch wired in [the full article is on the Arduino website: https://www.arduino.cc/en/tutorial/button ].

                                                                                    With the switch open circuit the Arduino reads a low voltage on the pin 2 as this is effectively grounded through the resistor. When the switch is pushed the +5v appears on the input. In your Arduino code you would probably loop around in a 'WHILE LOOP' constantly reading the switch and adjusting the LED state accordingly. That is the fun part as you are effectively crafting the code to do what you want.

                                                                                     

                                                                                    A simple switch would need pushing and I guess physical contact between train and switch could easily scratch or derail the train. You could maybe get one under the track that detects the extra weight as the train passes over.

                                                                                     

                                                                                    Contactless Switch is Better

                                                                                    Probably a better way is to go for a contactless setup but it would be slightly more difficult to understand. There are several ways including Hall Effect switches but my preferred route would be to use an Infra-Red (IR) diode and photo-detector placed either side of the track. The classic bank-burglar beam break setup just in miniature: The IR LED would run from the Arduino +5v supply via a suitable resistor - this would emit a constant level of IR light across the track and onto the photo-detector. The photo-diode would need a transistor amplifier but effectively become your switch input....I'll try and find/draw the bits you need but there aren't many.

                                                                                     

                                                                                    *** Easier still you could also just buy the sensors (search Adafruit IR Beam Break Sensor) as they incorporate the LED resistor and the photo-detector amplifier. You can see an example of them being used here: https://learn.adafruit.com/ir-breakbeam-sensors/arduino

                                                                                     

                                                                                    Coding

                                                                                    For your idea you would need two beam break sensors - one on the buffer approach and the other right up close to the buffer. When ready we'll gladly help with any code suggestions for you as well

                                                                                    2 of 2 people found this helpful
                                                                              • Re: Flashing Led's
                                                                                SGarciaV

                                                                                Hi Gary. I see that you've gotten lots of great responses. Personally, I am partial to the 555 :-D

                                                                                 

                                                                                I recently built a circuit similar to the one described in the following video:

                                                                                 

                                                                                https://youtu.be/gYnd_nMi39g

                                                                                 

                                                                                As for the Arduino, once you have the board you need to install the Arduino IDE. You can get that at the following link:

                                                                                 

                                                                                https://www.arduino.cc/en/main/software

                                                                                 

                                                                                Two important settings of the IDE that *must* be correct are the serial port designation and the board type. There are lots of Arduino models, such as Uno, Nano, Mega, Leonardo and many more from other vendors. To get started, I would purchase one that is compatible with either the Uno or Nano.

                                                                                 

                                                                                If the Arduino IDE is open, close it. Connect the Arduino to the PC via the provided USB cable. Note that the Uno uses a different cable than the Nano (for example).

                                                                                 

                                                                                Once the Arduino is connected to the PC, the OS should recognize it and assign a serial port to it. Note that my experience and comments are in regard to a Windows installation.

                                                                                 

                                                                                Now launch the Arduino IDE. Locate the settings for the port and select the port that was assigned to the Arduino that you connected. Also select the correct board.

                                                                                 

                                                                                Go to the File menu option and open the Blink example. This is a really simple program, which in the Arduino world programs are called sketches, that blinks the internal LED. Once the program is open, click on the button to compile and download the sketch to the Arduino. If you get an error, check that the Arduino is connected and also check that you selected the correct serial port and board.

                                                                                 

                                                                                Search E14 and Youtube, there are lots of tutorials to get you started. Here is one possible video:

                                                                                 

                                                                                https://youtu.be/kLd_JyvKV4Y

                                                                                 

                                                                                Sorry, at 37 minutes, I don't have time to watch it to comment on the video. Also search for Jeremy Blum's Arduino videos. Hopefully this info will be helpful to you. Good luck on your projects and welcome to Element 14, where everyone knows Ohm's Law! ;-)

                                                                                2 of 2 people found this helpful
                                                                                  • Re: Flashing Led's
                                                                                    commanderkelly

                                                                                    Hello and thank you, I have the Uno board and downloaded the softwear to windows. I'll check them videos out thank you.

                                                                                     

                                                                                    Gary.

                                                                                    • Re: Flashing Led's
                                                                                      14rhb

                                                                                      I too have a fond liking for the 555 having used it for many projects through the 80's/90's. It was amazing what projects that IC could be used for and indeed people wrote whole books on the subject.

                                                                                       

                                                                                      However I will often now undertake such projects using a PIC microcontroller that operates on its own internal clock. Some of these 8-bit MCU have very small footprints. The timing is extremely accurate (for LED flashing anyway), they can be reconfigured easily and have almost no other components. I used a very small Surface Mount Technology device (SMT) on this quick project ledog - Light Emitting Dog

                                                                                    • Re: Flashing Led's
                                                                                      kmikemoo

                                                                                      commanderkelly Welcome to the wonderful world of Arduino.  The Uno is my favorite.  You'll have a lot of fun integrating it into your railroad.  Prepare to lose even more sleep due to your hobby.