2

I connected my "arduino(nano)" to "water flow sensor" and wrote a code which simply prints the readings like 0-1023 and tested it. First i got the readings but now i'm not getting it.
My code looks something like this.

void setup(){
 Serial.begin(115200);
}

void loop(){
 int vla=analogRead(2);
 Serial.println(vla);
 delay(1500);
}

and my connection.

Sensor to Supply module
Vcc --> 5v
Gnd --> Gnd

Sensor to Arduino(Nano)
Sig --> D2

2
  • 1
    Also asked at forum.arduino.cc/index.php?topic=501527
    – per1234
    Sep 22, 2017 at 5:54
  • posting details about your exact flow sensor and library being used along with your schematic and full code may get you better answers; I have used water flow sensors to a good extent for some prototypes but cant answer your question without better details since many people around simply down vote answers without understanding the question and the intent of the person who answered :-)
    – techniche
    Sep 22, 2017 at 6:03

1 Answer 1

1

Sensor to Arduino(Nano) Sig --> D2

Your connections are wrong.

int vla=analogRead(2);

is reading from analog channel 2, which is pin A2 on your Nano, not D2

D2 is not an analog pin and thus you can't use it with analogRead().

6
  • I tried it but i'm getting only junk value, i even tried adding a pullup. Sep 22, 2017 at 4:54
  • i think its 16 for a2 and 2 for d2 Sep 22, 2017 at 5:02
  • 2
    Use A0, A1, A2 and so on for analog pins. To avoid any confusion. For example: int vla=analogRead(A2);
    – Jot
    Sep 22, 2017 at 5:56
  • "i think its 16 for a2 and 2 for d2". analogRead(A2), analogRead(2), and analogRead(16) all do the same thing. See the source code: github.com/arduino/Arduino/blob/1.8.4/hardware/arduino/avr/…
    – per1234
    Sep 22, 2017 at 5:58
  • 1
    But @Jot is right, analogRead(A2) makes the intent of the code the most clear.
    – per1234
    Sep 22, 2017 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.