BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Need some help with battery reading


#1

Need some help with battery reading. I am monitoring a 12v leisure battery for a greenhouse project. I have connected a 1M ohm resistor in series with pin A0 on the Wemos D1 mini. On the blynk app I have two value displays, one has pin A0 assigned and the other has pin V0 assigned. I have a reading on A0 (raw ADC value) but nothing on V0. Any help would be great. Code below.

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>

char auth[] = "***************************************";

char ssid[] = "*************";
char pass[] = "**************";

#define DHTPIN 2
#define DHTTYPE DHT22

DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  int hAsInt = int(h); // converts to int removing unessisary decimal points
  int tAsInt = int(t);
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

// Simple monitoring of internal voltage levels:
void VCCInput() {
  //Blynk.virtualWrite(V0, ESP.getVcc() * 0.001);
  Blynk.virtualWrite(V0, analogRead(A0)*0.0145);  // ADC range up to 14.8v
}

void setup()
{
  // Debug console
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);

  dht.begin();

  timer.setInterval(1000L, sendSensor);
}

void loop()
{
  Blynk.run();
  timer.run();
}

Blynk Joystick Controlled Tracked Rover with Wemos D1 Mini Pro
#2

First off, it is always best to start your own topic, not add onto others. I have moved and or removed your posts accordingly.

That is becasue you are not doing anything to call your VCCInput() function.

I recommend another non-coinciding timer (E.g. 1035L), or merge the battery commands into existing DHT timer function.


#3

Apologies I’m fairly new to posting. I added timer.setInterval(2000L, VCCInput); and that worked
Thanks for the help Gunner


#4

It will not matter much with only two little timers… but best to lern the habbit sooner. By non-coinciding I meant something offset enough that both timers (which start counting at the same time) will not try to run their functions at the same time every two seconds.


#5

Ah, got it. New to the programming also. “timer.setInterval(1035L, VCCInput);”
Thanks


#6

If you wanted a 2 second reading then offsetting by 35ms would work just as well there - 2035L

1 - second timer
1 - second timer, followed 35ms later by 2 second timer
1 - second timer
1 - second timer, followed 35ms later by 2 second timer
… and so on.