Smart irrigation system: Build a system that can automatically water plants based on weather conditions and soil moisture levels.

Here's an example Python program for a smart irrigation system based on Arduino UNO:

Program code:

import serial import time # Set up the serial connection to Arduino arduino = serial.Serial('COM3', 9600) time.sleep(2) # Define the pins used for sensors and actuators soil_moisture_pin = 'A0' water_pump_pin = 3 # Define the threshold for soil moisture level soil_moisture_threshold = 500 # Main loop while True: # Read the soil moisture level from the sensor arduino.write(soil_moisture_pin.encode()) soil_moisture = arduino.readline().decode().rstrip() # Read the weather condition from an API (not shown in this code) weather_condition = 'sunny' # Determine if watering is needed based on soil moisture level and weather condition if int(soil_moisture) < soil_moisture_threshold and weather_condition == 'sunny': # Turn on the water pump to water the plants arduino.write(str(water_pump_pin).encode()) arduino.write(b'1') print('Watering plants') time.sleep(10) # Turn off the water pump after 10 seconds arduino.write(str(water_pump_pin).encode()) arduino.write(b'0') print('Water pump turned off') # Wait for 1 minute before checking again time.sleep(60)

Explanation:

This program reads the soil moisture level from a sensor connected to the Arduino UNO's analog input pin A0, and determines whether watering is needed based on the soil moisture level and a weather condition (which could be obtained from an API). If watering is needed, the program turns on a water pump connected to the Arduino UNO's digital output pin 3 for 10 seconds, and then turns it off.

To connect the components, you would need the following electronics:

  • Arduino UNO board
  • Soil moisture sensor (e.g. FC-28)
  • Water pump
  • Jumper wires
  • Breadboard
  • Power supply (e.g. 9V battery or AC adapter)

The soil moisture sensor should be connected to the Arduino UNO's analog input pin A0, and the water pump should be connected to a digital output pin (in this example, pin 3). The power supply should be connected to the Arduino UNO board and the breadboard.

To connect the components, follow these steps:

  1. Connect the VCC (power) and GND (ground) pins of the soil moisture sensor to the power supply's + and - terminals, respectively.
  2. Connect the soil moisture sensor's signal (out) pin to the Arduino UNO's analog input pin A0.
  3. Connect the water pump's positive wire (red) to a digital output pin on the Arduino UNO (in this example, pin 3).
  4. Connect the water pump's negative wire (black) to the power supply's - terminal.
  5. Connect the power supply's + terminal to the breadboard's + rail.
  6. Connect the breadboard's - rail to the Arduino UNO's GND pin.

Here's a schematic diagram of the connections:

+-------------+ +-------------+ | | | | | Power supply| | Arduino UNO | | | | | +------+------+ +------+------+ | +-----------------+ | | | Breadboard | | | +------+----+-----+ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | +------+------+ | | | | | | | Soil moisture| | | | sensor | | | | | | | +------+------+ | | | | | | +--------+---------+ | | | | | | +------+--|----------------------+ | | | | | Water | | | | pump | | | | | | | +---------+ | | | | | | | | | | A0 |----------------------+ 3 |----------------------+

No comments:

Post a Comment

Please disable your ad blocker to support this website.

Our website relies on revenue from ads to keep providing free content.