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

asked Sep 22, 2017 at 4:03
2
  • 1
    Also asked at forum.arduino.cc/index.php?topic=501527 Commented 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 :-) Commented 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().

answered Sep 22, 2017 at 4:39
6
  • I tried it but i'm getting only junk value, i even tried adding a pullup. Commented Sep 22, 2017 at 4:54
  • i think its 16 for a2 and 2 for d2 Commented 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); Commented 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/… Commented Sep 22, 2017 at 5:58
  • 1
    But @Jot is right, analogRead(A2) makes the intent of the code the most clear. Commented Sep 22, 2017 at 6:00

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.