The aim of this project is to make a thermostat which can work according to 3 temperatures, selected through 3 button presses .
Button 1 for 30 degrees Celsius
Button 2 for 37 degrees C
Button 3 for 45 deg C
The other objective is , to display both the CURRENT temperature and the SET temperature on OLED display.
I am using Dallas instruments 18b20 temperature sensor, and i2c OLED display, with arduino UNO CH340 version. In my opinion any arduino will work as it is a simple circuit diagramwith simple piece of code running.
I have shared arduino code for this thermostat below.
And the youtube video ,too.
My programing skills are novice.
I hope the libraries i uses, for OLED display, ONE WIRE, DALAS TEMPERATURE SENSOR, ADAFRUIT GFX LIB, all are easily available through ARRDUINO IDE.
any questions , feel free to ask.
GOT A better code? please share with me, specially code to get same working using one SWITCH (used as toggle switch).#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);
#define SSD1306_LCDHEIGHT 64 // OLED display drivers end here
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into port 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire); //Temperature Sensor Drivers End here
int tempset = 0;
int relay = 7;
int b1 = 9;
int b2 = 10;
int b3 = 11;
int t1;
int t2;
int t3;
void setup() {
pinMode(b1, INPUT); //Button 1 with internal pull up
pinMode(b2, INPUT); //Button 2 with internal pull up
pinMode(b3, INPUT); //Button 3 with internal pull up
pinMode(relay, OUTPUT);
Serial.begin(9600);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay(); //till here is OLED i2c serial communication on 0x3c
sensors.begin();// Start up the dallas temperature sensor
display.setCursor(29, 8);
display.setTextSize(1);
display.print("Temperature");
display.setCursor(0, 16);
display.setTextSize(1);
display.print("CURRENT");
display.setTextSize(1);
display.setCursor(85, 16);
display.setTextSize(1);
display.print("SET");
display.setTextSize(1);
display.display();
}
void loop() {
sensors.requestTemperatures(); // Send the command to get temperatures
display.setCursor(4, 24);
display.println(sensors.getTempCByIndex(0));
display.setCursor(85, 24);
display.println(tempset);
display.display();
t1 = digitalRead(b1);
if (t1 == HIGH )
{
tempset = 30;
}
t2 = digitalRead(b2);
if (t2 == HIGH )
{
tempset = 37;
}
t3 = digitalRead(b3);
if (t3 == HIGH )
{
tempset = 45;
}
if (sensors.getTempCByIndex(0) >= tempset)
{
digitalWrite(relay, HIGH); //HIGH turn off relay
}
else
{
digitalWrite(relay, LOW);
}
}
No comments:
Post a Comment