Complete Guide to Plant Sensor Readings and Device Integration
By farmester • 2026-04-17 • Technology
Complete Guide to Plant Sensor Readings and Device Integration
Introduction
Modern plant monitoring systems rely on various sensors to track environmental conditions that affect plant health. This comprehensive guide covers all supported sensor types, their practical examples, and how to connect them from different devices and platforms.
Sensor Types Overview
1. Soil Moisture
Purpose: Measures the water content in soil
Unit: Percentage (%)
Optimal Range: 40-60% for most houseplants
Example Reading: 45.5%
Soil moisture is crucial for preventing both overwatering and underwatering. Low readings (0-30%) indicate dry soil needing water, while high readings (80-100%) suggest overwatering risks.
2. Temperature
Purpose: Monitors ambient temperature around the plant
Unit: Degrees Celsius (°C) or Fahrenheit (°F)
Optimal Range: 18-24°C (64-75°F) for most indoor plants
Example Reading: 22.5°C
Temperature affects photosynthesis, nutrient uptake, and overall plant metabolism. Extreme temperatures can stress plants and affect growth.
3. Humidity
Purpose: Measures moisture content in the air
Unit: Percentage (%)
Optimal Range: 40-70% for most houseplants
Example Reading: 65.0%
Humidity levels affect transpiration rates and can prevent issues like leaf browning or pest problems.
4. Light Level
Purpose: Measures light intensity available to the plant
Unit: Lux (lx) or μmol/m²/s
Optimal Range: 200-2000 lux depending on plant type
Example Reading: 850 lux
Light levels determine photosynthesis efficiency and growth patterns. Different plants have varying light requirements.
5. pH Level
Purpose: Measures soil acidity/alkalinity
Unit: pH scale (0-14)
Optimal Range: 6.0-7.5 for most plants
Example Reading: 6.8 pH
Soil pH affects nutrient availability and absorption. Incorrect pH can lead to nutrient deficiencies even in nutrient-rich soil.
6. Water Level
Purpose: Monitors water reservoir levels in self-watering systems
Unit: Percentage (%) or millimeters
Optimal Range: Above 20% to prevent empty reservoirs
Example Reading: 75%
Critical for automated watering systems to ensure continuous water supply.
Device Integration Examples
ESP32/ESP8266 (Arduino IDE)
#include <WiFi.h>
#include <HTTPClient.h>
#include <ArduinoJson.h>
const char* ssid = "your_wifi_name";
const char* password = "your_wifi_password";
const char* apiKey = "your_api_key_here";
const char* plantId = "your_plant_id_here";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
}
void sendSensorData(String sensorType, float value, String unit) {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
http.begin("https://obrrwsglqjwifcvzxnkx.supabase.co/functions/v1/plant-api/readings");
http.addHeader("Content-Type", "application/json");
http.addHeader("x-api-key", apiKey);
StaticJsonDocument<200> doc;
doc["plant_id"] = plantId;
doc["sensor_type"] = sensorType;
doc["value"] = value;
doc["unit"] = unit;
doc["device_id"] = "esp32_001";
String jsonString;
serializeJson(doc, jsonString);
int httpResponseCode = http.POST(jsonString);
Serial.println("Response: " + String(httpResponseCode));
http.end();
}
}
void loop() {
// Read sensors and send data
float soilMoisture = analogRead(A0) / 1024.0 * 100; // Example reading
sendSensorData("soil_moisture", soilMoisture, "%");
delay(300000); // Wait 5 minutes
}
Raspberry Pi (Python)
import requests
import json
import time
import random
API_KEY = "your_api_key_here"
PLANT_ID = "your_plant_id_here"
BASE_URL = "https://obrrwsglqjwifcvzxnkx.supabase.co/functions/v1/plant-api/readings"
def send_sensor_data(sensor_type, value, unit):
headers = {
"Content-Type": "application/json",
"x-api-key": API_KEY
}
data = {
"plant_id": PLANT_ID,
"sensor_type": sensor_type,
"value": value,
"unit": unit,
"device_id": "raspberry_pi_001"
}
try:
response = requests.post(BASE_URL, headers=headers, json=data)
print(f"Sent {sensor_type}: {value}{unit} - Status: {response.status_code}")
return response.status_code == 200
except Exception as e:
print(f"Error sending data: {e}")
return False
# Example usage
while True:
# Simulate sensor readings
soil_moisture = random.uniform(30, 70)
temperature = random.uniform(18, 26)
humidity = random.uniform(40, 80)
send_sensor_data("soil_moisture", soil_moisture, "%")
send_sensor_data("temperature", temperature, "°C")
send_sensor_data("humidity", humidity, "%")
time.sleep(300) # Wait 5 minutes
cURL Commands
Soil Moisture
curl -X POST \
"https://obrrwsglqjwifcvzxnkx.supabase.co/functions/v1/plant-api/readings" \
-H "x-api-key: YOUR_API_KEY_HERE" \
-H "Content-Type: application/json" \
-d '{
"plant_id": "YOUR_PLANT_ID",
"sensor_type": "soil_moisture",
"value": 45.5,
"unit": "%",
"device_id": "sensor_001"
}'
All Sensor Types
Replace the sensor_type, value, and unit accordingly:
- Temperature:
"sensor_type": "temperature","value": 22.5,"unit": "°C" - Humidity:
"sensor_type": "humidity","value": 65.0,"unit": "%" - Light Level:
"sensor_type": "light_level","value": 850,"unit": "lux" - pH Level:
"sensor_type": "pH_level","value": 6.8,"unit": "pH" - Water Level:
"sensor_type": "water_level","value": 75,"unit": "%"
Postman Setup
- Method: POST
- URL:
https://obrrwsglqjwifcvzxnkx.supabase.co/functions/v1/plant-api/readings - Headers:
Content-Type:application/jsonx-api-key:YOUR_API_KEY_HERE
- Body (raw JSON):
{
"plant_id": "YOUR_PLANT_ID",
"sensor_type": "soil_moisture",
"value": 45.5,
"unit": "%",
"device_id": "postman_test"
}
Getting Started
Step 1: Create API Key
- Go to Settings in your plant monitoring dashboard
- Navigate to API Keys section
- Create a new API key and copy it securely
Step 2: Get Plant ID
- Visit your Plants page
- Select the plant you want to monitor
- Copy the plant ID from the URL or plant details
Step 3: Choose Your Platform
Select the integration method that best fits your setup:
- ESP32/ESP8266: For dedicated sensor nodes
- Raspberry Pi: For complex multi-sensor setups
- cURL: For testing and scripting
- Postman: For API testing and validation
Best Practices
- Data Frequency: Don't send readings too frequently (recommended: every 5-15 minutes)
- Error Handling: Always implement retry logic for failed requests
- Battery Optimization: For battery-powered devices, implement deep sleep between readings
- Data Validation: Validate sensor readings before sending to avoid false alerts
- Security: Never hardcode API keys in production code; use environment variables
Troubleshooting
Common Issues:
- 401 Unauthorized: Check API key validity
- 404 Not Found: Verify plant ID exists and belongs to your account
- 400 Bad Request: Validate JSON format and required fields
- 500 Server Error: Contact support if persistent
This comprehensive guide should help you integrate any device with the plant monitoring system and understand the different sensor types for optimal plant care.