I am currently working on a project where I need to read a DHT11 humidity and temperature sensor . The connection between the MCU and the serial device is quite low, but I managed to get the measured values (humidity + temperature) as a 4-byte array (the fifth byte is the checksum):
The values I get from the DHT11 sensor are:
- byte[0] = humidity integer part - byte[1] = humidity decimal part - byte[2] = temperature integer part - byte[3] = temperature decimal part - byte[4] = checksum of the first four bytes
Now I would like to convert byte[0] and byte[1] to float and the same for temperature (byte [2] and byte [3]). What is the efficient way to accomplish this on an Arduino Mega 2560 in C / C ++?
Example:
byte[0] = 20 and byte[1] = 12 => 20.12 [float]
source share