George Kartsonas
Published

Automated Shower Boiler

Do you live in a country where you use solar energy to warm up the water? Well, how about we automate the process of the shower boiler.

IntermediateFull instructions provided1 hour6,687
Automated Shower Boiler

Things used in this project

Hardware components

SainSmart 2-Channel Relay Module
×1
Seeed Studio Grove Starter kit for Arduino&Genuino 101
×1
Arduino 101
Arduino 101
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Automated Shower Boiler Code

Arduino
#include <math.h>
#include <CurieBLE.h>
#include <Wire.h>
#include "rgb_lcd.h"

rgb_lcd lcd;

const int colorR = 255;
const int colorG = 0;
const int colorB = 0;
const int B = 4275;
const int R0 = 100000;
const int pinTempSensor = A3;
const int relayPin = 13; 
const int ledPin = 12;
int Greenled = 8;

BLEPeripheral blePeripheral; // create peripheral instance

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // create service

// create switch characteristic and allow remote device to read and write
BLECharCharacteristic switchChar("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(relayPin, OUTPUT); // use the relay on pin 13 as an output
  pinMode(ledPin, OUTPUT);
  pinMode(Greenled, OUTPUT);
  // set the local name peripheral advertises
  blePeripheral.setLocalName("LEDCB");
  // set the UUID for the service this peripheral advertises
  blePeripheral.setAdvertisedServiceUuid(ledService.uuid());

  // add service and characteristic
  blePeripheral.addAttribute(ledService);
  blePeripheral.addAttribute(switchChar);

  // assign event handlers for connected, disconnected to peripheral
  blePeripheral.setEventHandler(BLEConnected, blePeripheralConnectHandler);
  blePeripheral.setEventHandler(BLEDisconnected, blePeripheralDisconnectHandler);

  // assign event handlers for characteristic
  switchChar.setEventHandler(BLEWritten, switchCharacteristicWritten);
// set an initial value for the characteristic
  switchChar.setValue(0);

  // advertise the service
  blePeripheral.begin();
  Serial.println(("Bluetooth device active, waiting for connections..."));

// set up the LCD's number of columns and rows:
    lcd.begin(16, 1);
    
    lcd.setRGB(colorR, colorG, colorB);
    
    delay(1000);
}

void loop() {

    // poll peripheral
  blePeripheral.poll();

  // put your main code here, to run repeatedly:
      int a = analogRead(pinTempSensor);
      float R = 1023.0/((float)a)-1.0;
      R = 100000.0*R;

      float temperature=1.0/(log(R/100000.0)/B+1/298.15)-273.15;

       if (temperature < 20) {
    // turn LED on:
    digitalWrite(relayPin, HIGH);
    digitalWrite(Greenled, LOW);
  } else {
    // turn LED off:
    digitalWrite(relayPin, LOW);
    digitalWrite(Greenled, HIGH);
  }
      Serial.print("temperature= ");
      Serial.println(temperature);
      delay(1000);

    // Print a message to the LCD.
      lcd.print(" Temperature: ");
      lcd.print(temperature);
}

void blePeripheralConnectHandler(BLECentral& central) {
  // central connected event handler
  Serial.print("Connected event, central: ");
  Serial.println(central.address());
}

void blePeripheralDisconnectHandler(BLECentral& central) {
  // central disconnected event handler
  Serial.print("Disconnected event, central: ");
  Serial.println(central.address());
}

void switchCharacteristicWritten(BLECentral& central, BLECharacteristic& characteristic) {
  // central wrote new value to characteristic, update LED
  Serial.print("Characteristic event, written: ");

  if (switchChar.value()) {
    Serial.println("LED on");
    digitalWrite(ledPin, HIGH);
    digitalWrite(relayPin, HIGH);
  } else {
    Serial.println("LED off");
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  }
    // scroll 13 positions (string length) to the left
    // to move it offscreen left:
    for (int positionCounter = 0; positionCounter < 13; positionCounter++) {
        // scroll one position left:
        lcd.scrollDisplayLeft();
        // wait a bit:
        delay(100);
    }

    // scroll 29 positions (string length + display length) to the right
    // to move it offscreen right:
    for (int positionCounter = 0; positionCounter < 29; positionCounter++) {
        // scroll one position right:
        lcd.scrollDisplayRight();
        // wait a bit:
        delay(100);
    }

    // scroll 16 positions (display length + string length) to the left
    // to move it back to center:
    for (int positionCounter = 0; positionCounter < 16; positionCounter++) {
        // scroll one position left:
        lcd.scrollDisplayLeft();
        // wait a bit:
        delay(100);
    }

    // delay at the end of the full loop:
    delay(150);
}

Credits

George Kartsonas

George Kartsonas

19 projects • 46 followers

Comments