Hackster is hosting Hackster Holidays, Finale: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Tuesday!Stream Hackster Holidays, Finale on Tuesday!
vincent wong
Published © GPL3+

Smart Home Sensor Node

Build a sensor node using Arduino/Genuino 101 which integrated with openHAB 2, which you can build a smart home control system in no time.

BeginnerFull instructions provided14,134
Smart Home Sensor Node

Things used in this project

Hardware components

Arduino 101
Arduino 101
×1
DHT11 Temperature & Humidity Sensor (4 pins)
DHT11 Temperature & Humidity Sensor (4 pins)
×1
Adafruit Photocell
×1

Software apps and online services

openHAB 2
Arduino IDE
Arduino IDE

Story

Read more

Schematics

Smart Home Sensor Node

Code

smart_home_sensor_node.ino

C/C++
// smart howe sensor node

#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>

#define DHTPIN            2         // Pin which is connected to the DHT sensor.
#define LIGTHPIN          0

#define DHTTYPE           DHT11     // DHT 11 

DHT_Unified dht(DHTPIN, DHTTYPE);

uint32_t delayMS;

float temp, humid, light;
char buffer[20];

void setup() {
  Serial.begin(9600); 
  // Initialize device.
  dht.begin();
  // Print temperature sensor details.
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  // Set delay between sensor readings based on sensor details.
  delayMS = sensor.min_delay / 1000;
}

void loop() {
  // Delay between measurements.
  delay(delayMS);

  // Get temperature event and print its value.
  sensors_event_t event;  
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    temp = -1.0;
  }
  else {
    temp = event.temperature;
  }
  
  // Get humidity event and print its value.
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    humid = -1.0;
  }
  else {
    humid = event.relative_humidity;
  }


  light = analogRead(LIGTHPIN);
  
  // print to serial
  sprintf(buffer, "%.1f %.1f %.1f", temp, humid, light);
  Serial.println(buffer);

  // delay
  delay(2000);
}

Credits

vincent wong
81 projects • 205 followers

Comments