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

No value in Blynk apps

#1

Hello, I need help. I am measuring the voltage value of a car battery. The serial monitor seem to shown the value but zero value on Blynk. Iam using voltage sensor module. Below is my coding. Thank you.

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

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "76af7438f59c44a0ae69ca498d7a1eab";
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "-";
char pass[] = "-";

 
#define DHTPIN 0          // D3
 
// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11

 
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
 
float setpoint = 0;
bool relayoff = true;
const int relayPin = 5;  // D1;

BLYNK_WRITE(V0)  // slider widget
{
  setpoint = param.asFloat();
  relayoff = true;  
}
void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
 
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, t);
  Blynk.virtualWrite(V6, h);
  if((setpoint < t) && (relayoff == true))
  { 
    digitalWrite(relayPin, 0); // assuming relay is active HIGH
    relayoff = true;
  }  
  if((setpoint > t) && (relayoff == true))
  { 
    digitalWrite(relayPin, 1); // assuming relay is active HIGH
    relayoff = true;
  }
}
int analogInput = A0;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; //  
float R2 = 7500.0; // 
int value = 0;  

void setup(){
   pinMode(analogInput, INPUT);
   Serial.begin(9600);
   Serial.print("DC VOLTMETER");
   Serial.begin(9600);
   Blynk.begin(auth, ssid, pass);
   dht.begin();
   pinMode(relayPin, OUTPUT);
 
  // Setup a function to be called every second
  timer.setInterval(5000L, sendSensor);
}
BLYNK_READ(V1){
 Blynk.virtualWrite(V1, vin);}
 
void loop(){
   // read the value at analog input
   value = analogRead(analogInput);
   vout = (value * 3.3) / 1024.0;
   vin = vout / (R2/(R1+R2)); 
   
  Serial.print("INPUT V= ");
  Serial.println(vin,2);
  delay(500);

  Blynk.run();
  timer.run();
}

Serial monitor

0 Likes

#2

Which lines of your code do you think are responsible for pushing the voltage reading out to Blynk?
Here’s a clue, the code will contain the command Blynk.virtualWrite(Virtual Pin number, value)

Also, you should read this:

Pete.

1 Like

#3

This line

0 Likes

#4

What type of widget is attached to V1, and how is it configured?

Pete.

1 Like

#5

Iam using Value Display widget, currently setting it V1 0-1023 and reading rate= PUSH

0 Likes

#6

So at the moment, nothing is triggering the BLYNK_READ function, so nothing happens.

You currently have a function called sendSensor which is taking temperature and humidity readings and is being called by a timer every 5 seconds. What you should really do is to move the battery voltage reading code out of your void loop and put it in to sendSensor along with your existing code and move the Blynk.virtualWrite(V1, vin) into this function as well. Then delete the BLYNK_READ(V1) function.

Pete.

1 Like

#7

I had followed your every detail instruction and boom its worked! Thank you very much for your help and guide sir. Iam really appreciate it :smile:

1 Like

#8

Another question sir, I already used the A0 pin on my nodeMCU for the voltage sensor, can i use digital pin for my current sensor?

0 Likes

#9

Presumably you’re using a voltage divider to measure the battery voltage.
How were you planning on measuring the current?

Pete.

0 Likes

#10

Yes, I am using voltage divider to measure the battery voltage.
For the current, I am planning to use ACS712 current sensor as picture below

image

0 Likes

#11

The ACS712 provides an analogue output, so can’t be used with a digital pin.
You’d need to use a multiplexer to give more analogue pins.

The ACS712 has a maximum current rating of 30A (assuming you buy the correct module) and all of the current being drawn has to go via the sensor. If this is for a leisure battery then it could be okay (maybe).

Pete.

1 Like

#12

Multiplexer for example like ADS1115 (in the picture below)? Will it need extra coding to pair it with nodeMCU?

image

0 Likes

#13

I was thinking more like the 74HC4051 Multiplexer, which is in effect an electronically controlled selector switch that connects your existing analogue to one of 8 (in this case) analogue inputs, rather than an analogue to digital converter like the ADS1115 - although either would work.

Both would requite additional coding, but in different ways.

Another option is to use an ESP32 board, but once again, coding changes would be needed.

Are you 100% sure about being able to pass all the current you want to measure through the ACS712?

Pete.

2 Likes

#14

Better buy LoLin ESP32 with 18 ADC for only 5$ ?

1 Like

#15

well i am only measuring current about 2A max so maybe the ACS712 will able to do it. OR maybe I just buy a sensor that can detect both current and voltage?

0 Likes

#16

But I already bought the ESP8266 and the ACS712 sensor, wanna make full use of them

0 Likes

#17

Unfortunately both your voltage and current sensing methods each require an analog pin, of which an ESP8266 only has one. So if you want to make full use, then you need to either add in a ADC multiplexor, change to an ESP32 with multiple ADC ports or use a different sensor like the INA219 that runs on i2C and will read both voltage and current as well as being much more accurate than the ACS712.

I have used both for similar monitoring of a battery and charge… and a bunch of other stuff…

2 Likes

#18

Nice project! Is that INA219 sensor you using in your project doesnt required analogpin and can detect both current, voltage and even power? It is suitable to detect 15V max and 2A max rating?

0 Likes

#19

It uses the i2C communication bus.

Yes, no problem. 0 to 26 VDC and the current is read via a shunt so not sure the max, but probably whatever the primary contacts are good for. I think I have seen as high as 4-5A on my solar charger.

https://www.google.com/search?q=ina219+arduino

2 Likes

#20

Great! I’ve decided to give INA219 a try and already ordered it from my supplier

0 Likes