{"id":23085276,"url":"https://github.com/saeed-dev2/soil_irrigation_and_motion_detection_system","last_synced_at":"2026-08-01T20:31:41.987Z","repository":{"id":255410109,"uuid":"840730407","full_name":"Saeed-dev2/SOIL_IRRIGATION_AND_MOTION_DETECTION_SYSTEM","owner":"Saeed-dev2","description":"\"An Automated System Leveraging ESP32 and FreeRTOS to monitor soil moisture and detect motion. It controls irrigation via a relay and triggers a buzzer for motion alerts. Ideal for efficient and responsive garden management\"","archived":false,"fork":false,"pushed_at":"2024-11-05T15:06:19.000Z","size":29,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-05T16:28:58.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Saeed-dev2.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-10T14:08:58.000Z","updated_at":"2024-11-05T15:06:24.000Z","dependencies_parsed_at":"2024-09-14T08:52:24.460Z","dependency_job_id":"4125fcad-9b36-46a7-aaa9-ed63eccd3f08","html_url":"https://github.com/Saeed-dev2/SOIL_IRRIGATION_AND_MOTION_DETECTION_SYSTEM","commit_stats":null,"previous_names":["saeed-dev2/soil_irrigation_and_motion_detection_system"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saeed-dev2%2FSOIL_IRRIGATION_AND_MOTION_DETECTION_SYSTEM","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saeed-dev2%2FSOIL_IRRIGATION_AND_MOTION_DETECTION_SYSTEM/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saeed-dev2%2FSOIL_IRRIGATION_AND_MOTION_DETECTION_SYSTEM/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Saeed-dev2%2FSOIL_IRRIGATION_AND_MOTION_DETECTION_SYSTEM/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Saeed-dev2","download_url":"https://codeload.github.com/Saeed-dev2/SOIL_IRRIGATION_AND_MOTION_DETECTION_SYSTEM/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230005100,"owners_count":18158365,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-16T17:51:57.056Z","updated_at":"2026-08-01T20:31:41.974Z","avatar_url":"https://github.com/Saeed-dev2.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Smart Irrigation System \n\nThis project implements a Smart Irrigation System using an ESP32 microcontroller, soil moisture sensor, PIR sensor, relay module, and a buzzer. The system monitors soil moisture levels and detects motion to control irrigation and provide Alerts.\n\n## Components Used\n\n- **ESP32 microcontroller**\n- **Soil Moisture Sensor**\n- **PIR Sensor**\n- **Relay Module (SRD-05VDC-SL-C)**\n- **Buzzer**\n- **Jumper Wires**\n- **Breadboard**\n  \n\n## Features\n\n- **Soil Moisture Monitoring**: Continuously monitors soil moisture levels and activates the relay then the built in Led is on of the ESP-32 and to start irrigation when moisture falls below a predefined threshold ``100``.\nyou can change the threshold according your Requirement.\n- **Motion Detection**: Detects motion using a PIR sensor and activates a buzzer to provide an alert.\n- **Configurable Threshold**: The soil moisture threshold for triggering irrigation can be adjusted based on sensor Calibration.\n\n## Circuit Diagram\n\n### Connections\n\n1. **Soil Moisture Sensor:**\n   - VCC to 3.3V of ESP32\n   - GND to GND of ESP32\n   - Data to GPIO34 of ESP32 (analog pin)\n\n2. **PIR Sensor:**\n   - VCC to 3.3V of ESP32\n   - GND to GND of ESP32\n   - Output to GPIO35 of ESP32 (digital pin)\n\n3. **Relay Module:**\n   - VCC to 3.3V of ESP32\n   - GND to GND of ESP32\n   - IN to GPIO2 of ESP32\n\n4. **Buzzer:**\n   - One pin to GPIO4 of ESP32\n   - Other pin to GND of ESP32\n\n## Installation and Setup\n\n1. **Install ESP-IDF**: Follow the official [ESP-IDF installation guide](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/) to set up the development environment.\n\n2. **Clone the Repository**:\n    ```sh\n    git clone https://github.com/your-username/smart-irrigation-esp32.git\n    cd smart-irrigation-esp32\n    ```\n\n3. **Configure the Project**:\n    ```sh\n    idf.py menuconfig\n    ```\n\n4. **Build the Project**:\n    ```sh\n    idf.py build\n    ```\n\n5. **Flash the Firmware**:\n    ```sh\n    idf.py -p /dev/ttyUSB0 flash monitor\n    ```\n\n\n## Code Explanation\n\n### Main Application\n\nThe main application function initializes the ADC for the soil moisture sensor, configures the GPIOs for the PIR sensor, relay, and buzzer, and enters a loop to continuously monitor the sensors and control the relay and buzzer accordingly.\n\n```c\n/**\n * @file smart_irrigation.c\n * @brief Smart Irrigation System with Soil Moisture Sensor and PIR Sensor\n *\n * This program monitors soil moisture levels and detects motion using a PIR sensor.\n * It controls a relay for irrigation and activates a buzzer when motion is detected.\n */\n\n#include \u003cstdio.h\u003e\n#include \"freertos/FreeRTOS.h\"\n#include \"freertos/task.h\"\n#include \"driver/gpio.h\"\n#include \"driver/adc.h\"\n#include \"esp_log.h\"\n\n// GPIO pin definitions\n#define SOIL_SENSOR_PIN    ADC1_CHANNEL_6 ///\u003c ADC channel for soil moisture sensor (GPIO34)\n#define PIR_SENSOR_PIN     GPIO_NUM_35    ///\u003c GPIO pin for PIR sensor\n#define RELAY_PIN          GPIO_NUM_2     ///\u003c GPIO pin for relay module\n#define BUZZER_PIN         GPIO_NUM_4     ///\u003c GPIO pin for buzzer\n\n// Threshold for soil moisture level\n#define MOISTURE_THRESHOLD 100 ///\u003c Soil moisture threshold for triggering irrigation\n\nstatic const char *TAG = \"SmartIrrigation\"; ///\u003c Tag for logging\n\n/**\n * @brief Main application function\n *\n * This function initializes the ADC for the soil moisture sensor, configures the GPIOs\n * for the PIR sensor, relay, and buzzer, and enters a loop to continuously monitor\n * the sensors and control the relay and buzzer accordingly.\n */\nvoid app_main(void) {\n    // Initialize ADC for soil moisture sensor\n    adc1_config_width(ADC_WIDTH_BIT_12);\n    adc1_config_channel_atten(SOIL_SENSOR_PIN, ADC_ATTEN_DB_0);\n\n    // Configure GPIO for PIR sensor\n    gpio_config_t pir_config = {\n        .pin_bit_mask = (1ULL \u003c\u003c PIR_SENSOR_PIN),\n        .mode = GPIO_MODE_INPUT,\n        .pull_up_en = GPIO_PULLUP_ENABLE,\n        .pull_down_en = GPIO_PULLDOWN_DISABLE,\n        .intr_type = GPIO_INTR_DISABLE\n    };\n    gpio_config(\u0026pir_config);\n\n    // Configure GPIO for relay and buzzer\n    gpio_set_direction(RELAY_PIN, GPIO_MODE_OUTPUT);\n    gpio_set_direction(BUZZER_PIN, GPIO_MODE_OUTPUT);\n\n    while (1) {\n        // Read soil moisture value\n        int soil_moisture_value = adc1_get_raw(SOIL_SENSOR_PIN);\n        ESP_LOGI(TAG, \"Soil Moisture: %d\", soil_moisture_value);\n\n        // Read PIR sensor value\n        int pir_value = gpio_get_level(PIR_SENSOR_PIN);\n\n        // Control relay based on soil moisture\n        if (soil_moisture_value \u003c MOISTURE_THRESHOLD) {\n            gpio_set_level(RELAY_PIN, 1); // Activate relay\n            ESP_LOGI(TAG, \"Soil is dry! Activating relay...\");\n        } else {\n            gpio_set_level(RELAY_PIN, 0); // Deactivate relay\n            ESP_LOGI(TAG, \"Soil moisture is adequate.\");\n        }\n\n        // Control buzzer based on PIR sensor\n        if (pir_value == 1) {\n            ESP_LOGI(TAG, \"Motion detected! Activating buzzer...\");\n            gpio_set_level(BUZZER_PIN, 1); // Turn on buzzer\n            vTaskDelay(pdMS_TO_TICKS(5000)); // Buzzer on for 5 seconds\n            gpio_set_level(BUZZER_PIN, 0); // Turn off buzzer\n        }\n\n        vTaskDelay(pdMS_TO_TICKS(2000)); // Delay for 2 seconds before the next reading\n    }\n}\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaeed-dev2%2Fsoil_irrigation_and_motion_detection_system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsaeed-dev2%2Fsoil_irrigation_and_motion_detection_system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsaeed-dev2%2Fsoil_irrigation_and_motion_detection_system/lists"}