HunterSteven Wall
Published

Cooler Temperature Alert

Allows you to see your cooler temperature at all times, and if it gets above a certain temperature, an alert will be sent to your phone.

IntermediateFull instructions provided605
Cooler Temperature Alert

Things used in this project

Hardware components

Photon
Particle Photon
×2
Adafruit Waterproof DS18B20 Digital temperature sensor
Adafruit Waterproof DS18B20 Digital temperature sensor
If you plan on using the Maker Kit code for the temperature sensor, there are a few temperature sensors that will work. The temperature sensors it checks for is in the code, so make sure you look before buying one!
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets
Maker service
IFTTT Maker service

Story

Read more

Schematics

Photon 1

The red wire is the power, so it goes from the red wire in the temperature to sensor to pin 3V3 on the photon. The yellow wire is for data, so there it goes from the yellow wire on the temperature sensor to pin D4 on the photon. The black wire is ground, so it connects the black wire on the temperature sensor to the GND pin on the photon. There is a 10 K ohm resistor between the power and the data wires from the temperature sensor.

Photon 2

This photon just needs to be powered.

Code

Temperature Sensor/Photon 1

C/C++
This code uses the temperature sensor to upload an event that records the date, time, and temperature. It also includes code to subscribe to the second photon. The published event will upload to a google sheet in order to keep track of real time data .
// This #include statement was automatically added by the Particle IDE.
#include <OneWire.h>

/************************************************************************
This sketch reads the temperature from a OneWire device and then publishes
to the Particle cloud. From there, IFTTT can be used to log the date,
time, and temperature to a Google Spreadsheet. Read more in our tutorial
here: http://docs.particle.io/tutorials/topics/maker-kit

This sketch is the same as the example from the OneWire library, but
with the addition of three lines at the end to publish the data to the
cloud.

Use this sketch to read the temperature from 1-Wire devices
you have attached to your Particle device (core, p0, p1, photon, electron)

Temperature is read from: DS18S20, DS18B20, DS1822, DS2438

Expanding on the enumeration process in the address scanner, this example
reads the temperature and outputs it from known device types as it scans.

I/O setup:
These made it easy to just 'plug in' my 18B20 (note that a bare TO-92
sensor may read higher than it should if it's right next to the Photon)

D3 - 1-wire ground, or just use regular pin and comment out below.
D4 - 1-wire signal, 2K-10K resistor to D5 (3v3)
D5 - 1-wire power, ditto ground comment.

A pull-up resistor is required on the signal line. The spec calls for a 4.7K.
I have used 1K-10K depending on the bus configuration and what I had out on the
bench. If you are powering the device, they all work. If you are using parisidic
power it gets more picky about the value.

NOTE: This sketch requires the OneWire library, which can be added from the
<-- Libraries tab on the left.
************************************************************************/

OneWire ds = OneWire(D4);  // 1-wire signal on pin D4

unsigned long lastUpdate = 0;
int led = D7;
float lastTemp;
void setup() {
 Particle.subscribe("alertcooleruser",myHandler,"410050001851373237343331");
 //CHANGE EVENT NAME TO CLAYTON'S EVENT
    pinMode(led,OUTPUT);
    digitalWrite(led,LOW);
   Serial.begin(9600);
}
void myHandler(const char *event, const char *data)
{
 digitalWrite(led,HIGH);
 
 }
  // Set up 'power' pins, comment out if not used!


// up to here, it is the same as the address acanner
// we need a few more variables for this example

