0

Some sensors give as output a voltage between 0 and 5V. The analog inputs of the NodeMCU require voltages between 0 and 3.3V. I plan to make a voltage divider with two resistors like in this link for compatibility.

To provide the desired voltage the quotient of the values of the resistances is fixed (approx. 1/2 for this case). However, the absolute values of the resistances are not.

Q: How to choose those absolute values? Which are the criteria and why?

I have a good background in electromagnetism but I know very few about electronic Engineering.

I think that low values must work, e.g. 1Ω and 2Ω (and surely greater values). But I am unsure of VERY high resistance values because I suspect that there should be some current intensity requirements.

Thank you.

  • @Juraj Thank you. I missed that! – user1420303 Jan 21 at 20:26
  • The nodemcu has a voltage divider built in for 3.3v max. – Majenko Jan 21 at 20:42
  • @Majenko , thanks for your comment, on which input/outputs it works? – user1420303 Jan 21 at 21:11
  • The ADC pin. You notice there's two ADC pins - one that is the 1V and the other that is the 1V but with a voltage divider. – Majenko Jan 21 at 21:59
5

As @Majenko commented, the A0 input has a fixed voltage divider (see NodeMCU Schematics) that connects the A0 input to a 220kOhm resistor, then to the ADC pin of the ESP8266, then to ground via a 100kOhm resistor.

enter image description here

This effectively fixes the resistor values that can be used to scale the input of the NodeMCU. For a 0-5.0V input range (with sufficiently low impedance) you need to scale the ADC pin from 0-1.0V by adding a ~180kOhm resistor between the 5V output and the A0 input of the NodeMCU, creating a 400kOhm-> ADC -> 100kOhm divider like this:

schematic

simulate this circuit – Schematic created using CircuitLab

  • what are the trade-off with this compared to adding a parallel resistor between A0 and GND? – dandavis Jan 21 at 21:19
  • I don't think there are any trade-offs to be honest. You need to divide your 0-5.0V sensor output by 5 to create a 0-1.0V signal on the ADC pin of the ESP8266 and this is about the simplest and most efficient way to achieve that. The resistor values are sufficiently high as to create very little load on your sensor output. The only drawback I can think of is in the case of very high frequency signals. – StarCat Jan 21 at 21:31
  • Thank you! I think that I understood it correctly. – user1420303 Jan 21 at 21:36
  • For digital inputs, do I need to add two resistances, right? – user1420303 Jan 21 at 21:52
  • 1
    Digital inputs dont’t have an internal voltage divider on the NodeMCU board and accept 3.3V input. To scale from 5V to 3.3V you need a divider 3/5 divider. For example: 5V Input->2.2kOhm->NodeMCU input->3.3kOhm->GND – StarCat Jan 21 at 22:03
1

The low end of the values is limited by how much current your sensor can provide. If you use 1Ω and 2Ω resistors in series then your sensor will need to provide 1.67A to create 5V across the divider. I doubt that your sensor can do that. For most sensors, you would want to use resistors in the kilohm or tens of kilohm range.

The high end is limited by the input impedance of the analog input pin. If your resistor values are large compared to this input impedance then the input impedance of the analog pin will affect how the voltage divider works. If the analog input is multiplexed and the ADC has a sample-and-hold at the input, then very large resistances in the divider will not allow the sampling capacitor to charge fast enough. For most ADC inputs, you would want to use resistors in the tens or hundreds of kilohms.

  • Thank you! There is still something that I do not get about low values: If the sensor works giving an output up to 5V when it is connected to an Arduino, and the sensor cannot provide 1.67A, it implies that there is already an enough large resistor in the Arduino board (or NodeMCU). Doesn't it? In such case, there should not be a problem using small resistances in the divisor. In other words, if the sensor can work with the board without any additional resistance, how can it be that adding resistances forces the sensor to provide greater currents? Excuse if it is a silly question. Thanks. – user1420303 Jan 21 at 21:09
  • 1
    the less resistance in the divider, the more wasted heat and constant current consumption there is to deal with. Sure a 1ohm pair scales 5v into 2.5v, but it also wastes 2.5W of power and makes enough heat to fry 10 common resistors. If the sensor cannot supply those amps, it will drop the voltage or fry the sensor. – dandavis Jan 21 at 21:16
  • 1
    @user1420303 The problem is that the resistance of the divider is in parallel with the input resistance of the microcontroller, not in series. Putting resistances in parallel results in an equivalent resistance that is less than either of the original resistances. Very large currents will flow through your divider. – Elliot Alderson Jan 21 at 23:28
  • @ElliotAlderson thank you! I didn't notice that they are in parallel – user1420303 Jan 22 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.