Chandler ScovernBenJWilliam L
Published © GPL3+

Temperature, Light, and Noise Detection System

Be lazy with this full complete monitoring system which allows you to check activities in various rooms while you're not there.

IntermediateFull instructions provided3 hours340
Temperature, Light, and Noise Detection System

Things used in this project

Hardware components

Breadboard (generic)
Breadboard (generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Photon
Particle Photon
×3
Tactile Switch, SPST-NO
Tactile Switch, SPST-NO
×1
DHT11 Temperature & Humidity Sensor (3 pins)
DHT11 Temperature & Humidity Sensor (3 pins)
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
Resistor 47.5k ohm
Resistor 47.5k ohm
×2
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
ELEGOO 37-in-1 Sensor Module Kit V1.0
ELEGOO 37-in-1 Sensor Module Kit V1.0
Needed Components: Ky-028 Module, Ky-030 Module, Ky-018 Module
×1

Software apps and online services

Visual Studio 2017
Microsoft Visual Studio 2017

Story

Read more

Schematics

DHT and Microphone Wiring

LCD display module

Thermistor and light sensor module

Code

DHT and microphone module code

C/C++
/* 
 * IOT Project 
 * Author: Ben Janke
 * Date: November 22, 2023
 */

// Include Particle Device OS APIs
#include "Particle.h"
#include "Adafruit_Sensor.h"
#include "DHT.h"
#include "DHT_U.h"


SYSTEM_MODE(AUTOMATIC);

SYSTEM_THREAD(ENABLED);

SerialLogHandler logHandler(LOG_LEVEL_INFO);

//Define Pins
int humiditySensor = A2;
int microphone = A5;
//Set Time Delay in Seconds
int timeDelay = 80;

//Setup DHT
DHT dht(humiditySensor, DHT11);

void publishData() {
  int temp = dht.readTemperature();
  delay(1000);
  int humidity = dht.readHumidity(true);
  delay(1000);
  if (humidity > 0) {
    Particle.publish("Humidity1",  String(humidity));
  }
  if (temp > 0) {
    Particle.publish("Temperature1", String(temp));
  }
  delay(1000);
  if (digitalRead(microphone) == HIGH) {
    Particle.publish("Microphone", String(1));
  }
  else {
    Particle.publish("Microphone", String(0));
  }
}
void call(const char *eventName, const char *data) {
  publishData();
}
void setup() {
  dht.begin();
  pinMode(humiditySensor, INPUT);
  pinMode(microphone, INPUT);
  Particle.subscribe("device1Call", call);
}

void loop() {
  delay(1000*timeDelay);
  publishData();
}

LCD display module

C/C++
/* 
 * IOT Project
 * Author: Ben Janke
 * Date: 12/2/2023
 */

// Include Particle Device OS APIs
#include "Particle.h"
#include "LiquidCrystal.h"

SYSTEM_MODE(AUTOMATIC);

SYSTEM_THREAD(ENABLED);

//Define Pins
int buttonOne = D10;
int buttonTwo = D6;
LiquidCrystal lcd(D0, D1, D2, D3, D4, D5);

int selectedDevice = 1;
int selectedMode = 1;
bool isButtonOnePressed = false;
bool isButtonTwoPressed = false;

int lastTemp = 22;
int lastHumidity = 22;
int lastNoise = 4444;

int lastTemp2 = 333;
int lastLight = 4444;

SerialLogHandler logHandler(LOG_LEVEL_INFO);

void changeLCDData(int mode, int device) {
  lcd.clear();
  lcd.setCursor(0, 1);
  lcd.print(String(mode) + " " + String(device));
  if (device == 1) {
    if (mode == 1) {
      lcd.setCursor(0, 0);
      lcd.print(lastTemp2);
      lcd.print(" Celsius"); 
    }
    else {
      lcd.setCursor(0, 0);
      if (lastLight == 0) {
        lcd.print("No");
      }
      else if (lastLight == 1) {
        lcd.print("Low");
      }
      else {
        lcd.print("High");
      }
      lcd.print( " light level");
    }
  }
  else if (device ==2){
    if (mode == 1) {
      lcd.setCursor(0, 0);
      lcd.print(lastTemp);
      lcd.print(" Celsius");
    }
    else {
      lcd.setCursor(0, 0);
      if (lastNoise == 0) {
        lcd.print("Quiet");
      }
      else {
        lcd.print("Noisy");
      }
    }
  }
}
void recieveTemperature1(const char *event, const char *data) {
  lastTemp = atoi(data);
  changeLCDData(selectedMode, selectedDevice);
}
void recieveMicrophone(const char *event, const char *data) {
  lastNoise = atoi(data);
  changeLCDData(selectedMode, selectedDevice);
}
void recieveLight(const char *event, const char *data) {
  lastLight = atoi(data);
  changeLCDData(selectedMode, selectedDevice);
}
void recieveTemperature2(const char *event, const char *data) {
  lastTemp2 = atoi(data);
  changeLCDData(selectedMode, selectedDevice);
}

//Setup subscribe events
void setup() {
 pinMode(buttonOne, INPUT);
 pinMode(buttonTwo, INPUT);
 Particle.subscribe("Temperature1", recieveTemperature1);
 Particle.subscribe("Microphone", recieveMicrophone);
 Particle.subscribe("LightReading", recieveLight);
 Particle.subscribe("TempReading2", recieveTemperature2);
 lcd.begin(16,2);
}

void loop() {
  delay(1000);
  if (digitalRead(buttonOne)== HIGH && isButtonOnePressed == false) {
    isButtonOnePressed = true;
    if (selectedDevice == 1) {
      selectedDevice = 2;
      Particle.publish("device2Call");
    }
    else {
      selectedDevice = 1;
      Particle.publish("device1Call");
    }
    changeLCDData(selectedMode, selectedDevice);
  }
  else if (digitalRead(buttonOne) == LOW) {
    isButtonOnePressed = false;
  }
  if (digitalRead(buttonTwo) == HIGH && isButtonTwoPressed == false) {
    isButtonTwoPressed = true;
    if (selectedDevice == 1) {
      Particle.publish("device1Call");
      if (selectedMode == 1) {
        selectedMode = 2;
      }
      else {
        selectedMode = 1;
      }
    }
    if (selectedDevice == 2) {
      Particle.publish("device2Call");
      if (selectedMode < 2) {
        selectedMode++;
      }
      else {
        selectedMode = 1;
      }
    }
    changeLCDData(selectedMode, selectedDevice);
  }
  else if (digitalRead(buttonTwo) == LOW) {
    isButtonTwoPressed = false;
  }
}

Light sensor and thermistor module

C/C++
/* 
 * IOT Project
 * Author:  Ben Janke
 * Date: November 23, 2023
 */

// Include Particle Device OS APIs
#include "Particle.h"

SYSTEM_MODE(AUTOMATIC);

SYSTEM_THREAD(ENABLED);

SerialLogHandler logHandler(LOG_LEVEL_INFO);

//Define Pins
int readingTemp;
int readingLight;
int tempSensor = A5;
int lightSensor = A1;
int timeDelay = 80;

int interpolateThermistor(int value) {
  int x = (-0.0673*value)+83.274;
  return x;
}
void publishData(){
  if (readingLight > 3943) {
    Particle.publish("LightReading", String(0));
  }
  else if (readingLight > 3000) {
    Particle.publish("LightReading", String(1));
  }
  else {
    Particle.publish("LightReading", String(2));
  }
  delay(1000);
  Particle.publish("TempReading2", String(interpolateThermistor(readingTemp)));
}
void call(const char *eventName, const char *data) {
  publishData();
}
void setup() {
  pinMode(tempSensor, INPUT);
  pinMode(lightSensor, INPUT);
  Particle.subscribe("device2Call", call);
}

void loop() {
  delay(1000*timeDelay);
  readingTemp = analogRead(tempSensor);
  readingLight = analogRead(lightSensor);
  publishData();
}

Credits

Chandler Scovern
1 project • 0 followers
BenJ
1 project • 0 followers
William L
1 project • 0 followers

Comments