0-100% soil moisture level
0-100% soil moisture level
3%
5%
-20C to 85C
-40C to 125C
3.3V to 5V
<1mA (standby), 10mA (active)
Wi-Fi 802.11 b/g/n, Bluetooth 4.2
50x25x15mm
20g
Applications
| The M5 Stack Earth Moisture Unit is suitable for various applications, including |
By providing accurate and reliable soil moisture data, the M5 Stack Earth Moisture Unit is an essential component for IoT projects focused on agriculture, gardening, and environmental monitoring.
M5 Stack Earth Moisture Unit DocumentationOverviewThe M5 Stack Earth Moisture Unit is a sensor module designed to measure the moisture level in soil. It is a popular IoT component used in agriculture, gardening, and environmental monitoring projects. This unit is compatible with the M5 Stack development board and provides an easy-to-use interface for measuring soil moisture levels.Technical SpecificationsOperating Voltage: 3.3V to 5.5V
Communication Protocol: I2C
Measurement Range: 0-100% soil moisture
Accuracy: 5%
Response Time: 10msPinoutThe M5 Stack Earth Moisture Unit has a 4-pin interface:VCC (Red wire): Connect to the power supply (3.3V to 5.5V)
GND (Black wire): Connect to the ground
SCL (Yellow wire): Connect to the I2C clock pin (SCL)
SDA (White wire): Connect to the I2C data pin (SDA)Example Code 1: Basic Soil Moisture MeasurementThis example demonstrates how to use the M5 Stack Earth Moisture Unit to measure the soil moisture level and display it on the M5 Stack's built-in LCD screen.
```c
#include <M5Stack.h>
#include <Wire.h>#define MOISTURE_UNIT_ADDRESS 0x36 // I2C address of the M5 Stack Earth Moisture UnitM5Stack m5;void setup() {
m5.begin();
Wire.begin();
}void loop() {
int moistureLevel = 0;
Wire.beginTransmission(MOISTURE_UNIT_ADDRESS);
Wire.write(0x00); // Register address for moisture measurement
Wire.endTransmission();
Wire.requestFrom(MOISTURE_UNIT_ADDRESS, 1);
moistureLevel = Wire.read();m5.Lcd.setCursor(0, 0);
m5.Lcd.print("Soil Moisture: ");
m5.Lcd.print(moistureLevel);
m5.Lcd.print("%");delay(1000);
}
```
Example Code 2: Automating Watering SystemThis example demonstrates how to use the M5 Stack Earth Moisture Unit to automate a watering system. When the soil moisture level falls below a certain threshold, the system triggers a relay module to turn on a water pump.
```c
#include <M5Stack.h>
#include <Wire.h>#define MOISTURE_UNIT_ADDRESS 0x36 // I2C address of the M5 Stack Earth Moisture Unit
#define RELAY_PIN 22 // Pin connected to the relay moduleM5Stack m5;void setup() {
m5.begin();
Wire.begin();
pinMode(RELAY_PIN, OUTPUT);
}void loop() {
int moistureLevel = 0;
Wire.beginTransmission(MOISTURE_UNIT_ADDRESS);
Wire.write(0x00); // Register address for moisture measurement
Wire.endTransmission();
Wire.requestFrom(MOISTURE_UNIT_ADDRESS, 1);
moistureLevel = Wire.read();if (moistureLevel < 30) { // Soil moisture level threshold
digitalWrite(RELAY_PIN, HIGH); // Turn on the water pump
} else {
digitalWrite(RELAY_PIN, LOW); // Turn off the water pump
}delay(1000);
}
```
Example Code 3: IoT-Based Soil Moisture MonitoringThis example demonstrates how to use the M5 Stack Earth Moisture Unit to send soil moisture data to a cloud-based IoT platform (e.g., MQTT) using a Wi-Fi module.
```c
#include <M5Stack.h>
#include <Wire.h>
#include <WiFi.h>
#include <PubSubClient.h>#define MOISTURE_UNIT_ADDRESS 0x36 // I2C address of the M5 Stack Earth Moisture Unit
#define WIFI_SSID "your_wifi_ssid"
#define WIFI_PASSWORD "your_wifi_password"
#define MQTT_SERVER "your_mqtt_server"
#define MQTT_PORT 1883
#define MQTT_TOPIC "soil_moisture"M5Stack m5;
WiFiClient espClient;
PubSubClient client(espClient);void setup() {
m5.begin();
Wire.begin();
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
client.setServer(MQTT_SERVER, MQTT_PORT);
}void loop() {
int moistureLevel = 0;
Wire.beginTransmission(MOISTURE_UNIT_ADDRESS);
Wire.write(0x00); // Register address for moisture measurement
Wire.endTransmission();
Wire.requestFrom(MOISTURE_UNIT_ADDRESS, 1);
moistureLevel = Wire.read();if (!client.connected()) {
reconnect();
}
client.loop();char soilMoistureString[10];
sprintf(soilMoistureString, "%d", moistureLevel);
client.publish(MQTT_TOPIC, soilMoistureString);delay(1000);
}void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
if (client.connect("M5StackClient")) {
Serial.println("connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
```
These examples demonstrate the basic usage of the M5 Stack Earth Moisture Unit in various IoT applications. You can modify and extend these examples to fit your specific project requirements.