Giter VIP home page Giter VIP logo

water-irrigation-control-system's Introduction

Smart Home Water Irrigation Control System

Overview

This Python script implements a smart home project that controls water irrigation based on a soil moisture sensor. The system uses a Raspberry Pi and GPIO (General Purpose Input/Output) pins to interact with the soil moisture sensor and a water pump.

Requirements

To run this code, you need the following hardware components:

  • Raspberry Pi (any model with GPIO pins)
  • Soil moisture sensor
  • Water pump
  • Jumper wires for connections

Make sure you have the necessary Python libraries installed, such as RPi.GPIO.

Pin Configuration

The code assumes the following GPIO pin configuration:

  • sensor_pin: GPIO pin number connected to the soil moisture sensor (input pin)
  • pump_pin: GPIO pin number connected to the water pump (output pin)

Ensure that you have made the correct connections between the Raspberry Pi, soil moisture sensor, and water pump.

Functionality

The code performs the following operations:

  1. Imports the necessary libraries: RPi.GPIO for GPIO control and time for time-related operations.

  2. Defines the pin numbers for the GPIO communication, sensor_pin and pump_pin.

  3. Defines the setup() function, which initializes the GPIO pins. It sets the GPIO pin numbering mode to BCM and configures pump_pin as an output pin and sensor_pin as an input pin.

  4. Defines the read_moisture() function, which reads the moisture level from the soil moisture sensor. It uses the GPIO.input() function to retrieve the sensor value.

  5. Defines the control_irrigation() function, responsible for controlling the water irrigation process based on the moisture level. It performs the following steps:

    • Sets a moisture_threshold value, which can be adjusted based on sensor readings.
    • Reads the current moisture level using the read_moisture() function.
    • If the moisture level is below the threshold, it activates the water pump by setting pump_pin to a high state using GPIO.output().
    • Prints a message indicating that watering is in progress.
    • Pauses the program execution for a specified duration (5 seconds in this example) using time.sleep().
    • Deactivates the water pump by setting pump_pin to a low state.
    • Prints a message indicating that watering is finished.
    • If the moisture level is above or equal to the threshold, it prints a message indicating that irrigation is not required.
  6. In the main program, it checks if the script is being run directly and not imported as a module (if __name__ == '__main__').

    • Sets up the GPIO pins using the setup() function.
    • Calls the control_irrigation() function to control the irrigation process.
    • Catches the KeyboardInterrupt exception to handle program termination via Ctrl+C.

Usage

  1. Make the necessary hardware connections between the Raspberry Pi, soil moisture sensor, and water pump.

  2. Install the required Python libraries, such as RPi.GPIO.

  3. Save the Python script to a file, e.g., irrigation_control.py.

  4. Run the script using python irrigation_control.py or a similar command.

  5. Observe the console output, which will indicate whether watering is needed and control the water pump accordingly.

water-irrigation-control-system's People

Contributors

heshamomar820 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.