Skip to content

Commit

Permalink
Merge pull request #2 from cloudsteak/add-time-module
Browse files Browse the repository at this point in the history
Add time module. 1.1.0
  • Loading branch information
the1bit authored Sep 17, 2024
2 parents 7bb318a + 7068299 commit 42bb6f6
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 40 deletions.
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

## Project Background

This project is designed to monitor temperature using the **DS18B20** sensor and display the readings in both Celsius and Fahrenheit on a **16x2 LCD** display. It aims to create a simple but effective way to visualize real-time temperature in a DJ booth or any other environment where monitoring temperature is essential for comfort and equipment safety.
This project is designed to monitor temperature using the **DS18B20** sensor and get current datetime using the **DS3231+AT24C32 RTCM** real-time module. Then display the current time in EU timeformat and temperature in Celsius and on a **16x2 LCD** display. It aims to create a simple but effective way to visualize real-time temperature in a DJ booth or any other environment where monitoring temperature is essential for comfort and equipment safety.

The code leverages the I2C protocol to communicate with the LCD and the **DallasTemperature** library to read from the temperature sensor. The display welcomes the user with a custom message and then continuously updates the temperature values in both Celsius and Fahrenheit.

## Components (Physical)

- **AR-NANOCH-TYPE-C**: Arduino Nano clone development board.
- **DS18B20**: One-wire digital temperature sensor.
- **DS3231+AT24C32 RTCM**: Real-time clock module with EEPROM.
- **KC-1602-BB-I2C**: 16x2 I2C LCD display for displaying messages and temperature readings.
- **4.7kΩ resistor**: Used to pull up the data line of the DS18B20 sensor.
- **Breadboard**: Optional, for wiring connections.
Expand All @@ -27,6 +28,7 @@ You need to install the following libraries using the Arduino IDE's Library Mana
- **OneWire**: Used for communicating with the DS18B20 temperature sensor.
- **DallasTemperature**: Simplifies reading from the DS18B20 sensor.
- **LiquidCrystal_I2C**: For controlling the 16x2 LCD display via I2C.
- **Wire**: Required for I2C communication.

To install these libraries:

Expand All @@ -42,6 +44,13 @@ To install these libraries:
- **GND (Black)**: Connect to Arduino's **GND**.
- **Data (Yellow)**: Connect to Arduino **D2**. Add a **4.7kΩ resistor** between the **VCC** and **Data** lines.

- **DS3231+AT24C32 RTCM** connections:

- **VCC**: Connect to Arduino's **5V**.
- **GND**: Connect to Arduino's **GND**.
- **SDA**: Connect to Arduino's **A4**.
- **SCL**: Connect to Arduino's **A5**.

- **16x2 LCD display** (I2C):
- **VCC**: Connect to Arduino's **5V**.
- **GND**: Connect to Arduino's **GND**.
Expand All @@ -59,29 +68,26 @@ Once the hardware is connected and the libraries are installed:

## What This Code Does

This project uses the **DS18B20 temperature sensor** and an **I2C LCD** to display the current temperature in both Celsius and Fahrenheit. Here’s how the code works:
This project uses the **DS18B20 temperature sensor**, **DS3231+AT24C32 RTCM module** and an **I2C LCD** to display the current temperature and current time in Celsius. Here’s how the code works:

1. **Setup Phase**:

- Time is initialized using the **DS3231+AT24C32 RTCM** module.
- The temperature sensor is initialized.
- The LCD is initialized and the backlight is turned on.
- Version number message is displayed on the LCD, then waits for 2 seconds.
- Clear the LCD display.
- A welcome message, **"Welcome SIPP!"**, is displayed on the first line of the LCD.
- A message, **"Let's get party!"**, is displayed on the second line.
- The setup waits for 5 seconds before moving into the loop.
- The LCD is cleared again.

2. **Main Loop**:
- Time is read from the **DS3231+AT24C32 RTCM** module.
- The time is converted to **EU time format** (24-hour clock, ). Format: HH:MM:SS (mm-dd)
- The temperature is read from the **DS18B20** sensor in **Celsius**.
- The Celsius temperature is converted to **Fahrenheit**.
- The first row of the LCD displays the temperature in Celsius with a **degree symbol (ºC)**.
- The second row displays the temperature in Fahrenheit with a **degree symbol (ºF)**.
- The display updates every second.

