Arduino pwm floating/random pins problem

 if (digitalRead(4) == HIGH)
 {
  tft.fillRect(analogRead(10),analogRead(6),analogRead(5),analogRead(3),0xFFFF);
  Serial.println(analogRead(10));
 }

why those pins (10,6,5,3) give me random/floating numbers, theyre on 5V and INPUT_PULLUP, whats the problem here (i check from serial and display)

Which Arduino are you using?

How would we know that from the code that you have posted ?

im tired of saying UNO :sweat_smile:

UNO R3. (with more detail)

Please post your code and explain what you expect to see and what you are actually seeing. Instead of using pin numbers it would be nice to use descriptive constants. A wiring diagram would be helpful.

What does PWM have to do with it? Why do you have have inputs configured with internal pullups when you are using them as analog inputs?

1 Like
pinMode(10,INPUT_PULLUP);
pinMode(6,INPUT_PULLUP);
pinMode(5,INPUT_PULLUP);
pinMode(3,INPUT_PULLUP);

Why are you using analogRead() on digital pins ?

The OP may find this useful or not,


with locating the Uno's pins and their uses.

ok i made in tinkercad

The analog read function only works on analog pins (14 and higher). It's clever enough to realize that if you use 3, that you really mean 17 so a couple of those reads did work, just not on the pins you expected, hence the floating results.

pin 3 is also giving the same results

??? There is NOTHING in your code snippet to convey what you THINK you are reading. Please let us know what you require and we can help.

i dont have any other single line of code that uses those pins

When you do

analogRead(3);

the code reads pin A3 (ie, pin 17)
What do you have connected to A3, if anything ?

Do you think you are reading a PWM frequency? Do you think you are reading a voltage? Do you think you are reading a digital input?

What does this data REPRESENT???

Analog IN 3 is empty, i use PWM 3

an 255

There's your problem.

Pin 3 can do PWM output

You cannot read an analogue value from it because it is a purely digital GPIO pin