Arduino Nano 33 IoT - Measure Voltage

In this guide, we will show you how to use an Arduino Nano 33 IoT to measure voltage from 0V to 25V with a voltage sensor. We will explain:

Arduino Nano 33 IoT voltage sensor

Hardware Preparation

1×Arduino Nano 33 IoT
1×Micro USB Cable
1×Voltage Sensor
1×Jumper Wires
1×Recommended: Screw Terminal Expansion Board for Arduino Nano
1×Recommended: Breakout Expansion Board for Arduino Nano
1×Recommended: Power Splitter for Arduino Nano

Or you can buy the following sensor kits:

1×DIYables Sensor Kit (30 sensors/displays)
1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Voltage Sensor

A Voltage Sensor is a tool that has a built-in simple circuit to divide voltage, using very accurate resistors to help measure voltage easily. It contains two resistors: one is 30 KΩ and the other is 7.5 KΩ. If the ADC uses a 5V reference, this sensor can measure voltages from 0 to 25V DC. When the ADC uses a 3.3V reference, the sensor can measure voltages from 0 to 16.5V DC.

Pinout

A voltage sensor has two groups of pins:

  • Input Connection (connect here to measure voltage):
    • VCC pin: Connect this positive pin to the high voltage side.
    • GND pin: Connect this negative pin to the low voltage side.
  • Output Connection (connect this to the Arduino Nano 33 IoT):
    • Vout pin (S): Connect this pin to one of the Arduino Nano 33 IoT's analog pins.
    • NC pin (+): Do not connect this; leave it unconnected.
    • GMS pin (-): Connect this pin to the Arduino Nano 33 IoT's GND (0V).
    Voltage Pinout
    image source: diyables.io

Wiring Diagram

The wiring diagram between Arduino Nano and 33 IoT voltage sensor

This image is created using Fritzing. Click to enlarge image

※ NOTE THAT:

Please note that the Arduino Nano 33 IoT pins A4 and A5 have built-in pull-up resistors for I2C communication. Although these pins can be used as digital input pins, it is recommended to avoid using them for digital input. If you must use them, do not use internal or external pull-down resistors for these pins

Arduino Nano 33 IoT Code

/* * This Arduino Nano 33 IoT code was developed by newbiely.com * * This Arduino Nano 33 IoT code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-nano-iot/arduino-nano-33-iot-measure-voltage */ #define ANALOG_IN_PIN A7 // The Arduino Nano 33 IoT pin connected to voltage sensor #define REF_VOLTAGE 3.3 #define ADC_RESOLUTION 4096.0 #define R1 30000.0 // resistor values in voltage sensor (in ohms) #define R2 7500.0 // resistor values in voltage sensor (in ohms) void setup() { Serial.begin(9600); } void loop() { // read the analog input int adc_value = analogRead(ANALOG_IN_PIN); // determine voltage at adc input float voltage_adc = ((float)adc_value * REF_VOLTAGE) / ADC_RESOLUTION; // calculate voltage at the sensor input float voltage_in = voltage_adc * (R1 + R2) / R2; // print results to serial monitor to 2 decimal places Serial.print("Measured Voltage = "); Serial.println(voltage_in, 2); delay(500); }

Detailed Instructions

If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:

  • Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
  • Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
  • Launch the Arduino IDE on your computer.
  • Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
  • Copy the code above and paste it into the Arduino IDE.
  • Click the Upload button in the Arduino IDE to send the code to the Arduino Nano 33 IoT.
  • Check by measuring the 5V and 3.3V outputs on the Arduino Nano 33 IoT.
  • Look at the results in the Serial Monitor.
COM6
Send
Measured Voltage = 4.96 Measured Voltage = 4.96 Measured Voltage = 4.96 Measured Voltage = 4.96 Measured Voltage = 3.39 Measured Voltage = 3.39 Measured Voltage = 3.39 Measured Voltage = 3.39
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

※ NOTE THAT:

The reading may change because the common voltage level is 5 volts. This level might not always be steady and can shift depending on the power source.

Video Tutorial

Learn More

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!