I am really a started here and I have this strange situation. I running the script below, it is supposed to get the readings from a water sensor and print the value in the console.
The problem is it prints values when nothing is connected. No pins at all. Only the power is connected via a USB cable. Nothing else. The console should be printing the value of zero but for some reason it prints values around 410 or 420.
I have tried restarting, unplugging the USB cable and use another port but nothing changes. The arduino still gives wrong readings despite nothing being connected to it.
Is my board broken please?
/*
* Created by ArduinoGetStarted.com
*
* This example code is in the public domain
*
* Tutorial page: https://arduinogetstarted.com/tutorials/arduino-water-sensor
*/
#define POWER_PIN 7
#define SIGNAL_PIN A0
int value = 0; // variable to store the sensor value
void setup() {
Serial.begin(9600);
pinMode(POWER_PIN, OUTPUT); // configure D7 pin as an OUTPUT
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
}
void loop() {
digitalWrite(POWER_PIN, HIGH); // turn the sensor ON
delay(10); // wait 10 milliseconds
value = analogRead(SIGNAL_PIN); // read the analog value from sensor
digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
Serial.print("Sensor value ");
Serial.println(value);
delay(1000);
}
Thanks but something doesnt really make sense. When I connect the pins to a sensor I still get the same readings. When I dip the sensor into the water I get the same readings again. They are still within the range 410 and 420. When I clean the sensor from the water, again no change in the range of the values.
The sensor looks to work ok. In the sense that it gets power, it has a led and the led blinks. I even tried another sensor, but still got the same behaviour.
Thanks! I managed to confuse myself. I was experimenting, changing the pins to see if it works on another one and forgot to put it back at the correct place at the end. That was so stupid,
I didnt really expect it to have such a high reading when nothing is connected to it but you are right.
Thanks again!
A second pair of eyes is often usual. Failing that I explain to myself (or the cat) how the project is wired and what the code does which often results in spotting what is wrong