Tuesday, December 30, 2008

AVR in sleep mode. (power saving mode)

I used AVR tiny13 for small applications very often, and mostly it is powered by only small battery. It is easy to put the AVR MCU to power save mode with avrlib, just few lines of code would do. To wake up the AVR MCU, you should setup interrupt before falling into sleep mode, either pin change interrupt or external INT0.

Here is my sample code (waked up by pin change interrupt)

//do nothing in interrupt func.

//main code:

//setup interrupt
GIMSK |= 1<< PCIE;
PCMSK |= 1<< PCINT0;

on_bulb(); //turn on light bulb

while(1) {
b1_low; //turn off
sei(); //enable interrupt
set_sleep_mode(SLEEP_MODE_PWR_DOWN); //set sleep mode
sleep_mode(); //sleep now
//wake up point here //

while (PINB & 0x1) { //if PINB is high


I only measured once I finished the demo circuit, and it should use around 10 times less power when AVR is in sleep mode. Have fun.

Thursday, December 18, 2008

PIR motion sensing.

When we design lighting circuit, we would like to light up the LEDs only when there is somebody around. The PIR sensor is a motion sensor based on passive infrared sensor which senses infrared emitted by human body. I got the PIR Module "KC7783R" from local store, which includes the PIR sesnor and also the KC7783 motion detection IC.

The PIR module is very easy to use, it contains only 3 pins (1-Signal, 2-Vcc, 3-Gnd), where it detects somebody moving, the signal line goes high for a period of time (3 secs for example).

Here is my test circuit to drive one auto-flashing RGB Led with PIR module:

Live action:

My another demo of using PIR module, combining the use of AVRtiny13 as a timer. When it detects motion, it will light up the light bulb for 10 seconds, afterward it will go into deep sleep to save power and wait for the next interrupt send by PIR module.

Video demo:

Monday, December 8, 2008

Making a Digital Clock.

Digital Clock is a good start project for learning microcontroller, Naliga used a PIC MCU to make a digital clock, includes schematic, pcb layout and source codes. It is easy to follow and detail, you can find the link here: