Mini Projects

Connecting Multiple Moisture sensor to Arduino Board with Code | Soil moisture sensor with Arduino with code

DIY Daily 4 min read

Parts Needed

  • Arduino Uno R3
  • FC-28 Sensor PCB
  • Sensor + Probe (total)
  • Probe Fork Gap

Code Explanation

Interface moisture sensor with an Arduino board.First, the code defines a constant sensor with a value of A0. A0 is the analog pin on the Arduino board to which the moisture sensor is connected.In the setup() function, the code begins serial communication with the computer at a baud rate of 9600 using the Serial.begin() function. So this will allow the Arduino to send data to and receive data from the computer through the USB cable.In the loop() function, the code reads the analog signal from the moisture sensor using the analogRead() function and stores the value in the sensorValue variable. The value is then printed to the serial monitor using the Serial.print() and Serial.println() functions, with the text “Moisture Level” displayed before the value.The code includes a delay() function with a parameter of 1000 milliseconds, which pauses the program for 1 sec before taking another reading. This is to prevent rapid and unnecessary readings that could interfere with the accuracy of the data.This code provides a basic framework for reading data from the moisture sensor and displaying the readings in the serial monitor for further analysis or processing.

Connection Table

Sensor 1 PinConnects ToSensor 2 PinConnects To
VCCArduino 5VVCCArduino 5V
GNDArduino GNDGNDArduino GND
AOArduino A0AOArduino A1
DONot usedDONot used
//define sensor pin
#define sensor A0

void setup() {
  Serial.begin(9600); //start serial communication
}

void loop() {
  //read sensor
  int sensorValue = analogRead(sensor);
  Serial.print("Moisture Level: ");
  Serial.println(sensorValue);
  
  delay(1000); //wait for 1 second before taking readings again
}

Serial Monitor Data

Connecting 2 Moisture sensor to Arduino Board with code and Circuit Diagram

Serial Monitor Data for 2 moisture sensors

Code

//define sensor pins
#define sensor1 A0
#define sensor2 A1

void setup() {
  Serial.begin(9600); //start serial communication
}

void loop() {
  //read sensor 1
  int sensor1Value = analogRead(sensor1);
  Serial.print("Sensor 1: ");
  Serial.println(sensor1Value);
  
  //read sensor 2
  int sensor2Value = analogRead(sensor2);
  Serial.print("Sensor 2: ");
  Serial.println(sensor2Value);
  
  delay(1000); //wait for 1 second before taking readings again
}

Connecting 3 Moisture Sensors toan Arduino Board with code and Circuit Diagram

Code

#define sensor1 A0
#define sensor2 A1
#define sensor3 A2

void setup() {
  Serial.begin(9600); //start serial communication
}

void loop() {
  //read sensor 1
  int sensor1Value = analogRead(sensor1);
  Serial.print("Sensor 1: ");
  Serial.println(sensor1Value);
  
  //read sensor 2
  int sensor2Value = analogRead(sensor2);
  Serial.print("Sensor 2: ");
  Serial.println(sensor2Value);
  
  //read sensor 3
  int sensor3Value = analogRead(sensor3);
  Serial.print("Sensor 3: ");
  Serial.println(sensor3Value);
  
  delay(1000); //wait for 1 second before taking readings again
}

#Analog Sensor #arduino #Arduino Analog Read #Arduino Beginner #Arduino Code #Arduino Garden #Arduino Project #Arduino Sensor #Arduino Uno #Automated Watering #Circuit Diagram #DIY Electronics #DIY Sensor #Electronics Schematic #Electronics Tutorial #Embedded Systems #FC-28 #Garden Tech #Hobby Electronics #Home Automation #IoT Garden #Jumper Wires #LM393 #Maker Project #Microcontroller #Moisture Monitoring #Moisture Sensor Tutorial #Plant Care #Plant Monitoring #Resistive Sensor #Sensor Array #Sensor Calibration #Sensor Wiring #Smart Garden #Soil Moisture Sensor #Soil Sensor #STEM Project #Tech Tutorial #WordPress Blog

DIY Daily

Electronics tinkerer and tutorial writer at DIY Daily.

Leave a Comment

Your email address will not be published. Required fields are marked *