Dust Sensor Output LOL Shield

I decided to use the dust sensor again to question how a more emotional visual feedback using the LOL shield could potentially change behavior over time. As I was thinking of doing a dust painting originally for my thesis, this serves as a good prototype testing the validity of that idea. Sending data from one Yun to another allows you to separate the  dustsensor and the LED display so that a friend can monitor your smoking habits or alternatively you can monitor another room and place the sensor where you think it best fits. A sad face signifies levels over 400, meaning there is someone smoking in the room. A normal face means that you could improve by cleaning, a happy face means great values. I plan to encase this (unfortunately the laser cutting lab was fully booked the moment I realized the idea) and give it as a birthday present to my friend that has asthma. She has roommates that never clean and is now able to use these values to communicate to them better. She is also trying to quit smoking.

The code below reads the dust values and outputs a 0, 1 or 2 depending on the parameters. This was needed as Arduino does not understand the char and only reads in ints.

#include <Bridge.h>
#include <HttpClient.h>
// set up net client info:
const unsigned long postingInterval = 10; //delay between updates to sparkfun and xively.com
unsigned long lastRequest = 0; // when you last made a request
String dataString = “”;

int dustPin = 0;
int dustVal = 0;
int redVal = 0;
int blueVal = 0;
int greenVal = 0;

#define RED 3
#define GREEN 5
#define BLUE 6

int ledPower = 2;

int delayTime = 280;

int delayTime2 = 40;

float offTime = 9680;
void setup() {
// start serial port:
Bridge.begin();
Console.begin();
// Do a first update immediately
updateData();
sendData();
lastRequest = millis();

Serial.begin(9600);

pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(RED, OUTPUT);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
digitalWrite(RED, HIGH);
pinMode(ledPower, OUTPUT);
pinMode(4, OUTPUT);
}

void loop() {

// get a timestamp so you can calculate reading and sending intervals:
long now = millis();

// if the sending interval has passed since your
// last connection, then connect again and send data:
if (now – lastRequest >= postingInterval) {
updateData();
sendData();
lastRequest = now;
}

digitalWrite(BLUE, 255); // turn the LED off by making the voltage LOW
digitalWrite(GREEN, 255); // turn the LED off by making the voltage LOW
digitalWrite(RED, 255); // turn the LED off by making the voltage LOW

// ledPower is any digital pin on the arduino connected to Pin 3 on the sensor

if (dustVal < 224) {
digitalWrite(BLUE, 0);
delay(1000); // wait for a second
}

if (dustVal > 225 && dustVal < 500) {
digitalWrite(GREEN, LOW); // turn the LED off by making the voltage LOW
delay(1000);
}

if (dustVal > 501) {
digitalWrite(RED, 0);
delay(1000); // wait for a second
}

digitalWrite(ledPower, LOW); // power on the LED
delayMicroseconds(delayTime);
dustVal = analogRead(dustPin); // read the dust value via pin 5 on the sensor
delayMicroseconds(delayTime2);
digitalWrite(ledPower, HIGH); // turn the LED off
delayMicroseconds(offTime);

delay(150);

Serial.println(dustVal);

}

void updateData() {
// convert the readings to a String to send it:
dataString = “dustval=”;
dataString += dustVal;
// dataString += random(0-600);
}
// this method makes a HTTP connection to the server:
void sendData() {
// form the string for the API header parameter:
// form the string for the URL parameter:
String url = “”;
Console.println(dustVal);
if (dustVal < 300) {
url = “http://technoshaman.noip.me:3000/input/eqR0gB1wPXHGlzePZQDqt7El4VZ?private_key=WEoGXwZORrUV3XaL6lNbixNEY5r&dustval=0″;
}if (dustVal >= 300 && dustVal < 400) {
url = “http://technoshaman.noip.me:3000/input/eqR0gB1wPXHGlzePZQDqt7El4VZ?private_key=WEoGXwZORrUV3XaL6lNbixNEY5r&dustval=1″;
} if(dustVal >= 400) {
url = “http://technoshaman.noip.me:3000/input/eqR0gB1wPXHGlzePZQDqt7El4VZ?private_key=WEoGXwZORrUV3XaL6lNbixNEY5r&dustval=2″;
}

//url += dustVal;
// Send the HTTP GET request

HttpClient client;
HttpClient client2;
//Process xively;
//Console.print(“\n\nSending data… “);
//Console.println(url);
client.get(url);

delay(1000);
// If there’s incoming data from the net connection,
// send it out the Console:
while (client.available()) {
char c = client.read();
//Console.println(c);
}
Console.flush();

// Serial.println(dustVal);

}

The code below receives the data and outputs it with Chalieplexing. Unfortunately the delays needed for an animation slowed down the communication significantly over the server, so I was only able to do static animations.

#include <Bridge.h>
#include <HttpClient.h>
#include <Console.h>
#include <Charliplexing.h>
byte line = 0; //Row counter
char buffer[10];
int value;

void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
Bridge.begin();
digitalWrite(13, HIGH);
LedSign::Init();
//Serial.begin(9600);
Console.begin();
}

void loop() {
HttpClient client;
client.get(“http://technoshaman.noip.me:3000/output/eqR0gB1wPXHGlzePZQDqt7El4VZ/dustval/latest.csv”);

while (client.available()) {
char c = client.read() ;
//drawBitmapOk();
Console.write(c);
if (c == ‘0’) {
drawBitmapSmile();
}if (c == ‘1’) {
drawBitmapOk();
}if(c == ‘2’) {
drawBitmapSad();
}
Console.flush();
delay(1000);
}
}

void DisplayBitMap(int lineint)
{
//int data[9] = {95, 247, 123, 511, 255, 1, 5, 31, 15};
//for(line = 0; line < 9; line++) {
for (byte led = 0; led < 14; ++led) {
if (lineint & (1 << led)) {
LedSign::Set(led, line, 1);
} else {
LedSign::Set(led, line, 0);
}
}
line++;
if (line >= 9) line = 0;
}

void drawBitmapOk() {
delay(100);
DisplayBitMap(0);
DisplayBitMap(816);
DisplayBitMap(816);
DisplayBitMap(816);
DisplayBitMap(0);
DisplayBitMap(0);
DisplayBitMap(2040);
DisplayBitMap(0);
DisplayBitMap(0);
}
void drawBitmapSad() {
delay(100);
DisplayBitMap(0);
DisplayBitMap(816);
DisplayBitMap(816);
DisplayBitMap(816);
DisplayBitMap(0);
DisplayBitMap(0);
DisplayBitMap(1008);
DisplayBitMap(1032);
DisplayBitMap(0);
}
void drawBitmapSmile() {
delay(100);
DisplayBitMap(0);
DisplayBitMap(816);
DisplayBitMap(816);
DisplayBitMap(816);
DisplayBitMap(0);
DisplayBitMap(1032);
DisplayBitMap(528);
DisplayBitMap(480);
DisplayBitMap(0);
}

 

Leave a Reply

Your email address will not be published.