Go Down

Topic: My simplest "Arduino" circuit (Read 4958 times) previous topic - next topic

Nick Gammon

Nov 23, 2013, 03:58 am Last Edit: Nov 23, 2013, 04:20 am by Nick Gammon Reason: 1
Here is my simplest Arduino-based gadget:

It consists of an AtTiny85, one LED, one resistor and one CR2032 battery.

The objective was to have a "flashing LED" that could be used as a burglar deterrent, with a minimal power consumption.

Sketch below:

Code: [Select]

// ATtiny85 sleep mode, wake on pin change interrupt or watchdog timer
// Author: Nick Gammon
// Date: 12 October 2013

//                  +-\/-+
// Ain0 (D 5) PB5  1|    |8  Vcc
// Ain3 (D 3) PB3  2|    |7  PB2 (D 2) Ain1
// Ain2 (D 4) PB4  3|    |6  PB1 (D 1) pwm1
//            GND  4|    |5  PB0 (D 0) pwm0
//                  +----+

#include <avr/sleep.h>    // Sleep Modes
#include <avr/power.h>    // Power management
#include <avr/wdt.h>      // Watchdog timer

const byte LED = 3;  // pin 2

// watchdog interrupt
ISR (WDT_vect)
  wdt_disable();  // disable watchdog
}  // end of WDT_vect

void resetWatchdog ()
 // clear various "reset" flags
 MCUSR = 0;    
 // allow changes, disable reset, clear existing interrupt
 WDTCR = bit (WDCE) | bit (WDE) | bit (WDIF);
 // set interrupt mode and an interval (WDE must be changed from 1 to 0 here)
 WDTCR = bit (WDIE) | bit (WDP2) | bit (WDP1) | bit (WDP0);    // set WDIE, and 2 seconds delay
 // pat the dog
 }  // end of resetWatchdog
void setup ()
 resetWatchdog ();  // do this first in case WDT fires
 pinMode (LED, OUTPUT);
 }  // end of setup

void loop ()
 digitalWrite (LED, HIGH);
 delay (1);
 digitalWrite (LED, LOW);
 goToSleep ();
 }  // end of loop
void goToSleep ()
 set_sleep_mode (SLEEP_MODE_PWR_DOWN);
 ADCSRA = 0;            // turn off ADC
 power_all_disable ();  // power off ADC, Timer 0 and 1, serial interface
 noInterrupts ();       // timed sequence coming up
 resetWatchdog ();      // get watchdog ready
 sleep_enable ();       // ready to sleep
 interrupts ();         // interrupts are required now
 sleep_cpu ();          // sleep                
 sleep_disable ();      // precaution
 power_all_enable ();   // power everything back on
 }  // end of goToSleep

It sleeps most of the time (lazy thing!) and wakes every 2 seconds to flash the LED for one millisecond. It should use about 4 µA while asleep and when awake the LED will consume about 2 mA. Since that is only for 1 mS per 2 seconds that should average out at about another 1 µA.

If we assume that the battery has a capacity of 210 mAh then it should last for:

Code: [Select]

210 / 5 * 1000 / 24 / 365 = 4.79 years
Please post technical questions on the forum, not by personal message. Thanks!

More info:


Got a calendar started to track it?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Nick Gammon


Code: [Select]

// Date: 12 October 2013

Although the date/time on the sketch is 18 October 2013. Anyway, close enough. I'll have to check back again in 5 years. :)
Please post technical questions on the forum, not by personal message. Thanks!

More info:

Nick Gammon

A more sophisticated version would flash the LED randomly, as if it was connected to the Ethernet. Although my network switch tends to flash every couple of seconds, so it isn't too bad.
Please post technical questions on the forum, not by personal message. Thanks!

More info:


Interesting... I've been wondering about how one puts a project into "production" so to speak, as opposed to development in a Uno.

Nick, where's the best place to read up on that please? Big question of course is how on gets the sketch loaded? Is there an idiot's guide somewhere?

Nick Gammon

My page on breadboard Arduinos may help:


I used SPI (ICSP) to upload the sketch on a breadboard, and when it did what I wanted, I just removed the chip and soldered it in "dead bug" style. I chopped off the other legs (perhaps foolishly) on the socket, so reprogramming it will be a bit of a pain, as it is in upside down.

If I get desperate (eg. to change the interval to 3 seconds) I can always either solder on extra wires for programming onto those stubs, or unsolder the battery wires, get at the chip, reprogram it, and put everything back.
Please post technical questions on the forum, not by personal message. Thanks!

More info:


Thanks Nick- I'll look at that.



Looks simple enough:  even I should manage that  8)

My local supplier has both the ATTINY85-20PU and ATMEGA328P-PU available. Both are 20MHz versions, is that ok?

Also, one last question Nick if I may: how big a deal is to convert your explanation to the Tiny? Will I be able to figure that out when I look at the pins?

Nick Gammon

The 20 MHz version will be fine, considering it is running at 8 MHz.

The programming pins are pretty clearly labelled in the datasheet.

I describe the uploading process (which I used in this case) here:

Please post technical questions on the forum, not by personal message. Thanks!

More info:


Wow, so many years! And did you know about this?

Early CD versions of the Pink Floyd's album Pulse came with a blinking red LED on the side of the case.


This was designed by EMI contractor Jon Kempner, who was awarded the platinum disc, using the now discontinued LM3909 LED flasher IC. The circuit was powered by a single AA cell; the battery life was stated to be over 6 months. Some versions were also made with 2 AA batteries and later editions of the CD set did not feature the blinking LED.
Arduino Uno R3, Arduino Mega 2560 R3, Ethermega (R3), and some Ethernet Shields (R3), Chronodots, TMP36 sensors, DS18B20 sensors, LCDs/TFTs, RS232C to learn and play...


Nice and simple.
Would it be much more complicated to have Attiny85 sleep for 8 hours, for example? I am looking to have a relay switch on every 8 hours for 10 minutes.


Feb 13, 2014, 08:28 am Last Edit: Feb 13, 2014, 09:36 am by Peter_I Reason: 1

(And I wonder how I managed not to see this one when I was building my Cable Locker Intruder Alarm ?)

I'm deeply impressed that it is possible to run for so long on a small battery, simply by "not wasting power when it is not needed".

Ill have to make an LED-throwie in that style!
It would just hang there and blink forever!
(Or at least, it would die of corrosion before running out of power)
"Nothing is foolproof to a sufficiently talented fool"


Feb 16, 2014, 04:05 pm Last Edit: Feb 16, 2014, 10:23 pm by gvgv Reason: 1
You say, that ATtiny85 will wake on pin change interrupt or watchdog timer. Which instructions enable pin change interrupt? Sorry for stupid questions.


A bit off topic, but related...

If I program a chip like the atTiny using the Uno as ISP (in IDE: File > Examples > ArduinoISP), may I leave the Arduino and the target chip connected once the sketch runs in the atTiny? In real use of course the tiny will be disconnected, but I'm thinking of during code development where it's common to upload many version of code.

I'm assuming the target fires up its sketch when programmed through the Uno as ISP. But with the tiny's i/o pins being the same ones as the are connected for ISP, I'm not sure if it's wise? But my understanding of ISP is that the whole point is to be able to leave the chip in the programming circuit.

Advice please?

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131