Lauren WilkieRiley CashHunter Phelps
Published

UNCC 3171 IOT Project (Spring 2023 Group 8)

You can now be out of the room while waiting for your water to boil!

IntermediateWork in progressOver 1 day4
UNCC 3171 IOT Project (Spring 2023 Group 8)

Things used in this project

Hardware components

Argon
Particle Argon
×3
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Jumper wires (generic)
Jumper wires (generic)
×1
LED (generic)
LED (generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×3
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets

Story

Read more

Schematics

Main particle Argon

Receives information from both the temperature and motion sensor so that it knows when to send the water boiling message.

Temperature Sensor

Schematic showing the temperature sensor diagram.

Motion sensor

Schematic for motion sensor diagram

Code

"Water is Boiling" Code

C/C++
int temp = 0;
int pirValue = 0;

void Boiling(const char* event, const char* data) {
  temp = atoi(data);
}

void Boiling2(const char* event, const char* data) {
  pirValue = atoi(data);
}

void setup() {
  Particle.subscribe("Temperature", Boiling, MY_DEVICES);
  Particle.subscribe("Motion detected!", Boiling2, MY_DEVICES);
  Particle.subscribe("Motion not detected", Boiling2, MY_DEVICES);
}

void loop() {
  if (temp > 200 && pirValue != 1) {
    Particle.publish("Water is Boiling");
    temp = 0;
    pirValue = 0;
  }
}

Temperature Code

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <OneWire.h>

// Define the pin for the DS18B20 temperature sensor
const int TEMP_SENSOR_PIN = D2;

// Create an instance of the OneWire protocol object
OneWire oneWire(TEMP_SENSOR_PIN);

void setup() {
  // Enable serial communication for debugging
  Serial.begin(9600);
  // Connect to the Particle Cloud
  Particle.connect();
}

void loop() {
  // Read the temperature from the DS18B20 sensor
  float tempC = readTemperature();
  // Convert the temperature to Fahrenheit
  float tempF = tempC * 1.8 + 32;
  
  if (tempF > -999) {
    // Publish the temperature to the Particle Cloud
    Particle.publish("Temperature", String(tempF));
    // Print the temperature to the serial monitor for debugging
    Serial.printf("Temperature: %.2fF\n", String(tempF));
  }
  // Wait for a few seconds before reading the temperature again
  delay(1000);
}




// Helper function to read the temperature from the DS18B20 sensor using the OneWire protocol
float readTemperature() {
  byte data[9];
  byte addr[8];

  // Reset the OneWire bus
  oneWire.reset();

  // Search for a DS18B20 sensor on the bus
  if (!oneWire.search(addr)) {
    Serial.printf("No more sensors on the bus");
    // Return a negative temperature value to indicate an error
    return -1000;
  }

  // Check if the found device is a DS18B20
  if (OneWire::crc8(addr, 7) != addr[7]) {
    Serial.printf("CRC is not valid");
    // Return a negative temperature value to indicate an error
    return -1000;
  }

  // Send a command to start a temperature measurement
  oneWire.reset();
  oneWire.select(addr);
  oneWire.write(0x44);

  // Wait for the temperature conversion to complete (750ms for 12-bit resolution)
  delay(750);

  // Send a command to read the temperature
  oneWire.reset();
  oneWire.select(addr);
  oneWire.write(0xBE);

  // Read the temperature data
  for (byte i = 0; i < 9; i++) {
    data[i] = oneWire.read();
  }

  // Convert the temperature data to a temperature value
  int16_t rawTemp = (data[1] << 8) | data[0];
  float tempC = (float) rawTemp / 16.0;

  // Return the temperature in Celsius
  return tempC;
}

Motion Sensor Code

C/C++
int pirPin = D2;
int ledPin = D3;
int pirValue;

void setup() {

  Serial.begin(9600);

  pinMode(pirPin, INPUT);

  pinMode(ledPin, OUTPUT);
}

void loop() {
  pirValue = digitalRead(pirPin);

  if (pirValue == HIGH) {
    digitalWrite(ledPin, LOW);
    Particle.publish("Motion detected!", String(pirValue));
    delay(1000);
  }
  else {
    Particle.publish("Motion not detected", String(pirValue));
    digitalWrite(ledPin, HIGH);
    delay(5000);
  }
}

Credits

Lauren Wilkie

Lauren Wilkie

0 projects • 0 followers
Riley Cash

Riley Cash

0 projects • 0 followers
Hunter Phelps

Hunter Phelps

0 projects • 0 followers

Comments

Add projectSign up / Login