Voltage Measurement by analogRead Operation

A useful way of reading a voltage signal level is through an Analog Input port on the Arduino. With accompanied code to collect, interpret, calculate, display, and act upon a static of dynamic voltages from a circuit, discrete numerical values are presented to a user. In this project, those values are displayed via the Arduino Sketch Serial Monitor. As necessary to bring those values together, in an effort to read an actual voltage, it is necessary to build a circuit or tap an existing circuit, and write the code to get the readings desired. In this case, it is important to also perform a conversion of read values from binary equivalent numbers due to the Arduino UNO in this project that uses a 10-bin A/D converter (210 – 10-bit resolution or 1024 distinct values for a single point of measurement).

There are numerous basic applications from this function as a separate or partitioned segment of capability that pertains to other relevant purposes. The reason it is so important to understand this capability is because of its relevance as a fundamental building block elsewhere. Just as there are many other building blocks, this is a key capability that has a bearing on how projects come together using both a combination of hardware and software.

This code includes variables to initialize conditions by which the entire program operates. These variables must be declared using a data type that specifies how they are acted upon. In this example, integer and float data types get declared to establish precision for accuracy and proper computations or handling. Afterward, the program involves set up commands to configure the program and operate functions as intended. Finally, the void loop() function provides for the instructions to execute programmatically.

In this example, under the void loop(), the physical voltage read into the analog port is the value presented to the analog-to-digital converter. As this value is stored into variable memory readVal, it is multiplied by a coefficient (5./1023.). This calculation becomes necessary as the numerical value read into the readVal memory isn’t a voltage level as given by a meter. So, the calculation of 5VDC ÷ 1023 values gives a ratio of two maximum values as represented as voltage (numerator) and resolution (denominator). This calculation normalizes the digital value read at the analog port input to a voltage value read into memory (V2) or displayed as desired. V2, in turn, is read out at the serial monitor utility from the Arduino Sketch IDE to make tangible the entire operation. Meaning, a readout of voltage using an Arduino module and a host computer instead of a separate dedicated meter.

// declare variables
int readPin=A3;
int readVal;
float V2=0;
int delayTime=500;

void setup() {
// put setup code here, to run once while using any relevant variable declared above

pinMode(readPin,INPUT);
Serial.begin(9600);
}

void loop() {
// put main code here, to run repeatedly. runs in a continuous loop until interrupted or physically halted

readVal=analogRead(readPin);
V2=(5./1023.)*readVal;
Serial.println(V2);
delay(delayTime);

}

Stable Circuit Operating Voltage
Port Connections. Reference Voltage & Analog Input Voltage
Simple Voltage Divider Circuit (330Ω & 100Ω)
Code Implementation of Voltage Meter
Selected Voltage Value for Arduino AnalogRead
Serial Monitor Value Reading from Arduino AnalogRead

Further Project Details: -Paul McWhorter

About

Servant of Christ Jesus. U.S. Military Veteran, Electrical Engineer, Pepperdine MBA, and M.A. Biblical and Theological Studies.

, ,

Comments are closed.