Plant Monitor: Moisture
Part of the Projects section of Coddy's Arduino journey. Lesson 17 of 24.
This project watches a house plant: how wet its soil is, a coloured light for dry, fine or wet, an alarm when it stays dry, and a report on a screen.
A real build pushes a soil moisture sensor into the pot. It gives a voltage that changes with how wet the soil is, read with analogRead(). The simulator has no soil, so a potentiometer (a knob) on A0 stands in: turn it down for dry soil and up for wet. The sketch is the same either way.
A percent is easier to read than 0 to 1023: 0% is bone dry, 100% is soaking. map() converts one range into the other:
int reading = analogRead(A0);
int moisture = map(reading, 0, 1023, 0, 100);Soil dries over hours, so one reading a second is plenty.
Challenge
EasyMeasure the soil:
- write
readMoisture(): read A0 and return the moisture in percent withmap() - in
loop(), print it asMoisture: 42%, then wait 1000 ms
Press Run, turn the knob, then Check.
Try it yourself
// The knob stands in for a soil moisture sensor
const int sensorPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
// read the sensor, turn it into a percent, print it, wait a second
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Projects
2Reaction Game
Reaction Game: Random WaitReaction Game: TimerReaction Game: False StartReaction Game: Best Time5Plant Monitor
Plant Monitor: MoisturePlant Monitor: Status LightPlant Monitor: Dry AlarmPlant Monitor: ReportPractice on your own: Arduino playground