Hardware components | ||||||
| × | 1 | ||||
Software apps and online services | ||||||
|
This is first edition of project to monitor air quality. It is using GPRS for internet connectivity and GPS for location. It uses Grove dust sensor to monitor the foreign particles in air.
This is the Grove Dust sensor. I have used for monitoring air quality.
I have attached the GitHub link for the Code. I will be updating this project and will soon complete it. Any suggestions are welcomed.
full picture of the board and sensor connected.
#include <SPI.h>
#include "PubNub.h"
//import all the necessary files for GPRS connectivity
#include "LGPRS.h"
#include "LGPRSClient.h"
#include <LGPS.h>
#include "GPSWaypoint.h"
#include "GPS_functions.h"
#define ledPin 13
/*
JST Pin 1 (Black Wire) => //Arduino GND
JST Pin 3 (Red wire) => //Arduino 5VDC
JST Pin 4 (Yellow wire) => //Arduino Digital Pin 8
*/
int pin = 8;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 2000;//sampe 30s ;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
GPSWaypoint* gpsPosition;
//define the required keys for using PubNub
char pubkey[] = "pub-c-9d4ba088-6b35-4afb-b1ab-fb72728b51c3";
char subkey[] = "sub-c-fa4c8f02-638c-11e5-85c0-0619f8945a4f";
char channel[] = "bike-map";
void setup()
{
pinMode(ledPin, OUTPUT);
pinMode(8,INPUT);
Serial.begin(9600);
Serial.println("Serial setup");
//Connect to the GRPS network in order to send/receive PubNub messages
Serial.println("Attach to GPRS network with correct APN settings from your mobile network provider");
//example here is with mobile provider EE in the UK
//attachGPRS(const char *apn, const char *username, const char *password);
//while (!LGPRS.attachGPRS("mobile.o2.co.uk", "o2web", "password"))
while (!LGPRS.attachGPRS("bsnlnet", "", ""))
{
Serial.println(" . ");
delay(1000);
}
Serial.println("LGPRS setup");
PubNub.begin(pubkey, subkey);
Serial.println("PubNub setup");
LGPS.powerOn();
}
void flash(bool success)
{
/* Flash LED three times. */
for (int i = 0; i < 3; i++) {
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(100);
}
}
void loop()
{
ratio = lowpulseoccupancy/(sampletime_ms*10.0); // Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; // using spec sheet curve
Serial.print("concentration = ");
Serial.print(concentration);
Serial.println(" pcs/0.01cf");
Serial.println("\n");
lowpulseoccupancy = 0;
Serial.println("Getting GPS Data");
//Aquire GPS position
char GPS_formatted[] = "GPS fixed";
gpsPosition = new GPSWaypoint();
gpsSentenceInfoStruct gpsDataStruct;
getGPSData(gpsDataStruct, GPS_formatted, gpsPosition);
Serial.println(" GPS Data aquired");
char* buffer_latitude = new char[30];
sprintf(buffer_latitude, "%2.6f", gpsPosition->latitude);
char* buffer_longitude = new char[30];
sprintf(buffer_longitude, "%2.6f", gpsPosition->longitude);
// float concentration_example = 1.2323;
String upload_GPS = "[{\"latlng\":[" + String(buffer_latitude) + "," + String(buffer_longitude)+ "], \"data\":\""+concentration+"\"}]";
const char* upload_char = upload_GPS.c_str();
//Once Position is Aquired, upload it to PubNub
LGPRSClient *client;
Serial.println("publishing a message");
client = PubNub.publish(channel, upload_char, 60);
if (!client) {
Serial.println("publishing error");
delay(1000);
return;
}
while (client->connected()) {
while (client->connected() && !client->available()); // wait
char c = client->read();
Serial.print(c);
}
client->stop();
Serial.println();
flash(true);
delay(5000);
}
Comments