### Code Breakdown:

- **sensors.requestTemperatures()**: Requests the current temperature from the sensor.
- **getTempCByIndex(0)**: Reads the temperature in Celsius from the sensor.
- **lcd.clear()**: Clears the LCD before writing new content.
- **lcd.setCursor(x, y)**: Positions the cursor on the LCD at row `y` and column `x`.
- **delay(1000)**: Delays the loop for 1 second, causing the display to update every second.
- The first row of the LCD displays the time in the format above.
- The second row displays the temperature in Celsius with a **degree symbol (ºC)**.
- The display updates every 250 milliseconds, because time module is updated sharply every second and we need to catch the time update. If we update the display every second, we may miss the time update and the display shows the same time for 2 seconds.

The code is designed to be flexible and could be easily extended to handle additional sensors or display features.
76 changes: 50 additions & 26 deletions djbooth_sensor/djbooth_sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <RTClib.h>

RTC_DS3231 rtc; // Real-time module

#define ONE_WIRE_BUS 2 // Data cable on D2

Expand All @@ -13,56 +16,77 @@ LiquidCrystal_I2C lcd(0x27, 16, 2); // 16x2 LCD display, I2C address: 0x27 or 0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// int runCounter = 0;

void setup() {
//randomSeed(analogRead(0)); // Seed the random number generator with noise from an unused analog pin
// Init time module
Serial.begin(9600);

String statusMessage = "";

if (!rtc.begin()) {
statusMessage = "Couldn't find RTC";
Serial.println(statusMessage);
while (1);
}

if (rtc.lostPower()) {
// If the RTC lost power and you need to set the time, uncomment the following line and adjust the date and time.
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}

sensors.begin(); // Temperature sensor init

lcd.begin(16, 2); // Display size: 16 column és 2 row
lcd.begin(16, 2); // Display size: 16 column és 2 row
lcd.backlight(); // Backlight on

// ***********************
// Version information
// ***********************
lcd.setCursor(0, 0); // First row, first position
lcd.print(" Version: 1.1.0 ");

lcd.setCursor(0, 1); // Second row, first position
lcd.print("- Cloud Mentor -");
delay(2000); // Wait
lcd.clear(); // Clear screen

// ***********************
// Welcome message
// ***********************
lcd.setCursor(0, 0); // First row, first position
lcd.print("Welcome SIPP!");
lcd.print(" Welcome SIPP!");

lcd.setCursor(0, 1); // Second row, first position
lcd.print("Let's get party!");
delay(5000); // Wait
lcd.clear(); // Clear screen
}

void loop() {
//int randomNumber = random(10, 41); // Generate a random number between 10 and 40
//runCounter++;

// Temp sensor
sensors.requestTemperatures(); // Get temperature from sensor
float temperatureC = sensors.getTempCByIndex(0); // convert it to celsius

// Convert Celsius to Fahrenheit
float temperatureF = temperatureC * 9.0 / 5.0 + 32.0;
// Time module
char currentTime[20];
DateTime now = rtc.now();
sprintf(currentTime, "%02d:%02d:%02d (%02d-%02d)", now.hour(), now.minute(), now.second() ,now.month(), now.day());

String textOne = "Temp: ";
String rowOne = textOne + temperatureC;
String textTwo = "Temp: ";
String rowTwo = textTwo + temperatureF;
lcd.clear();
// ***********************
// First Row
// ***********************
lcd.setCursor(0, 0); // First row, first position
lcd.print(" "); // Clear row
lcd.setCursor(0, 0); // First row, first position
lcd.print(rowOne);
lcd.print(" "); // Print a space
lcd.print((char) 223); // º character
lcd.print("C"); // Celsius
lcd.print(currentTime);

// ***********************
// Second Row
// ***********************
String tempRow = " Temp: " + String(temperatureC, 1); // Limit to 1 decimal point
lcd.setCursor(0, 1); // Second row, first position
lcd.setCursor(0, 1); // Second row, first position
lcd.print(rowTwo);
lcd.print(tempRow);
lcd.print(" "); // Print a space
lcd.print((char) 223); // º character
lcd.print("F"); // Farenheit
delay(1000);

lcd.print("C"); // Celsius

// Wait before restart the sequence (250 ms)
delay(250);
}

0 comments on commit 42bb6f6

Please sign in to comment.