Blog Startseite AI generated Robot Image

Plant Watering System with Soil Moisture Monitoring and MQTT Communication

11.12.2024 - Engine: Gemini

Plant Watering System with Soil Moisture Monitoring and MQTT Communication

Indoor Plant Watering System with Soil Moisture Monitoring and MQTT Communication

Materials:

  • Arduino (e.g., Uno or Nano)
  • Soil moisture sensor (e.g., FC-28 or MH-Z19C)
  • Water pump
  • Relay module
  • MQTT broker (e.g., Mosquitto)
  • MQTT client (e.g., MQTT.js or Paho.js)

Setup:

  1. Connect the soil moisture sensor to the Arduino:
    • Analog connection: VCC to 5V, GND to GND, Signal to A0
    • Digital connection: VCC to 5V, GND to GND, Signal to D2
  2. Connect the water pump to the relay module:
    • VCC to 5V, GND to GND, Signal to IN
  3. Connect the relay module to the Arduino:
    • VCC to 5V, GND to GND, IN1 to D3 (or other digital pin)
  4. Connect the Arduino to the MQTT broker:
    • Ethernet shield or Wi-Fi module
  5. Connect the MQTT client to the MQTT broker:
    • Install the MQTT client library (e.g., MQTT.js)
    • Establish connection to the broker

Functionality:

  1. Soil Moisture Monitoring:
    • The soil moisture sensor measures the moisture content in the soil.
    • Readings are transmitted to the Arduino via the serial interface.
  2. MQTT Communication:
    • The Arduino publishes soil moisture readings to the broker over MQTT.
    • The MQTT client subscribes to the topic to receive these readings.
  3. Watering:
    • When soil moisture drops below a set threshold, the MQTT client sends a message to the Arduino to activate the water pump.
    • The Arduino turns on the relay module, activating the water pump.
  4. Monitoring and Control:
    • The MQTT client can be used to monitor soil moisture in real-time and remotely control the watering system.

Code Sample:

MQTT Broker:

# Start Mosquitto broker
mosquitto -c /etc/mosquitto/mosquitto.conf

Arduino Code:

#include <MQTT.h>

const char *broker = "mqtt.example.com";
const char *topic = "soil-moisture";

MQTTClient client(broker, 1883);

void setup() {
  Serial.begin(9600);
  client.connect("arduino-1");
  client.subscribe(topic);
}

void loop() {
  int moisture = analogRead(A0);
  client.publish(topic, String(moisture));
}

MQTT Client Code (JavaScript):

const mqtt = require('mqtt');

const client = mqtt.connect('mqtt://mqtt.example.com');

client.on('connect', () => {
  client.subscribe(topic);
});

client.on('message', (topic, message) => {
  console.log('Soil moisture:', message.toString());
});

Note:

All texts on this blog are generated using Artificial Intelligence (AI). The purpose of this blog is to test the generated content in the context of SEO and analyze its rankings. Please be aware that I cannot take responsibility for the accuracy or completeness of the texts published here.


© 2024 ivosys.de - Made with iMicroBlog by ivosys.de - Code CSS3 HTML5 Javascript PHP