Skip to content

SCArcherKuo/RemoteTemperatureSensor

Repository files navigation

Temperature Sensor with WiFi Cloud Logging

An ESP8266-based indoor temperature monitoring device that uploads sensor data to the ThingSpeak IoT cloud platform over WiFi, with local display via an LCD screen and IR motion-triggered backlight control.


Features

  • 🌡️ Dual temperature sensing — simultaneously reads the DS18B20 external probe temperature and the DS3231 RTC built-in room temperature
  • ☁️ Cloud data upload — writes data to a ThingSpeak channel every 60 seconds over HTTPS (SSL)
  • 📺 Real-time LCD display — 16×2 LCD shows the current timestamp and both temperature readings
  • 🚶 IR motion-triggered backlight — automatically turns on when motion is detected; turns off after 180 seconds of inactivity
  • 🕐 Accurate RTC timekeeping — DS3231 real-time clock module provides precise date and timestamp data
  • 🔄 Auto WiFi reconnection — automatically attempts to reconnect if the connection is lost

Motivation

This project began with a simple concern: avoiding the risk of temperature loss for stored samples and plants. A failure of a freezer, incubator, or growth chamber — even briefly — can ruin weeks or months of work. The idea that such a small, inexpensive device could meaningfully reduce the chance of those losses felt worth the effort — and indeed, it has come through on a few occasions.


Real Prototype

Demo Picture

Demo Picture

Demo Video

Demo Video

Click the thumbnail to watch the demo on YouTube.

ThingSpeak Record

ThingSpeak Record

Note: The device was initially placed inside a refrigerator and later moved to a plant growth chamber — this is why the recorded temperature rises noticeably partway through the chart.


Hardware Requirements

Component Model / Spec
Microcontroller ESP8266 (e.g. NodeMCU, Wemos D1)
Temperature sensor DS18B20 (1-Wire interface)
Real-time clock DS3231 RTC module (I2C interface)
Display LCD 1602 (I2C backpack, 16 cols × 2 rows)
Motion sensor Passive IR (PIR) sensor

Wiring

Component ESP8266 Pin
IR sensor (signal) GPIO 2 (D4)
DS18B20 (data wire) GPIO 0 (D3)
DS3231, LCD I2C bus (SDA / SCL)

The DS18B20 uses a 1-Wire bus on GPIO 0 and is independent of the I2C bus used by the RTC and LCD.


Software Dependencies

Install the following libraries in the Arduino IDE:

Library Purpose Notes
ESP8266WiFi WiFi connectivity Bundled with ESP8266 core
WiFiClientSecure HTTPS / SSL support Bundled with ESP8266 core
ThingSpeak Cloud data upload By MathWorks
OneWire 1-Wire bus Required for DS18B20
DallasTemperature DS18B20 sensor
RTClib DS3231 RTC By Adafruit
LiquidCrystalIO LCD 1602 (I2C backpack) Not the standard LiquidCrystal_I2C; requires IoAbstractionWire
IoAbstraction I2C abstraction layer Required by LiquidCrystalIO

⚠️ The LCD driver used here is LiquidCrystalIO (by Dave Cherry / davetcc), configured for a PCF8574-based I2C backpack at address 0x3F. If your backpack uses a different address or pin wiring (EN,RW,RS instead of RS,RW,EN), update the LiquidCrystalI2C_RS_EN call in DisplayLCD1602.h accordingly.


Project File Structure

.
├── 20220729_TemperatureSensorWithWiFi.ino  # Main sketch
├── SecretsWiFi.h         # WiFi & ThingSpeak credentials (must be created manually)
├── TemperatureDS18B20.h  # DS18B20 sensor wrapper
├── DisplayLCD1602.h      # LCD 1602 display wrapper
└── TimeDS3231.h          # DS3231 RTC wrapper

Setup

1. Create SecretsWiFi.h

Create a SecretsWiFi.h file in the project directory and fill in your WiFi and ThingSpeak details:

#define SECRET_SSID "your_wifi_ssid"
#define SECRET_PASS "your_wifi_password"
#define SECRET_CH_ID 000000                    // ThingSpeak Channel ID
#define SECRET_WRITE_APIKEY "xxxxxxxxxxxxxxxx" // ThingSpeak Write API Key

⚠️ Do not commit this file to any public version control repository (e.g. GitHub).

2. Configure your ThingSpeak channel

Log in to ThingSpeak, create a channel, and configure the following fields:

Field Data
Field 1 DS18B20 probe temperature (°C)
Field 2 DS3231 room temperature (°C)
Field 3 Unix timestamp (seconds)

3. Flash the sketch

  1. Open Arduino IDE
  2. Select your ESP8266 board from Tools → Board
  3. Select the correct serial port
  4. Click Upload

How It Works

Boot
 └─► Initialize (WiFi, ThingSpeak, DS18B20, LCD, RTC)
      └─► Main loop (runs every second)
           ├─ Check WiFi; reconnect automatically if disconnected
           ├─ Read RTC time, room temp, DS18B20 temp, IR status
           ├─ Motion detected → reset backlight timer (180 s)
           ├─ Update LCD with timestamp & dual temperatures (if backlight on)
           └─ Every 60 s → upload data to ThingSpeak

Configurable Parameters

Parameter Default Description
recordingIntervalSec 60 ThingSpeak upload interval (seconds)
lightOnResetSec 180 Backlight on-duration after motion trigger (seconds)
IRsensor 2 IR sensor GPIO pin
DS18B20 resolution 12 bits Temperature resolution (9–12 bits)
ONE_WIRE_BUS 0 DS18B20 data wire GPIO pin

Sensor error codes:
If the DS18B20 fails to respond, readDSTemperatureC() returns 888 (°C) and readDSTemperatureF() returns 888 (°F). These sentinel values can be used to detect wiring or sensor faults at runtime.


License

Copyright © 2017, The MathWorks, Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  4. In all cases, the software is, and all modifications and derivatives of the software shall be, licensed to you solely for use in conjunction with MathWorks products and service offerings.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

About

No description, website, or topics provided.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors