I am using an Arduino UNO and two soil moisture sensors.
The data that has been printed to the serial monitor shows that the soil has 100 per cent moisture but I had not connected the sensors to anything.
This is the coding:
int soilsensor1 = analogRead(0);
int soilsensor2 = analogRead(1);
void setup() {
Serial.begin(9600);// put your setup code here, to run once:
}
void loop() {
Serial.print("sensor1 ");
Serial.println(soilsensor1);
Serial.print("sensor2 ");
Serial.println(soilsensor2);// put your main code here, to run repeatedly:
I suspect the analog pins or the soil sensors had burned out because I connected alot of modules t the arduino.(Such as LCD display ,buzzer,LEDs,and temparature sensors)
Really appreciate you help.
Please look at the AnalogReadSerial Example.
You should do the analogRead in the main loop (not outside) and use an Analog Pin (like A0).
Use also a delay (in debug only) at the end of the loop.
int soilsensor1 = analogRead(0);
int soilsensor2 = analogRead(1);
void setup() {
Serial.begin(9600);// put your setup code here, to run once:
}
Using 0 and 1 with analogRead() instead of A0 and A1 will work, because the compiler knows that an analogRead uses an analog input and not a digital input, but if you are referencing the same pins with a digitalRead(), digitalWrite(), or pinMode() command the Ax notation would be needed, because 0 and 1 would then refer to the digital pins.
Also, in the code above, the analog inputs are read only once, to set the initial value of the variables, before setup() is run. It is a common mistake to assume that somehow the variables will be updated when the input to the analog pin changes, but it doesn't work that way.
You have to do an analogRead() each time you want a new value from an analog input pin.
I like to put "AIPin" at the end of Analog Input pin names to remind me that they are analog inputs.
const byte soilsensor1AIPin = A0;
const byte soilsensor2AIPin = A1;
void setup()
{
// put your setup code here, to run once:
Serial.begin(9600);
}
void loop()
{
// put your main code here, to run repeatedly:
Serial.print("sensor1 ");
Serial.println(analogRead(soilsensor1AIPin));
Serial.print("sensor2 ");
Serial.println(analogRead(soilsensor2AIPin));
delay(1000);
}