Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
wzksam
Published

Environmental Sensor Tree

Show environmental parameters such as temperature, humidity and air quality when people come by.

BeginnerFull instructions provided2,288
Environmental Sensor Tree

Things used in this project

Story

Read more

Schematics

Environmental Tree grove connection

Code

Environemental Tree

Arduino
//OLED
#include <Wire.h>
#include <SeeedGrayOLED.h>
#include <avr/pgmspace.h>

//BME temp
#include "DFRobot_BME680_I2C.h"
#include "Wire.h"
DFRobot_BME680_I2C bme(0x76);  

//SHT temp
#include <Arduino.h>
#include "SHT31.h"
SHT31 sht = SHT31();

//pir
#define PIR 2


//led ring
#include "Adafruit_NeoPixel.h"
#ifdef __AVR__
  #include <avr/power.h>
#endif

#define PIN            6
#define NUMPIXELS      20
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);




void setup() {
  Wire.begin();  
  bme.begin();
  sht.begin();
  SeeedGrayOled.init(SH1107G);  //initialize SEEED Gray OLED display
  SeeedGrayOled.clearDisplay();           //clear the screen and set start position to top left corner
  SeeedGrayOled.setNormalDisplay();       //Set display to Normal mode
  SeeedGrayOled.setVerticalMode();        // Set to vertical mode for displaying text
  SeeedGrayOled.setTextXY(0,0);  
  SeeedGrayOled.putString("Hello World");
  pinMode(PIR, INPUT);

  #if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif

  pixels.setBrightness(255);
  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {
    delay(1000);
if(digitalRead(PIR)==HIGH){

  for(int i=0;i<NUMPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(25,150,129)); 
    pixels.show(); 
  }
  
  bme.startConvert();
  bme.update();
//  SeeedGrayOled.clearDisplay();
  SeeedGrayOled.setTextXY(0,0);  
  SeeedGrayOled.putString("Temp: ");
  SeeedGrayOled.putNumber((sht.getTemperature() + bme.readTemperature()/100)*0.5);  //avg of two temp sensors
  SeeedGrayOled.putString(" C   ");
  SeeedGrayOled.setTextXY(2,0);  
  SeeedGrayOled.putString("Hum: ");
  SeeedGrayOled.putNumber((sht.getHumidity() + bme.readHumidity()/1000)*0.5);
  SeeedGrayOled.putString(" %");
  SeeedGrayOled.setTextXY(4,0);
  SeeedGrayOled.putString("Loudness: ");
  SeeedGrayOled.putNumber((float)analogRead(0));
  SeeedGrayOled.putString("  ");
  SeeedGrayOled.setTextXY(6,0);
  SeeedGrayOled.putString("Harmful gas");
  SeeedGrayOled.setTextXY(7,0);
  SeeedGrayOled.putString("density: ");
  SeeedGrayOled.putNumber((float)analogRead(1)/1024*100);
  SeeedGrayOled.putString(" %");
  SeeedGrayOled.setTextXY(9,0);
  SeeedGrayOled.putString("Pres: ");
  SeeedGrayOled.putNumber(bme.readPressure());
  SeeedGrayOled.putString(" Pa");
  SeeedGrayOled.setTextXY(11,0);
  SeeedGrayOled.putString("Altitude: ");
  SeeedGrayOled.putNumber(bme.readAltitude());
  SeeedGrayOled.putString(" m");

  if(((sht.getTemperature() + bme.readTemperature()/100)*0.5)>28){ //When temp>28C, led flash red and oled displays "too hot"
      SeeedGrayOled.setTextXY(14,0);
      SeeedGrayOled.putString("Too hot!");
      for(int i=0;i<NUMPIXELS;i++){
      pixels.setPixelColor(i, pixels.Color(150,0,0)); 
      pixels.show(); 
      delay(100);
    }
  }

}else{    //when there's no people  around

  SeeedGrayOled.clearDisplay();
  SeeedGrayOled.setTextXY(0,0);  
  SeeedGrayOled.putString("Not detected ");
  for(int i=0;i<NUMPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,150)); 
    pixels.show(); 
    delay(50);
  }
    for(int i=0;i<NUMPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0)); 
    pixels.show(); 
    delay(50);
 
  }
  

}

}

Credits

wzksam

wzksam

1 project • 1 follower

Comments