Dylan Pauel
Published © GPL3+

Particulate Matter Matters

Our project aims to see whether there is a correlation between the intensity of particulate matter in air and people moving around.

IntermediateShowcase (no instructions)1 hour183
Particulate Matter Matters

Things used in this project

Hardware components

Photon
Particle Photon
×1
Breadboard (generic)
Breadboard (generic)
×1
Gikfun GP2Y1010AU0F Optical Dust Sensor
×1
DHT22 Temperature Sensor
DHT22 Temperature Sensor
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Capacitor 220 µF
Capacitor 220 µF
×1
Jumper wires (generic)
Jumper wires (generic)
×15

Software apps and online services

Particle.io
coolterm

Story

Read more

Custom parts and enclosures

finalcuttingenclosure_GWhAYWfOC3.ai

enclosure1_zTbvEnYB2m.JPG

enclosure2_98SOOSuiFu.JPG

enclosure3_Dl621Smg7k.JPG

Schematics

img_1430_FBtqVysbxi.JPG

20170417_144243_yfAhnq3zR3.jpg

pic1_SMZaQk3beC.jpg

pic2_Q933kkrpKH.jpg

pic3_yRGA2fi3Uw.jpg

image_jlkRI6gUtZ.png

pic_1_P3F4UhD1UJ.jpg

pic_5_bO9gKEGZ0g.png

pic_7_e9dyp1QUOy.png

yaser_2S1OrrDL1s.png

deploying_SNOiMTGoZt.jpg

Code

Untitled file

Arduino
// This #include statement was automatically added by the Particle IDE.
#include <HC_SR04.h>

// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>

// This #include statement was automatically added by the Particle IDE. Robb Drinkwater rdrink@saic.edu
#include <SparkFunPhant.h>


/******************************************************************************
 * SparkFun_VL6180X_demo.ino
 * Example Sketch for VL6180x time of flight range finder.1``
 * Casey Kuhns @ SparkFun Electronics
 * 10/29/2014
 * https://github.com/sparkfun/SparkFun_ToF_Range_Finder-VL6180_Arduino_Library
 * 
 * The VL6180x by ST micro is a time of flight range finder that
 * uses pulsed IR light to determine distances from object at close
 * range.  The average range of a sensor is between 0-200mm
 * 
 * Resources:
 * This library uses the Arduino Wire.h to complete I2C transactions.
 * 
 * Development environment specifics:
 * 	IDE: Arduino 1.0.5
 * 	Hardware Platform: Arduino Pro 3.3V/8MHz
 * 	VL6180x Breakout Version: 1.0
 *  **Updated for Arduino 1.6.4 5/2015**
 * 
 * This code is beerware. If you see me (or any other SparkFun employee) at the
 * local pub, and you've found our code helpful, please buy us a round!  
 *  
 * Distributed as-is; no warranty is given.
 ******************************************************************************/

#include <Wire.h>



/*const float GAIN_1    = 1.01;  // Actual ALS Gain of 1.01
const float GAIN_1_25 = 1.28;  // Actual ALS Gain of 1.28
const float GAIN_1_67 = 1.72;  // Actual ALS Gain of 1.72
const float GAIN_2_5  = 2.6;   // Actual ALS Gain of 2.60
const float GAIN_5    = 5.21;  // Actual ALS Gain of 5.21
const float GAIN_10   = 10.32; // Actual ALS Gain of 10.32
const float GAIN_20   = 20;    // Actual ALS Gain of 20
const float GAIN_40   = 40;    // Actual ALS Gain of 40
*/
/*
 Standalone Sketch to use with a Arduino Fio and a
 Sharp Optical Dust Sensor GP2Y1010AU0F
 
 Blog: http://arduinodev.woofex.net/2012/12/01/standalone-sharp-dust-sensor/
 Code: https://github.com/Trefex/arduino-airquality/
 
 For Pin connections, please check the Blog or the github project page
 Authors: Cyrille Médard de Chardon (serialC), Christophe Trefois (Trefex)
 Changelog:
   2012-Dec-01:  Cleaned up code
 
 This work is licensed under the
 Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
 To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
 or send a letter to Creative Commons, 444 Castro Street, Suite 900,
 Mountain View, California, 94041, USA.
*/
#define trigPin 1
#define echoPin 2
#define DHTPIN 4            // what pin we're connected to
#define DHTTYPE DHT22       // DHT 22 (AM2302)
#define led 5 //d5
int measurePin = 6;
int ledPower = 12;
int range = 300; //range set for sensor to detec t
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
 

