Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Garrett Bartley
Published © GPL3+

ATTiny Joule Thief NeoPixel

Joule thieves aren't just for lighting plain old LEDs!

IntermediateFull instructions provided5,800

Things used in this project

Hardware components

ATtiny85
Microchip ATtiny85
I used the ATTiny45, but it will also work on the ATTiny85
×1
SparkFun Electrolytic Decoupling Capacitors - 100uF/25V
×1
SparkFun Electrolytic Decoupling Capacitors - 1000uF/25V
×1
SparkFun Capacitor Ceramic 0.1uF
×1
SparkFun SPDT Slide Switch
×1
SparkFun LED - RGB Addressable, PTH, 8mm
×1
SparkFun Transistor - NPN (2N3904)
×1
SparkFun 1N4001 Diode Rectifier - 1A 50V
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1
AA Battery
×1
AA Battery Holder
×1
7mm Inner Diameter Ferrite Ring Iron Toroid
×1
22 gauge solid core wire
I used the wires inside an ethernet cable. Thinner wire works well also, just make sure it's a solid core.
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Breadboard Diagram

Code

Code

Arduino
You should play with the WATCHDOG_SLEEP variable to speed up or slow down color transitions.
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>

#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off)

volatile bool f_wdt = 1;
uint16_t j = 164;

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, 1, NEO_GRB + NEO_KHZ800);

// 0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
// 6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
#define WATCHDOG_SLEEP 0

void setup() {
  adc_disable();
  setup_watchdog(WATCHDOG_SLEEP);
  
  strip.begin();
  strip.setBrightness(64);
  strip.show();
}

void loop() {
  rainbow();
}


void rainbow() {
  strip.setPixelColor(0, Wheel((j) & 255));
  strip.show();
  j++;
  
  system_sleep();
}


uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } 
  else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } 
  else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}


ISR(WDT_vect) {
  f_wdt = 1;
}


void setup_watchdog(int ii) {
  byte bb;
  int ww;

  if(ii>9)
    ii = 9;

  bb = ii & 7;

  if(ii>7)
    bb |= (1<<5);

  bb |= (1<<WDCE);

  ww = bb;

  MCUSR &= ~(1<<WDRF);
  WDTCR |= (1<<WDCE) | (1<<WDE);
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}


void system_sleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_mode();
  sleep_disable();
}

Credits

Garrett Bartley

Garrett Bartley

16 projects • 52 followers
Husband, father, maker.

Comments