LED to indicate Arduino is running - Page 1
Forum section: electronics / beginners

author: scott216
author_rank: Regular Contributor
timestamp: October 12, 2014, 11:05:26 pm
content: From time to time I'll have an Arduino lock-up. In the past if I wanted to check for a lock-up I setup a heartbeat LED which will blink when the Arduino is running. If the program hangs, the LED will stop blinking. I have a project now where I want the LED to stay on continuously if the sketch is running and turn off if the Arduino locks-up. I was thinking I could still have a heartbeat output, but instead of going directly into an LED, it would go into a little circuit which controls the LED. The circuit would look for the heartbeat and if it didn't see a heartbeat, the LED would turn off. I don't know how to build a circuit that would do this. Any suggestions?

author: suicidaleggroll
author_rank: Super Contributor
timestamp: October 12, 2014, 11:15:19 pm
content: How have you controlled the heartbeat in the past? What if the Arduino locks up while the output is high instead of low? Doesn't Arduino have a watchdog timer?I've never used an Arduino, is locking up really that common? It seems like a fundamental problem that should be fixed, rather than jumping through hoops trying to implement some kind of signal to tell you when it's screwing up. Maybe if it's that big of an issue you should use a different (aka: more reliable) platform?I can think of a lot of ways to accomplish this, but it all seems like a roundabout way to notify the user of a problem that should never happen in the first place.

author: ludzinc
author_rank: Unknown
timestamp: October 12, 2014, 11:17:33 pm
content: Just use the output to retrigger a monostable multivibrator.Typically a 555 is used for this, amongst other options.See here:http://www.eleinmec.com/article.asp?4

author: scott216
author_rank: Regular Contributor
timestamp: October 12, 2014, 11:22:48 pm
content: Quote from: suicidaleggroll on October 12, 2014, 11:15:19 pmIf the LED stops blinking I don't care if the output is high or low, I'll see that it stops blinking. It's doesn't happen much, I think the Arduino is pretty reliable. I've seen it generally happen with some sort of communication problem, like with Ethernet or I2C, and also with a memory problem. Like a string was too long or it ran out of memory.Watchdog timer works on some Arduinos and not others - I think it depends on the bootloader. One problem with watchdog is it kind-of hides the problem. The Arduino could be hanging and rebooting and I wouldn't know it.

author: scott216
author_rank: Regular Contributor
timestamp: October 12, 2014, 11:24:37 pm
content: Quote from: ludzinc on October 12, 2014, 11:17:33 pmThanks, I'll check that out. I figured a 555 would probably be involved one way or another.

author: suicidaleggroll
author_rank: Super Contributor
timestamp: October 12, 2014, 11:27:32 pm
content: Quote from: scott216 on October 12, 2014, 11:24:37 pmRemember the comment I made about it failing high or low. You don't want a solution that counts in one state and resets in another, you need a solution that counts in steady state (high or low) and resets on transitions.

author: zapta
author_rank: Super Contributor
timestamp: October 12, 2014, 11:30:16 pm
content: You want a ''retrigerable" and "edge triggered" monostable, like this one (there are many others)http://www.nxp.com/documents/data_sheet/74LVC1G123.pdf

author: scott216
author_rank: Regular Contributor
timestamp: October 13, 2014, 01:15:09 am
content: Thanks for all the help. I just built this circuit with a 555 timer and it looks like it should do what I need.http://www.doctronics.co.uk/555.htm#retriggering

author: SL4P
author_rank: Super Contributor
timestamp: October 13, 2014, 02:32:12 am
content: Quote from: scott216 on October 12, 2014, 11:05:26 pmIsn't that a bit indeterminate? If it locks up - putting a LED toggle conveniently in the (buggy) lock-up code may be harder than it appears (why not fix the code?) !Or put your LED toggle somewhere within the main loop(), perhaps with a divider to make it 'visible'... say 5Hz or whatever. Then you'll see when the loop has become 'locked-up'. Perhaps even using an interrupt & counter to restart or break out of your code (a-la watchdog style).Even better, you can update a global variable at various places in your code, and oly when the crash timer fires - read that variable to see the most recent place the variable was updated (i.e. most recent updated value from your code).

