Introduction: Urban Sensing Networks

About: URBANlab is an institutional research and design collective composed of CCA faculty, students and professionals interested in advanced research and design that investigates the challenges and potentials of the…
           

Often government data sets available to us online are taken from major nearby metropolitan areas or infrastructural centers. With an easy to follow introduction to new softwares and technologies the "urban sensor kit" allows anyone to obtain location specific information and share that information with a growing community of designers, researchers, and many others. This urban sensor kit is designed to create a user controlled community that, together will be able to form a large global network towards the future sustainable urban and architectural design.This Instructable is aimed to help you create your own "urban sensor kit" that will be able to collect, record, and share accurate and up-to-date locational information, creating the most precise and site specific data sets available.
  

 This project will allow you to hook up your own humidity, temperature and photocell sensor at home to host a webpage shared between the rest of the network. The webpage contains stored data collected from each user and displays information on sensor's history and activity in graph forms in a Pachube feed. Now you too can contribute towards our urban network!!

Step 1:

Hardware:

- Arduino Uno
http://www.sparkfun.com/products/10356
- 6' USB A to B cable
http://www.sparkfun.com/products/512
- Miniature breadboard
http://www.sparkfun.com/products/137
- Male to Male jumper wires
http://www.sparkfun.com/products/9387
- Photocell
http://www.sparkfun.com/products/9088
- Humidity and Temperature Sensor
http://www.sparkfun.com/products/10167
- 330 Ohm Resistors
http://www.sparkfun.com/products/10465
- 10k Ohm Resistors
http://www.sparkfun.com/products/10466



Software:

1- Processing
http://(http://processing.org/)
2- Arduino
http://(http://www.arduino.cc/)


Third Part Libraries:

3- DHT(Arduino)
http://www.ladyada.net/learn/sensors/dht.html
4- EEML(Processing)
5-Urban Sensing Code (Copy Paste into IDE)

Arduino Code:

// Sensor sketch based on ladyada DHT (http://www.ladyada.net/learn/sensors/dht.html) and Photocell (http://www.ladyada.net/learn/sensors/cds.html) code samples
// DHT library Written by ladyada (https://github.com/adafruit/DHT-sensor-library)

#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

#define DHTTYPE DHT22   // DHT 22  (AM2302)

int photocellPin = 0;
int photocellReading;

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

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

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  photocellReading = analogRead(photocellPin);

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Serial.println("Failed to read from DHT");
  } else {
    Serial.print(h); //humidity
    Serial.print(",");
    Serial.print(t); //temperature
    Serial.print(",");
    Serial.println(photocellReading);//photocell
  }
}


Processing Code:

import processing.serial.*;
import eeml.*;

Serial myPort;
String inString;
String inString0;
String inString1;
String inString2;
String list;
int lf=10;

DataOut dOut;
float lastUpdate;

void setup(){
  myPort = new Serial(this, Serial.list()[0],9600); 
  myPort.bufferUntil(lf);
  // set up DataOut object; requires URL of the EEML you are updating, and your Pachube API key  
    dOut = new DataOut(this, "YOUR SENSOR FEED HERE e.g (https://api.pachube.com/v2/feeds/39533.xml)", "YOUR API KEY HERE");  

    //  and add and tag a datastream   
    dOut.addData(0,"humidity");
    //  and add and tag a datastream   
    dOut.addData(1,"temperature");
     //  and add and tag a datastream   
    dOut.addData(2,"photocell");
     //  and add and tag a datastream   
}

void draw()
{
    // update once every 5 seconds (could also be e.g. every mouseClick)
    if ((millis() - lastUpdate) > 5000){
        println("ready to POST: ");
        dOut.update(0, inString0); // update the datastream
        dOut.update(1, inString1); // update the datastream
        dOut.update(2, inString2); // update the datastream
        int response = dOut.updatePachube(); // updatePachube() updates by an authenticated PUT HTTP request
        println(response); // should be 200 if successful; 401 if unauthorized; 404 if feed doesn't exist
        lastUpdate = millis();
    }  
}

void serialEvent(Serial p){
  inString = (myPort.readString());
  String[] list = split(inString, ',');
  inString0 = list[0];
  inString1 = list[1];
  inString2 = list[2];
}


Services:

- Pachube Account
http://(http://www.pachube.com/)

Step 2:

Getting Started:
Links below include Step-by-step instructions for setting up and connecting the Arduino and Processing software as well as imported third- party libraries. For installation click on the relevent platform:


Processing:
http://processing.org/download/

Arduino :
http://arduino.cc/en/Guide/HomePage

Third Party Libraries:
Download libraries and place within the "libraries" folder of your processing and Arduino sketch book.
https://github.com/adafruit/DHT-sensor-library (DHT)
http://www.eeml.org/library/ (EEML)

Step 3:

Diagram:

- The generated diagram guides you through circuit building to include DHT sensor and photocell.

Step 4:

Run:

Sketches are little scripts that you can send to the Arduino to tell it how to behave. In order to see if Arduino is now working, we will have to first apply the blink sketch in the example section;

Blink Sketch:
- Arduino/ File/ Examples/ Digital/ Blink  http://www.ladyada.net/learn/arduino/lesson1.html


Serial Port:

Step 5:

- Create Pachube Account

   Go to http://www.pachube.com/signup and sign up for a Pachube account.

- Create New API Key
 
    Login to Pachube, and click on 'my settings'
    Click 'new API key' and select permissions options 'get' and 'put'
    Leave 'Domain', 'Source IP address' and 'Expires' blank.
    A new key will appear above, where a link to 'Show key' will be available.
    Click this, and copy the key text, which will look something like: JPexklR22r-oZYk180uF5mMnbr4--hzQw9e3CU.

- Create Feed

    When logged in to Pachube, use this link to create a new feed: http://www.pachube.com/feeds/new
    There are two ways to make your real time data available to Pachube and to other Pachube users: either by
    automatic update or by manual update we want to set the feed to manually update
    Name your feed i.e. Humidity and Temperature@CCA
    Enter Tags i.e. Humidity, Temperature
    Enter Location Name and enter location latitude and longitude
    Accept other default and Click 'Save'


- Post Sensor Feeds

     Open Processing
     Open Urban Sensing Sketch