Measuring Vin (not Vcc) on a NodeMCU

Not sure if this is an issue, feature request, or simply impossible given the hardware, but is there any way to measure the voltage at Vin (not Vcc) on the NodeMCU boards? Thanks

1 Like

you Need to create a voltage divider on the vin pin and measure in a0
Basically the circuit has two resistors
The sum of the two resistor should be a high value. Like 50k or more, so your circuit will not consume power
Now you have to create a divisor such that the maximum input value you have e.g 12volts is divided such that the result is slightly less than 3.3v (this is because the input on the nodemcu
Reads up to that value)
Search web for resistor divisor calculators so you find values you can buy.
Then on esphome you do the math to calculate the right voltage.

Here is good info for what you want https://randomnerdtutorials.com/esp8266-adc-reading-analog-values-with-nodemcu/

4 Likes

Thank you both. This is helpful!

Hi all. I also have an issue where the battery percentage does not seem to work. HA says “unknown”.
Anyone who can point out what I’m doing wrong?

ESPHome used. Unfortunately I have inssuficient Arduino knowledge for that other page to be enough help…

  - platform: adc
    pin: GPIO33
    name: "Battery Raw Voltage"
    id: batt_v
    unit_of_measurement: "V"
    device_class: voltage
    attenuation: 12db
    update_interval: 10s
    filters:
      - multiply: 1.272727
      - round: 1 
  - platform: template
    name: "ESP Battery level"
    id: batt_lvl
    unit_of_measurement: "%"
    device_class: battery
    state_class: measurement
    lambda: |-
      return (((id(batt_lvl).state) /4.2) * 100);
    filters:
      - sliding_window_moving_average:
          window_size: 10
          send_every: 10
          send_first_at: 10

Im not sure why this overly gets under my skin so i apologize…

Please dont use generalized/vague names when you post questions. Its really for your benefit to use detailed ans accurate information. NodeMCU is a very broad term and doesnt say much. I think its technically a firmware but the name is commonly used for a esp form factor. Like a 38 pin “nodemcu”

Not only are there esp8266 NodeMCU but there are esp32NodeMCU and beyond that they both come in different varieties from different manufacturers which arent all identical. For example they come in 30 and 38pin varieties. D1 mini is the same thing, it comes in many variations and in 8266 or esp32. To make it even more confusing esp8266 d1 mini’s are also sold under the NodeMCU or added on somehow, its very confusing.

If you leave room for the readers to guess, they’ll 100% give you guesses for answers and that might not go well one day following someone’s guesses.

Help us help you. Be specific and details, details, details.

The thread is five years old, and while I can’t speak for anyone else, I can say that yes, back then, I did not know the proper terminology, and given that Aliexpress vendors used “NodeMCU” as a way to distinguish the 38 pin dev kit boards from, I assumed that this was actually what it meant. You are correct that it’s really a firmware and not a form factor, and that there are multiple chips that use it.

Point for you. Someone dug it up from the dead which brought it right to the top. 5 years or 5 days really doesn’t matter to me if people see it. It’s a huge flipping problem on here and people post questions on here and think we’re a bunch of mind readers. I probably explain this on here 3 times a week so settle down, no one singled you out or was picking on you.

I used to assume it was specific to those run of the mill esp8266 dev boards too but, it’s not. Which board doesn’t always matter in a question but, it doesn’t hurt either and it’s a good habit to have.