Arduino Temperature Sensor for Ghost Hunting
by 28ConleyD in Circuits > Arduino
57 Views, 0 Favorites, 0 Comments
Arduino Temperature Sensor for Ghost Hunting
This temperature sensor not only detects in Fahrenheit but also in Celsius allowing for people all around the world to us this design. This temp sensor if for air temperature which is very good for ghost hunting.
Supplies
- Red Board
- Jumper wires (Roughly 25)
- LCD screen
- Potentiometer
- TMP36 Temperature Sensor
- Bread Board
- Arduino IDE (computer download)
- computer
- USB A to mini USB B cord
Wire
use this wiring diagram and photo to wire
need everything except
- Arduino IDE (computer download)
- computer
- USB A to mini USB B cord
Code
need
- Arduino IDE (computer download)
- computer
- USB A to mini USB B cord
put code into Arduino IDE connect the red board and computer with the USB A to mini USB B cord, then choose which port then upload code
use this code or code you own
/*
TMP36 Auto-Calibrating Temperature Sensor Code
----------------------------------------------
Works accurately on USB, battery, or any power source.
It measures its own voltage (Vcc) each time,
so the math stays correct even if the supply voltage changes.
Hardware:
- SparkFun RedBoard or Arduino Uno
- TMP36 temperature sensor
- 16x2 LCD (LiquidCrystal)
Wiring (facing flat front of TMP36):
Left pin -> +5V
Middle pin -> A0
Right pin -> GND
LCD wiring (same as SparkFun examples):
RS -> 13
EN -> 12
D4 -> 11
D5 -> 10
D6 -> 9
D7 -> 8
*/
#include <LiquidCrystal.h>
LiquidCrystal lcd(13, 12, 11, 10, 9, 8);
// -------------------- USER SETTINGS --------------------
const int sensorPin = A0; // TMP36 output wire connected to analog pin A0
const float offsetC = -4.4; // Calibration offset (°C) to fine-tune accuracy - start at 0.0 and adjust as needed to a known value.
const int samples = 20; // Number of readings to average (smoother display)
const unsigned long updateDelay = 1000; // Delay between updates (1 second)
// -------------------------------------------------------
void setup() {
lcd.begin(16, 2); // 16 columns, 2 rows LCD
lcd.clear();
lcd.print("TMP36 Sensor");
delay(2000);
lcd.clear();
Serial.begin(115200); // Optional: open Serial Monitor to see detailed info
}
// -------------------------------------------------------
void loop() {
// Measure Arduino’s actual supply voltage in millivolts (mV)
// This accounts for any drift when using a 9V battery or USB.
long vcc_mV = readVcc(); // Example: returns 5000 mV or 4760 mV
float Vcc = vcc_mV / 1000.0; // Convert to volts for math (e.g., 4.76 V)
// Take multiple readings from TMP36 and average them to reduce noise
long total = 0;
for (int i = 0; i < samples; i++) {
total += analogRead(sensorPin);
delay(5); // Small pause between readings
}
float averageReading = total / (float)samples;
// Convert analog reading (0–1023) to actual voltage from the sensor
// We use measured Vcc instead of a fixed "5.0" volts to stay accurate.
float voltage = averageReading * (Vcc / 1023.0);
// Convert voltage to temperature
// TMP36 outputs:
// 0.5 V = 0°C
// +10 mV = +1°C increase
float tempC = (voltage - 0.5) * 100.0 + offsetC; // Apply calibration offset
float tempF = tempC * 9.0 / 5.0 + 32.0; // Convert to Fahrenheit
// Display results on LCD
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("C: ");
lcd.print(tempC, 1); // One decimal place (e.g., 21.3°C)
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print("F: ");
lcd.print(tempF, 1); // One decimal place (e.g., 70.4°F)
// Optional: also show voltage in Serial Monitor for debugging
Serial.print("Vcc (mV): "); Serial.println(vcc_mV);
Serial.print("Sensor V: "); Serial.print(voltage, 3); Serial.println(" V");
Serial.print("TempC: "); Serial.println(tempC, 2);
Serial.print("TempF: "); Serial.println(tempF, 2);
Serial.println("--------------------");
delay(updateDelay); // Wait before repeating
}
// -------------------------------------------------------
// Function: readVcc()
// Measures Arduino’s supply voltage in millivolts (mV)
// It uses the built-in 1.1 V reference inside the microcontroller.
// This lets us know the *real* system voltage, even if the battery sags.
long readVcc() {
// Configure ADC to use Vcc as reference and measure internal 1.1V bandgap
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2); // Let ADC settle
ADCSRA |= _BV(ADSC); // Start conversion
while (bit_is_set(ADCSRA, ADSC)); // Wait for conversion to finish
uint16_t result = ADC; // Read ADC result
// Convert to mV:
// Vcc = 1.1V * 1023 / ADC_value
// Multiply by 1000 for millivolts
long vcc = 1125300L / result; // 1.1 * 1023 * 1000 = 1125300
return vcc; // Example: returns 4970 (4.97V)
}