Jerry AutryDouglas Lawrence
Published © GPL3+

Temperature Sensor - UNCC MEGR 3171 Fall 2017

Always be prepared for the outdoors. Find out the exact temperature outside your home without the need to open a weather app or go outside!

IntermediateFull instructions provided4 hours1,721
Temperature Sensor - UNCC MEGR 3171 Fall 2017

Things used in this project

Hardware components

Photon
Particle Photon
×2
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×2
Breadboard (generic)
Breadboard (generic)
×2
Resistor 4.75k ohm
Resistor 4.75k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×13
Temperature Sensor
Temperature Sensor
DS18B20 Model
×1
Adafruit SSD1306 OLED Display
×1

Software apps and online services

Particle DEV
Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Story

Read more

Schematics

Temperature Display

This wiring diagram shows the photon connection to the Adafruit OLED display

Temperature Sensor

This wiring diagram shows the photon setup to record temperature

Code

Temperature Display

C/C++
This code is what controls the photon that tells the OLED display to show the temperature recorded and published from the other photon
/*********************************************************************
This is an example for our Monochrome OLEDs based on SSD1306 drivers

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/category/63_98

This example is for a 128x64 size display using SPI to communicate
4 or 5 pins are required to interface

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada  for Adafruit Industries.
BSD license, check license.txt for more information
All text above, and the splash screen must be included in any redistribution
*********************************************************************/

#include "Adafruit_SSD1306/Adafruit_GFX.h"
#include "Adafruit_SSD1306/Adafruit_SSD1306.h"

/* Uncomment this block to use hardware SPI
// If using software SPI (the default case):
#define OLED_MOSI   D0
#define OLED_CLK    D1
#define OLED_DC     D2
#define OLED_CS     D3
#define OLED_RESET  D4
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);
*/

// use hardware SPI
#define OLED_DC     D3
#define OLED_CS     D4
#define OLED_RESET  D5
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);


#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2



#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH  16

static const unsigned char logo16_glcd_bmp[] =
{ 0B00000000, 0B11000000,
  0B00000001, 0B11000000,
  0B00000001, 0B11000000,
  0B00000011, 0B11100000,
  0B11110011, 0B11100000,
  0B11111110, 0B11111000,
  0B01111110, 0B11111111,
  0B00110011, 0B10011111,
  0B00011111, 0B11111100,
  0B00001101, 0B01110000,
  0B00011011, 0B10100000,
  0B00111111, 0B11100000,
  0B00111111, 0B11110000,
  0B01111100, 0B11110000,
  0B01110000, 0B01110000,
  0B00000000, 0B00110000 };

#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif

//Get Temperature data from cloud
void tempF(const char *JtwoguysonecodeF, const char *dataF)
{
  // display the temperature
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,0);
  display.printlnf("%s Fahrenheit\n", dataF, 3);
  display.display();
  display.clearDisplay(); // clears the screen and buffer
}

void setup()   {
  Serial.begin(9600);

  // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
  display.begin(SSD1306_SWITCHCAPVCC);
  // init done
  display.display(); // show splashscreen
  delay(100);
  display.clearDisplay();  // clears the screen and buffer

  // Subscribe to tempearture variable
  Particle.subscribe("JtwoguysonecodeF", tempF);

}

Temperature Sensor

C/C++
This code is used by the photon which is connected to the temperature sensor, which will record live temperature and publish to the Internet of Things
// This #include statement was automatically added by the Spark IDE.
#include "OneWire.h"

// This #include statement was automatically added by the Spark IDE.
#include "spark-dallas-temperature.h"

// -----------------
// Read temperature
// -----------------

// Data wire is plugged into port 0 on the Photon
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(D0 );

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature dallas(&oneWire);

// Create a variable that will store the temperature value
double temperature = 0.0;
double temperatureF = 0.0;

void setup()
{
  // Register Particle variables
  Particle.variable("temperature", &temperature, DOUBLE);
  Particle.variable("temperatureF", &temperatureF, DOUBLE);

  // setup the library
  dallas.begin();
}

void loop()
{

  // Request temperature conversion
  dallas.requestTemperatures();

  // get the temperature in Celcius
  float tempC = dallas.getTempCByIndex(0);
  //Filter out voltage spikes
  if (tempC < -50) {
      //The below statement leaves tempC as is if the sensor reports < -50C
      tempC = tempC;
      delay(1000);
    }
    else
    {
      // convert to double
      temperature = (double)tempC;
    }

  // convert to Fahrenheit
  float tempF = DallasTemperature::toFahrenheit( tempC );
  //Filter out voltage spikes
  if (tempF < -50) {
      //The below statement leaves tempC as is if the sensor reports < -50C
      tempF = tempF;
      delay(1000);
    }
    else
    {
      // convert to double
      temperatureF = (double)tempF;
    }

  // Publish Particle Variable
  Particle.publish("Jtwoguysonecode", String(temperature));
  Particle.publish("JtwoguysonecodeF", String(temperatureF));

  //Delay 5 seconds
  delay(5000);

}

/*
The API request will look something like this:
GET /v1/devices/{DEVICE_ID}/temperature

# EXAMPLE REQUEST IN TERMINAL
# Device ID is 0123456789abcdef
# Your access token is 123412341234
curl -G https://api.particle.io/v1/devices/0123456789abcdef/temperature \
  -d access_token=123412341234
*/

Credits

Jerry Autry

Jerry Autry

1 project • 1 follower
UNCC Mechanical Engineering Student
Douglas Lawrence

Douglas Lawrence

1 project • 1 follower

Comments