Create a monitor for your home plants so you know when they need watering.

What will I learn?

You will learn how to read analog values from a connected sensor and perform some action based on the value read from the sensor. You also learn about the moisture sensor and switches.

Prerequisites

A Computer with a configured Arduino IDE tested and working. If you don’t know how to get the basic set up working, check out my guide for Getting started (1/5)

Important notes

  • This project contains components that cannot handle 5V, so take care to use resistors (1 KOhm) with the LEDs.
  • Respect minus and plus, otherwise you may damage the components.
  • Start out by figuring out what components can handle 5V and what components can’t. If you connect a component that cant handle 5V you may destroy the component.

What you need

  • Breadboard
  • Dupont wires & jumper wires
  • CP2102
  • Arduino Pro Mini
  • Moisture sensor
  • 3 x 1 KOhm resistor
  • 3 LEDs in three different colors

Connecting instructions

  • Arduino VCC → Moisture sensor VCC pin
  • Arduino GND → Moisture sensor GND pin
  • Arduino A0 → Moisture sensor A0 pin
  • Arduino D7 -> Positive pin of First LED
  • First LED negative pin -> 1KOhm resistor and then to GND
  • Arduino D8 -> Positive pin of Second LED
  • Second LED negative pin -> 1KOhm resistor and then to GND
  • Arduino D9 -> Positive pin of Third LED
  • Third LED negative pin -> 1KOhm resistor and then to GND

Fritzing

plantmonitor_bb

 

Code

/**
* Plant Monitor - measures the moisture level of the soil in your home plants
* and signal based on LEDs when it is time to water them.
* Connections:
* - Arduino VCC → Moisture sensor VCC pin
* - Arduino GND → Moisture sensor GND pin
* - Arduino A0 → Moisture sensor A0 pin
* - Arduino D7 -> Positive pin of First LED
* - First LED negative pin -> 1KOhm resistor and then to GND
* - Arduino D8 -> Positive pin of Second LED
* - Second LED negative pin -> 1KOhm resistor and then to GND
* - Arduino D9 -> Positive pin of Third LED
* - Third LED negative pin -> 1KOhm resistor and then to GND
*
* Author: Jakob Maaløe
* https://wackydeveloper.wordpress.com
*/

const int FIRST_GREEN = 7;
const int YELLOW = 8;
const int RED = 9;
const int SPEAKER = 10;

const int MOISTURE_SENSOR = 0;

const int FREQUENCY = 100;

void setup() {

// Serial Begin so we can see the data from the mosture sensor in our serial input window.
Serial.begin(9600);

// setting the led pins to outputs
pinMode(FIRST_GREEN, OUTPUT);
pinMode(YELLOW, OUTPUT);
pinMode(RED, OUTPUT);
pinMode(SPEAKER, OUTPUT);
}

void loop() {

// read the input on analog pin 0:
int sensorValue = analogRead(MOISTURE_SENSOR);
Serial.println(sensorValue);

if (sensorValue < 350) { // OK 0 - 350
Serial.println("Plant is ok");
digitalWrite(FIRST_GREEN, HIGH);
digitalWrite(YELLOW, LOW);
digitalWrite(RED, LOW);
}
else if (sensorValue = 650) { // VERY dry >= 600
Serial.println("Plant is VERY dry");
digitalWrite(FIRST_GREEN, HIGH);
digitalWrite(YELLOW, HIGH);
digitalWrite(RED, HIGH);
tone(SPEAKER, FREQUENCY);
delay(300);
noTone(SPEAKER);
}

// delay 1 second between reads
delay(1000);
}

Next steps

Can you add a buzzer or alarm sound when the plant is dangerously dry? You could also change this it to a wireless monitor by getting inspiration from the Snail mail alarm.
If you are satisfied, you can also continue to the next project, the Thermometer.

Advertisements