void loop(void) {
  byte i;
  byte present = 0;
  byte type_s;
  byte data[12];
  byte addr[8];
  float celsius, fahrenheit;

  if ( !ds.search(addr)) {
    Serial.println("No more addresses.");
    Serial.println();
    ds.reset_search();
    delay(250);
    return;
  }

  // The order is changed a bit in this example
  // first the returned address is printed

  Serial.print("ROM =");
  for( i = 0; i < 8; i++) {
    Serial.write(' ');
    Serial.print(addr[i], HEX);
  }

  // second the CRC is checked, on fail,
  // print error and just return to try again

  if (OneWire::crc8(addr, 7) != addr[7]) {
      Serial.println("CRC is not valid!");
      return;
  }
  Serial.println();

  // we have a good address at this point
  // what kind of chip do we have?
  // we will set a type_s value for known types or just return

  // the first ROM byte indicates which chip
  switch (addr[0]) {
    case 0x10:
      Serial.println("  Chip = DS1820/DS18S20");
      type_s = 1;
      break;
    case 0x28:
      Serial.println("  Chip = DS18B20");
      type_s = 0;
      break;
    case 0x22:
      Serial.println("  Chip = DS1822");
      type_s = 0;
      break;
    case 0x26:
      Serial.println("  Chip = DS2438");
      type_s = 2;
      break;
    default:
      Serial.println("Unknown device type.");
      return;
  }

  // this device has temp so let's read it

  ds.reset();               // first clear the 1-wire bus
  ds.select(addr);          // now select the device we just found
  // ds.write(0x44, 1);     // tell it to start a conversion, with parasite power on at the end
  ds.write(0x44, 0);        // or start conversion in powered mode (bus finishes low)

  // just wait a second while the conversion takes place
  // different chips have different conversion times, check the specs, 1 sec is worse case + 250ms
  // you could also communicate with other devices if you like but you would need
  // to already know their address to select them.

  delay(1000);     // maybe 750ms is enough, maybe not, wait 1 sec for conversion

  // we might do a ds.depower() (parasite) here, but the reset will take care of it.

  // first make sure current values are in the scratch pad

  present = ds.reset();
  ds.select(addr);
  ds.write(0xB8,0);         // Recall Memory 0
  ds.write(0x00,0);         // Recall Memory 0

  // now read the scratch pad

  present = ds.reset();
  ds.select(addr);
  ds.write(0xBE,0);         // Read Scratchpad
  if (type_s == 2) {
    ds.write(0x00,0);       // The DS2438 needs a page# to read
  }

  // transfer and print the values

  Serial.print("  Data = ");
  Serial.print(present, HEX);
  Serial.print(" ");
  for ( i = 0; i < 9; i++) {           // we need 9 bytes
    data[i] = ds.read();
    Serial.print(data[i], HEX);
    Serial.print(" ");
  }
  Serial.print(" CRC=");
  Serial.print(OneWire::crc8(data, 8), HEX);
  Serial.println();

  // Convert the data to actual temperature
  // because the result is a 16 bit signed integer, it should
  // be stored to an "int16_t" type, which is always 16 bits
  // even when compiled on a 32 bit processor.
  int16_t raw = (data[1] << 8) | data[0];
  if (type_s == 2) raw = (data[2] << 8) | data[1];
  byte cfg = (data[4] & 0x60);

  switch (type_s) {
    case 1:
      raw = raw << 3; // 9 bit resolution default
      if (data[7] == 0x10) {
        // "count remain" gives full 12 bit resolution
        raw = (raw & 0xFFF0) + 12 - data[6];
      }
      celsius = (float)raw * 0.0625;
      break;
    case 0:
      // at lower res, the low bits are undefined, so let's zero them
      if (cfg == 0x00) raw = raw & ~7;  // 9 bit resolution, 93.75 ms
      if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms
      if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms
      // default is 12 bit resolution, 750 ms conversion time
      celsius = (float)raw * 0.0625;
      break;

    case 2:
      data[1] = (data[1] >> 3) & 0x1f;
      if (data[2] > 127) {
        celsius = (float)data[2] - ((float)data[1] * .03125);
      }else{
        celsius = (float)data[2] + ((float)data[1] * .03125);
      }
  }
  
  fahrenheit = celsius * 1.8 + 32.0;
  lastTemp = celsius;
  Serial.print("  Temperature = ");
  Serial.print(celsius);
  Serial.print(" Celsius, ");
  Serial.print(fahrenheit);
  Serial.println(" Fahrenheit");

  // now that we have the readings, we can publish them to the cloud
  String temperature = String(fahrenheit); // store temp in "temperature" string
  Particle.publish("readcoolertemp", temperature, MY_DEVICES); // publish to dashboard
  delay(5000); // 5-sec delay
}

Photon 2

C/C++
This code subscribes to the first photon. It converts the data into an integer and compares it to an if statement. It will publish an event when it is over the desired temperature that will send an alert to your phone through the IFTTT app.
int LED = D7;
int toohot;
int temp;

void setup() {
   
    pinMode(LED,OUTPUT); 
    
    //We need to subscribe to the second photon.
    Particle.subscribe("readcoolertemp" , myHandler, "410030000f51373331333230");
    // first is the event name, then the action call, and lastly its uploading to my devices since both photons are under the same account.
    
    // The LED needs to be off to start with. 
    digitalWrite(LED,LOW);
    delay(2500);
    toohot = 45;
}


void loop() {

}
void myHandler(const char *event, const char *data) // The nyHandler function tells the photon when an event is published from the photon it is subscribed to.
{
 digitalWrite(LED, HIGH);
 
 int temperature = atoi(data);
 if (temperature > toohot) {
 Particle.publish("alertcooleruser", "hot", MY_DEVICES);
 // this publish will allow the other photon to receive a signal, which allows for two way communication.
 digitalWrite(LED,HIGH);
 delay(2500);
}
else {
    Particle.publish("dontalertuser", "fine", MY_DEVICES);
    //if the temperature goes below the too hot temperature, this will turn the LED off.
    digitalWrite(LED,LOW);
    delay(2500);
}
}

Credits

Hunter

Hunter

1 project • 0 followers
Steven Wall

Steven Wall

1 project • 0 followers

Comments