Reading data from the soil moisture sensor module
You will now learn how to code a program that reads the information from the moisture sensor and shows on the serial monitor if the plant pot needs watering or is moist enough.
Let's start developing the program to collect the sensor data from the STM32 Blue Pill, as follows:
- Let's get started writing the code. This time, we won't need any additional libraries. Define which of the STM32 Blue Pill card pins will be used as input for reading the sensor data. Also, declare a variable to save the reading data from the sensor, as follows:
const int sensorPin = PB12; int sensorValue = 0;
The input pin will be the
PB12
pin (labeled B12 on the Blue Pill). Also, we initialize thesensorValue
variable to a value of0
. - Next, in the
setup()
part, we need to start the serial data transmission and assign the speed of the transfer (as usual, we will use 9,600 bits per second (bps) as the standard value). Here is the code...