# K8055 and anolog temp sensor

i have a temprature sensor (ntc) and humidistat that i have wired into the anolog inputs with resistors ect, of my k8055 and can get a reading, but the scales are reversed, when i heat the thermistor the temp reading goes down, same with the humidistat,

could you tell me why that is and how i can work around it,
the code i use is below

``````Private Sub Timer3_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer3.Tick
Dim data1 As Integer
Dim data2 As Integer
Dim degrees1 As String 'this variable hold the value in degrees centigrade A1
ReadAllAnalog(data1, data2) 'get the analog values (0..255) from the interface board
degrees1 = ((45 * data1 / 256) - 0) 'convert '0..255'-value to degrees
'101 : # of steps between -0 and +45°
'256 : 8-bit AD -> 256 values
'-0 : minimum temp. that can be measured

If (degrees1 - Int(degrees1)) <= 0.3 Then degrees1 = Int(degrees1) 'round degrees to 0,  or 1
If (degrees1 - Int(degrees1)) > 0.3 And (degrees1 - Int(degrees1)) <= 0.7 Then degrees1 = Int(degrees1) + 0.5
If (degrees1 - Int(degrees1)) >= 0.7 Then degrees1 = Int(degrees1) + 1
If degrees1 = Int(degrees1) Then degrees1 = degrees1 & ",0" 'if there is no fraction, add a ".0"
Label10.Text = degrees1 'display the temperature

End Sub``````

i changed the values degrees1 = ((45 * data1 / 256) - 0) ’ 45 so it was the max and -0 so it was the min,

The resistance of the NTC decreases when temperature increases.
You get decreasing values if the NTC is between the GND and the analog input of the K8055.
Reversing the NTC and the fixed resistor is one solution or invert the data in your program.

I think NTC is quite non-linear. You may have to do some linearization calculation too…

thanks very much vel255,

The right way to round a number to a multiple of 0.5:

``````Dim temperature As Decimal = 0.8
temperature = Math.Round(temperature * 2) / 2 ' Algorithm to round to 0.5

' 0.0 = 0.0
' 0.1 = 0.0
' 0.2 = 0.0
' 0.3 = 0.5
' 0.4 = 0.5
' 0.5 = 0.5
' 0.6 = 0.5
' 0.7 = 0.5
' 0.8 = 1.0
' 0.9 = 1.0
' 1.0 = 1.0``````

Format it to a string for displaying:

``lblTemperature.Text = FormatNumber(temperature, 1) ' Format the temperature``