Had some time this weekend and a desire to create something new and interesting, so went ahead and created an Arduino/NodeMCU based indoor dial thermometer. This device displays the temperature in degree centigrade on a D-Shaped Gauge as well as on a 7-Segment display.

In addition to that, it also saves the temperature and humidity readings in a MySQL DataBase hosted on a home based Raspberry Pi Server. The data is then displayed using the "Our Smart Home" app.

Awards

This project got featured on Cults3D and Instructables
 
https://cults3d.com/en/3d-model/gadget/arduino-based-indoor-dial-thermometerhttps://www.instructables.com/NodeMCU-Based-3D-Printed-Indoor-Gauge-Thermometer/

 

Components Required

For this project we need:

  • 2 x TM1637 Display Modules
  • 1 x DHT22 or DHT11 Module
  • 1 x NodeMCU Microcontroller
  • 1 x 28BYJ-48 Stepper Motor with ULN2003 Driver Board
  • 1 x 10K Resistor
  • A 3D Printer
  • Copper Wire and Some Nuts & Bolts

Circuit Diagram

The circuit is very simple. Connect the ULN2003 driver board’s IN1, IN2, IN3 and IN4 to the NodeMCUs digital pins D0, D1, D2 and D3. Then connect the OUT Pin of the DHT22 to the D5 Pin of NodeMCU. After that connect the 2 x Display Modules to the microcontroller. We are going to use a Common Clock Pin D4 for both modules. Then connect the DIO of one of the modules to D6 (TEMP) and the other one to D7 (HUM) pins on the NodeMCU. Important: Please avoid using the boot config pins D3, D4, D8 and the RTC pin D0 for the displays. Now, on the D8 Pin we are going to connect the switch. This switch has a very important role in this circuit. This switch acts as the 'home' or the 'starting point' of the stepper motor. When the switch is open Pin D8 is connected to GND through the pull-down resistor and we read a LOW. When the switch is closed, Pin D8 connects to 3.3v pin of NodeMCU and we read a HIGH. When the 'temperature changes' or the 'device boots up', the pointer starts moving 'counterclockwise'. As soon as the pointer hits the home position, Pin D8 reads HIGH and the logic moves the pointer 'clockwise' to display the temperature on the gauge as read by the DHT22 module.

The Code


The code starts by including all the necessary libraries.
Then it defines all the variables needed for setting up the WiFi connection.
Next, it assigns a static IP address to the ESP8266 (if you want to use DHCP then go ahead and delete these three lines from the code).

After that, it sets up the 2 x URLs that are needed for updating the heartbeat, temperature and humidity.

String URLUpdateStatus = "http://192.168.0.7/Arduino/Weather/UpdateStatus.php";
String URLUpdateTemp   = "http://192.168.0.7/Arduino/Weather/UpdateTemperature.php";

Before going ahead let's have a quick look at the 2 php files. The "UpdateStutus.php" file uses an UPDATE query to update the timestamp of the device sending the request to the current epoch time and hence updating the heartbeat.

<?PHP
    try {
        $Token    = $_GET["Token"];
        $Location = $_GET["Location"];
        include "ConnectionStringArduino.php"; // Create connection
        $sql      = 'Update `Status` SET `DateTime`=\''.time().'\',`State`=\'1\' WHERE `Device`=\''.$Location.'\' AND `Token` = \''.$Token.'\';';
        $result   = $con->query( $sql ); if($result === FALSE) { die(mysqli_error());}
        mysqli_close($con);
    } catch (Exception $e) {}
?>

The "UpdateTemperature.php" uses an INSERT query to add a new row to the database with the current values of Temperature and Humidity. 

<?PHP
    try {
        $Location = $_GET["Location"];
        $TEMP     = $_GET["TEMP"];
        $HUM      = $_GET["HUM"];
           ...

Read more »