Tamer Savaşcı
Published © GPL3+

Programmable Wireless Room Thermostat (Bluetooth Accessible)

Wireless room thermostat with LCD screen. Two Arduinos, Pro Mini is master, Uno is slave. Now with Bluetooth accessible.

IntermediateFull instructions provided5 hours11,626
Programmable Wireless Room Thermostat (Bluetooth Accessible)

Things used in this project

Story

Read more

Schematics

Wireless Room Thermostat (Master part code) Transmitter

it is for Transmitter

Wireless Room Thermostat (Slave part code) Reciever

it is for receiver

Code

Wireless Room Thermostat (Slave part code) Reciever

Arduino
This code for slave part (receiver)
//   WIRELESS ROOM THERMOSTAT v1.0 (RECEIVER)
//
//  Writer: Tamer Savaşcı
//  Date: 27.01.2017
//
//  email: tsavasci@yahoo.com


#include <SPI.h>
#include <nRF24L01p.h>
#include <virtuabotixRTC.h>
#include <SoftwareSerial.h>
SoftwareSerial bluetoothModule(A0, A1);
/* Arduino  ->  Bluetooth module
  A0 (Rx)   ->  Tx
  A1 (Tx)   ->  Rx
*/

nRF24L01p receiver(7, 8);            // CSN = 7, CE = 8
virtuabotixRTC myRTC(5, 4, 3);    // SCLK = 5, I/O(DAT) = 4, CE = 3

int relay = 2;
float set_temp;
float room_temp;
char BT_readChar;
int relay_status = 0;
int BT_Force = 0;

void BT ()
{
  BT_readChar = bluetoothModule.read();
  switch (BT_readChar)
  {
    case 'a':
      BT_Force = 1;
      digitalWrite(relay, HIGH);
      relay_status = 1;
      Serial.println("Forced mode: on");
      bluetoothModule.println("Forced mode: on");
      break;

    case 'b':
      BT_Force = 0;
      Serial.println("Combi is waiting RF command by Bluetooth command");
      bluetoothModule.println("Combi is waiting RF command by Bluetooth command");
      break;
  }
}

