Go Down

Topic: How to make an Arduino Ohmmeter (Read 1 time) previous topic - next topic


I found this to be a really useful project, so I've written up a how to guide for anyone interested in making a quick resistance/voltage drop meter with an Arduino Uno: http://www.circuitbasics.com/arduino-ohm-meter/



You can use Secret Arduino Voltmeter to improve the accuracy of the measurements.

Code: [Select]
// Arduino Ohm Meter
// http://www.circuitbasics.com/arduino-ohm-meter/

The code sets up analog pin A0 to read analog voltage. The idea is to make a voltage divider, and read the voltage at the middle of the two resistors.

Using Secret Arduino Voltmeter the accuracy of the measurements will be greatly improved.

int analogPin= 0;
int raw= 0;  // Raw reading of the voltage divider
float Vin= 5.0; // 5V
float Vout= 0; // reading of the voltage divider
float R1= 1000; // can change to 10K or 100K resistor improve accuracy
float R2= 0; // Resistance of the unknown resistor
float buffer= 0;

void setup()
Vin = readVcc()/1000.0;
Serial.print("Vin: ");
Serial.println( readVcc(), DEC );

void loop()

raw= analogRead(analogPin);
buffer= raw * Vin;
Vout= (buffer)/1024.0;
buffer= (Vin/Vout) -1;
R2= R1 * buffer;
Serial.print("Vout: ");
Serial.print("R2: ");

// Secret Arduino Voltmeter
// http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
long readVcc() {
  // Read 1.1V reference against AVcc
  // set the reference to Vcc and the measurement to the internal 1.1V reference
  #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
    ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__)
    ADMUX = _BV(MUX5) | _BV(MUX0);
  #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__)
    ADMUX = _BV(MUX3) | _BV(MUX2);
    ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Start conversion
  while (bit_is_set(ADCSRA,ADSC)); // measuring
  uint8_t low  = ADCL; // must read ADCL first - it then locks ADCH 
  uint8_t high = ADCH; // unlocks both
  long result = (high<<8) | low;
  result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000
  return result; // Vcc in millivolts


Seems like that method has the caveat that no voltage drop measure may exceed 1.1 V.
Arduino UNOs, Pro-Minis, ATMega328, ATtiny85, LCDs, MCP4162, keypads,<br />DS18B20s,74c922,nRF24L01, RS232, SD card, RC fixed wing, quadcopter

Go Up