Coding a program to send the sensed data to the internet
In this section, we will continue using the NodeMCU development board to receive the data from the STM32 and send it to the internet. However, unlike Chapter 10, IoT Plant Pot Moisture Sensor, where a digital value (1 or 0) was sent directly between both microcontrollers, we now need to send the voltage value using serial communication between these microcontrollers.
Serial transmission is done by sending the data using the RX/TX pins.
Let's create the program to connect the NodeMCU and the STM32:
- In
setup()
, we need to add new serial data transmission to 115200 bps. It is the recommended speed for the NodeMCU board:void setup() { serial.begin(9600); Serial1.begin(115200); }
- The
loop()
instance needs a new line after the sensor reading and voltage conversion. Thewrite()
function sends the data as an integer value:void loop() { int sensorValue = analogRead(sensorPin)...