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();
}
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)
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.
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).
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?
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?
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…
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?
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.