Record voltage at digital pin

Is there any way to record the voltage at the digital pins of a Nano with code?

Short answer: connect it to an analog pin as well and read the analog pin.

Longer non-answer:
Why do you want to know the voltage?
What does ‘record’ mean? Measure and store?

What do you expect the voltage to be considering that a digital pin can only be HIGH or LOW ?


What do you want to do with it?
The only way is to measure it with a potential divider and use one of the Nano’s analog inputs with 1V1 Vref.

Tom… :grinning: :+1: :coffee: :australia:

I’m trying to figure out why a pin is reading low when it should be high.
I’m serial printing the pin value immediately after the digitalRead in a button debounce function, so as far as I can see the misread shouldn’t be code related, yet it happens predictably and reliably when the function is called at a certain point in the sketch.

I’m just trying to eliminate possibility of the pin being around the threshold for HIGH/LOW.

Are there any implications for connecting the button to both analogue and digital pins, either in terms of code (eg read timings) or the physical circuit?

Can you please post the code that produces the phenomenon?
You are declaring the pin as an output?

Tom… :grinning: :+1: :coffee: :australia:

connect both pins together and read the digital pin and analog read the analog pin

As you haven’t posted the code, we have no clue what the problem is. You need to show us the code if you expect any kind of informed explanation.

@MarkT I take your point about a lack of code.
The debounce funcition is successfully called at multiple points in the sketch. The second time it’s called within a particular function (and it’s been called upto 6 times in the meantime), the digitalRead fails to recognise the button has been released.

  bool buttonState = digitalRead(rotaryButtonPin);
Serial.println ( buttonState );

Since there’s nothing in between these lines, I can’t see how it would be code dependant, which is why I want to verify the voltage at the pin WRT time.
(The only things before this code in this in the function are variable declarations. The pin uses the internal pullup.)


That I presume, is why you are here, let us see ALL your code, or some shorter code that exhibits the same phenomenon so we can voice our opinions/suggestions.

What is your project and what is it supposed to do.


Tom… :grinning: :coffee: :coffee: :australia:

How about:

  int buttonValue = analogRead(rotaryButtonPin);
  bool buttonState = buttonValue < 512 ? false : true;
  Serial.println (buttonValue);

Move your rotaryButtonPin to an analog input.

which function is this code in ?


Well do something about it, like post ALL your code.

We are at post #13 and you still have not provided the basic information.

If you want to verify the pin voltage, do it independently with a DMM and/or a scope.
Your output may be operating for only a fraction of a second in your program loop.
ANOTHER reason for you to post ALL your code… PLEASE!!!

Tom… :grinning: :coffee: :coffee: :australia:
PS, I am off to bed, maybe the world will be better when I awake… :sleeping: :sleeping: :sleeping: :sleeping: :sleeping:

@TomGeorge All 1700 lines? :pleading_face:
Sleep well!

Why not?


You developed the code, at what stage during your programming in STAGES did the problem appear?

Have you documented/commented your code?
Can you tell us the application when you post your code please.

Tom… :grinning: :+1: :coffee: :australia:

1 Like

Absolutely, many of us are very proficient at speed-reading code and navigating complex
code bases of 100,000’s of lines (we do this for a living!)

Don’t forget leaping over tall buildings and outrunning bullets.


1 Like

If you had been programming for decades, this won’t be at all surprizing. Remember
we cheat and use computers to do the heavy lifting!

1 Like

The problem is that computers don’t think outside the box :wink: I will happily paste a video in a text box and check if the application crashes or not. Or modify connection strings and check if I get unhandled exceptions :smiley: