Hello there, I am having trouble running an ATMEGA328P-PU standalone on 2 AAA batteries. I am trying to build an IR remote using the IRRemote library. The atmega chip was taken out from an arduino duemilanove (just for testing) so it has the original bootloader made to run at 16 mhz. So i took the atmega apart, put it on the breadboard, connected a crystal oscillator 16 mhz with the 22 picofarad capacitors as indicated, connected both GND's, the VCC and the AVCC and that was it. I uploaded the blink sketch before, to see if it was working. I powered the atmega with 5V and the LED on the breadboard started to blink as it should have. Went down to 3.3V from the Arduino board, still working. Connected the 2 AAA batteries instead, and it didn't work. What am I doing wrong? Should i reburn the bootloader and use only the internal 8 MHz? If i do so, would IRRemote still work as expected? EDIT: Or were the batteries simply depleted?
You cannot expect to use a 16 MHz clock frequency with an ATmega328 on 3 V, but 8 MHz should be safe. Any code with strict timing requirements (like IRRemote) needs to know the actual clock frequency used.
Measuring the voltage from the batteries with a multimeter would be a good first step to rule out bad batteries (measure the power while it's trying to run the arduino - often times alkaline batteries will look fine when you measure the open circuit voltage, only to have the voltage fall off a cliff the moment you try to get any current)
You probably need to switch to 8mhz internal, or a slower crystal - referring to the datasheet, the spec is:
0-4mhz @ 1.8-5.5v 0-10mhz @ 2.7-5.5v 0-20mhz @ 4.5-5.5v
So it's not expected to work at 16mhz @ 3v.
I'd kick it down to 8mhz internal and make an appropriate board definition - make sure you set the fuses right before you remove the crystal :-P
The problem is that your bootloaded chip will be set to brown out at 3V. (In fact more than that). You need a chip with the correct fuses.
Okay so 8 mhz will be it, but how about the IRLibrary? Would it still work running on 8mhz? I couldn't find anything about the frequency it needs so i am a bit worried about getting corrupted codes at 8mhz. There is a clock speed in the reference files which can be changed but i am still not sure about this.