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 --> GndSensor to Arduino(Nano)
Sig --> D2
-
1Also asked at forum.arduino.cc/index.php?topic=501527per1234– per12342017年09月22日 05:54:15 +00:00Commented 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– techniche2017年09月22日 06:03:51 +00:00Commented Sep 22, 2017 at 6:03
1 Answer 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()
.
-
I tried it but i'm getting only junk value, i even tried adding a pullup.Afroze Kabeer Khan– Afroze Kabeer Khan2017年09月22日 04:54:55 +00:00Commented Sep 22, 2017 at 4:54
-
i think its 16 for a2 and 2 for d2Afroze Kabeer Khan– Afroze Kabeer Khan2017年09月22日 05:02:54 +00:00Commented Sep 22, 2017 at 5:02
-
2Use A0, A1, A2 and so on for analog pins. To avoid any confusion. For example: int vla=analogRead(A2);Jot– Jot2017年09月22日 05:56:26 +00:00Commented Sep 22, 2017 at 5:56
-
"i think its 16 for a2 and 2 for d2".
analogRead(A2)
,analogRead(2)
, andanalogRead(16)
all do the same thing. See the source code: github.com/arduino/Arduino/blob/1.8.4/hardware/arduino/avr/…per1234– per12342017年09月22日 05:58:40 +00:00Commented Sep 22, 2017 at 5:58 -
1But @Jot is right,
analogRead(A2)
makes the intent of the code the most clear.per1234– per12342017年09月22日 06:00:18 +00:00Commented Sep 22, 2017 at 6:00