B4R Question Monitoring the power supply

Filippo

Expert
Licensed User
Longtime User
Hi

I know questions here should only be for B4r, but maybe someone can help me.

Has anyone already done something with monitoring the power supply?
I'm trying to write such a program for my Seeeduino xiao, but it doesn't really work.
When the voltage drops below a certain level(2,50 Volt), the power led should start blinking.
But no matter how high the voltage is, the Power-Led does not blink.
I use 2x AA batteries as power supply.
I'm doing something wrong, but what?

Here is the sketch I use:
B4X:
const int pbPwLed = 1; // Power-Led
const int pbAnalog = 0; // Analog-Input

float voltage = 0.0;
int batvalue = 0;
unsigned long lastblink = millis();

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

  pinMode(pbPwLed, OUTPUT);
  pinMode(pbAnalog, OUTPUT);
 
}

void loop() {
  ManageBattery();
}

void ManageBattery() {
  batvalue = analogRead(pbAnalog);
  voltage = batvalue * (3.30 / 1023.00);
  if (voltage < 2.50) {
    //Power-Led Blinken lassen
    if ((millis() - lastblink) > 250){
      digitalWrite(pbPwLed, !digitalRead(pbPwLed)); // LED wird ein- bzw. ausgeschaltet
      lastblink = millis();
    }
  }
  else{
    digitalWrite(pbPwLed, HIGH);  // turn ON the LED
  }
 
  Serial.print("Input Voltage = ");
  Serial.println(voltage);
}
 

klaus

Expert
Licensed User
Longtime User
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
and 1.1V.

With ESP8266 NodeMCU board i used 300K serial resistor to the ADC pin and measured 3....4.2 VDC (of Li-battery power supply) like:

B4X:
    pinADC.Initialize(pinADC.A0, pinADC.MODE_INPUT)
    Dim adc As UInt = pinADC.AnalogRead
    Log("adc = ", adc)
    VCC = adc / 1024 / 0.157 - 0.18    'ESP-07 300K resistor (100K from ADC to GND parallel resistor is already at the board)
    Log("Vcc, volts = " , VCC)
 
Last edited:
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Hi Klaus,

I asked 2 days ago the SeeedStudio forum why it does not work and how it should work, here is the answer:

Now it seems logical to me why my plans could not work.
I will now use the solution with the 3.7 volt Lipo battery.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…