I am operating a circuit with current of around 1 milli Amp and a battery of 9V in the sleep mode and a current of 40 mAmp and battery of 9V in the active mode. I have seen the concept of milli ampere hour but I think we need to take in the voltage in to account as well to accurately calculate the battery power. Can anyone please provide with the concept and the formula to calculate the battery life for example for a 9V or 6V battery with 6000 mah or any value.
If precise measurement is desired, you'll need to use a current sense resistor and measure the voltage drop across it with an analog pin. Ohm's Law will tell you how many mA is being used by the circuit. You'll need to sample frequently, or your counter will lose accuracy. This approach is useful when you don't have distinct operating modes or when the operating states are not controlled by the Arduino itself. However you do "waste" some power on the sense resistor.
If an approximation is acceptable, and you know how much current your circuit will draw in various modes (like 1mA idle and 40mA active), and the Arduino is the one actually changing those modes, your job is easier. Just use millis() to keep track of how long your sketch is in the active and idle states, and add them up to get mAh. This doesn't take voltage into consideration, but honestly I don't think the voltage is a huge factor at these current levels.
But, improving upon the second, simpler approach, you could add a simple voltage divider to divide your source voltage in half so the Arduino can safely read it on an analog pin. You can use that reading to apply a correction factor to your mA count. The voltage divider (if you choose appropriate resistor values) should waste less power than a current sense resistor, and you don't have to sample as often -- just after mode changes and every 1000ms or so.
To a very rough first approximation, if a battery has a capacity of 1,000 mAH, and you draw 1mA, it should last 1,000 hours. But go have a look at battery university for the details.
if a battery has a capacity of 1,000 mAH, and you draw 1mA, it should last 1,000 hours.
Also, you'll see that for large currents, say 500-1000 mA range, the life is much shorter than 1000 hours,
and maybe only 15-20 minutes rather than 1-2 hours, due to internal losses and heat buildup in the battery.
The Mah rating of a specific battery is almost always misleading like with many other 'marketing specifications'. One really needs to dig down into the battery's datasheet and look at the discharge curves of Mah Vs current draw for a realistic Mah rating that you will be using, then it's simply Mah/current flow = hours of use before discharged.
The 10 hour discharge rate is the most common one used I think - at high discharge rates various electrochemical effects can
reduce effective capacity (the same is true for fast-charging, columb efficiciency drops).