Dennis Davis
Published © LGPL

Bathroom temperature and humid sensor

Temperature and humidity sensor that tell you the temperature and humidity to help you take shorter showers and to stop mold from growing.

BeginnerFull instructions provided24 hours100
Bathroom temperature and humid sensor

Things used in this project

Hardware components

0.96" OLED 64x128 Display Module
ElectroPeak 0.96" OLED 64x128 Display Module
×1
Gravity: I2C BME280 Environmental Sensor
DFRobot Gravity: I2C BME280 Environmental Sensor
×1
Buzzer
Buzzer
×1
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Arduino water sensor
×1

Story

Read more

Schematics

bredBord

showing what I have used to create this project.

Schematics of the breadbord

Schematics of the breadbord

Code

Water sensor with BME, OLED, and buzzer

C/C++
turning on and off the water sensor that will also turn on the BME280 and buzzer.
#include<math.h>
#include<SPI.h>
#include<Wire.h>
#include<Adafruit_GFX.h>
#include<Adafruit_SSD1306.h>
#include<Adafruit_BME280.h>
#include<wemo.h>
#include<Ethernet.h>
#include<mac.h>
#include<hue.h>
int SCREEN_WIDTH = 128;
int SCREEN_HIGHT = 64;
int SCREEN_ADDRESS = 0x3c;
int OLED_RESET = 4;
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HIGHT, &Wire, OLED_RESET);
Adafruit_BME280 bme;
float tempC;
float tempF;
float pressPA;
float humidRH;
const char degree = 0xF8;
bool status;
int hexAddress = 0x76;
int water = 0;
const int button1 = 22;
int sensor = 23;
int sensorPin = 21;
bool buttonState;
int oldButton;
int pushButton;
int onOff;
//int clk = 20;
//int dio = 19;
//TM1637 tm1637(clk,dio);
int led = 3;
bool ledState = false;
int redled = 5;
int mic = 14;
int DBlevel;
int lastTime;
int currentTime;
int buzzer = 6;
bool buzzerState = false;
int theTime;
int wemoNum;
int HueColor;


void setup() {
  Serial.begin(9600);
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.printf("SSD1306 allocation failed");
  }

  status = bme.begin(hexAddress);
  if (status == false) {
    Serial.printf("BME280 at address 0x%02X failed to start", hexAddress);
  }

  Ethernet.begin(mac);
  wemoNum = 1;
  switchON(wemoNum);

  display.display();
  delay(2000);
  display.clearDisplay();
  pinMode(button1, INPUT);
  digitalWrite(sensor, OUTPUT);
  pinMode(sensorPin, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(redled, OUTPUT);
  digitalWrite(led, LOW);
  digitalWrite(redled, LOW);
  pinMode(mic, INPUT);
  pinMode(buzzer, OUTPUT);
}

void loop() {
  testdrawstyles();
  tempC = bme.readTemperature();
  pressPA = bme.readPressure();
  humidRH = bme.readHumidity();

  tempF = tempC * (9.0 / 5.0) + 32.2;

  currentTime = millis();

  DBlevel = analogRead(mic);
  Serial.printf("DBlevel:%i\n", DBlevel);


  water = analogRead(sensor);
  buttonState = digitalRead(button1);
  if (buttonState != oldButton) {
    if (buttonState == true) {
      onOff = !onOff;
    } else {
      oldButton = buttonState;
    }
  }


  if (onOff == true) {
    digitalWrite(sensorPin, HIGH);
  } else {
    digitalWrite(sensorPin, LOW);
  }
  analogRead(water);
  if (water > 100) {
    ledState = true;
    digitalWrite(led, HIGH);
  } else {
    ledState = false;
    digitalWrite(led, LOW);
  }


}

void testdrawstyles(void) {
  currentTime = millis();
  display.clearDisplay();

  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.printf("Temp:%0.1f%c\nwater sensor:%i\nhumid:%0.2f", tempF, degree, water, humidRH);
  display.display();


  if (humidRH > 45 && tempF > 81 && ledState == true) {
    digitalWrite(redled, HIGH);
    if (buzzerState) {
      digitalWrite(buzzerState, true);
    } else {
      digitalWrite(redled, LOW);
      digitalWrite(buzzerState, false);
    }
    if ((currentTime - lastTime) > theTime) {
      buzzerState = !buzzerState;
      if (buzzerState) {
        digitalWrite(buzzer, HIGH);
        theTime = 35;
      } else {
        digitalWrite(buzzer, LOW);
        theTime = 3000;
      }
      lastTime = millis();
    }

  }
  if (humidRH > 55 && ledState == true) {
    switchON(wemoNum);
  } else {
    switchOFF(wemoNum);
  }

  HueColor = map(tempF, 45, 100, 45000, 0);

  if (ledState == true) {
    setHue(2, true, HueColor, 255, 255);
  } else {
    setHue(2, false, 0, 0, 0);
  }

}

Credits

Dennis Davis

Dennis Davis

3 projects • 8 followers

Comments