Arduino digitalWrite() output shows inconsistent voltages on multiple pins

I’m testing Arduino digital output pins with a multimeter.
My code is the simplest blink:

void setup() {
  pinMode(13, OUTPUT);
}

void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

Expected:

  • HIGH ≈ 5.0 V
  • LOW ≈ 0.0 V

Actual readings:

  • Sometimes ~4.5 V
  • Sometimes ~3.1 V
  • Sometimes only a few millivolts when LOW
  • This happens not only on pin 13 but also on other pins.

Update: here the simulation that I use: Circuit design [ROBO 001] digitalWrite - Tinkercad

remove the LED and test again

Check the definition of High and Low for 5V logic.

  • Try a different voltmeter and/or change the batteries in your meter.

Which Arduino? What color LED? What resistor value? Which pin state (HIGH or LOW)?

Why?


From the UNO data sheet

To paraphrase Zappa, is it a real Uno or a Sears Uno?

You are indirectly measuring the output resistance of the Arduino pins:  

Source Rz (HIGH)    Sink Rz (LOW)
(5 − Vmeas) / I     Vmeas / I

Also, how are you powering your board, and have you measured Vcc at the board? While USB is "nominally" 5V, it can be a couple tenths of a volt below that by the time it gets through assorted protection circuits and cables...

Is a one second delay long enough to let the DMM display settle to the measured voltage? Have you tried setting the delay to a higher value?

Deleted. Someone got there first !

Real world test results:

Sketch #1:

void setup() {
   for( byte pin=2; pin<=13; ++pin ) {
      pinMode(pin, OUTPUT);
      digitalWrite(pin, HIGH);
   }
}

void loop() {
}

Voltage measured at 5V pin: 4.71V
Voltage measured at pins 2-12: 4.69-4.71V
Voltage measured at pin 13: 4.41V (due to loading of SCK LED)

Sketch #2:

void setup() {
   for( byte pin=2; pin<=13; ++pin ) {
      pinMode(pin, OUTPUT);
      digitalWrite(pin, LOW);
   }
}

void loop() {
}

Voltage measured at 5V pin: 4.71V
Voltage measured at pins 2-13: 0.00V

Conclusion: no problem found, operation as expected.

Welcome!

Sorry, but you left out one important detail: which Arduino board are you using? This matters because some Arduino’s include built-in USB protection circuitry that causes a slight voltage drop from the USB power input. This protection prevents voltage from feeding back into your computer and potentially damaging it.

For example, my original UNOs run at about 4.6 V for this reason.

Since you did not specify otherwise, I am assuming your board is powered through the USB port on your computer. The voltage range for a USB 2.0 port is typically 4.75 V to 5.25 V, though newer specifications allow it to go up to 5.5 V.

If my assumption is wrong and you are powering the board through Vin, keep in mind that a regulator like the LM7805 typically outputs between 4.8 V and 5.2 V. I am not certain which regulator your specific board uses, though.


Hey guys, here is the tinkercad link: Circuit design [ROBO 001] digitalWrite - Tinkercad

Are you testing a real board, or just using the simulation?

Measure voltage at VCC-pin of the MCU of the Arduino UNOR3 Board and then go through the foloowing data sheet:

If VCC = 5V (or close), you will get minimum (guaranteed) 4.1V (VOH) at the digital pin after executing digitalWrite(DPin, HIGH). Be sure that you have connected a load of 2.2k resistor with the digital pin.

I am using simulation, sir!

Then all bets are off. Simulations are not the real thing, only a rough approximation. They will not be accurate to the level of real hardware.

In theory the theory and the practice are the same things.

In practise the practise and the theory are two totaly different thing.

:slight_smile:

However,

If it woroks in theory, there is a chance that it will work in practice.

If it does not work in theory, it will never be working in practice.

Exception:
In China, many years ago, a foreign logging company predicted based on the interpretation of their real-time logging data that no oil-bearing zone existed in the subsurface The Chinese disagreed with this assessment. They proceeded to run the casing and perforate it anyway— and to everyone’s surprise, oil began to flow.