Things used in this project

Hardware components:
Pi 3 02
Raspberry Pi 3 Model B
×1
Sparrow Wireless Sensor Node Kit
×1
13285 01
PIR Motion Sensor (generic)
Optional.
×1
Software apps and online services:
Dhub1
DeviceHub.net DeviceHub Cloud Service - Free package

Schematics

Project Diagram
Qfaeiv334glwjtise2ih
Remote sensor & PIR connection diagram
This diagram shows how to connect the PIR sensor to the Sparrow Nest programming board
Ftihxlllgkb7llukpfvm

Code

Python Code for DeviceHubPython
This code runs on RaspberryPi
from devicehub import Sensor, Device, Project
from time import sleep
from random import randint
import serial

PROJECT_ID      = 'your Project ID'
DEVICE_UUID     = 'your Device UUID'
API_KEY         = 'your API Key'

SENSOR_NAMES    = ['Temperature', 'Humidity', 'Pressure', 'Light', 'IR', 'UV', 'Remote_Presence', 'Remote_Temperature']
SENSOR_VALUES   = []
SENSORS         = []

def add_sensor(type, name, dev):
        AN = Sensor(type, name)
        dev.addSensor(AN)
        return AN

def analog_input(dev, sensor, value):
        sensor.addValue(float(value))
        dev.send()
        return


ser=serial.Serial('/dev/ttyUSB0', 9600)
ser.flushInput()
ser.flushOutput()
line = ser.readline()
line = ser.readline()
print 'first', line

project = Project(PROJECT_ID, ssl_verify=False)
device = Device(project, DEVICE_UUID, API_KEY)

for s in SENSOR_NAMES:
        num = add_sensor(Sensor.ANALOG, s, device)
        SENSORS.append(num)


while True:
        try:

                SENSOR_VALUES = []
                line = ser.readline()
                print line
                print len(line)
                fields = line[:-1].split(',')
                #if( len(line) > 35 and fields != None):
                if(fields != None):
                        for f in fields:
                                SENSOR_VALUES.append(f)

                        for i in range(0, 8):
                                print SENSOR_NAMES[i], SENSOR_VALUES[i]
                                analog_input(device, SENSORS[i], SENSOR_VALUES[i])
                        print 'Data Sent OK!'

        except:
                print 'Something went wrong, retrying...'
        sleep(8.0)
CSV code for the Sparrow nodeC/C++
This code runs on the Sparrow node attached to the RasperryPi
#include <Wire.h>
#include "SI1145.h"
#include <SHT2x.h>
#include <BaroSensor.h>
#include "SparrowTransfer.h"
 
//create object
SparrowTransfer ST; 
 
struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  uint8_t presence;
  float temperature;
 
};
//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;

struct SENSOR_DATA{
  //we store here sensor readings
  float temperature;
  float humidity;
  float pressure;
  float light;
  float IR;
  float UV; 
  uint8_t remote_presence; 
  float remote_temp;
};

SENSOR_DATA node;

int controlPin = 7; // control pin for all sensors on the node
int greenLedPin = 11; // green LED

Adafruit_SI1145 uv = Adafruit_SI1145();

int getSensorData(){ //reads all sensors
  node.temperature = SHT2x.GetTemperature(); //temperature in degrees C
  node.humidity = SHT2x.GetHumidity(); //humidity in RH
  node.pressure = BaroSensor.getPressure(); //pressure in mbar
  node.light = uv.readVisible(); //visible light 
  node.IR = uv.readIR(); //infrared light level
  node.UV = uv.readUV() / 100.0; //UV index

  return 1;
}

void blinkLED() //blinks the green LED
{
  digitalWrite(greenLedPin,LOW);
  delay(20);
  digitalWrite(greenLedPin,HIGH);  
}

void sendSensorData(){ //sends sensor data over the serial interface as CSV
  Serial.print(node.temperature); //temperature in degrees C
  Serial.print(",");
  Serial.print(node.humidity); //humidity in RH
  Serial.print(",");
  Serial.print(node.pressure); //pressure in mbar
  Serial.print(",");
  Serial.print(node.light); //visible light 
  Serial.print(",");
  Serial.print(node.IR); //infrared light level
  Serial.print(",");
  Serial.print(node.UV); //UV index
  Serial.print(",");
  Serial.print(node.remote_presence); // presence from the remote sensor
  Serial.print(",");
  Serial.println(node.remote_temp); // temperature from the remote sensor
}

