Reputation: 1
The conversion formula does not work as expected(21.6 Celsius degree in the room but will return another value of 34 or more depending on the formula used).
I use a KY-013 temperature sensor and the mcp3008 driver. I connected the temperature sensor to the channel 1 of the driver. I connected the driver as mentioned on this website: https://randomnerdtutorials.com/raspberry-pi-analog-inputs-python-mcp3008/.
I also tried with a humidity soil sensor and it works fine.
The MCP3008(channel = 1) returns me a value between 0 and 1. How Should I convert it into Celsius degree?
I tried to use the formula mentioned on the datasheet:
Temp = math.log(10000.0 * ((1024.0 / RawADC - 1)));
Temp = 1 /(0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp);
Temp = Temp - 273.15; // convert from Kelvin to Celsius
return Temp;
But since Raspberry has value 1 when the channel does not receive anything i replaced RawADC
with 1 - RawADC
.
It returned somewhere around 34 degrees.. but in the room, I recorded with a thermostat the 21.7 degrees.
I tried other formulas similar to:
voltage = 5 * (1 - RawADC)
temp = (voltage / 1024 - 0.5) * 100
#-55 is the minimal temp that the sensor can read
#125 is the maximum
return temp-55
or something like:
delta_temp = 125 - (-55)
delta_v = 5 - 0
m = delta_temp/delta_V
b = -55 # at point 0 voltage => -55degre
T = (1 - RawADC) * 5 * m + b
I even tried the simple rule of 3 but the result was still NOT as expected.
My current code is:
from gpiozero import MCP3008
from time import sleep
import math
while True:
#create an object called temp that refers to MCP3008 channe1
temp = MCP3008(1)
print(temp.value) # display 0.49 or 0.53 depending
sleep(0.1)
voltage = (1- temp.value) *5
Temp = math.log(10000.0 * (1024.0 / voltage - 1))
Temp = 1 /(0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp)) * Temp)
Temp = Temp - 273.15 # convert from Fahrenheit to Celsius
print(Temp) # display a value over -74
Upvotes: 0
Views: 156