void time_function()
{
  myRTC.updateTime();
  Serial.print("Date / Time : ");
  Serial.print(myRTC.dayofmonth);
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
  Serial.print("(");
  Serial.print(myRTC.dayofweek);
  Serial.print(")");
  Serial.print(" ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
  delay(3000);
}

void RF()
{
  while (receiver.available())         // while receiver active
  {
    receiver.read();
    receiver.rxPL(room_temp);           // read receiver
    digitalRead(BT_Force);
    if (BT_Force == 0)
    {
      if (set_temp > room_temp)             // if "set_temp" value bigger than "room temp"
      {
        digitalWrite(relay, HIGH);      // trigger the relay
        relay_status = 1;
        Serial.println("Combi opened due to RF temp data"); // Combi is ON
        Serial.println();
        bluetoothModule.println("Combi opened due to RF temp data");
        bluetoothModule.println();
        digitalRead(BT_Force);
      }
      else                             // otherwise cut the power of relay
      {
        digitalWrite(relay, LOW);
        relay_status = 0;
        Serial.println("Combi closed due to RF temp data"); // combi is OFF
        Serial.println();
        bluetoothModule.println("Combi closed due to RF temp data");
        bluetoothModule.println();
        digitalRead(BT_Force);
      }
    }
    else
    {
      Serial.println("Combi is working in forced mode by Bluetooth command");
      bluetoothModule.println("Combi is working in forced mode by Bluetooth command");
    }
  }
}

void seri()
{
  Serial.print("set_temp: ");
  Serial.println(set_temp);
  Serial.print("Room temp: ");
  Serial.println(room_temp);
  Serial.print("BT Forced status: ");
  Serial.println(BT_Force);
  Serial.println ();
}

void BT_info()
{
  bluetoothModule.print("set_temp: ");
  bluetoothModule.println(set_temp);
  bluetoothModule.print("Room temp: ");
  bluetoothModule.println(room_temp);
  bluetoothModule.println();
  if (relay_status < 1)
  {
    bluetoothModule.println("Combi:On");
    bluetoothModule.println ();
  }
  else
  {
    bluetoothModule.println("Combi:Off");
    bluetoothModule.println ();
  }
}

void setup()
{
  bluetoothModule.begin(9600);
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  receiver.channel(90);
  receiver.RXaddress("Tamer");
  receiver.init();
  pinMode (2, OUTPUT);
  //myRTC.set_tempDS1302Time(00, 19, 01, 04, 9, 03, 2017);  // This line is for the first upload to arduino than deactive it with (//)
}

void loop()
{
  time_function();
  while (myRTC.dayofweek < 6)
  {
    while (myRTC.hours < 6)
    {
      time_function();
      set_temp = 19;                        // set_temp combi to 19
      Serial.println("Weekdays");
      Serial.println("Gece Modu");
      seri();
      bluetoothModule.println("Weekdays");
      bluetoothModule.println("Gece Modu");
      BT_info();
      RF();
      BT();
    }
    while (myRTC.hours < 8)
    {
      time_function();
      set_temp = 22;
      Serial.println("Weekdays");
      Serial.println("Uyanis Modu");
      seri();
      bluetoothModule.println("Weekdays");
      bluetoothModule.println("Uyanis Modu");
      BT_info();
      RF();
      BT();
    }
    while (myRTC.hours < 17)
    {
      time_function();
      set_temp = 19;
      Serial.println("Weekdays");
      Serial.println("Home is empty");
      seri();
      bluetoothModule.println("Weekdays");
      bluetoothModule.println("Home is empty");
      BT_info();
      RF();
      BT();
    }
    while (myRTC.hours >= 17)
    {
      time_function();
      set_temp = 22;
      Serial.println("Weekdays");
      Serial.println("People in the house");
      seri();
      bluetoothModule.println("Weekdays");
      bluetoothModule.println("People in the house");
      BT_info();
      RF();
      BT();
    }
  }
  while (myRTC.dayofweek < 8)
  {
    while (myRTC.hours <= 7)
    {
      time_function();
      set_temp = 19;
      Serial.println("Weekend");
      Serial.println("Gece Modu");
      seri();
      bluetoothModule.println("Weekend");
      bluetoothModule.println("Gece Modu");
      BT_info();
      RF();
      BT();
    }
    while (myRTC.hours > 7)
    {
      time_function();
      set_temp = 22;
      Serial.println("Weekend");
      Serial.println("People in the house");
      seri();
      bluetoothModule.println("Weekend");
      bluetoothModule.println("People in the house");
      BT_info();
      RF();
      BT();
    }
  }
}

Wireless Room Thermostat (Master part code) Transmitter

Arduino
This code for the transmitter.
//   WIRELESS ROOM THERMOSTAT v1.0 (TRANSMITTER)
//   
//  Writer: Tamer Savaşcı
//  Date: 27.01.2017
// 
//  
//  email: tsavasci@yahoo.com



#include <dht11.h>                              // dht11 library
#define DHT11PIN 2                              // DHT11PIN is digital 2
#include <SPI.h>                                // SPI library
#include <nRF24L01p.h>                          // nRF24 library
#include <LiquidCrystal.h>                      // LCD library
LiquidCrystal lcd(3, 4, 5, 6, 10, A0);          // LCD pins
nRF24L01p verici(7, 8);                         // CSN = 7, CE = 8 for nRF24
float sicaklik;                                 // creating sending messsage int
dht11 DHT11;                                    // DHT11 begin

void setup()
{
  Serial.begin(9600);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);                    // SPI begin
  verici.channel(90);
  verici.TXaddress("Tamer");                    // unique name for the com channel
  verici.init();                                // transmitter begin
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
}

void loop()
{
  int chk = DHT11.read(DHT11PIN);               // chk int. İf its 0 its ok
  Serial.println();
  Serial.print("Nem (%): ");
  Serial.println((float)DHT11.humidity, 2);     // humidity
  Serial.print("Sicaklik (Celcius): ");
  Serial.println((float)DHT11.temperature, 2);  // Temp 
  Serial.println(chk);                          // DHT11 check
  sicaklik = DHT11.temperature, 2;              // define the sending message
  verici.txPL(sicaklik);                        // message for the nRF24
  boolean gonderimDurumu = verici.send(FAST);   // Com. status check

  if (gonderimDurumu == true)                   // if com. fails it will false
  {
    Serial.println("mesaji gonderildi");        // Debugging 
    
    lcd.clear();                                // LCD clear
    lcd.setCursor(0, 0);                        // setting LCD cursor position
    lcd.print("Gonderildi..");                  // com status writing to LCD 
    lcd.setCursor(0, 1);                        
    lcd.print(chk);                             // DHT11 chk value for debugging 
    delay(3000);                                // wait 3 seconds 
    lcd.clear();                                
    lcd.setCursor(0, 0);                        
    lcd.print("Nem %   : ");                    
    lcd.print((float)DHT11.humidity);
    lcd.setCursor(0, 1);                        
    lcd.print("Sicaklik: ");                    
    lcd.print((float)DHT11.temperature);
  }
  else
  {
    Serial.println("mesaji gonderilemedi");
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Gonderilemedi.");
    lcd.setCursor(0, 1);
    lcd.print(chk);
    delay(3000);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Nem %   : ");
    lcd.print((float)DHT11.humidity);
    lcd.setCursor(0, 1);
    lcd.print("Sicaklik: ");
    lcd.print((float)DHT11.temperature);
  }
  delay(180000);                              // wait for 3 min
}

Credits

Tamer Savaşcı

Tamer Savaşcı

3 projects • 17 followers
Curious chemist..

Comments