How long will a 9V power my Uno project?

I am doing a field experiment and need to power my arduino uno with project with two 9 volt batteries. I know this isn't the best but it is what I have, so please let's not focus on that.

My project uses:
1 HW-125 micro sd reader
1 DS3231 RTC
1 16 channel digital to analog break out board
2 12V solenoid valves
6 HW-390 capacitive soil moisture sensors

I am using power down mode from the low power library in a for loop to make the arduino sleep for 6 hours at a time, wake up, read the moisture probes, write to the SD card, and if needed turn the valves on for 5 seconds every 3ish days. The valves will be connected to a second 9V battery, not the arduino at all.

My code ( I know it could be more efficient, but it works and that's good enough for me):

#include <SD.h>                              
#include <SPI.h>
#include <Wire.h>
#include <light_CD74HC4067.h>
#include <DS3231.h>
#include <uRTCLib.h>
#include <avr/sleep.h> //Needed for sleep_mode
#include <avr/power.h> //Needed for powering down perihperals such as the ADC/TWI and Timers
#include <LowPower.h>

// SD card 
const int chipSelect = 10;                    
File Data1;

// RTC 
uRTCLib rtc(0x68);

// dry and wet solenoid valves
const uint8_t dryValve = 9;
const uint8_t wetValve = 8;

// 3 drought treatment probes
const int p1ValAir = 615;
const int p1ValWater = 300;

const int p2ValAir = 557;
const int p2ValWater = 230;

const int p3ValAir = 510;
const int p3ValWater = 203;

// 3 wet treatment probes
const int p4ValAir = 499;
const int p4ValWater = 184;

const int p5ValAir = 500;
const int p5ValWater = 194;

const int p6ValAir = 503;
const int p6ValWater = 197;

//Mux control pins
int s0 = 4;
int s1 = 5;
int s2 = 6;
int s3 = 7;

CD74HC4067 mux(s0, s1, s2, s3);

//Mux in "SIG" pin
int SIG_pin = A3;

void setup() {
  Serial.begin(9600);

// valves
  pinMode(dryValve, OUTPUT);
  pinMode(wetValve, OUTPUT);

// for analog probes on MUX
  pinMode(s0, OUTPUT); 
  pinMode(s1, OUTPUT); 
  pinMode(s2, OUTPUT); 
  pinMode(s3, OUTPUT); 

  digitalWrite(s0, LOW);
  digitalWrite(s1, LOW);
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  
// SD
SD.begin(chipSelect);
 Data1 = SD.open("Data1.csv", FILE_WRITE);
 String header = "Date, Time, Temp, p1, p2, p3, dryAverage, p4, p5, p6, wetAverage";      
 Data1.println(header);      
 Data1.close();  

 // RTC
 URTCLIB_WIRE.begin();
}

void loop() {
  int p1Val = analogRead(A0);
    int p2Val = analogRead(A1);
      int p3Val = analogRead(A2);
        int p4Val = readMux(0);
          int p5Val = readMux(1);
            int p6Val = readMux(2);

// percentages for dry probes
  int percent1 = map(p1Val, p1ValAir, p1ValWater, 0, 100);
  percent1 = constrain(percent1, 0, 100);
    int percent2 = map(p2Val, p2ValAir, p2ValWater, 0, 100);
    percent2 = constrain(percent2, 0, 100);
      int percent3 = map(p3Val, p3ValAir, p3ValWater, 0, 100);
      percent3 = constrain(percent3, 0, 100);

// percentages for wet probes
  int percent4 = map(p4Val, p4ValAir, p4ValWater, 0, 100);
  percent4 = constrain(percent4, 0, 100);
    int percent5 = map(p5Val, p5ValAir, p5ValWater, 0, 100);
    percent5 = constrain(percent5, 0, 100);
      int percent6 = map(p6Val, p6ValAir, p6ValWater, 0, 100);
      percent6 = constrain(percent6, 0, 100);

// get average of 3 dry probes
  int drySum = percent1 + percent2 + percent3;
  int dryAverage = drySum / 3;

// get average of 3 wet probes
  int wetSum = percent4 + percent5 + percent6;
  int wetAverage = wetSum / 3;

// RTC reading
rtc.refresh();


// read to SD card here
Data1 = SD.open("Data1.csv", FILE_WRITE);  

// record date, time, and temp to SD card
 Data1.print(rtc.month());
 Data1.print("/");
 Data1.print(rtc.day());   
  Data1.print(",");
  Data1.print(rtc.hour());
  Data1.print(":");
  Data1.print(rtc.minute());
  Data1.print(",");
  Data1.print(rtc.temp() / 100);
  Data1.print(",");

// record dry probe data to SD
  Data1.print(percent1);
  Data1.print(",");
  Data1.print(percent2);    
  Data1.print(",");
  Data1.print(percent3);
  Data1.print(",");
  Data1.print(dryAverage);    
  Data1.print(",");

// record wet probe data to SD
  Data1.print(percent4);    
  Data1.print(",");
  Data1.print(percent5);   
  Data1.print(","); 
  Data1.print(percent6);
  Data1.print(",");
  Data1.print(wetAverage);    
  Data1.print(",");    

// save data to SD
  Data1.println("");
  Data1.close();

  Serial.println("data saved");

// turn on dry pump for 10 seconds when dry average = 30%
if (dryAverage <= 30) {
  digitalWrite(dryValve, HIGH);  
  delay(1000);                      
  digitalWrite(dryValve, LOW);    
  delay(500);  
}

// turn on wet pump for 5 seconds when wet average = 60%
if (wetAverage <= 60) {
  digitalWrite(wetValve, HIGH);  
  delay(1000);                      
  digitalWrite(wetValve, LOW);    
  delay(500);  
}

  Serial.print("Average dry moisture = ");
  Serial.println(dryAverage);
  delay(500);

  Serial.print("Average wet moisture = ");
  Serial.println(wetAverage);
  delay(500);

  // enter deep sleep mode for 6 hours
  sleepyTime();
}

// deep sleep for longer than 8 seconds - sorta
void sleepyTime()
{
  digitalWrite(LED_BUILTIN,LOW);
  for (int i = 0; i < 2700; i++) { 
   LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF); 
    //Serial.println(i);
    //delay(200);
  }
  digitalWrite(LED_BUILTIN,HIGH);
}

