My simplest "Arduino" circuit

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:

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

// ATMEL ATTINY 25/45/85 / ARDUINO
//
//                  +-\/-+
// 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
  wdt_reset();  
  }  // 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:

210 / 5 * 1000 / 24 / 365 = 4.79 years

Got a calendar started to track it?

Here:

// 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. :slight_smile:

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.

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?

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.

Thanks Nick- I'll look at that.

Jim

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?

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:

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.

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.

Nice!

(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)

Very nice example!

Made me look for a tutorial. :slight_smile:

Nick,
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?

It must depend on, what your pins are supposed to do when running.

I guess that the pins on the ISP you are connected to are "low" when not programming, and should that not equal a short to ground if a connected pin on the tiny is "high"?

(In my programming setup I have resistors on the pins, that should at least stop me from drawing too many mA by accident)

Peter_I:
(In my programming setup I have resistors on the pins, that should at least stop me from drawing too many mA by accident)

Good idea... so just series resistors in the wires from the Arduino pins to the target's? What size- couple of hundred Ohms?

I'm sure the whole process must be safe, but I'm just concerned that the instant the code is uploaded to the target it will start running. Should I fit the components on the target's pins before uploading the sketch?

I'm also going by this Instructable, whose steps imply that you connect the atTiny to the Arduino, attach the atTiny's LEDs or whatever for its sketch, then upload the sketch via the Arduino. The Instructable is silent on my concern of the atTiny still being connected to the Arduino when its (the atTiny's that is) sketch fires up.

I'm thinking I should post this question in another thread... this is the wrong place.

EDIT.... I re-posed this question in a new thread here which I think is better. Let's let this thread revert to its original purpose in the gallery. Sorry about that....

This thread looks like it was made to be necro'd. So Nick, is it still blinking?

Jimmy

Yes, it still blinks away, faithfully. :slight_smile:

I just measured the battery voltage: 2.994V. Considering it is a 3V battery, I can't complain.

Similar project here: Simple project - torch-locator