MAX 471 voltage sensor, I can't get accurate result

Hi everyone! I am trying to get result of max471 voltage sensor with D1. I looked for library but couldn’t find one. Compiled with arduino and it is working.
This sketch works on d1 mini and compiles, but gives false result.

// MAX471 Power Meter by speed57
 Value widget     = V1
 Terminal Widget  = V5
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h> 
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

#define VT_PIN A0 

  int vt_read = analogRead(VT_PIN);
  float voltage = vt_read * (5.0 / 1024.0) * 5.0;
char auth[] = "xxxxxxx";  
char ssid[] = "xxxxxxx";                            
char pass[] = "xxxxxxx";

SimpleTimer timer;

WidgetTerminal terminal(V5);

void setup()
  Blynk.begin(auth, ssid, pass);
  while (Blynk.connect() == false) {}
  terminal.println(F(" Blynk v"BLYNK_VERSION ":MAX471 Power Meter"));
  timer.setInterval(1000L, PowerMeter);  

void PowerMeter() 
  Blynk.virtualWrite(V1, voltage);
  terminal.println("Volts: "); 
  terminal.println(voltage, 3);
  Serial.print("Volts: "); 
  Serial.print(voltage, 3);

void loop()

give us a clue.

In Multimeter battery shows 4v but here is not same result

Could your multimeter be reading around 4.4V or is it very close to 4.0V?

WeMos D1 Mini is a 3.3V device not 5V so you need to adjust your formula.

Also don’t go over 16V when wired to the WeMos as opposed to 25V with a 5V Arduino.

isn’t this actually a current sensor?

There are 2 types, one does current and voltage.

it was around 4.02V
so should I go like this

float voltage = vt_read * (3.3 / 1024.0) * 3.3;

mine is this one

Almost, the second 3.3 should stay at 5 as that is how the 471 is designed.

I think it came out to 4.4V when I checked earlier.

where did you get this one?

The other margin of error that is probably creeping in is that the AO port can only read up to 3.2V, not 3.3V, on the D1’s.

A poor decision on the resistors they picked when boosting the 1V native maximum on an ESP AO pin to the WeMos operating voltage of 3.3V. When I asked them about the poor decision they said they simply copied the resistors from the NodeMCU layout, classic.

So perhaps use 3.2 and 5 but then also a calibrating factor of something like * 0.92

@wanek maybe here

1 Like

yep, thanks @Costas!

regarding the voltage measurement, i usually use a 1 mega ohm trimpot, like this. the viper is hooked up to the analog pin, the other 2 are vcc and gnd. then i can calibrate easily until in serial monitor shows exactly 1023, when maximum voltage is applied.

(first of course i set a target voltage around 2 volts, with the multimeter hooked up to viper, not the mcu, to protect the analog pin)

1 Like

I got it from about $1.20

I think @Costas 's is fair enough if you get them faster.

my shopping experience unfortunately shows that you do not get faster from ebay, because 99% of ebay sellers are from china :slight_smile:
i usually buy from aliexpress. they have this at 1.09 usd

I was connecting them wrong now I got almost same value as multimeter. I disconnected VIN pin from D1 mini.
there is one problem though, I can’t get update only when I hard reset the esp.

Nice find :smiley:

@speed57 you need the analogRead and formula in PowerMeter() function.

my trimpot voltage divider i use it like this:

int battery = map(analogRead(A0), 0, 1023, 0, VOLTAGEMAX);  // is defined in millivolts
  if (battery != oldBattery) {
    Blynk.virtualWrite(BATTERY, analogRead(A0));    //or, to get millivolts: battery);
    oldBattery = battery;
Blynk.virtualWrite(V1, voltage, analogRead(A0));

no luck with this :frowning:

should I do like this?

int battery =  map(analogRead), 3.3, 1023, 5.0, voltage);