Voltage Measurement
If you want to measure a voltage with an Arduino, this is one way to do it. I find it quite easy and it gives good results.
- 1. Make an educated guess of the expected amount of voltage you want to measure. Keep in mind the arduino can only handle up to 5V and 20mA at it's analog inputs.
- 2. Connect the wires as shown in the picture.
- 3. Program your arduino to print the voltage.
Resistance Measurement
You cannot directly measure the resistance, but you can measure the voltage drop of a known resistor.
- 1. Make an educated guess of the expected amount of resistance you want to measure. Keep in mind the arduino can only handle up to 5V and 20mA at it's analog inputs.
- 2. Connect the wires as shown in the picture.
- 3. Program your arduino to print the resistance.
#define PIN_MEASURE A0
#define PIN_OUT 8
#define REF_R2 470
void setup() {
Serial.begin(9600);
pinMode(LED_BUILTIN, OUTPUT);
pinMode(PIN_OUT, OUTPUT);
}
void measureResistance(){
digitalWrite(PIN_OUT, HIGH);
delay(100);
long reading = 0;
for (byte i = 0; i < 10; i++){
reading += analogRead(PIN_MEASURE);
}
reading = (long)(reading/10);
float voltageR1 = (5.0 / 1023.0) * reading;
Serial.print("Voltage over R1: ");
Serial.print(voltageR1, 2);
Serial.println(" V");
int resistance = REF_R2 * (voltageR1 / (5.0 - voltageR1));
Serial.println("Resistor R1: " + String(resistance) + " Ω\n\n");
digitalWrite(PIN_OUT, LOW);
}
void loop() {
measureResistance();
delay(1000);
}
Current Measurement
To measure the current in my example I use following trick:
- 1. Make an educated guess of the expected amount of current you want to measure. Keep in mind the arduino can only handle up to 5V and 20mA at it's analog inputs.
- 2. Connect the wires as shown in the picture.
- 3. Program your arduino to calculate and print the current.