Start a Garden

Free Arduino Code for Smart Microgreen Systems

Creating a smart microgreen system can significantly improve the efficiency of your growing process, allowing you to automate watering, lighting, temperature control, and other essential aspects of microgreen care. By using Arduino, an open-source electronics platform, you can build a fully customized and automated microgreen system that can be monitored and controlled remotely.

In this article, we will provide a free Arduino code that you can use to control various elements of your smart microgreen system, including automated watering, LED lighting, and temperature monitoring.


Why Use Arduino for Microgreen Systems?

Arduino is an excellent choice for building smart microgreen systems for several reasons:

  • Affordability: Arduino boards are inexpensive, and you can build a system without breaking the bank.
  • Flexibility: Arduino allows you to design a system tailored to your specific needs. You can add multiple sensors, automate watering schedules, and more.
  • Customization: You can easily tweak and modify the code to suit the type of microgreens you are growing and your system setup.
  • Accessibility: Arduino has a large community of enthusiasts and developers, so there’s plenty of support if you need help or guidance.

What You Need for Your Smart Microgreen System

Before we dive into the Arduino code, here’s a list of materials you’ll need to build your own smart microgreen system:

Hardware

  • Arduino Uno or similar board
  • Soil moisture sensor (for detecting water levels in the soil)
  • LED grow lights (for controlled lighting)
  • Relay module (for controlling the power to the LED lights and watering system)
  • Water pump (for automated watering)
  • Temperature and humidity sensor (e.g., DHT11 or DHT22)
  • Jumper wires
  • Breadboard (for testing the circuit)
  • Power supply for Arduino and water pump

Software

  • Arduino IDE (to write and upload the code)
  • Arduino libraries (for controlling sensors and devices)

How the Smart Microgreen System Works

The core idea of the smart microgreen system is to monitor and control essential factors such as:

  • Watering: Use a soil moisture sensor to check if the soil is too dry and activate the water pump when necessary.
  • Lighting: Control the LED grow lights to simulate natural sunlight and ensure that your microgreens get the right amount of light.
  • Temperature: Use a temperature sensor (like the DHT22) to ensure that the growing environment remains within the optimal range for your microgreens.

The Arduino code below will automatically control the watering system, lighting, and temperature monitoring.


Free Arduino Code for Smart Microgreen System

cppCopyEdit// Include libraries
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

// Define pin numbers
#define MOISTURE_SENSOR_PIN A0   // Soil moisture sensor pin
#define LED_PIN 13               // Pin for LED grow lights
#define WATER_PUMP_PIN 8         // Pin for water pump
#define DHT_PIN 2                // Pin for DHT sensor

// Define DHT sensor type (DHT11 or DHT22)
#define DHT_TYPE DHT22

DHT dht(DHT_PIN, DHT_TYPE);  // Initialize DHT sensor
LiquidCrystal_I2C lcd(0x27, 16, 2);  // LCD for displaying readings

int moistureLevel;  // Variable to store soil moisture level
float temperature;  // Variable to store temperature
float humidity;     // Variable to store humidity
int moistureThreshold = 500;  // Moisture level threshold to trigger watering

void setup() {
  // Start serial communication for debugging
  Serial.begin(9600);

  // Initialize DHT sensor
  dht.begin();
  
  // Initialize LED pin and water pump pin
  pinMode(LED_PIN, OUTPUT);
  pinMode(WATER_PUMP_PIN, OUTPUT);

  // Initialize LCD screen
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Smart Microgreens");

  delay(2000);  // Wait for 2 seconds
}

void loop() {
  // Read moisture level
  moistureLevel = analogRead(MOISTURE_SENSOR_PIN);
  
  // Read temperature and humidity from DHT sensor
  temperature = dht.readTemperature();
  humidity = dht.readHumidity();

  // Display values on the LCD screen
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Temp: " + String(temperature) + "C");
  lcd.setCursor(0, 1);
  lcd.print("Humidity: " + String(humidity) + "%");

  // Check soil moisture level and activate water pump if necessary
  if (moistureLevel < moistureThreshold) {
    digitalWrite(WATER_PUMP_PIN, HIGH);  // Turn on water pump
    lcd.setCursor(0, 1);
    lcd.print("Watering...   ");
    delay(5000);  // Water for 5 seconds
    digitalWrite(WATER_PUMP_PIN, LOW);   // Turn off water pump
  }

  // Check the time to activate LED lights (12 hours on, 12 hours off)
  int currentHour = hour();
  if (currentHour >= 6 && currentHour < 18) {
    digitalWrite(LED_PIN, HIGH);  // Turn on LED lights during the day
  } else {
    digitalWrite(LED_PIN, LOW);   // Turn off LED lights at night
  }

  // Debugging output to the Serial Monitor
  Serial.print("Moisture Level: ");
  Serial.println(moistureLevel);
  Serial.print("Temperature: ");
  Serial.println(temperature);
  Serial.print("Humidity: ");
  Serial.println(humidity);
  
  delay(2000);  // Wait for 2 seconds before next loop
}

How the Code Works

1. Soil Moisture Sensor

The code begins by reading data from the soil moisture sensor. It checks the moisture level and compares it to a threshold (set to 500 in the code). If the moisture level falls below this threshold, the system activates the water pump for a set duration (5 seconds in this case) to water the microgreens.

2. Temperature and Humidity Sensor

The DHT22 sensor measures the temperature and humidity. These values are displayed on an LCD screen and also printed to the Serial Monitor for debugging purposes.

3. LED Grow Lights

The LED grow lights are programmed to turn on between 6 AM and 6 PM to simulate natural daylight for your microgreens. At night, the lights automatically turn off to mimic darkness.

4. LCD Display

An LCD screen shows real-time readings for the temperature and humidity, allowing you to easily monitor the growing conditions for your microgreens.

5. Serial Monitor Output

You can also view all sensor data (moisture level, temperature, and humidity) on the Serial Monitor. This is useful for troubleshooting and ensuring the system is working correctly.


Customizing the Code

You can further customize this Arduino code to suit your specific microgreen system needs:

  • Change moisture thresholds: Adjust the moistureThreshold to better suit the needs of different microgreens.
  • Modify watering time: Increase or decrease the time the water pump runs depending on the size of your growing area and the water requirements of your microgreens.
  • Add more sensors: You can add more sensors, such as a light sensor, to adjust light levels automatically.
  • Connect with a cloud service: If you want remote monitoring and control, you can integrate the system with a cloud service like Blynk or ThingSpeak.

Conclusion

Building a smart microgreen system using Arduino is a rewarding way to automate and optimize your growing process. By using sensors to monitor and control the watering, lighting, and temperature, you can ensure your microgreens thrive with minimal effort.

With the free Arduino code provided above, you can set up a basic smart microgreen system, and with a bit of customization, take it to the next level. Whether you’re growing for personal use or scaling up for a larger operation, this system can be adapted to meet your needs and help you grow healthier, more abundant crops.

Leave a Comment

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

Scroll to Top