Welcome to Solarduino , A blog about DIY Solar PV and Arduino projects

How to convert 5V Analog Sensor Output value to 3.3V Analog Value for NodeMCU

If you like to DIY Arduino mini projects, there are many selection of micro-controllers in the market such as Arduino UNO, nano, mega, and nodeMCU. Sensors and modules are among the components normally attach to micro controller for data collection and measurement from environment. Typically there are 2 basic types of inputs and outputs to the micro-controller which are the Digital Inputs/Outputs (I/O) and Analog (I/O).

Digital I/O are pins that either operate High (5V or 3.3V subject to micro controller) or Low (0V), it is typically used for ON or OFF load switching or Pulse Width Modulation (high frequency of ON-OFF cycles) for dimming or motor speed control. Analog I/O are pins that provide a value range within 0 to 5V or 0 to 3.3V subject to micro-controller to represent a measurable range value from sensors thus providing detailed information such as temperature value, speed value etc.

Most sensors in the market provide 0-5V analog output. If you have a micro-controller that only can detect Analog Input values between 0 to 3.3V, they will be a risk of damage besides the inaccuracy of reading conversion. On the opposite, if a sensor provides 0 to 3.3V analog output and you have a micro-controller that can detect Analog Input values between 0 to 5V, there will be absolutely no problem as the conversion value can be via programming code. 

NodeMCU micro-controller

The NodeMCU micro-controller is similar to Arduino micro-controller board. It is compatible with Arduino IDE software and is built-in with the ESP8266 module which can be connected to the internet. You can grab some at our affiliate link here !!!  

Node MCU Micro controller Base

The based below the Node MCU can provide more flexibility on the connection ports to support more sensors. Besides, it also has 12V input port and able to provide 5V power supply to support the sensors. Support us by purchase it from our affiliate link here !!!

NodeMCU is the representative micro-controller that having 3.3V Analog I/O pins thus 5V to 3.3V analog value conversion is very important. NodeMCU is a very useful and famous micro-controller as it has built-in Wifi module and widely used for Internet of Thing (IOT) applications such as online monitoring and home automation. However, it only has 1 Analog (I/O) pin thus normally used with Multiplexer Module to extend the Analog Pins. 

16 Channel Analog Multiplexer Module

This module is an extension board that allows micro-controller to have more Analog Pins for sensor measurement. It is very important for NodeMCU as it only has one Analog Pin. Support us by grabbing one at our affiliate link here !!!

For more information or how to use the 16 channel multiplexer on NodeMCU, kindly check it out on my blog page here. Multiplexer is a module that requires 4 Digital pins to convert into 16 Analog pins. It operates with 5V power supply and able to transfer 5V analog values to the output thus 5V to 3.3V conversion is needed between the NodeMCU and multiplexer module.

5V to 3.3V is actually requires a voltage step down converter. To step down a DC voltage signal, we normally use the voltage divider method that consists of two resistors connected in series as shown in the diagram below. This method can be used to convert both Digital and Analog Pins. All you need is just 2 high-accuracy resistors with different resistance values. The resistance values for R2 over (R1 + R2) must maintain a value of 0.66 which is also equivalent to 3.3V over 5.0V. Make sure to get 1% tolerance resistor at least 1/4W rating. R1 can be 170 ohm while R2 can be 330 ohm or R1 (1.7k ohm) while R2 (3.3k ohm). If you do not have the exact value for the resistor, R1 value can be slightly higher.

If you can’t find the exact resistance values, not to worry as the deviation or slight difference can be adjusted in the programming code. However, make sure the ratio value of R2 over (R1 + R2) must be as close and not to exceed 0.66.

1% Tolerance Resistors

1% tolerance resistors have high accuracy resistance value thus suitable for precise application especially for measurement. You may purchase the resistor at our affiliate link here !!

Hardware Connection

Once you get your sensor module and resistors ready, you may start to do hardware wiring. Below is the schematic of the voltage divider part. If you purchase resistors, I recommend you to get a mini breadboard to put next to the Arduino for wiring which is available here !!! Optionally you can solder to secure them.

Dupont Line Wires

You may need Dupont Line Wires (male to female) to connect Arduino board and Voltage Sensor. It is available at our affiliate link here !!! 

Software Codes

The final step would be adding source code onto Arduino board. I assume you have installed the Arduino Software. If you still have not installed the software, the link here can bring you to the official download site. Once you have downloaded the software, you may download the code file (.ino) for this application below (right click save link). 

If this is the first time you are dealing with NodeMCU, you need to add NodeMCU board manager file into the IDE software so that the software can support the Node MCU board. To add the Support File, open Arduino IDE Software, go to files>preferences>Additional Boards Manager URLs, paste this link http://arduino.esp8266.com/stable/package_esp8266com_index.json to the blank space and click OK. Go to Tool > Board > make sure the board is showing NodeMCU 1.0 (ESP-12E module).

Wireless Smart Energy Monitor

This is an energy meter for the whole household monitoring and the measurement unit is fit inside electrical panel while there is a portable monitor display which is constantly communicate and acquire data via wireless with the measurement transmitter unit. You can get it at our affiliate link here !!!

In this example, we will be using a Potentiometer as a 5V sensor to NodeMCU micro controller. The potentiometer will be powered by the 5V power supply. If without the Voltage Divider, the potentiometer output values will reached a maximum of 1023 Analog Values even the potentiometer not yet rotated to the maximum. All the analog values without step down are not accurate. On the other hand, after the Voltage Divider, the potentiometer will only reach maximum value when it reaches the end point.

Before we end, we would like to give gratitude to you for taking the time to read the post. We would need readers like you to support us in order to keep growing. You can support us in the following ways :

Donate & Fund Raising

If you like my work, please send me a donation to encourage me to do more. Thanks

Aliexpress Affiliate

We are the member of Aliexpress affiliate marketing. Do support us by clicking the affiliate product links if you do wish to purchase them.

Like and Share

If you like our post, we need your support to like and share our posts or videos so that it can reach more and more people like you !!

5V to 3.3V Voltage Divider.ino