Author Topic: Need help with analogRead  (Read 5918 times)


  • Newbie
  • *
  • Posts: 2
Need help with analogRead
« on: February 02, 2018, 02:31:54 am »
I want to read an Analogport. I tried this, but it does not work and I don't know why.
I relied on this pinout:
Any help appreciated. Thank you.

#define LED_PIN 1  //P1

void setup() {
  pinMode(LED_PIN, OUTPUT);
  pinMode(7, INPUT);

void loop() {
  if (analogRead(A7)>0) {digitalWrite(LED_PIN, HIGH);}
    else {digitalWrite(LED_PIN, LOW); }


  • Hero Member
  • *****
  • Posts: 881
Re: Need help with analogRead
« Reply #1 on: February 02, 2018, 11:16:46 pm »
Define 'not working'.

If I upload that code, and then connect A7 to GND, the LED at P1 goes out. As there is probably some noise on A7 that is making it so it is above 0, hence P1 stays lit unless A7 is pulled down (although, if you wanted to keep that behaviour, but make it more reliable, you would change INPUT to INPUT_PULLUP, so that the pin is pulled HIGH/1023 internally).

What did you actually want the code to do?