ESE527-Project Summary Report Srijani Dutta

Overview and Introduction

My project was to design a Smart Energy Home Management System which employs multiple sensors, adaptive controller, and actuators to various appliances one might manage in a home environment. This Smart System lets the user control the settings of various appliances in his home and after a brief period of time the system “learns” the user’s preferences and adapts the system accordingly and makes the system completely autonomous, still enabling the user to control the settings whenever he wants.

My system demonstrates a simple coffee maker and AC/Heater mechanism found in homes which the user operates at specific times during the day. These inputs are recorded over a set period of time and after that period, the system automates itself at those specific times.

2.   Project Design and Algorithms

Solution Concept The system uses microcontrollers which take in user input through various means. User input can be obtained through Serial monitor on the system or through switches. These inputs are timestamped to note the time of the input and these times are remembered by the MCU. After a certain period, the MCU goes into the automation loop which repeats this inputs at those times automatically. b) Design Review I have used 2 MCUs, the mbed and the Arduino to form my system. All programming has been done in Embedded C language.

I initially tried using the Serial Monitor to accept user input, but then realised that a serial.read()/serial.write() function is blocking, and does not let the other functionality of the code to happen if it keeps waiting for the user input. Hence, I went for a KeyPad input, where I attached my mbed MCU to a keypad, and used the * and # keys to signify the UP and DOWN arrow button on a heater or an AC for increasing or decreasing the temperature of the home. I also used a temperature sensor to determine the current room temperature and increased or decreased from that point on. The increments or decrements were done in steps of 0.5. The final temperature is stored in a variable which is updated every time. The Keypad was attached to the mbed using the mbed’s digital I/O pins. The keypad was continuously scanned in a while loop to keep track of the key press. The coffee maker is embedded with the Arduino. I have used an LED to glow on off to represent the coffee maker turning on or off.

The user wakes up and turns the coffee maker ON and increases the temperature of the Heater to a certain value. After a while, the user turns the coffee make OFF and turns down the heat before leaving for work. When he comes back from work, he turns the heat up a little and after a few hours turns it down before going to sleep.

Ideally, the user has to input for at least 4 weeks for the system to start adapting. But, I am estimating the system with 3 inputs at 4 times during the day. Also, each day is 24 hours, hence I shortened the day to 24 seconds, which represents one day. All inputs are given within this 24 second period.

At these 4 times, the user can switch the coffee maker ON/OFF and turn Heater up and down.

c)  Algorithm Review

The coffee maker switch is simple SPST switch which is connected to the digital input off the mbed. Whenever the switch is pressed the pin reads a HIGH and records it as ON and turns the LED ON. Whenever the switch is pressed a timer in the mbed is started to record the time of switch press. When the switch is closed the timer is turned off. The time recorded in the timer gives the duration of the ON time of the coffee maker. This is repeated as many times. Also, these timer values are stored in different time variables which are added on to get the total time. Then at the end of the 3 days, these total times are averaged over 3.

Similarly, after the coffee maker settings are changed the Heater up and down switches are pressed. Again, these are done within the 24 second period to ensure inputs within the day.

At the end of the 3 days, the program enters the automation loop to use the averaged values to switch the coffee maker ON/OFF and Heater Up and Down to the particular temperature at the particular times.

d) Code

MBED

include "mbed.h"

AnalogIn temp(p19); InterruptIn button(p5);

float tempC;

DigitalOut myled(LED1); Serial pc(USBTX,USBRX); DigitalOut row8(p21); DigitalOut row1(p22); DigitalOut row2(p23); DigitalOut row4(p24); DigitalIn col3(p25); DigitalIn col5(p26); DigitalIn col6(p27); DigitalIn col7(p28);

float usertemp; Ticker day; Timer t; int daycount = 1; int tempsetcount = 0; float timeset1; float timeset2; float timeset3; float timeset4; float tempval1; float tempval2; float tempval3; float tempval4; float timeset1avg = 0; float timeset2avg = 0; float timeset3avg = 0; float timeset4avg = 0; float tempval1avg = 0; float tempval2avg = 0; float tempval3avg = 0; float tempval4avg = 0;

