-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from cloudsteak/init-temp-only
feat: Temperature measurement
- Loading branch information
Showing
2 changed files
with
155 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,87 @@ | ||
# arduino-djbooth-sensor | ||
DJ booth sensor with Arduino | ||
# DJ booth Sensor Project | ||
|
||
## 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. | ||
|
||
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. | ||
- **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. | ||
- **Jumper wires**: For connecting components to the Arduino. | ||
- **1599 EBK (170x86x35) Project Box**: Optional, for housing the components. | ||
|
||
## Prerequisites and Installation | ||
|
||
Project directory: ./djbooth_sensor | ||
|
||
### 1. Install Required Libraries: | ||
|
||
You need to install the following libraries using the Arduino IDE's Library Manager: | ||
|
||
- **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. | ||
|
||
To install these libraries: | ||
|
||
1. Open Arduino IDE. | ||
2. Go to **Sketch** -> **Include Library** -> **Manage Libraries**. | ||
3. Search for each of the required libraries and click **Install**. | ||
|
||
### 2. Hardware Connections: | ||
|
||
- **DS18B20** connections: | ||
|
||
- **VCC (Red)**: Connect to Arduino's **5V**. | ||
- **GND (Black)**: Connect to Arduino's **GND**. | ||
- **Data (Yellow)**: Connect to Arduino **D2**. Add a **4.7kΩ resistor** between the **VCC** and **Data** lines. | ||
|
||
- **16x2 LCD display** (I2C): | ||
- **VCC**: Connect to Arduino's **5V**. | ||
- **GND**: Connect to Arduino's **GND**. | ||
- **SDA**: Connect to Arduino's **A4**. | ||
- **SCL**: Connect to Arduino's **A5**. | ||
|
||
### 3. Code Upload: | ||
|
||
Once the hardware is connected and the libraries are installed: | ||
|
||
1. Open the **Arduino IDE**. | ||
2. Copy the provided code into the IDE. | ||
3. Select the correct board (`Arduino Nano`) and port under **Tools**. | ||
4. Upload the code to the Arduino. | ||
|
||
## 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: | ||
|
||
1. **Setup Phase**: | ||
|
||
- The temperature sensor is initialized. | ||
- The LCD is initialized and the backlight is turned on. | ||
- 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. | ||
|
||
2. **Main Loop**: | ||
- 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 code is designed to be flexible and could be easily extended to handle additional sensors or display features. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <OneWire.h> | ||
#include <DallasTemperature.h> | ||
#include <LiquidCrystal_I2C.h> | ||
#include <Wire.h> | ||
|
||
#define ONE_WIRE_BUS 2 // Data cable on D2 | ||
|
||
// I2C address, values 0x27 or 0x3F | ||
LiquidCrystal_I2C lcd(0x27, 16, 2); // 16x2 LCD display, I2C address: 0x27 or 0x3F | ||
|
||
|
||
// Temperature sensor | ||
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 | ||
sensors.begin(); // Temperature sensor init | ||
|
||
lcd.begin(16, 2); // Display size: 16 column és 2 row | ||
lcd.backlight(); // Backlight on | ||
lcd.setCursor(0, 0); // First row, first position | ||
lcd.print("Welcome SIPP!"); | ||
|
||
lcd.setCursor(0, 1); // Second row, first position | ||
lcd.print("Let's get party!"); | ||
delay(5000); // Wait | ||
} | ||
|
||
void loop() { | ||
//int randomNumber = random(10, 41); // Generate a random number between 10 and 40 | ||
//runCounter++; | ||
|
||
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; | ||
|
||
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 | ||
// *********************** | ||
// Second Row | ||
// *********************** | ||
lcd.setCursor(0, 1); // Second row, first position | ||
lcd.setCursor(0, 1); // Second row, first position | ||
lcd.print(rowTwo); | ||
lcd.print(" "); // Print a space | ||
lcd.print((char) 223); // º character | ||
lcd.print("F"); // Farenheit | ||
delay(1000); | ||
|
||
} |