SubName: Reading a TMP36 temperature sensor
Description: You can use this simple code to read the temperature readings from a TMP36 temperate sensor.
A few weeks ago I was speaking to B4X user Sorex when he mentioned to me a temperature sensor called a TMP36, I had never heard of this particular temperature sensor before so I decided to buy 5 of them.
Note: Yes there is already code on the forum for this sensor, but I thought that I would share this code as it is a direct conversion from demo Arduino IDE code.
This sensor is relatively stable but at times it can drift up and down a little bit. I would personally use the DS18B20 temperature module if you are looking for a seriously stable temperature reading, to me the DS18B20 is a more stable temperature sensor with less temperature drift. If you are looking for a general purpose temperate sensor at a bargain price then you can't really go wrong with the TMP36, look at the spoiler below to view the readings that I was reading.
Tags: Temperature, Sensor, TMP36, Wemos D1 Mini @3.3v, Arduino @5.0v
Wemos D1 Mini (Sensor running at 3.3v)
Arduino (Sensor running at 5.0v)
TMP36 is in a TO-92 package
Description: You can use this simple code to read the temperature readings from a TMP36 temperate sensor.
A few weeks ago I was speaking to B4X user Sorex when he mentioned to me a temperature sensor called a TMP36, I had never heard of this particular temperature sensor before so I decided to buy 5 of them.
Note: Yes there is already code on the forum for this sensor, but I thought that I would share this code as it is a direct conversion from demo Arduino IDE code.
This sensor is relatively stable but at times it can drift up and down a little bit. I would personally use the DS18B20 temperature module if you are looking for a seriously stable temperature reading, to me the DS18B20 is a more stable temperature sensor with less temperature drift. If you are looking for a general purpose temperate sensor at a bargain price then you can't really go wrong with the TMP36, look at the spoiler below to view the readings that I was reading.
AppStart
Volts = 0.7025v
20.3°C
68.5°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7025v
20.3°C
68.5°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7025v
20.3°C
68.5°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7025v
20.3°C
68.5°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7025v
20.3°C
68.5°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7058v
20.6°C
69.0°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7090v
20.9°C
69.6°F
Volts = 0.7025v
20.3°C
68.5°F
Volts = 0.7090v
20.9°C
69.6°F
B4X:
'WIRE LEGEND for TMP36 Temperature Sensor connected to an Wemos D1 Mini
'GND = GND
'VCC = 3.3V
'VT = A0
Sub Process_Globals
'These global variables will be declared once when the application starts.
'Public variables can be accessed from all modules.
Public Serial1 As Serial
Private V_Pin_A0 As Pin
Private ESPPin As D1Pins
Private TmrReadings As Timer
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
V_Pin_A0.Initialize(0, ESPPin.D0)
TmrReadings.Initialize("Readings_Tick", 1000)
TmrReadings.Enabled = True
End Sub
Sub Readings_Tick
Dim PinVoltage, TemperatureC As Float
PinVoltage = V_Pin_A0.AnalogRead * 3.30 '3.30 is the VCC voltage (3.3v in this case) that is powering the sensor, change to 5.0 if you are using 5.00V from an Arduino
PinVoltage = PinVoltage / 1024.0
Log("Volts = ", PinVoltage, "v")
TemperatureC = (PinVoltage - 0.5) * 100 'Converting from 10mv per degree with 500mV offset to degrees C ((voltage - 500mV) times 100)
Log(NumberFormat(TemperatureC, 0, 1), "°C") 'Centigrade reading
Log(NumberFormat(TemperatureC * 9.0 / 5.0 + 32.0, 0, 1), "°F") 'Fahrenheit reading
End Sub
Wemos D1 Mini (Sensor running at 3.3v)
Arduino (Sensor running at 5.0v)
TMP36 is in a TO-92 package
Last edited: