Implementation of Ohmmeter using ZKit-51

Resistance is the reluctance or a kind of friction in a carrier which opposes the flow of current through it. The resistance of an element is measurable and it is represented by an unit known as Ohm. Ohmmeter is a device used to measure the electrical resistance. This project shows how to construct a simple ohmmeter using 8051 microcontroller.

Theory & Design

The resistance of an element can be measured by building a voltage divider circuit with a known input voltage (`V_i`), a known resistor value (`R_k`), and the unknown resistor (`R_u`), as shown in the figure below. By measuring the output voltage (`V_u`), it is possible to determine the value of unknown resistance.
Figure 1. Voltage Divider Circuit

The output voltage `V_u` is given by, the voltage divider equation.


The equation is re-arranged to obtain the unknown resistance `R_u`.


From the above derivation, we find that the unknown resistance is measured with the known resistance `R_k` , input voltage `V_i` and the voltage `V_u` across the unknown resistor. Since `R_k` and `V_i` is known already, only the `V_u` has to be measured. In our design of a digital ohmmeter using ZKit-51, we use an ADC to measure the voltage `V_u` in the above circuit, to calculate the resistance `R_u` using the above formula in software.

The range of resistance to be measured will vary based on the known resistor used in the circuit.

Known resistor

Measurement range

10 ohms

< 30 ohm

10 kilo ohm

31 ohm - 41 kilo ohm

1 mega ohm

18 kilo ohm - 4 mega ohm

What you need


  • Build the voltage divider circuit as shown in the diagram.

  • Connect voltage divider circuit to ZKit-51 ADC module to measure the voltage across unknown resistor.

  • Connect ZKit-51 ADC module with ZKit-51-motherboard using FRC connector.

  • Calculation of the unknown resistor value will be done in software part.
Figure 2. Circuit Connection Diagram


The code for resistance measurement using ZDev library is given below,

#include <board.h>
#include <stdio.h>
#include <adc.h>
#include <lcd.h>
#include <delay.h>

#define KNOWN_RESISTANCE 10000
/* Input volt=5.1, adjusted for non-floating point value manipulation. */
#define INPUT_VOLTAGE 5070

/* Calculate unknown resistance from measured voltage. */
uint32_t resistance_value(uint8_t digi_volt, uint32_t res, uint16_t vin)
        uint32_t resistance;
        uint16_t analog_volt;

        analog_volt = (digi_volt * 16);
        resistance =
                ((analog_volt * (res / 1000)) / ((vin - analog_volt) / 10));
        return (resistance * 100L);

int main()
        uint8_t volt;
        uint32_t resistance;
        uint8_t prev_value = 0;

        while (1) {
                volt = adc_read8(2);
                if (volt == prev_value)
                prev_value = volt;
                resistance = resistance_value(volt, KNOWN_RESISTANCE, INPUT_VOLTAGE);
                printf("%ld ohms", resistance);