Jon Phillips
Published © MIT

Smartroom controller

Control heat, air, and lighting without ever getting up from the couch.

IntermediateWork in progress116
Smartroom controller

Things used in this project

Hardware components

Photon 2
Particle Photon 2
×1
Rotary Encoder with Push-Button
Rotary Encoder with Push-Button
×1
Switch Actuator, Head for spring return push-button
Switch Actuator, Head for spring return push-button
×2
Adafruit Monochrome 1.3" 128x64 OLED graphic display
×1
Flora RGB Neopixel LEDs- Pack of 4
Adafruit Flora RGB Neopixel LEDs- Pack of 4
×1
Humidity and Temperature Sensor
Adafruit Humidity and Temperature Sensor
×1
Buzzer
Buzzer
×1
Slide Switch
Slide Switch
×1
Rechargeable Battery, 3.7 V
Rechargeable Battery, 3.7 V
×1

Hand tools and fabrication machines

Bambu lab 3D printer
Soldering Station, Hobbyist
Soldering Station, Hobbyist
Epilog laser engraver and cutter
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Voltometer

Story

Read more

Custom parts and enclosures

Enclosure for Smart Room controller

Schematics

Smart Room Controller

Code

Smart Room Controller

C/C++
/* 
 * Project Smart Room Controller
 * Author: Jon Phillips
 * Date: 28 Oct 2023
 */

#include "Particle.h"
#include <IoTClassroom_CNM.h>
#include <Encoder.h>
#include <neopixel.h>
#include <colors.h>
#include <Adafruit_BME280.h>
#include <Adafruit_SSD1306.h>
#include <hue.h>




SYSTEM_MODE(MANUAL);



const int PIXELCOUNT = 2;
Adafruit_NeoPixel pixel(PIXELCOUNT, SPI1, WS2812B);
Adafruit_BME280 bme;

Adafruit_SSD1306 display(-1);

Encoder enCoder(D8,D9);

int tempC;
int tempF;
int bmeStatus;
int encRead;
int thermoStat;
int thermoSet;
int fanOn;
int heatOn;
int i;
int currTime;
int prevTime;
int bulbState;
int counterCool;
int counterHeat;
float t;
char degree = 0xF8;
bool heat;
bool cool;
bool lftIsclicked;
bool rtIsclicked;
bool encIsclicked;
bool lftIson;
const int BUZZER = D13;
const int wemoHeat=5;
const int wemoCool=3;
unsigned int lastTone;
Button leftButton (D3); 
Button rightButton (D4);
Button encButton (D15);


void setup() {
    

    Serial.begin(9600);
    waitFor(Serial.isConnected,5000);

    WiFi.on();
    WiFi.clearCredentials();
    WiFi.setCredentials("IoTNetwork");

    WiFi.connect();
    while(WiFi.connecting()){
        Serial.printf(".");
    }
    Serial.printf("\n\n");

    pinMode(BUZZER,OUTPUT);

    pixel.begin();
    pixel.show();
    pixel.setBrightness(60);

    bmeStatus = bme.begin(0x76);
    if (bmeStatus == false){
        Serial.print("BME failed to start");
    }
    delay(5000);
    
    display.begin(SSD1306_SWITCHCAPVCC,0x3C);
    display.setTextColor(WHITE);
    display.clearDisplay();


}


void loop() {

currTime = millis();
tempC = bme.readTemperature();
tempF = (tempC*9/5+32);
encRead = enCoder.read();
thermoSet = map(encRead,0,96,60,100);
cool = false;
heat = false;
fanOn = thermoSet+3;
heatOn = thermoSet-3;
pixel.clear();
noTone(BUZZER);

if(tempF<heatOn){
    heat = true;
}

if(tempF>fanOn){
    cool = true;
}

if(encRead<0){
    enCoder.write(0);
    encRead = 0;
}
if(encRead>96){
    enCoder.write(96);
    encRead = 96;
}

if(heat){
    wemoWrite(wemoHeat,HIGH);
    pixel.setPixelColor(0,red);
    pixel.show();
    
}

if(heat){
    counterHeat++;
}
  else{
    counterHeat = 0;
}
if(counterHeat == 1){
    tone(BUZZER, 3300,1000);
   
}    

if(cool){
    wemoWrite(wemoCool,HIGH);
    pixel.setPixelColor(1,blue);
    pixel.show();
}
if(cool){
    counterCool++;
  }
  else{
    counterCool = 0;
  }
if(counterCool == 1){
    tone(BUZZER, 3300,1000);
   
  }

if (cool==false && heat==false){
    wemoWrite(wemoCool,LOW);
    wemoWrite(wemoHeat,LOW);
    pixel.clear();
    pixel.show();
    noTone(BUZZER);
}
   
display.setTextSize(2);
display.printf("Room Temp\n");
display.setTextSize(3);
display.printf("%i%cF\n",tempF,degree);
display.setTextSize(1);
display.printf("Target Temp = %i%cF",thermoSet,degree);
display.display();
display.clearDisplay();
display.setCursor(0,0);

if(leftButton.isClicked()){
    lftIsclicked = !lftIsclicked;     
    Serial.printf("left button %i\n",lftIsclicked);
}


 if(rightButton.isClicked()){
    rtIsclicked = !rtIsclicked;
    Serial.printf("right button %i\n",rtIsclicked);
}


if(lftIsclicked){
    if(rtIsclicked){
       
          setHue(4,true,HueRed,50,255);
        
    }

    else{
        
        setHue(4,true,255,100,0.33);
        

    } 
         
}

else{
    
    setHue(4,false);
    
}

Credits

Jon Phillips

Jon Phillips

4 projects • 5 followers
Recently graduated a full time Deep Dive IoT bootcamp and interested in starting a career in robotics. Also pursing a degree in Comp Prog.

Comments