Run on a battery for months

Hi all,

I have nearly finished a project where I worked quite a long time on. It is a human presence detector (ToF sensor) which works on battery and RF. It is a product which works as soon as you insert the battery.

Now I’m facing an issue with the prototype. The 9V battery is dead after 24hrs, while it should run at least for weeks, hopefully even months.

I know the ToF sensor is constantly measuring, but I have no idea on how to make this smarter.

Would you mind to take a look at the scheme, and code, to see what’s missing?
Please be aware: I’m not using the adafruit ToF sensor!!! instead I’m using the ST-VL53L1X

datasheet ToF sensor: https://www.st.com/resource/en/datasheet/vl53l1x.pdf
datasheet LM7805: https://asset.conrad.com/media10/add/160267/c1/-/en/000179205DS01/datablad-179205-spanningsregelaar-lineair-type-78-stmicroelectronics-l7805cv-to-220ab-positief-vast-5-v-15-a.pdf
datasheet MCP1700: https://docs.rs-online.com/5b2b/0900766b80dd189b.pdf

SCHEME: Imgur: The magic of the Internet

/* THEBULB. THE SO-LOO-TION SENSOR */

#include <Wire.h>
#include <VL53L1X.h>

VL53L1X sensor;


void setup()
{
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(400000); // use 400 kHz I2C

  pinMode(LED_BUILTIN,OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(12, OUTPUT); 
 
  sensor.setTimeout(500);
  if (!sensor.init())
  {
    Serial.println("Let op: de sensor wordt momenteel niet gedetecteerd. Controleer aansluitingen. ");
    while (1);
  }
  
  sensor.setDistanceMode(VL53L1X::Long);
  sensor.setMeasurementTimingBudget(50000);
  sensor.startContinuous(100);

}

void loop()
{  
  Serial.print(sensor.read());

  if (sensor.readRangeContinuousMillimeters () <=1000 ) {  //schakelafstand wordt hier ingevoerd. Onder deze waarde is de schakeling actief. 
    digitalWrite (LED_BUILTIN, HIGH);
    digitalWrite (7, HIGH);
    digitalWrite (12, HIGH); 
    }else {                                              //hoger dan de schakelafstand.      
    digitalWrite (LED_BUILTIN, LOW);
    digitalWrite (7, LOW);
    digitalWrite(12, LOW);  
    }

  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT");}
  Serial.println();
}

using linear voltage regulator like lm7805 causes a lot of power losses also the 9v battery has a capacity of 500-600 mah which is considerably low, I recommend using AA battery for your project without the regulator also improve the code by shutting off the unnecessary component of the atmega328p like ADC, BOD etc to minimise the current consuption of the ic

m_k_akash thanks for your reply. Okay, so yes I can take the voltage regulator out, do you if that will cause problems for the rest?

Also do you maybe have a link or suggestion on code to shut off the unnecessary component? I’ve not seen this before, sorry i’m a noob hehe. Then I can add that to.

Thanks so much!

Here is a tutorial to reduce the current consuption of atmega328p, just google the operating voltage of all the modules you used in your project and note down the max and min voltage for each module then use a voltage that suits all the module, also remove if any unwanted leds used ,you can also go for the 8mhz internal oscillator of the atmega328p and remove the 16mhz crystal completely which also help your project to work in low voltage and low current consuption

I did made some tests, here are my results.

Without the voltage regulator, only on 3V the setup is consuming 30mA.
Which is still quite a lot, it would be better to lower that even more.
A battery with 2000mA capacity, then it will run for 66 hours.

A remote control can work on battery’s while it has less power.

Without the crystal, I can’t get the setup working… which is odd, because why not?
I made 2 separate setups (one with crystal, one without), checked wiring and such all good.

The LowPower library does not (seem) to do much… here is my adjusted code with low.power

/* THEBULB. THE SO-LOO-TION SENSOR */
#include <Wire.h>
#include <LowPower.h>
#include <VL53L1X.h>

VL53L1X sensor;


void setup()
{
  Serial.begin(115200);
  Wire.begin();
  Wire.setClock(400000); // use 400 kHz I2C

  pinMode(LED_BUILTIN,OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(12, OUTPUT); 
 
  sensor.setTimeout(500);
  if (!sensor.init())
  {
    Serial.println("Let op: de sensor wordt momenteel niet gedetecteerd. Controleer aansluitingen. ");
    while (1);
  }
  
  sensor.setDistanceMode(VL53L1X::Long);
  sensor.setMeasurementTimingBudget(50000);
  sensor.startContinuous(100);

}

void loop()
{  
  LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, 
                SPI_OFF, USART0_OFF, TWI_OFF);
  Serial.print(sensor.read()); 

  if (sensor.readRangeContinuousMillimeters () <=1000 ) {  //schakelafstand wordt hier ingevoerd. Onder deze waarde is de schakeling actief. 
    digitalWrite (LED_BUILTIN, HIGH);
    digitalWrite (8, HIGH);
    digitalWrite (12, HIGH); 
    }else {                                              //hoger dan de schakelafstand.      
    digitalWrite (LED_BUILTIN, LOW);
    digitalWrite (8, LOW);
    digitalWrite(12, LOW);
 
    }

  if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT");}
  Serial.println();
}

For the ic to work in 8 mhz ,you need to burn the 8mhz bootloader Here is the tutorial to do it

8MHz, not 8mhz!! Now that _would- be low current consumption

Hi. Let me show you how to post links on the forum. It's very easy, you just press the link icon.
datasheet ToF sensor
datasheet LM7805
datasheet MCP1700
Can you post a schematic diagram please? Fritzing can do this, just select Schematic View and make it look neat and not like a spider's web. Attach the image to your post, don't use some horrid image hosting site.