author: zapta
author_rank: Super Contributor
timestamp: October 13, 2014, 04:56:15 am
content: Quote from: scott216 on October 13, 2014, 01:15:09 amIf your MCU will get stuck in the trigger state the LED will stay on. This is why you want an edge triggered monostable.

author: kolbep
author_rank: Frequent Contributor
timestamp: October 13, 2014, 05:54:57 am
content: Enable the WDT, and possibly BOR,then have code at the start of the program, that if, when it starts up, it detects that it was a WDT reset or BOR (anything really except for normal powerup), if it does see the flag, then light up a LED to let you know it locked and was restarted.Although, I am more used to PICS, so I do not know what functionality like that the Arduino has.

author: scott216
author_rank: Regular Contributor
timestamp: October 13, 2014, 11:54:29 am
content: Quote from: zapta on October 13, 2014, 04:56:15 amGood point. Thanks.

author: scott216
author_rank: Regular Contributor
timestamp: October 13, 2014, 12:06:54 pm
content: Quote from: kolbep on October 13, 2014, 05:54:57 amWhat's BOR? I'm not sure if there's a way for the Arduino to know it restarted from a timeout; I'll check for this on the Arduino forum, maybe there's a way.BTW - I haven't event done the programming for this project yet, so I it may never hang-up. I'm just trying to anticipate problems. It's my first project using RS-485 communication (Arduino is receiving only, no sending).

author: ozwolf
author_rank: Regular Contributor
timestamp: October 13, 2014, 12:15:43 pm
content: Why not try one of these from Freetronics?http://www.freetronics.com/products/watchdog-timer-module#.VDvBDqEcSt8Documentation says that the module will actually blip the reset line if Arduino locks up.

author: scott216
author_rank: Regular Contributor
timestamp: October 13, 2014, 12:22:05 pm
content: Quote from: ozwolf on October 13, 2014, 12:15:43 pmThat would work. I see in the schematic it uses a 555. Is this an edge-triggered monostable circuit or something different?

author: Kjelt
author_rank: Super Contributor
timestamp: October 13, 2014, 12:54:06 pm
content: Try to find out where the uC hangs, if it is for instance I2C than it could be that one of the I2C chips "hangs" the bus. In that case you can try to reset that chip or clear the bus by transmitting some I2C CLK signals. If that still does not help you should reboot the whole pcb. In any case it is better to first try to recover from an error and determine exactly what causes the error.

author: ozwolf
author_rank: Regular Contributor
timestamp: October 13, 2014, 12:57:45 pm
content: Quote from: scott216 on October 13, 2014, 12:22:05 pmHave a read of the Quickstart Guide and you will note that the module requires your code (sample code in Guide) to blip an I/O pin (connected to IN) at intervals < default 5 mins or optional 1 minute. So all you're doing is resetting the 555 module before it has a chance to time out and fire the OUT which is connected to your RESET pin on microcontroller.I haven't used this module myself, as I'm happy with using the Timer ISR routine on the Arduino to flash the LED on pin D13 at 1/2 second intervals. My logic being that if the Arduino is locked up the Timer ISR will fail as well. However, my method will not RESET automatically like the Watchdog Timer Module does.

author: SL4P
author_rank: Super Contributor
timestamp: October 13, 2014, 06:36:37 pm
content: Quote from: ozwolf on October 13, 2014, 12:57:45 pmNot strictly true. (Sorry Oz!)If your code is in a 'deadly embrace' loop - the ISR will continue to fire - with the LED blinking happily while the code does nothing...!e.g:http://www.pcmag.com/encyclopedia/term/41017/deadly-embrace

