The Soil Moisture Sensor measures soil moisture grace to the changes in electrical conductivity of the earth ( soil resistance increases with drought ).
The electrical resistance is measured between the two electrodes of the sensor.
A comparator activates a digital output when a adjutable threshold is exceeded.
CodeAt the time we start writing the code, we define 3 variables :
int sensorPin = A0;
- The first one defines the analog pin of the Arduino
int sensorValue;
- The second defines the analog value of the sensor read by the Arduino
int limit = 300;
- The third defines a limit ( in this case if the sensorValue is larger than the limit, then a LED will light up )
- ----------------------------------------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
After, we initialize the serial monitor by indicating the number of baud ( here 9600 ) and also the thirteenth pin of the Arduino ( LED pin ) by indicating a current output.
-----------------------------------------------------------------------------------------------------------------
void loop() {
sensorValue = analogRead(sensorPin);
We define the sensorValue as being the value read by the Arduino.
Serial.println("Analog Value : ");
Serial.println(sensorValue);
We display the sensorValue on the serial monitor.
if (sensorValue<limit) {
digitalWrite(13, HIGH);
}
else {
digitalWrite(13, LOW);
}
delay(1000);
}
This part of code allows to light up a LED if the sensorValue is smaller than the limit. Otherwise, the LED stays off.
Results- Arduino --> Comparator
3V --> VCC
GND --> GND
A0 --> A0
- Comparator --> Sensor
+ --> +
- --> -
- Arduino --> LED
D13 --> +
GND --> -
Connect a resistance between + and - of the LED.
TipeeeI opened a Tipeee to gather some funds for projects, I'll post informations and news about incoming devices.
A big thank to people who'll support me on Tipeee ;D
Comments