How to know how much power does your project need?

I want to know if are there any scripts or functions to let you know how much power does your project need? How to write a script to check that? And then how many AA or AAA batteries do i need? Also should i use AA or AAA batteries?

Another question i have is i plugged a 9v battery to dc jack but the arduino wasn't turned on so is it mean that the 9v battery isn't enough power to turn the arduino on?

Connect all your components together and measure the current draw from the power source.

PP3 9v batteries have little capacity for Arduino projects.

Do you have a multimeter? [u]How to measure current[/u].

Somebody can probably tell you how much current the Arduino takes with nothing else connected, but I don’t know. If you are running motors or lots of LEDs, etc., of course your current consumption will go up.

A AAA alkaline battery is rated for about 1000 milliamp-hours and a AA battery is rated for about 2400 milliamp-hours so a AA will last about twice as long. According to the Energizer datasheet, mAh life is calculated by allowing the 1.5V battery to drain-down to 0.8V so unless you have more batteries for more “extra” voltage you won’t get full life from the batteries.

This can get a little tricky because 4 single-cell batteries is ~6V which is barely enough to power the Arduino through the voltage regulator. 6V (fresh batteries) is OK but of course you won’t get “full life” out of them.

If you add a couple more batteries for 9V you’ll get a lot more life because the Arduino will continue to operate until the batteries get down to around 5V. But, it’s not as “efficient” because the higher the voltage, the more energy you waste in the voltage regulator. (You won’t have to change batteries as often but in the long run you’ll spend more money on batteries.)

You can use 3 batteries and bypass the regulator, but then you’re starting-out at less than 5V and you’ll probably get even less battery life.

The ideal setup is to use a higher voltage with a separate switchmode voltage regulator. Switching regulators are nearly 100% efficient so you can actually get more current out than you draw from the battery (while reducing the voltage) and you can drain the battery down past it’s normal life.

Another question i have is i plugged a 9v battery to dc jack but the arduino wasn’t turned on so is it mean that the 9v battery isn’t enough power to turn the arduino on?

If you check the voltage, it’s probably no-longer 9V when you plug it in…

The only real way to know is to measure it. You can look at the data sheets for all the components you are using, things like motors, lamps and such and do the math but in most circuits the current is constantly changing as motors, lights and other accessories come and go online and offline. So you figure the maximum current and allow for a supply source about 20% to 25% above your anticipated maximum.

Yes, using a sensor and code you could read what you are using as you are using it.

Ron