Skip to content

lcarnevale/esp32-yl69

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESP32 Soil Moisture Sensor YL-69 or HL-69 Driver

This project containes the ESP-IDF driver both for the YL-69 and HL-69 soil moisture sensor. This sensor outputs voltage value that changes accordingly to water content in the soil. Specifically, when the soil is:

  • wet the output voltage decreases;
  • dry the output voltage increases.

How to Use it

There are few steps to follow for running this component. Take a look at the list below.

  1. First of all, clone this repository or download latest release

  2. Set up the esp32-yl69 component into the requires of your CMakeLists.txt

//CMakeLists.txt
...
set(COMPONENT_REQUIRES esp32-yl69)
...
  1. Include the header file within your main application
//main.c
...
#include "yl69.h"
...
  1. Initialize the driver with the following function
//main.c
void setup() {
    yl69_setup(ADC_CHANNEL_6);
}
  1. And run the task as follow
//main.c
static void yl69_task(void *arg) {
    char yl69_buffer[1024];

    while(is_running) {
        uint32_t adc_reading = yl69_read();
        uint32_t adc_percentage = yl69_normalization(adc_reading);
        snprintf(yl69_buffer, sizeof(yl69_buffer), "{\"soil_mosture\": %d}", adc_percentage);
        printf("%s\n", yl69_buffer);

        vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
    
    vTaskDelete(NULL); 
}

void loop() {
    xTaskCreate(yl69_task, "yl69_task", 4*1024, NULL, 1, NULL);
}