void uvInit(){ // initializes the Si1145 light sensor
  if (! uv.begin()) { //no luck first time, try to initialize again
    Serial.println("Didn't find Si1145");
    digitalWrite(controlPin, HIGH);
    delay(100);
    digitalWrite(controlPin, LOW);
    delay(1000);
    if (! uv.begin()) while(1); //the light sensor could not be initialized
  }
}

void setup() {

  //start the library, pass in the data details  
  ST.begin(details(mydata));
  
  pinMode(controlPin, OUTPUT);  //sensor on/off control
  pinMode(greenLedPin, OUTPUT);      // this is where the red LED on the node is connected
  
  digitalWrite(controlPin, LOW); // enable all sensors
  delay(1000); //wait for things to settle
  
  Serial.begin(9600);
  
  uvInit(); // init light sensor
  
  BaroSensor.begin(); // init barometric sensor
}


void loop() {
  if(ST.receiveData()){ //check remote sensor readings
    node.remote_presence = mydata.presence;
    node.remote_temp = mydata.temperature;
  }
  
  if(getSensorData()){
    sendSensorData();
    blinkLED();
  }
  delay(1000);

}
Remote Sensor CodeC/C++
This code runs on the remote wireless sensor node.
#include "SparrowTransfer.h"
#include <Wire.h>
#include <SHT2x.h>

#define DEBUG 1

//create object
SparrowTransfer ST; 
 
struct SEND_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to send
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER SPARROW
  uint8_t presence;
  float temperature;
};
 
//give a name to the group of data
SEND_DATA_STRUCTURE mydata;

int redLedPin = 8;              // red LED
int greenLedPin = 11;           // green LED
int inputPin = 18;              // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int controlPin = 7;             // sensor on/off control
 
uint8_t detect(){
  int val = digitalRead(inputPin);  // read PIR input value
  if (val == HIGH) {            // check if the input is HIGH
      digitalWrite(redLedPin, LOW);  // turn LED ON
      return 1;
    }
  else {
      digitalWrite(redLedPin, HIGH); // turn LED OFF
      return 0;
    }
}

void blinkLED() //blinks the green LED
{
  digitalWrite(greenLedPin,LOW);
  delay(20);
  digitalWrite(greenLedPin,HIGH);  
}
 
void setup(){
 
  pinMode(greenLedPin, OUTPUT);      // declare green LED as output
  pinMode(redLedPin, OUTPUT);        // declare red LED as output
  pinMode(inputPin, INPUT);          // declare sensor as input
  pinMode(controlPin, OUTPUT);       // declare sensor control pin as output

  digitalWrite(controlPin, LOW);     // turn on sensors
  delay(1000);
  Wire.begin();
  
  //start the library, pass in the data details
  ST.begin(details(mydata));
  mydata.presence = 0;
  mydata.temperature = -1.23; //default value to test if something is wrong
 
  digitalWrite(greenLedPin, HIGH); //start with all LEDs off
  digitalWrite(redLedPin, HIGH); 
  
  #ifdef DEBUG //only for local debugging purposes
    Serial.begin(9600);
  #endif

}
 
void loop(){
 
  mydata.presence = detect();
  mydata.temperature = SHT2x.GetTemperature();

  #ifdef DEBUG
    Serial.println(mydata.presence);
    Serial.println(mydata.temperature);
  #endif
  
  ST.sendData();
  blinkLED();
  delay(1000);
}
Home Monitor Github
Main repo

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Face Detection Using OpenCV With Raspberry Pi
Intermediate
  • 2,372
  • 21

Protip

In this project, we are going to detect faces using OpenCV with Raspberry Pi.

Creating an IoT Server with Home Assistant and MQTT
Intermediate
  • 2,523
  • 17

Full instructions

Home Assistant is one powerful home automation platform and it is complacently open source. Access it from any web browser and automatons.

Adding RC Transmitter/Receiver to Control Mecanum Bot
Intermediate
  • 431
  • 6

Full instructions

We previously showed our Mecanum Bot being controlled by a wireless Xbox controller, now we added RC transmitter/receiver.

Automated GPS Controlled Photo Taker
Intermediate
  • 1,613
  • 19

Full instructions

For this build, I put together a backpack to take pictures when I am close to places that like. And what better place to test than London?

Setting up a "User Data" drive for Raspberry Pi
Intermediate
  • 34
  • 1

Full instructions

Mounting external memory to store users programs, files, etc...

DIY Smart Assistant Speaker/Lamp (Google Home or Alexa)
Intermediate
  • 1,644
  • 5

Full instructions

DIY build using 3D printed enclosure and parts, a recycled Bluetooth speaker, a Raspberry Pi, and a Philips Hue light bulb.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login