An Engineer's Blog

Back

Portable Digital Multimeter using microcontrollerBlur image

Overview#

This project introduces a functional digital multimeter using basic components to measure DC voltage, DC current, resistance and capacitance. The objectives are low-cost, small and compact which driven by only a microcontroller ATmega328p and using the Arduino IDE for source code development. As a result, our DMM can function with all the features aforementioned including an auto-scale automation.

"Final DMM Design Skeleton on breadboard"

Apparatus#

  1. Atmel Atmega328p
  2. 16Mhz Crystal
  3. USBasp Connector
  4. Shunt Resistor
  5. LM358 Operational Amplifier
  6. LCD 16x2
  7. LM7805 Voltage Regulator
  8. Fuse
  9. Buttons
  10. Piezo Buzzer

Measuring Voltage#

DC Voltage calculation is straight-forward since it depends entirely on the **Analog-Digital Converter (ADC)**module inside the Atmega328p. Although, it is important to lay out the conversion rate, especially the resolution since the power supply level, which is non-constant, play an active role in this formula.

Vcalc=analogReadVrngADCresolutionV_{calc} = \frac{analogRead * V_{rng}}{ADC_{resolution}}

Where the desired Voltage (Vcalc) is converted from an analog value (0-1023, or Resolution N = 1024) based on range of voltages. Also, the ADC resolution is specified for Atmega328p as 10 bits or 1024 voltage levels.

Or converted into code as

Vcalc = (analogRead(MEAS_VOLT_PIN) * Vrng6V) / MAX_ADC_VALUE;
cpp

Measuring Current#

For DC Current, there are essentially two approaches, both of which has their advantages and trade-off. The first one is High-side Current Sensing attempting to measure current based on Ohm’s Law, i.e. via measured voltage, at very low level of resistance in order to capture the most accurate current.

Another alternative approach is using a Current Sensor which based on the Hall Effect.

High-side Current Sensing#

The High-side Current Sensing method employs a shunt resistor and a Difference Amplifier that differentiate and amplify the voltage across the shunt resistor. Specifically, the function and gain of amplifier stage can be understood as

Vout=R3R6(Vin+Vin)V_{out} = \frac{R_3}{R_6} * (V_{in+} - V_{in-})

where the Feedback resistor R3R_3 and Grounding resistor R4R_4 has the same ratio with respect to their input resistor R6R_6 and R5R_5.

"High-side Current Sensing simulation" High-side Current Sensing Simulation using measured value with Shunt Resistor and LM358 Operational Amplifier

Specifically, the configuration with a gain set by the formula Av=R3R6=100kΩ10kΩ=10Av = \frac{R_3}{R_6} = \frac{100k\Omega}{10k \Omega} = 10 which results in the amplification of Vin+Vin=0.0618VV_{in+} - V_{in-} = 0.0618 V upto 10 times. As captured at the output of LM358, the output voltage actually captured at around Vout=0.629VV_out = 0.629 V.

With the use of 1Ω shunt resistor, the current is to be exact as the voltage with a mild variation for small resistive load and because of the resolution of Analog-Digital-Converter. The voltage input for microcontroller was read then converted back to the actual value of current (ImeasI_meas).

Imeas = analogRead(currentIn_pin) * getVcc() / MAX_ADC_VALUE;
cpp

An alternative approach#

As mentioned, another approach is using the Hall Effect Current Sensor ACS712 which worked for both DC and AC current based on its output voltage which directly proportional to the magnetic field strength through it. Although, after several setup attempts, it was clear that due to the physic nature of this type of measurement and the potential high cost for an accurate current sensor and thus Hall Effect Current Sensor was deemed to be unfit for this kind of project.

Measuring Resistance#

The methodology to measure unknown resistance is essentially based on Voltage Divider circuit where the voltage source (VCC = 5V) is applied to two resistances in series, one of which is known and the other is the input unknown resistor.

Vmeas=VinR2R2+RoutRout=R2(VinVmeas1)V_{meas} = V_{in} * \frac{R_2}{R_2+R_{out}} \Rrightarrow R_{out} = R_2 * (\frac{V_{in}}{V_{meas}} - 1)

Also, the voltage drop across one of two known resistances R10 or R1M is first read by the Analog Read in Arduino and instead of grounding the resistances, they are connected to 2 different digital input pins driven HIGH or LOW (grounding) in order to create AUTO RANGE between two scales (scale 1: 10 - 10 kΩ & scale 2: 10 kΩ - x MΩ)

"Resistance Sensing Simulation" Resistance Measurement with the measuring resistance and Voltage Divider at the input pin

The conversion is then similar to that of the voltage measurement which using the ADC module but added a deterministic variable to enter the correct state based on the input value.

switch (res_state){
    case 1: getRange_R10(); if (rawADC > lThreshold) res_state = rngR10; else res_state = rngR1Meg; break;
    case 2: getRange_R1Meg(); if (rawADC < hThreshold) res_state = rngR1Meg; else res_state = rngR10; break;
}
cpp

Connectivity#

In addition to resistance, the connectivity of a line can be detected by simply send in a small amount of current and detect other lead of the same line. Using a Digital pin D3 for input and another D4 for measurement, a closed loop of measurement can be formed where the D3 pin will send an output of HIGH-LOW (0-255) signal level and into D4. Next, the measurement pin will convert to digital signal (0-1) and act as the actuator if there is connectivity, i.e. digitalRead(D4) = 1

Measuring Capacitance#

There are two methods completely based on the functionality of a capacitor are used without any additional hardware usage as the advantages of the microcontroller ATmega328p.

Lower values#

This can be done based on solely the functionality of ATmega328p and breadboard, i.e. the value of the stray capacitance and pull-up resistance. The microcontroller will output 5V at the Analog pin A5 (farahOut_pin) through the measuring capacitor and back to the Analog pin A4 (farahIn_pin).

cpct = (float) rawADC * IN_CAP_TO_GND / (float) (MAX_ADC_VALUE - rawADC);
cpp

What was done is the raw ADC value is multipled with the stray capacitance IN_CAP_TO_GND and divided with the difference between raw analog value and the maximum resolution. The Stray capacitance varies from breadboard but usually has a consistent range from 24.48nF24.48\mathrm{n}F to 30pF30\mathrm{p}F.

"Low value capacitance measurement simulation" Capacitance Measurement with and without additional hardware

High values#

For high value of capacitance, however, it is required to have a better method in term of accuracy and thus charging seems more a viable solution. This method employ the use of microcontroller timer in order to capture the τ\tau constant and later calculate the actual capacitance value.

do {
 digVal = digitalRead(farahOut_pin);
 // Compare charging time with real time
 unsigned long u2 = micros(); t = u2 > u1 ? u2 - u1 : u1 - u2;
} while ((digVal < 1) && (t < 400000L)); // Charging, do measurement

pinMode(farahOut_pin, INPUT); // Stop measurement
cpct = analogRead(farahOut_pin); // Read measured value
cpp

"High value capacitance measurement simulation" Capacitance Measurement with CmeasC_{meas} and RpullUpR_{pullUp} without additional hardware

Portable Digital Multimeter using microcontroller
https://tin.ng/blog/2018-06-25--portable-digital-multimeter
Author Tin Nguyen
Published at June 25, 2018
Comment seems to stuck. Try to refresh?✨