double value1 = 0; 
double value2 = 0; 

DHT dht(DHTPIN, DHTTYPE);
double hum;                 // current hum
double temp;       
const char server[] = "data.sparkfun.com"; // Phant destination server
const char publicKey[] = "4JRg6MnXQmHqomWWagXZ"; // Phant public key - HAS TO BE CHANGED
const char privateKey[] = "b5ErRg92pjT2ABRRx7oE"; // Phant private key  - HAS TO BE CHANGED
Phant phant(server, publicKey, privateKey); // Create a Phant object

const int POST_RATE = 3000; // Time between posts, in ms.
unsigned long lastPost = 0; // global variable to keep track of last post time

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  pinMode(DHTPIN, INPUT);
  Particle.variable("hum", hum);
  Particle.variable("temp", temp);
  pinMode(ledPower,OUTPUT);  

}

void loop() {
  long duration, distance;
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
//  delayMicroseconds(1000); - Removed this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  double checkHum = dht.getHumidity();
  double checkTemp = dht.getTempFarenheit();
  if (checkHum > 0 && checkHum < 100)
        hum = checkHum;
        
  if (checkTemp > 32 && checkTemp < 100)
        temp = checkTemp;
    
  Serial.println("Temp: " + String(checkTemp));
  Serial.println("Hum: " + String(checkHum));
        
  delay(100);
  value1++;
  value2++;


  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
 
  voMeasured = analogRead(measurePin); // read the dust value
 
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
 
  // 0 - 3.3V mapped to 0 - 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (3.3 / 1024);
 
  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/
  // Chris Nafis (c) 2012
  dustDensity = 0.17 * calcVoltage - 0.1;

 
  Serial.print(" - Dust Density: ");
  Serial.println(dustDensity);
        // Use phant.add(<field>, <value>) to add data to each field.
    // Phant requires you to update each and every field before posting,
    // make sure all fields defined in the stream are added here.
  if (distance >= range || distance <= 0){  //set distance you want to be bfore
    Serial.println("Out of range");
    digitalWrite(led,HIGH);
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
    digitalWrite(led,LOW);
    delay(100);
    
    postToPhant();
 
  }
  
}

int postToPhant()
{    

    phant.add("temperature", temp);
    phant.add("humidity", hum);
    phant.add("dust", dustDensity); 
    delay(100);        
        	
    TCPClient client;
    char response[512];
    int i = 0;
    int retVal = 0;
    
    if (client.connect(server, 80)) // Connect to the server
    {
		// Post message to indicate connect success
        Serial.println("Posting!"); 
		
		// phant.post() will return a string formatted as an HTTP POST.
		// It'll include all of the field/data values we added before.
		// Use client.print() to send that string to the server.
        client.print(phant.post());
        delay(250);
		// Now we'll do some simple checking to see what (if any) response
		// the server gives us.
        while (client.available())
        {
            char c = client.read();
            Serial.print(c);	// Print the response for debugging help.
            if (i < 512)
                response[i++] = c; // Add character to response string
        }
		// Search the response string for "200 OK", if that's found the post
		// succeeded.
        if (strstr(response, "200 OK"))
        {
            Serial.println("Post success!");
            retVal = 1;
        }
        else if (strstr(response, "400 Bad Request"))
        {	// "400 Bad Request" means the Phant POST was formatted incorrectly.
			// This most commonly ocurrs because a field is either missing,
			// duplicated, or misspelled.
            Serial.println("Bad request");
            retVal = -1;
        }
        else
        {
			// Otherwise we got a response we weren't looking for.
            retVal = -2;
        }
    }
    else
    {	// If the connection failed, print a message:
        Serial.println("connection failed");
        retVal = -3;
    }
    client.stop();	// Close the connection to server.
    return retVal;	// Return error (or success) code.


    client.stop();	// Close the connection to server.
    return retVal;	// Return error (or success) code.

} 

Credits

Dylan Pauel

Dylan Pauel

1 project • 0 followers
Thanks to Mohammad Munshi, Jerrin Biju, Array Of Things, Motorola Solutions Foundation, Particle, and Lane Tech.

Comments