Arduino Mega 2560 Based Smart Farming System with GSM Remote Monitoring and Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor and control an agricultural environment. It includes sensors for measuring temperature, humidity, soil moisture, UV index, and IR radiation. The system can remotely control servomotors and a stepper motor for various tasks such as feeding water and nutrients. A water pump is controlled to supply the mixture to the field, and a water flow sensor manages the flow and amount of water. The Arduino Mega 2560 microcontroller is the central processing unit, interfacing with a GSM module for cloud communication. The status and sensor data are displayed on a serial monitor.
Component List
Arduino Mega 2560
- Microcontroller board based on the ATmega2560
- It has 54 digital input/output pins, 16 analog inputs, 4 UARTs, a 16 MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.
DHT11 Sensor V2
- A basic, ultra low-cost digital temperature and humidity sensor.
- It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and outputs a digital signal on the data pin.
DFRobot Capacitive Soil Moisture Sensor (V1.0)
- A soil moisture sensor that measures soil moisture levels by capacitive sensing rather than resistive sensing.
- It is made of corrosion-resistant material which gives it an excellent service life.
Adafruit SI1145 Digital UV Index + IR + Visible Light Sensor
- A sensor that can measure UV index, IR, and visible light.
- It communicates over I2C and provides an analog reading.
Servomotor MG995
- A high-torque standard servo that can rotate approximately 120 degrees (60 in each direction).
- It is suitable for various applications such as steering, robotics, and small-scale automation.
Water Flow Sensor
- A sensor that measures the flow rate of water.
- It typically contains a water rotor and a hall-effect sensor.
Mini Diaphragm Water Pump
- A small, electric water pump used for pumping water.
- It is typically used in applications where water needs to be transferred from one place to another.
Stepper Motor (Unipolar)
- A type of stepper motor that can be driven with a simple unipolar driver.
- It is used in precision control of angular or linear position, velocity, and acceleration.
SIM900A
- A complete Dual-band GSM/GPRS module in a SMT type.
- It can be integrated with a wide range of applications.
Power Supply
- Provides electrical power to the circuit.
- It typically converts mains AC to low-voltage regulated DC power for the electronic components.
Relay Module 5v-30v
- An electrically operated switch that allows you to turn on or off a circuit using voltage and/or current much higher than a microcontroller can handle.
Wiring Details
Arduino Mega 2560
- GND: Connected to the ground pins of SIM900A, Adafruit SI1145, DFRobot Soil Moisture Sensor, DHT11 Sensor, and the negative side of the power supply.
- A0: Connected to the analog output of the DFRobot Soil Moisture Sensor.
- D21/SCL: Connected to the SCL pin of the Adafruit SI1145.
- D20/SDA: Connected to the SDA pin of the Adafruit SI1145.
- D19/RX1: Connected to the TXD pin of the SIM900A.
- D18/TX1: Connected to the RXD pin of the SIM900A.
- D2 PWM: Connected to the DAT pin of the DHT11 Sensor.
- D3-D6 PWM: Connected to the respective A, B, C, D pins of the Stepper Motor.
- D7 PWM: Connected to the Signal pin of the Water Flow Sensor.
- D8-D10 PWM: Connected to the SIG pins of the Servomotors MG995.
- D11 PWM: Connected to the trigger pin of the Relay Module.
DHT11 Sensor V2
- GND: Connected to the ground.
- DAT: Connected to D2 PWM on the Arduino Mega 2560.
- VCC: Connected to the positive side of the power supply.
DFRobot Capacitive Soil Moisture Sensor (V1.0)
- A: Connected to A0 on the Arduino Mega 2560.
- VCC: Connected to the positive side of the power supply.
- GND: Connected to the ground.
Adafruit SI1145 Digital UV Index + IR + Visible Light Sensor
- +5V: Connected to the positive side of the power supply.
- GND: Connected to the ground.
- SCL: Connected to D21/SCL on the Arduino Mega 2560.
- SDA: Connected to D20/SDA on the Arduino Mega 2560.
Servomotor MG995
- SIG: Connected to D8-D10 PWM on the Arduino Mega 2560.
- VCC: Connected to the positive side of the power supply.
- GND: Connected to the ground.
Water Flow Sensor
- Signal: Connected to D7 PWM on the Arduino Mega 2560.
- Vcc: Connected to the positive side of the power supply.
- GND: Connected to the ground.
Mini Diaphragm Water Pump
- Positive (+): Connected to the common contact of the Relay Module.
- Negative (-): Connected to the ground.
Stepper Motor (Unipolar)
- A, B, C, D: Connected to D3-D6 PWM on the Arduino Mega 2560.
- COMMON_1, COMMON_2: Connected to the positive side of the power supply through the normally open contact of the Relay Module.
SIM900A
- GND: Connected to the ground.
- DB9-3 (RXD): Connected to D18/TX1 on the Arduino Mega 2560.
- DB9-2 (TXD): Connected to D19/RX1 on the Arduino Mega 2560.
- VCC: Connected to the positive side of the power supply.
Power Supply
- +: Connected to the VCC of various components and the V+ of the Relay Module.
- -: Not used in this configuration.
- GND: Connected to the ground pins of various components and the V- of the Relay Module.
Relay Module 5v-30v
- common contact: Connected to the positive side of the Mini Diaphragm Water Pump.
- normally open: Connected to the COMMON pins of the Stepper Motor.
- trigger: Connected to D11 PWM on the Arduino Mega 2560.
- V+: Connected to the positive side of the power supply.
- V-: Connected to the ground.
Documented Code
/*
* Arduino Mega Project
* This project reads data from a sensor array consisting of temperature,
* humidity, soil moisture, UV index, and IR radiation sensors. It sends
* this data to a cloud server via a GSM module and can remotely control
* motors for feeding water, nutrients, and mixing liquids. It also controls
* a water pump to feed the mixture to the farm field and a water flow
* controller to manage the flow and amount of water. The data and status
* are displayed on a serial monitor.
*/
#include <DHT.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_SI1145.h>
#include <Servo.h>
#include <Stepper.h>
#define DHTPIN 2
#define DHTTYPE DHT11
#define SOIL_MOISTURE_PIN A0
#define UV_SDA_PIN 20
#define UV_SCL_PIN 21
#define GSM_TX_PIN 18
#define GSM_RX_PIN 19
#define SERVO1_PIN 10
#define SERVO2_PIN 9
#define SERVO3_PIN 8
#define STEPPER_A_PIN 3
#define STEPPER_B_PIN 5
#define STEPPER_C_PIN 4
#define STEPPER_D_PIN 6
#define WATER_FLOW_PIN 7
#define RELAY_PIN 11
DHT dht(DHTPIN, DHTTYPE);
Adafruit_SI1145 uv = Adafruit_SI1145();
Servo servo1, servo2, servo3;
Stepper stepper(200, STEPPER_A_PIN, STEPPER_B_PIN, STEPPER_C_PIN, STEPPER_D_PIN);
void setup() {
Serial.begin(9600);
dht.begin();
uv.begin();
servo1.attach(SERVO1_PIN);
servo2.attach(SERVO2_PIN);
servo3.attach(SERVO3_PIN);
pinMode(RELAY_PIN, OUTPUT);
pinMode(WATER_FLOW_PIN, INPUT);
Serial1.begin(9600); // GSM module
}
void loop() {
float h = dht.readHumidity();
float t = dht.readTemperature();
int soilMoisture = analogRead(SOIL_MOISTURE_PIN);
float uvIndex = uv.readUV();
int waterFlow = digitalRead(WATER_FLOW_PIN);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C\t");
Serial.print("Soil Moisture: ");
Serial.print