This programm works with Chineese Soil Moisture Sensors YL-69. Read Analog value from A0 pin and out percent of Soil Moisture to UART .

Dependencies:   mbed-STM32F103C8T6 mbed

main.cpp

Committer:
AbiOne
Date:
2018-06-08
Revision:
0:7c21544e5cd3
Child:
1:278b6f18d227

File content as of revision 0:7c21544e5cd3:

#include "mbed.h"
#include "stm32f103c8t6.h"
//------------------------------------
// Hyperterminal configuration
// 9600 bauds, 8-bit data, no parity
//------------------------------------

Serial pc(SERIAL_TX, SERIAL_RX);

DigitalOut myled(LED1);

int main()
{
    float meas;
    float very_hum_value;
    float soil_hum_perc;
    
     
    AnalogIn analog_value(A0);
    
    
    while(1) {
        wait(1);
        meas = analog_value.read();
        
        soil_hum_perc = (meas - very_hum_value)/(1 - very_hum_value) * 100; // perevod v %
        pc.printf("Soil_Humidity: %f \%\n", meas);
        myled = !myled;
    }
}