Getting state change value from analogRead()

Thank you, I am getting more accurate readings from the Switch. :slight_smile:

This is nonsense.

The Arduino input pin is floating. No matter how many times you use analogRead() you will never get a stable value, because your circuit is not stable.

Simply connect the switch between the arduino pin and ground. Use pinMode(x, INPUT_PULLUP) and digitalRead(). Simple.

2 Likes

The way you had it your pin will float.

Just use
switchState = digitalRead(A1);

OR

switchState = digitalRead(15);

1 Like

You were 100% correct.

@nishantd2007,

Your topic was moved to its current location as it is more suitable.

Could you also take a few moments to Learn How To Use The Forum.

It will help you get the best out of the forum in the future.

Thank you

Thank you @PaulRB.. I got the proper connection and getting the values. :slight_smile:

1 Like

The next question is why you are using an Arduino? The Pi is quite capable of reading a switch without help from an Arduino.

Well, that wasted 30 minutes of my time...

1 Like

No! you assured your place in the line at the pearly gates :innocent:

1 Like

I thought we all got a place in line… just not necessarily passage when we get to the front. :expressionless:

a7

I am planning to use Arduino MKR1010 at a distant place and PI as a Server, and need to get the input from Arduino to PI.

@LarryD Thank you for your help.. :slight_smile:

You could also consider wemos D1 mini.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.