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
00001 #include "mbed.h" 00002 #include "stm32f103c8t6.h" 00003 //------------------------------------ 00004 // Hyperterminal configuration 00005 // 9600 bauds, 8-bit data, no parity 00006 //------------------------------------ 00007 00008 Serial pc(SERIAL_TX, SERIAL_RX); 00009 00010 DigitalOut myled(LED1); 00011 00012 int main() 00013 { 00014 float meas; 00015 float very_hum_value = 0.27; 00016 float soil_hum_perc; 00017 00018 AnalogIn analog_value(A0); 00019 DigitalOut VCC(PB_7); 00020 00021 while(1) { 00022 00023 VCC = 1;// VCC on 00024 wait(1); 00025 meas = analog_value.read(); 00026 VCC = 0; //VCC of 00027 00028 soil_hum_perc = (1 - (meas - very_hum_value)/(1 - very_hum_value)) * 100; // perevod v % 00029 pc.printf("Soil_Humidity: %f %% \n", soil_hum_perc); 00030 00031 wait(600); //period izmereniy 00032 } 00033 }
Generated on Fri Aug 26 2022 04:40:50 by
1.7.2