//#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
const int SCREEN_WIDTH = 128; // OLED display width, in pixels
const int SCREEN_HEIGHT = 64; // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Data wire is plugged into digital pin 2 on the Arduino
#define ONE_WIRE_BUS 8
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
int inputPin = 12; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup(void)
{
sensors.begin(); // Start up the library
Serial.begin(9600);
pinMode(inputPin, INPUT);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
while(true);
}
}
void loop(void)
{
// Send the command to get temperatures
sensors.requestTemperatures();
//print the temperature in Celsius
Serial.print("Temperature: ");
Serial.print(sensors.getTempCByIndex(0));
Serial.print((char)176);//shows degrees character
Serial.print("C | ");
//print the temperature in Fahrenheit
Serial.print((sensors.getTempCByIndex(0) * 9.0) / 5.0 + 32.0);
Serial.print((char)176);//shows degrees character
Serial.println("F");
delay(500);
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
if (pirState == HIGH) {
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 10);
// Display static text
if(val == HIGH){
if (pirState == LOW) {
// we have just turned on
display.print("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
}else{
display.println("Hello, World!");
}
display.println("Temperature:");
display.print(sensors.getTempCByIndex(0));
display.print((char)176);//shows degrees character
display.print("C | ");
display.display();
if(sensors.getTempCByIndex(0) == '0'||'10'){
display.println("Motion:");
display.print("No");
display.println("Cool");
}else(sensors.getTempCByIndex(0) == '11'||'30'){
display.println("Motion:");
display.print("No");
display.println("Hot");
}else(sensors.getTempCByIndex(0) == '20'||'35'){
display.println("Motion:");
display.print("Yes");
display.println("Human Detected");
}
}