How to stop a battery power at a defined voltage

Hi everyone,

I have a circuit with an arduino UNO, a sound sensor and a sd reader, and I power it with two linked 3,7 V LiPo batteries.

The project is a voice recorder.

What i'm looking for is a way to save the wave file that has been recorded before the circuit has passed a defined voltage, and then to cut the circuit and making the UNO fall asleep.

Two important things would be done with this:
1rst: the wave file will be recorded
2nd: The LiPo will not excessively discharge

I'm currently not sure about what to code to make this happen, and i don't want to do something dumb so i prefer to ask for help!

Thanks by advance.

You could use a Voltage Detector such as MCP-100 / 101 or one from the Seiko S-808 family to trigger a flag you would catch in your loop (or ISR) when battery is getting low

Hi J-M-L, thanks! But jsut in case do you know if there is away to do it only with coding? I didn't find the right library dedicated to this but maybe you do?

Also, the two individual Lipo batteries needs to be unpluged before reaching 3,2 v two keep them safe. Do the threshold be defined at 6,4 V, or can it go below?

you could read this and work your way with INTERNAL1V1 AREF or that one if you want something easier to read :slight_smile:

Hi J-M-L, i found a simple way to calculate the voltage: Analogread! (with a voltage divider)
But i don't really know how to insert it into my current code. Could you help me?

Here is the code :

#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 10
TMRpcm audio;
int audiofile = 0;
unsigned long i = 0;
bool recmode = 0;

void setup() {
  pinMode(A0, INPUT);
  pinMode(A1, INPUT);
  pinMode(6, OUTPUT);
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), button, LOW);
  SD.begin(SD_ChipSelectPin);
  audio.CSPin = SD_ChipSelectPin;


}

void loop() {
}

void button() {
  
 
  while (i < 300000) {
    i++;
  }
  i = 0;
  if (recmode == 0) {
    recmode = 1;
    audiofile++;
    digitalWrite(6, HIGH);
    switch (audiofile) {
      case 1: audio.startRecording("1.wav", 16000, A0);break;
      case 2: audio.startRecording("2.wav", 16000, A0); break;
      case 3: audio.startRecording("3.wav", 16000, A0); break;
      case 4: audio.startRecording("4.wav", 16000, A0); break;
      case 5: audio.startRecording("5.wav", 16000, A0); break;
      case 6: audio.startRecording("6.wav", 16000, A0); break;
      case 7: audio.startRecording("7.wav", 16000, A0); break;
      case 8: audio.startRecording("8.wav", 16000, A0); break;
      case 9: audio.startRecording("9.wav", 16000, A0); break;
      case 10: audio.startRecording("10.wav", 16000, A0); break;
    }
  }
  else {
    recmode = 0;
    digitalWrite(6, LOW);
    switch (audiofile) {
      case 1: audio.stopRecording("1.wav"); 
      break;
      case 2: audio.stopRecording("2.wav"); break;
      case 3: audio.stopRecording("3.wav"); break;
      case 4: audio.stopRecording("4.wav"); break;
      case 5: audio.stopRecording("5.wav"); break;
      case 6: audio.stopRecording("6.wav"); break;
      case 7: audio.stopRecording("7.wav"); break;
      case 8: audio.stopRecording("8.wav"); break;
      case 9: audio.stopRecording("9.wav"); break;
      case 10: audio.stopRecording("10.wav"); break;
    }
  }
}

The analog entry of the voltage is A1
I want the controller to save the wave file when the sensor value is 640 (3,2v)
Could you help me?

Can you write a small program using analogRead to monitor that pin?

What’s that “crap” about ?

while (i < 300000) {
    i++;
  }
  i = 0;