This project is based on three main functions :
- Measuring the evolution of a plant environment
- Sending and displaying the data on a web platform
- Creating an autonomous system
All our code has been developped on the mbed platform, all the libraries we used are available on the platform, except for the standby mode library (see part 3).
The microcontroller we used for this project is the STM32L432KC, it is an ultra low power SoC with a cortex M4 (https://www.st.com/resource/en/datasheet/stm32l432kc.pdf).
I - Measuring the evolution of a plant environmentOur system is measuring 5 different variables:
- Air temperature (DHT22 sensor)
- Air moisture (DHT22 sensor)
- RGB light intensity (Red Green Blue) (TCS34725 sensor)
- Ground temperature (DS18B20 sensor)
- Ground moisture ( capacitive soil moisture sensor)
The DHT22 sensor has been programmed thanks to the "DHT.h" library as follows:
#include "mbed.h"
#include "DHT.h"
Serial pc(USBTX, USBRX);
DHT sensor(D11, DHT22);
int main(void){
pc.baud(9600);
while(1){
err = sensor.readData();
pc.printf("err = %d\r\n", err);
pc.printf("Temperature is %4.2f C \r\n",sensor.ReadTemperature(CELCIUS));
pc.printf("Temperature is %4.2f F \r\n",sensor.ReadTemperature(FARENHEIT));
pc.printf("Temperature is %4.2f K \r\n",sensor.ReadTemperature(KELVIN));
pc.printf("Humidity is %4.2f \r\n",sensor.ReadHumidity());
wait(5);
}
}
The light sensor has been programmed thanks to the "TCS34725.h" library as follows:
#include "mbed.h"
#include "TCS34725.h"
Serial pc(USBTX, USBRX);
TCS34725 rgb (D4, D5);
int main(void){
pc.baud(9600);
rgb.init(1, 5);
uint16_t r, g, b, l;
while(1){
rgb.getColor(r, g, b, l);
pc.printf("red: %d, green: %d, blue: %d, lux: %d\r\n", r, g, b, l);
wait(5);
}
}
The DS18B20 sensor has been coded thanks to the "DS1820.h" library as follows:
#include "mbed.h"
#include "DS1820.h"
Serial pc(USBTX, USBRX);
DS1820 probe(A1);
int main(void){
pc.baud(9600);
if(probe.unassignedProbe(A1)){
pc.printf("error");
}
while(1){
probe.convertTemperature(true, DS1820::all_devices);
pc.printf("T = %f degres \r\n", probe.temperature());
wait(5);
}
}
The capacitive soil moisture sensor has been coded as follows:
#include "mbed.h"
#include "DS1820.h"
Serial pc(USBTX, USBRX);
AnalogIn hum_sol(A0);
int main(void){
pc.baud(9600);
}
while(1){
humSol = (((1 - hum_sol.read()) * 100) - 23) * 2.63;
pc.printf("HumSol = %d\r\n", humSol);
wait(5);
}
}
For more details see https://www.dfrobot.com/wiki/index.php/Capacitive_Soil_Moisture_Sensor_SKU:SEN0193
II - Send and display the data on a web platform1) Components.
Two components are necessary to send data on SigFox :
- One SigFox module.
- One antenna fixed on the module.
2) Data compression and emission.
In this final part, we wanted to allow the user to easily access the data measured by our system.
First of all, we had to compress our data. Indeed the sensors originally sent us 7 variables of 4 bytes, so the total data weighed 28 bytes. Whereas the SigFox network only allowed us to send 1 message of up to 12 bytes every 10 minutes.
Thus, as you can see in the Section 2, we compressed the variables and put them in 8-bit and 16-bit integer variables (signed or unsigned, depending on the sensor).
The data is stored in an array. The SigFox module, which is connected to an antenna, is plugged to our system via a serial connection initialized at 9600 bauds. We can tell the module to send the data to the network with AT commands as follows :
3) Callback
A message takes approximately 7 seconds to reach the SigFox interface. To treat the data, we chose to send it to the Microsoft Azure cloud. To do that, everytime raw data is received in SigFox, it is automatically translated by a "callback" into a JSON message and transferred to the Cloud.
This callback will for example convert this sequence of hexadecimal bits:
"00a8522c0011048806270798" to the following JSON message:
4) Microsoft Azure Cloud
a) Database
When the JSON message is received in the cloud, the data is added to a database. This will allow the user to easily access all the measures received, starting from the first installation of the device.
We used the SQL language to process our data. As you can see, we retrieved our data. But we are also using the color luminous intensities to compute the general light intensity and to determine the proportion of each color in the light received by the plant. We decided to make those calculations on the cloud because of the 12 bytes limit per message sent on the SigFox network.
b) Data visualisation
The user will be given login credentials to access the data on the Microsoft PowerBI application. The Microsoft Azure Cloud processes the data and forwards it to as many authorized Microsoft PowerBI accounts as needed.
The PowerBI interface allows the user to visualize the data in tables, charts, graphs and export it. The database is automatically updated each time a message is received on the cloud.
The hardest part of this project is to make our system completely energetically autonomous. The goal is to reduce our consumption as much as possible in order to provide enough energy to power our system with our solar panel.
There are different ways to save energy, we can for example modify our code to implement the sleep mode and/or to change the clock frequency (software solution).
But we can also modify our hardware; we can use a transistor to power our sensors. And we can change our source of energy in order to power our system with 3.3V instead of 5V.
For the software improvement, as of today, we have set up a sleep mode but we have not changed the clock frequency yet because of compatibility issues with some sensors. STM32Cube gives great examples on how to put the microcontroller in the different sleep mode (see https://www.st.com/en/embedded-software/stm32cubel4.html).
For the hardware improvement, as of today, we have set up transistors to power the sensors, but we are still working to modify our charger. The idea is to create a new charger more appropriate to our system, by setting the output at 3.3V. (Be careful if you want to power your stm32 directly in 3.3V, you need to modify it and power it directly on the 3.3V pin).
The transistor are use as follow:
We have created a PCB (Printed Circuit Board) to use our system. In order to make our PCB, we have used the software Altium.
Our final prototype
Comments