author: firewalker
author_rank: Super Contributor
timestamp: October 13, 2014, 08:00:19 pm
content: Why don't you use the watchdog included to the AVR chip? If there is a lockup it will reset the chip, and will flip a register bit. Using that bit you can later hard reset the chip (if needed).Alexander.

author: scott216
author_rank: Regular Contributor
timestamp: October 13, 2014, 08:11:50 pm
content: Quote from: firewalker on October 13, 2014, 08:00:19 pmI just found out about the register bit the watch dog timer resets. I might use a WDT instead.

author: kolbep
author_rank: Frequent Contributor
timestamp: October 13, 2014, 08:27:46 pm
content: BOR = brown out reset.the micro ia held in reset until the supply voltage exceeds a settable limit.That way if the battery goes flat, or the powersupply gives a low voltage, then the Micro does not behave eratically.

author: SevenLeggedSheep
author_rank: Newbie
timestamp: October 14, 2014, 04:27:14 am
content: Feed your "running" pulse into C48. Take the output (Arduino OK) from R122.Change R111 and C47 to your requirements, this circuit is designed to provide lockup indication for a PIC very quickly.It's only a simple enhancement to a very standard 555 heartbeat circuit, and it works reliably.HTH

author: ozwolf
author_rank: Regular Contributor
timestamp: October 14, 2014, 10:46:10 am
content: Quote from: SL4P on October 13, 2014, 06:36:37 pmThat's why I like this forum. Always an opportunity to learn. You're right. Searching "arduino watchdog timer" on Google, throws up quite a few good examples and solutions. Didn't even know there was an on-board WDT.

author: Psi
author_rank: Super Contributor
timestamp: October 14, 2014, 10:57:45 am
content: Quote from: scott216 on October 12, 2014, 11:05:26 pmi have a simple idea, no need for a 555.Generate some high frequency pulses/AC with the mcu (ideally in software and not using a hw timer). Coupled that signal to a LED through an appropriately sized capacitor.If the mcu is running current will flow through the cap and light the LED up, if the mcu stops the switching stops and the cap will blocks DC so LED=offYou can use Xc = 1/(2 pi F C) to calculate the reactance in ohms of a cap at a set frequency.

author: richard.cs
author_rank: Super Contributor
timestamp: October 14, 2014, 11:14:45 am
content: Quote from: Psi on October 14, 2014, 10:57:45 am^ This.You'll need a diode in antiparallel with the LED or you'll just pump the anode down negative and it'll turn off. Given you're hitting it with squarewaves I would still include some series resistance with the LED, maybe make that the dominant thing limiting the current and make the capacitor reactance small in comparison. If you wanted a low frequency you could make the capacitor large and then have a second capacitor that holds the LED on during the off cycle.

author: max_torque
author_rank: Super Contributor
timestamp: October 14, 2014, 11:27:08 am
content: As mentioned, and AC coupled charge pump circuit is a low component count solution, and if you "set" the output port in one critical function and "unset" it in another it also validates that both those functions are being called and running appropriately!(ie, do a software bitbang port drive, not using a hardware periferal like PWM etc, and don't toggle the port but set and unset it seperately)

author: SL4P
author_rank: Super Contributor
timestamp: October 14, 2014, 12:30:06 pm
content: My (last) word... I'd forego the added hardware - but carefully plan & test a software solution (perhaps patched WDT). Nothing extra to fail, and the chip already has everything you want - it just needs to be corralled into a solution for your requirements.

author: Seekonk
author_rank: Super Contributor
timestamp: October 14, 2014, 05:56:59 pm
content: A little programming error led me to this little trick. I was driving a FET and it stayed on long after it was supposed to turn off in the program. I looked for a logic error and couldn't find one. What I had done was forget to declare that pin as an output. After it wrote a one to that pin, that pin returned to being a floating input. FET gate capacitance kept the FET on till the charge drained off. I figure that trick has to be useful some day.