void dayover(){ t.stop(); t.reset(); pc.printf("\n\rDAY %d", daycount); tempsetcount = 0; if(daycount<4){ timeset1avg += timeset1; timeset2avg += timeset2; timeset3avg += timeset3; timeset4avg += timeset4; tempval1avg += tempval1; tempval2avg += tempval2; tempval3avg += tempval3; tempval4avg += tempval4; } daycount++; t.start(); }

void key_press(){ row4 = 1; if(col3){ tempsetcount++; if(tempsetcount == 1) timeset1 = t.read(); if(tempsetcount == 3) timeset3 = t.read(); while(col3){ usertemp = usertemp + 0.2;
pc.printf("\n\r%.2f", usertemp); } if(usertemp>43) usertemp = 43; if(tempsetcount == 1){ tempval1 = usertemp; pc.printf("\n\rThe Temperature set is %.2f at time = %.2f",tempval1,timeset1); } if(tempsetcount == 3){ tempval3 = usertemp; pc.printf("\n\rThe Temperature set is %.2f at time = %.2f",tempval3,timeset3); } } if(col6){ tempsetcount++; if(tempsetcount == 2) timeset2 = t.read(); if(tempsetcount == 4) timeset4 = t.read(); while(col6){ usertemp = usertemp - 0.2;
pc.printf("\n\r%.2f", usertemp);
} if(usertemp<18) usertemp = 18; if(tempsetcount == 2){ tempval2 = usertemp; pc.printf("\n\rThe Temperature set is %.2f at time = %.2f",tempval2,timeset2); } if(tempsetcount == 4){ tempval4 = usertemp; pc.printf("\n\rThe Temperature set is %.2f at time = %.2f",tempval4,timeset4); } }

}

int main(){ usertemp = 30.0; day.attach(&dayover,24.0); t.reset(); t.start(); int initflag = 0; while(1){ while(daycount<4) { key_press();
} if(!initflag){ initflag = 1; timeset1avg /= 3; timeset2avg /= 3; timeset3avg /= 3; timeset4avg /= 3; tempval1avg /= 3; tempval2avg /= 3; tempval3avg /= 3; tempval4avg /= 3; pc.printf("\n\rON LEARNING FROM THREE DAYS: "); pc.printf("\n\rAt time = %.2f , the temperature set by the user was %.2f",timeset1avg,tempval1avg); pc.printf("\n\rAt time = %.2f , the temperature set by the user was %.2f",timeset2avg,tempval2avg); pc.printf("\n\rAt time = %.2f , the temperature set by the user was %.2f",timeset3avg,tempval3avg); pc.printf("\n\rAt time = %.2f , the temperature set by the user was %.2f",timeset4avg,tempval4avg); pc.printf("\n\n"); } if(tempsetcount == 0){ while(t.read()<timeset1avg){ tempC = (temp.read()*77)+5; tempsetcount = 1; } if(tempC<tempval1avg){ pc.printf("\n\rHeating to %.2f at time = %.2f",tempval1avg,t.read()); } else{ pc.printf("\n\rCooling to %.2f at time = %.2f",tempval1avg,t.read()); } } if(tempsetcount == 1){ while(t.read()<timeset2avg){ tempC = (temp.read()*77)+5; tempsetcount = 2; } if(tempC<tempval2avg ){ pc.printf("\n\rHeating to %.2f at time = %.2f",tempval2avg,t.read()); } else{ pc.printf("\n\rCooling to %.2f at time = %.2f",tempval2avg,t.read()); } } if(tempsetcount == 2){ while(t.read()<timeset3avg){ //pc.printf("2"); tempC = (temp.read()*77)+5; tempsetcount = 3; } if(tempC<tempval3avg){ pc.printf("\n\rHeating to %.2f at time = %.2f",tempval3avg,t.read()); } else{ pc.printf("\n\rCooling to %.2f at time = %.2f",tempval3avg,t.read()); } } if(tempsetcount == 3){ while(t.read()<timeset4avg){

            tempC = (temp.read()*77)+5;
            tempsetcount = 4;
        }
        if(tempC<tempval4avg){
            pc.printf("%d",tempsetcount);
            pc.printf("\n\rHeating to %.2f at time = %.2f",tempval4avg,t.read());
        }
        else{
            pc.printf("%d",tempsetcount);
            pc.printf("\n\rCooling to %.2f at time = %.2f",tempval4avg,t.read());

        }
    }
}

}

Arduino

