OLED and Digital Temperature Sensor(DS18B20) With Arduino.
In the previous section, we interfaced OLED with Arduino and Digital Temperature Sensor (DS18B20) with Arduino separately. Now we are going to merge them together to make a temperature measuring device powered by a standard 5 Volt power supply or a power bank.
Items required:
In the previous section, we interfaced OLED with Arduino and Digital Temperature Sensor (DS18B20) with Arduino separately. Now we are going to merge them together to make a temperature measuring device powered by a standard 5 Volt power supply or a power bank.
Items required:
- Arduino Nano
- OLED Display
- Digital Temperature Sensor (DS18B20)
- Vero Board
- Female Header
- Terminal Block
- 4.7k Resistance
- Jumper Wire
Circuit Diagram:
Video Example:
Software:
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
/* | |
# This sample codes is for measuring Temperature | |
# Editor : ProjectHub | |
# Date : 23.01.2020 | |
# Ver : 1.0 | |
# Product: High Temperature Meter | |
*/ | |
#include <SPI.h> | |
#include <Wire.h> | |
#include <OneWire.h> | |
#include <DallasTemperature.h> | |
#include <Adafruit_GFX.h> | |
#include <Adafruit_SSD1306.h> | |
#define OLED_RESET 4 | |
#define SCREEN_WIDTH 128 | |
#define SCREEN_HEIGHT 64 | |
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); | |
#define ONE_WIRE_BUS 2 | |
OneWire oneWire(ONE_WIRE_BUS); | |
DallasTemperature sensors(&oneWire); | |
void setup() { | |
Serial.begin(9600); | |
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64 | |
Serial.println(F("SSD1306 allocation failed")); | |
for(;;);} | |
display.clearDisplay(); | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
display.setCursor(28, 0); | |
display.println(F("Project Hub")); | |
display.display(); | |
pinMode(LED_BUILTIN, OUTPUT); | |
sensors.begin(); | |
} | |
void loop() { | |
sensors.requestTemperatures(); | |
float data = sensors.getTempCByIndex(0); | |
Serial.print(data); | |
display.clearDisplay(); | |
display.setTextSize(1); | |
display.setTextColor(WHITE); | |
display.setCursor(28, 0); | |
display.println(F("Project Hub")); | |
display.println(F("")); | |
display.println(F("")); | |
display.setTextSize(3); | |
display.print(data); | |
display.setTextSize(1); | |
display.print(F("O")); | |
display.setTextSize(3); | |
display.print(F("C")); | |
display.display(); | |
delay(1000); | |
} |
No comments:
Post a Comment