#include <OneWire.h>
#include <DallasTemperature.h>
#include <TM1637Display.h>
// Define the connections for the TM1637 display
#define CLK 3
#define DIO 4
// Define the pin for the DS18B20 sensor
#define ONE_WIRE_BUS 2
// Create instances
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
TM1637Display display(CLK, DIO);
// Custom character for "C" (Celsius)
const uint8_t Celsius[] = {
SEG_A | SEG_F | SEG_E | SEG_D // Displays "C"
};
void setup() {
// Start the serial communication
Serial.begin(9600);
// Initialize the DS18B20 sensor
sensors.begin();
// Initialize the TM1637 display
display.setBrightness(0x0a); // Set brightness (0x00 to 0x0f)
display.clear();
}
void loop() {
// Request temperature from the DS18B20 sensor
sensors.requestTemperatures();
// Get the temperature in Celsius
float temperatureC = sensors.getTempCByIndex(0);
// Print the temperature to the Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");
// Display the temperature on the TM1637 display with one decimal place and "C"
int tempInt = int(temperatureC * 10); // Multiply by 10 to keep one decimal place
//display.showNumberDecEx(tempInt, 0b01000000, false, 4, 0); // Display with decimal point
display.showNumberDec(tempInt, false);
// Display "C" on the last digit
display.setSegments(Celsius, 1, 3); // Display "C" on the 4th digit (position 3)
// Wait for a second before the next reading
delay(1000);
}