int count; int oncount; int offcount; int flag; int onflag; int offflag; int initflag; int day; float coffeeonavg; float coffeeoffavg;

int coffeeflag;

ISR(TIMER1_OVF_vect) { flag = 1; }

ISR(TIMER1_COMPA_vect) { onflag++; }

ISR(TIMER1_COMPB_vect) { offflag++; }

void setup() { count = 0; flag = 0; onflag = -1; offflag = -1; initflag = 0; coffeeflag = 0; coffeeonavg = 0; coffeeoffavg = 0; oncount = 0; offcount = 0; day = 1; lcd.begin(16, 2); Serial.begin(9600);

pinMode(13,INPUT); pinMode(10,OUTPUT);

TCCR1A = 0; TCCR1B = 0; TCCR1B |= (1<<CS12) | (1<<CS10); TIMSK1 |= (1<<TOIE1); sei(); TCNT1 = 0;

sei(); }

void loop() { float temper; if(day<=3){ if(flag){ flag = 0; count++; if(count == 3){ day++; count = 0; Serial.write("DAY"); TCNT1 = 0; } sei(); } if(!digitalRead(13)){ if(!coffeeflag){ coffeeflag = 1; temper = 8*((float)TCNT1/65536); temper = (8*count)+temper; coffeeonavg += temper; Serial.print(coffeeonavg); } digitalWrite(10,HIGH); } else{ if(coffeeflag){ coffeeflag = 0; temper = 8*((float)TCNT1/65536); temper = (8*count)+temper; coffeeoffavg += temper; Serial.print(coffeeoffavg); } digitalWrite(10,LOW); }

}

else{ int tcount; if(!initflag){ initflag = 1; TIMSK1 |= (1<<OCIE1A); TIMSK1 |= (1<<OCIE1B); coffeeonavg = coffeeonavg/3; coffeeoffavg = coffeeoffavg/3; oncount = coffeeonavg/8; offcount = coffeeoffavg/8; Serial.print(coffeeonavg); Serial.print(coffeeoffavg); float temp = coffeeonavg - (8*oncount); OCR1A = temp*65536/8;
temp = coffeeoffavg - (8*offcount); OCR1B = temp*65536/8; TCNT1 = 0; } if(flag){ flag = 0; count++; if(count == 3){ day++; count = 0; onflag = -1; offflag = -1; Serial.write("DAY"); } TCNT1 = 0; sei(); } if((onflag == oncount)&&(coffeeonavg != coffeeoffavg)){ digitalWrite(10,HIGH); } if((offflag == offcount)&&(coffeeonavg != coffeeoffavg)){ digitalWrite(10,LOW); } } }

e) Data Management

Data like the temperature value, and the times are stored in integer variables.

  1. Design Implementation

Hardware Configuration Arduino Uno connected with the serial cable to the computer system. The digital input pin is used to connect to the switch. The 5V Vout of the Arduino is given to breadboard as the power supply. The output is shown on the serial monitor, as the end of day and duration of ON and OFF of the coffee maker. An LED is connected to another digital output pin to enable glowing ON and OFF. The LED is connected with 1K ohms limiting resistor.

The Keypad is connected to the mbed using its digital input output pins. The columns are made inputs and the rows are made output.

We use only the * and # keys hence access only row 4 and columns 3 and 6.

The temperature sensor LM34 is connected to an analog input of the mbed. The values of temperature are obtained by a simple line of code : tempC = (temp.read()*77)+5; Where temp.read() reads the analog voltage from the input.

All outputs are shown on the serial monitor. After 3 days, the system starts automating, comparing the room temperature value and deciding whether to heat/cool.

b) Software Configuration The programming of the MCUs are done in Embedded C language. Arduino has its own IDE for compiling code and burning it in the MCU.The mbed uses an online compiler at mbed.org.

All the processing is done in the code. Please refer to the code section.

c) Testing and Results The user inputs 4 times for 3 days, so within 24 seconds, user inputs 4 times. The output is displayed on the monitor and the LED glows ON/OFF.

  1. Sensitivity Analysis When the room temperature is varied, the cooling and heating outputs change accordingly. Once the system is automated, it runs forever. If the day period is increased, then the outputs are spread out.

Built With

  • actuator
  • mcu
  • sensor
Share this project:

Updates