Arduino-Based Smart Soil Moisture and Air Quality Monitoring System with LED Indicators and Motor Control
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to monitor soil moisture and air quality, and control a DC motor based on the readings. It uses an Arduino UNO microcontroller to interface with various sensors and actuators, including a soil moisture sensor, an air quality sensor (SGP30), a relay, a toggle switch, and multiple LEDs. The circuit also includes resistors to limit current to the LEDs.
Component List
Adafruit SGP30
- Description: Air quality sensor
- Pins: VCC, 3.3V, GND, SCL, SDA
SparkFun Soil Moisture Sensor
- Description: Measures soil moisture levels
- Pins: VCC, GND, SIG
Adafruit STEMMA Non-Latching Relay Breakout
- Description: Controls the DC motor
- Pins: 1, 2, 3, GND, VIN, SIGNAL, NC, COM, NO
Toggle Switch
- Description: Used to start/stop the system
- Pins: L1, COM, L2
Arduino UNO
- Description: Microcontroller
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
DC Motor
- Description: Actuator controlled by the relay
- Pins: pin 1, pin 2
Resistors
- Description: Current limiting resistors for LEDs
- Pins: pin1, pin2
- Properties: Various resistances (560 Ohms, 1000 Ohms)
LEDs (Red, Yellow, Green)
- Description: Indicate system status
- Pins: cathode, anode
Power Supply Bench
- Description: Provides power to the circuit
- Pins: -12V, GND, +12V, +5V, +3.3V
Wiring Details
Adafruit SGP30
- VCC: Connected to 3.3V on Arduino UNO
- GND: Connected to GND on Arduino UNO and Toggle Switch (L1)
- SCL: Connected to SCL on Arduino UNO
- SDA: Connected to SDA on Arduino UNO
SparkFun Soil Moisture Sensor
- VCC: Connected to 5V on Arduino UNO
- GND: Connected to GND on Arduino UNO
- SIG: Connected to A0 on Arduino UNO
Adafruit STEMMA Non-Latching Relay Breakout
- VIN: Connected to 3.3V on Arduino UNO
- GND: Connected to GND on Arduino UNO and Toggle Switch (L1)
- SIGNAL: Connected to D9 on Arduino UNO
- COM: Connected to -12V on Power Supply Bench
- NO: Connected to pin 2 on DC Motor
Toggle Switch
- L1: Connected to GND on Arduino UNO and Adafruit SGP30 (GND)
- COM: Connected to D8 on Arduino UNO
- L2: Connected to pin2 on Resistor (1000 Ohms)
Arduino UNO
- 3.3V: Connected to VCC on Adafruit SGP30 and VIN on Adafruit STEMMA Non-Latching Relay Breakout
- 5V: Connected to VCC on SparkFun Soil Moisture Sensor
- GND: Connected to GND on SparkFun Soil Moisture Sensor, Adafruit SGP30, and Adafruit STEMMA Non-Latching Relay Breakout
- SCL: Connected to SCL on Adafruit SGP30
- SDA: Connected to SDA on Adafruit SGP30
- D2: Connected to pin1 on Resistor (560 Ohms)
- D3: Connected to pin1 on Resistor (560 Ohms)
- D4: Connected to pin1 on Resistor (560 Ohms)
- D5: Connected to pin1 on Resistor (560 Ohms)
- D6: Connected to pin1 on Resistor (560 Ohms)
- D7: Connected to pin1 on Resistor (560 Ohms)
- D8: Connected to COM on Toggle Switch
- D9: Connected to SIGNAL on Adafruit STEMMA Non-Latching Relay Breakout
- D10: Connected to pin1 on Resistor (560 Ohms)
- A0: Connected to SIG on SparkFun Soil Moisture Sensor
DC Motor
- pin 1: Connected to GND on Power Supply Bench
- pin 2: Connected to NO on Adafruit STEMMA Non-Latching Relay Breakout
Resistors
Resistor (1000 Ohms):
- pin1: Connected to VCC on Adafruit SGP30
- pin2: Connected to L2 on Toggle Switch
Resistor (560 Ohms):
- pin1: Connected to various digital pins on Arduino UNO (D2, D3, D4, D5, D6, D7, D10)
- pin2: Connected to anode of corresponding LEDs
LEDs
Red LED:
- cathode: Connected to cathode of other LEDs
- anode: Connected to pin2 on Resistor (560 Ohms)
Yellow LED:
- cathode: Connected to cathode of other LEDs
- anode: Connected to pin2 on Resistor (560 Ohms)
Green LED:
- cathode: Connected to cathode of other LEDs
- anode: Connected to pin2 on Resistor (560 Ohms)
Power Supply Bench
- -12V: Connected to COM on Adafruit STEMMA Non-Latching Relay Breakout
- GND: Connected to pin 1 on DC Motor
Code Documentation
//****************************************************************************************************************
const int Grn1 = 2; const int Yel1 = 3; const int Red1 = 4; // Use digital I/O pin 2,3,4
const int Grn2 = 5; const int Yel2 = 6; const int Red2 = 7; // Use digital I/O pin 5,6,7
const int Switch = 8; // Use digital I/O pin 8
const int Motor = 9; // Use digital I/O pin 9
int SysState = 0; // Initial value for reading the button status
int H2O = 0; //value for storing moisture value
int H2OPin = A0;//Declare a variable for the soil moisture sensor
//This is a function used to get the soil moisture content
int readH2O(){
delay(10);//wait 10 milliseconds
H2O = analogRead(H2OPin);//Read the SIG value form sensor
return H2O;//send current moisture value
}
#include "SparkFun_SGP30_Arduino_Library.h" // Click here to get the library: http://librarymanager/All#SparkFun_SGP30
#include <Wire.h>
SGP30 mySensor; //create an object of the SGP30 class
//******************************************************************************************************************
void setup() {
// put your setup code here, to run once
Serial.begin(9600); // open serial over USB
pinMode(Grn1, OUTPUT); pinMode(Yel1, OUTPUT); pinMode(Red1, OUTPUT); // Sets Green, Yellow, and Red Light 1 as Output
pinMode(Grn2, OUTPUT); pinMode(Yel2, OUTPUT); pinMode(Red2, OUTPUT); // Sets Green, Yellow, and Red Light 2 as Output
pinMode(Motor, OUTPUT); // Sets Motor as Output
pinMode(Switch, INPUT); // Sets Start button as Input
// Sets value for inital light outputs to off (LOW)
digitalWrite(Grn1,LOW); digitalWrite(Yel1,LOW); digitalWrite(Red1,LOW);
digitalWrite(Grn2,LOW); digitalWrite(Yel2,LOW); digitalWrite(Red2,LOW);
Wire.begin();
//Initialize sensor
if (mySensor.begin() == false) {
Serial.println("No SGP30 Detected. Check connections.");
while (1);
}
//Initializes sensor for air quality readings
//measureAirQuality should be called in one second increments after a call to initAirQuality
mySensor.initAirQuality();
}
//******************************************************************************************************************
void loop() {
// Main code here, to run repeatedly
delay(1000);//take a reading every half second
SysState = digitalRead(Switch); //Sets the Start button as system state
// Turn on sampling system and read moisture
if(SysState == HIGH