int readMux(int channel){
  int controlPin[] = {s0, s1, s2, s3};

  int muxChannel[16][4]={
    {0,0,0,0}, //channel 0
    {1,0,0,0}, //channel 1
    {0,1,0,0}, //channel 2
  };

  //loop through the 4 sig
  for(int i = 0; i < 4; i ++){
    digitalWrite(controlPin[i], muxChannel[channel][i]);
  }

  //read the value at the SIG pin
  int val = analogRead(SIG_pin);

  //return the value
  return val;
}

Roughly how long will a 9V battery power the arduino? Thank you!

Welcome to the forum

You need to know the current draw in different states in order to make such an estimate

It would be better to use a battery with a much higher capacity, such as a Lipo

You need to measure the average current draw of the project during typical activity.

The battery capacity gives an estimate of the energy stored, either in Ampere hours (Ah) or milliAmpere hours (mAh).

Typical run time in hours = (battery capacity in mAh)/(average current draw in mA).

Example: a 9V PP3 block battery might have capacity 500 mAh, and an Arduino might draw 50 mA, so (500 mAh)/(50 mA) = 10 hours battery life (roughly).

Handy table for 9V PP3 battery types:

  • Sacrifice a 9v battery and run a test.
1 Like

Putting the Arduino asleep while the other peripherals continue emtying the battery makes no big difference. The life of the project running is likely minutes, or less.

My batteries are ~500 mAh

This sleep mode turns off everything connected to the arduino, except for INT, PCINT, and WDT

Something is amiss with your drawing. There is no connection between the battery and the Uno board. How is it being powered? You should have a connection to Vin. If your battery is connected to Vin, and you put the chip to sleep, the voltage regulator is still running, +5V is still being supplied to all your external devices and they are drawing some minimal standby current

You need to disable the power LED and any others that turn on. Expect your 5V regulator to draw about 10mA and your 3V3 regulator to also draw 10mA. Then there is the processor, that will require some power as well.

Please post a standard, verified schematic diagram for the entire project. The posted drawing is confusing and largely uninterpretable. As mentioned by @blh64 it is also probably wrong.

This sleep mode turns off everything connected to the arduino

No, it does not. For maximum power savings, the TPL511x power timers and Pololu power switches are well worth considering.

Finally, breadboards are for temporary experiments with low power logic circuits. They are not reliable, not designed for long term use or for motor, solenoid or servo power circuits.

1 Like

I doubt it's going to run for a day. :frowning:

One thing you've got going for you is that the 9V battery will still put-out 5V past the normal amp-hours. Everything will probably work OK down to 4V.

On the other hand, you can't count on one 9V turning-on 12V solenoids at all, even when the battery is fresh. :wink:

1 Like

Why don't you just suck it and see? Starting with a close check that the 9v battery will indeed reliably operate the 12v solenoids. If it doesn't, the rest is irrelevant.

1 Like

With a bare-bones circuit that's possible - but not by invoking some 'sleep mode' on your Uno as you're, evidently, figuring.

The Arduino Uno maybe consumes about 50mA in low power, so it will last about 10 hours just sleeping with your 500mAh battery.

You should reduce the low power consumption of the Arduino to less than 5 mA. It involves using something like an Arduino pro mini board, removing the power led, replace the power regulator for something more efficient, etc. You can search for "Arduino low power"...

Then you should solve the rest of power problems of your circuit.

Sorry the drawing is inaccurate, it was just to give an idea, oops! A 9V battery would be connected to the arduino to power the sd card module and RTC, and the other 9V would be just for the two valves.

The power timers look like a good option though! Thank you. Unfortunately breadboards are what I have right now and will hopefully hold out the 3ish weeks I need this experiment to run.

I do also have lithium ion batteries that I took from old power banks.. do you think those would be a better option for the arduino connection?! Do you think with the TPL511 turning on every 2 hours, with the two 9V would last 3-4 weeks?

I am very new to electronics and am VERY broke and pressed on time... any help is greatly appreciated!

Frick, thank you. The few posts I've read made it seem like this was an everything powered down option.

Thankfully I do know that these solenoids will operate as low as 6V

If your solenoids operate at 6V you could safely use:

  • n. 2 18650 lithium batteries in series that will give you more than 7V
    ( not sure how much power these solenoid will draw but considering 21 days x 4 turn on x 5 secs x 2 solenoids = 14 minutes max on time ) 4Ah batteries will give you plenty of power
  • use any board that draws less than 8mA in sleep mode and you are ok ( if powering with lithium 18650 4Ah batteries )
  • for example this firebeetle esp32 board has a mesured consumption of 0.05mA in sleep mode. Also the active time consumpion is very limited: consider a maximum of 15minutes x 55mA you have a consumption of 15mAh in 21 days
  • add your rtc and sd card and you should be good to go

Solenoids have a voltage rating for a reason and are manufactured in volume. Consider not all are the same and what changes as it ages and wears over time? I would go with the manufacturer's ratings.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.