Mirko Pavleski
Published © GPL3+

Arduino Room Comfort Thermometer

This is a thermometer intended for measuring the temperature in the room where we are staying, also known as room comfort thermometer.

BeginnerFull instructions provided9,458
Arduino Room Comfort Thermometer

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
WS2812 Addressable LED Strip
Digilent WS2812 Addressable LED Strip
×1
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×1
Pushbutton Switch, Momentary
Pushbutton Switch, Momentary
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Schematic

Code

Code

C/C++
#include "Wire.h"    // imports the wire library for talking over I2C 
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Adafruit_NeoPixel.h>
#define ONE_WIRE_BUS 5

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);
 float Celcius=0;

 int buttonPin = 2;    // momentary push button on pin 0
    int oldButtonVal = 0;

#define NUM_PIXEL 50 
#define PIN 6 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_PIXEL, PIN, NEO_GRB + NEO_KHZ800); 




 int nPatterns = 3;
    int lightPattern = 1;
int out =0;
int t =0;

void setup() 
{
  Serial.begin(9600); //turn on serial monitor
strip.begin();
clearStrip();
strip.show();
strip.setBrightness(10);
pinMode(buttonPin, INPUT);
    digitalWrite(buttonPin, HIGH);  // button pin is HIGH, so it drops to 0 if pressed

sensors.begin();

}
void testing(){
  for(int L = 0; L<50; L++) { 
clearStrip();
    strip.setPixelColor(L,wheel(((205+(L*3)) & 255)));//Gradient from blue (cold) to green (ok) to red (warm), first value here 205 = start color, second value here 42 = end color
 strip.show();
delay(100);
}
for(int L = 49; L>=0; L--) { 
clearStrip();
    strip.setPixelColor(L,wheel(((205+(L*3)) & 255)));//Gradient from blue (cold) to green (ok) to red (warm), first value here 205 = start color, second value here 42 = end color

strip.show();
delay(100);
}
delay(1000);
}
void dot() {
   sensors.requestTemperatures(); 
   Celcius=sensors.getTempCByIndex(0)*2;
  
int t = map(Celcius, 20, 70, 0, NUM_PIXEL);

for(uint16_t L = 0; L<t; L++) { 
clearStrip();
strip.setPixelColor(L,wheel(((205+(L*3)) & 255))); //Gradient from blue (cold) to green (ok) to red (warm), first value here 205 = start color, second value here 42 = end color
} 
strip.show(); //Output on strip 
Serial.print("The Temperature is: ");
Serial.print(Celcius);

delay(1000); 
} 

void line() {
   sensors.requestTemperatures(); 
   Celcius=sensors.getTempCByIndex(0)*2;
  
int t = map(Celcius, 20, 70, 0, NUM_PIXEL);

for(uint16_t L = 0; L<t; L++) { 

strip.setPixelColor(L,wheel(((205+(L*3)) & 255))); //Gradient from blue (cold) to green (ok) to red (warm), first value here 205 = start color, second value here 42 = end color
} 
strip.show(); //Output on strip 
Serial.print("The Temperature is: ");
Serial.print(Celcius);

delay(1000); 
} 

void loop() {
  // read that stapressurete of the pushbutton value;
  int buttonVal = digitalRead(buttonPin);
  if (buttonVal == LOW && oldButtonVal == HIGH) {// button has just been pressed
    lightPattern = lightPattern + 1;
  }
  if (lightPattern > nPatterns) lightPattern = 1;
  oldButtonVal = buttonVal;
  
  switch(lightPattern) {
    case 1:
      dot();
      break;
    case 2:
   line();
      break;
      case 3:
      testing();
      break;
       }
}
//Color wheel ################################################################ 
uint32_t wheel(byte WheelPos) { 
if(WheelPos < 85) { 
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); 
} 
else if(WheelPos < 205) { 
WheelPos -= 85; 
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); 
} 
else { 
WheelPos -= 205; 
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); 
} 
} 
void clearStrip(){ 
for(int i = 0; i < NUM_PIXEL; i++) { 
strip.setPixelColor(i, 0); 
} 
}

Credits

Mirko Pavleski

Mirko Pavleski

117 projects • 1165 followers

Comments