Devices & Components
PMS5003 dust sensor
Male Header 40 Position 1 Row (0.1")
SparkFun Snappable Protoboard
Breadboard (generic)
Arduino MKR1000
Hardware & Tools
Soldering iron (generic)
Software & Tools
Arduino IDE
Arduino Web Editor
Digital Ocean
Snappy Ubuntu Core
Fritzing
Project description
Code
Smart City Project Code
arduino
1#include <ArduinoHttpClient.h> 2#include <WiFi101.h> 3#include <PMS5003.h> 4// MKR1000 Pins setup 5const int SLEEP_PIN = 6; // this pin is for setting the sensor to sleep while it is not taking the data. 6const String uuid = ""; // This is the place where you should put your UUID 7 8// method setup 9const String content_type = "application/x-www-form-urlencoded";// this is for POST method 10 11// Your WiFi setup 12String postData =""; 13char serverAddress[] = "107.170.217.4";// This is the website of Smart City Project 14int port = 8080;// port number of the website 15 16// WiFi Login Data 17String ssid = "Name of Your Wifi"; 18String password ="Password of Your Wifi"; 19 20// initialize your variable value 21PMS5003 pms5003; 22String PM1 = "N/A"; 23String PM2_5 = "N/A"; 24String PM10 = "N/A"; 25String temperature = "N/A"; 26String humadity = "N/A"; 27 28// HTTP Connection 29WiFiClient wifi; 30HttpClient client = HttpClient(wifi, serverAddress, port); 31int status = WL_IDLE_STATUS; 32String response; 33int statusCode = 0; 34 35void setup() 36{ 37 Serial.begin(9600); // Serial for serial monitor. If the sensor is successfully sending data to website, this can be comment out 38 Serial1.begin(9600);// Serial1 port for PMS5006 39 pinMode(SLEEP_PIN,OUTPUT); // Setup Pin 6 as output pin 40 digitalWrite(SLEEP_PIN,HIGH); // Let the sensor start working as default 41 while(status != WL_CONNECTED) { // start connection 42 Serial.print("Attempting to connect to your wifi: " + ssid + "\ 43"); 44 // Connect to WPA/WPA2 network 45 status = WiFi.begin(ssid, password); 46 } 47 // print the SSID of the your WiFi 48 Serial.print("SSID: "); 49 Serial.println(WiFi.SSID()); 50 51 // print your WiFi Module's IP address: 52 IPAddress ip = WiFi.localIP(); 53 Serial.print("IP Address: ");Serial.println(ip); 54} 55 56void loop() { 57 Serial.println("PMS5003 Data on Process"); 58 59 //digitalWrite(SLEEP_PIN,HIGH); 60 //delay(20000); 61 for(;;){ 62 pms5003.processDataOn(Serial1); 63 PM1 = String(pms5003.getPM1(),DEC); 64 PM2_5 = String(pms5003.getPM25(),DEC); 65 PM10 = String(pms5003.getPM10(),DEC); 66 if (PM1 !="-1" && PM2_5 !="-1" && PM10 != "-1"){ 67 break; 68 } 69 } 70 71 72 postData ="uuid=" + uuid + "&PM1=" + PM1 + "&PM2_5=" + PM2_5 + "&PM10=" + PM10 + "&Temperature=" + temperature + "&Humadity=" + humadity; 73 74 Serial.println("making POST request"); 75 client.post("/",content_type,postData);// the conntent in content_type is for doing POST method. 76 77 statusCode = client.responseStatusCode(); // response code from server 78 response = client.responseBody(); // messages that is responed by server 79 80 // Serial Monitor output.(can be comment out when the data is sending to server correctly) 81 Serial.print("Status Code: ");Serial.println(statusCode); 82 Serial.print("Response: ");Serial.println(response); 83 84 Serial.print("PM1:\ ");Serial.println(PM1); 85 Serial.print("PM2.5:\ ");Serial.println(PM2_5); 86 Serial.print("PM10:\ ");Serial.println(PM10); 87} 88 89
Smart City Project
This is the files of PMS5003 library and Sketch of Arduino MKR1000
Smart City Project
This is the files of PMS5003 library and Sketch of Arduino MKR1000
Smart City Project Code
arduino
1#include <ArduinoHttpClient.h> 2#include <WiFi101.h> 3#include <PMS5003.h> 4// 5 MKR1000 Pins setup 6const int SLEEP_PIN = 6; // this pin is for setting the sensor 7 to sleep while it is not taking the data. 8const String uuid = ""; // This is 9 the place where you should put your UUID 10 11// method setup 12const String 13 content_type = "application/x-www-form-urlencoded";// this is for POST method 14 15// 16 Your WiFi setup 17String postData =""; 18char serverAddress[] = "107.170.217.4";// 19 This is the website of Smart City Project 20int port = 8080;// port number of the 21 website 22 23// WiFi Login Data 24String ssid = "Name of Your Wifi"; 25String 26 password ="Password of Your Wifi"; 27 28// initialize your variable value 29PMS5003 30 pms5003; 31String PM1 = "N/A"; 32String PM2_5 = "N/A"; 33String PM10 = "N/A"; 34String 35 temperature = "N/A"; 36String humadity = "N/A"; 37 38// HTTP Connection 39WiFiClient 40 wifi; 41HttpClient client = HttpClient(wifi, serverAddress, port); 42int status 43 = WL_IDLE_STATUS; 44String response; 45int statusCode = 0; 46 47void setup() 48 49{ 50 Serial.begin(9600); // Serial for serial monitor. If the sensor is successfully 51 sending data to website, this can be comment out 52 Serial1.begin(9600);// Serial1 53 port for PMS5006 54 pinMode(SLEEP_PIN,OUTPUT); // Setup Pin 6 as output pin 55 56 digitalWrite(SLEEP_PIN,HIGH); // Let the sensor start working as default 57 while(status 58 != WL_CONNECTED) { // start connection 59 Serial.print("Attempting to connect 60 to your wifi: " + ssid + "\ 61"); 62 // Connect to WPA/WPA2 network 63 status 64 = WiFi.begin(ssid, password); 65 } 66 // print the SSID of the your WiFi 67 68 Serial.print("SSID: "); 69 Serial.println(WiFi.SSID()); 70 71 // print 72 your WiFi Module's IP address: 73 IPAddress ip = WiFi.localIP(); 74 Serial.print("IP 75 Address: ");Serial.println(ip); 76} 77 78void loop() { 79 Serial.println("PMS5003 80 Data on Process"); 81 82 //digitalWrite(SLEEP_PIN,HIGH); 83 //delay(20000); 84 85 for(;;){ 86 pms5003.processDataOn(Serial1); 87 PM1 = String(pms5003.getPM1(),DEC); 88 89 PM2_5 = String(pms5003.getPM25(),DEC); 90 PM10 = String(pms5003.getPM10(),DEC); 91 92 if (PM1 !="-1" && PM2_5 !="-1" && PM10 != "-1"){ 93 break; 94 } 95 96 } 97 98 99 postData ="uuid=" + uuid + "&PM1=" + PM1 + "&PM2_5=" 100 + PM2_5 + "&PM10=" + PM10 + "&Temperature=" + temperature + "&Humadity=" + 101 humadity; 102 103 Serial.println("making POST request"); 104 client.post("/",content_type,postData);// 105 the conntent in content_type is for doing POST method. 106 107 statusCode = client.responseStatusCode(); 108 // response code from server 109 response = client.responseBody(); // messages 110 that is responed by server 111 112 // Serial Monitor output.(can be comment out 113 when the data is sending to server correctly) 114 Serial.print("Status Code: ");Serial.println(statusCode); 115 116 Serial.print("Response: ");Serial.println(response); 117 118 Serial.print("PM1:\ ");Serial.println(PM1); 119 120 Serial.print("PM2.5:\ ");Serial.println(PM2_5); 121 Serial.print("PM10:\ ");Serial.println(PM10); 122} 123 124
Downloadable files
Arduino MKR1000 with PMS5003
This is prototyping of Smart City Project Set
Arduino MKR1000 with PMS5003
Arduino MKR1000 + PMS5003 + proto board PCB
When you want to do DIY your device to join Smart City Project.
Arduino MKR1000 + PMS5003 + proto board PCB
Arduino MKR1000 Air Quality Sensor
This is connection from Arduino MKR1000 to PMS5003 sensor. It the connector that represents the PMS5003 sensor. Once you connect your Arduino MKR1000 board to the connector(the connector can be made by your-self) and then you just need to connect your PMS5003 sensor to the connector.
Arduino MKR1000 Air Quality Sensor

Arduino MKR1000 + PMS5003 + proto board PCB
When you want to do DIY your device to join Smart City Project.
Arduino MKR1000 + PMS5003 + proto board PCB
Arduino MKR1000 with PMS5003
This is prototyping of Smart City Project Set
Arduino MKR1000 with PMS5003
Comments
Only logged in users can leave comments