Moisture Sensor Interfacing with Arduino
Components Required:
A) 1 Arduino UNO
B) Computer with Arduino IDE
C) USB to Arduino connecting Cable
D) Jumper Wires
E) Moisture Sensor
F) Sample Soil
Description:
Here, we learn how to read the values from the moisture sensor to get the moisture of a soil sample.
Circuit Diagram:
Steps to Follow:
1. Establish the given circuit
2. Open Arduino IDE.
3. Click on File.
4. Go to New. – A new File will open
5. Remove the Pre-Written code..
6. Paste the code given in the “CODE Section”
7. Check whether your UNO has been detected by the ID by going to Tools.
8. Click on Port – Select the COM-Port on which Arduino UNO is detected.
9. Verify the Sketch by Clicking on the TICK icon.
10. Once, the sketch is verified, Upload the sketch using the ARROW icon.
Code:
const int sensor_pin = A1; /* Soil moisture sensor O/P pin */ void setup() { Serial.begin(9600); /* Define baud rate for serial communication */ } void loop() { float moisture_percentage; int sensor_analog; sensor_analog = analogRead(sensor_pin); moisture_percentage = ( 100 - ( (sensor_analog/1023.00) * 100 ) ); Serial.println("Moisture Percentage = "); Serial.println(moisture_percentage); Serial.println("%"); delay(1000); }