Tuesday, January 28, 2020

Analog Mode – Interfacing Soil Moisture Sensor and Arduino

Rakshith S
6th Sem BCA, NCMS



Working of Sensor
The soil moisture sensor consists of two probes which are used to measure the volumetric content of water. The two probes allow the current to pass through the soil and then it gets the resistance value to measure the moisture value.
When there is more water, the soil will conduct more electricity which means that there will be less resistance. Therefore, the moisture level will be higher. Dry soil conducts electricity poorly, so when there will be less water, then the soil will conduct less electricity which means that there will be more resistance. Therefore, the moisture level will be lower.
This sensor can be connected in two modes; Analog mode and digital mode. First, we will connect it in Analog mode and then we will use it in Digital mode.
Analog Mode – Interfacing Soil Moisture Sensor and Arduino
To connect the sensor in the analog mode, we will need to use the analog output of the sensor. When taking the analog output from the soil moisture sensor FC-28, the sensor gives us the value from 0-1023. The moisture is measured in percentage, so we will map these values from 0 -100 and then we will show these values on the serial monitor.
You can further set different ranges of the moisture values and turn on or off the water pump according to it.
Circuit Diagram
The connections for connecting the soil moisture sensor FC-28 to the Arduino are as follows.
  • VCC of FC-28 to 5V of Arduino
  • GND of FC-28 to GND of Arduino
  • A0 of FC-28 to A0 of Arduino
CIRCUIT DIAGRAM

Arduino Code
int sensor_pin = A0; // Soil Sensor input at Analog PIN A0


int output_value ;

void setup() {

   Serial.begin(9600);

   Serial.println("Reading From the Sensor ...");

   delay(2000);

   }

void loop() {

   output_value= analogRead(sensor_pin);

   output_value = map(output_value,550,0,0,100);

   Serial.print("Mositure : ");

   Serial.print(output_value);

   Serial.println("%");

   delay(1000);

   }
Code Explanation
In the loop function, we will read from the sensor analog pin and will store the values in the “output_ value” variable. Then, we will map the output values to 0-100, because the moisture is measured in percentage. When we took the readings from the dry soil, then the sensor value was 550 and in the wet soil, the sensor value was 10. So, we mapped these values to get the moisture. After that, we printed these values on the serial monitor.In the setup function, the “Serial.begin(9600)” command will help in communication between the Arduino and serial monitor. Then, we will print the “Reading from the Sensor …” on the serial monitor.

Usage of arduino with soil moisture


Arduino Ide serial monitor output readings




No comments:

Post a Comment

AI IN CRYPTOGRAPHY

Written by: PALLAVI V (Final year BCA) 1.     ABSTRACT: The integration of AI in Cryptography represents a significant advancement in ...