Arduino UNO + Ethernet Shield + LM35 + Dust Sensor

I decided to modify the project and use only the Wired connection for the Dust Sensor and the Temperature Sensor placed in my house.

Doing this I’ve a spare Adafruit Huzzah with ESP8266 that i could use for other projects!

The connection are easy, i’ve only made a Y cable for 5V and GND that goes from UNO to the Sensors.

The Vsignal pin of the sensor is connected to A5 of UNO and the PM10 cable from the Dust Sensor is connected to the D4 pin of Arduino Uno.

Arduino Uno Dust Sensor
Arduino Uno Dust Sensor

As usual all the datas are sent to the web service Thingspeak.

Arduino Uno Dust Sensor

Arduino Uno Dust Sensor
Arduino Uno Dust Sensor

The enclosure is the same with always a FAN to help the air to move from outside to inside.


The code:

#include <Ethernet.h>
#include <SPI.h>
#include “ThingSpeak.h”

// Local Network Settings
byte mac[] = { 0xD4, 0x28, 0xB2, 0xFF, 0xA0, 0xA1 }; // Must be unique on local network

// ThingSpeak Settings
unsigned long myChannelNumber =;
const char * myWriteAPIKey = “”;

// Initialize Arduino Ethernet Client
EthernetClient client;

// Sensor Temp Setup
float temp;
int LM35Pin = 5;

//Dust Sensor Setup
unsigned long starttime;
unsigned long triggerOnP2;
unsigned long triggerOffP2;
unsigned long pulseLengthP2;
unsigned long durationP2;
boolean valP2 = HIGH;
boolean triggerP2 = false;
float ratioP2 = 0;
unsigned long sampletime_ms = 20000;
float countP2;

void setup()
Serial.begin(9600); // Start Serial for debugging on the Serial Monitor
Serial.println(“Hello World”);
pinMode(4, INPUT);

void loop()

//Read Values
temp = analogRead(LM35Pin);
valP2 = digitalRead(4);

if(valP2 == LOW && triggerP2 == false){
triggerP2 = true;
triggerOnP2 = micros();

if(valP2 == HIGH && triggerP2 == true){
triggerOffP2 = micros();
pulseLengthP2 = triggerOffP2 – triggerOnP2;
durationP2 = durationP2 + pulseLengthP2;
triggerP2 = false;

if ((millis() – starttime) > sampletime_ms) {

//LM35 Conversion
temp = (((4.5 * temp * 100.0)/1024.0));

//Integer Calculation
ratioP2 = durationP2/(sampletime_ms*10.0);
countP2 = 1.1*pow(ratioP2,3)-3.8*pow(ratioP2,2)+520*ratioP2+0.62;
float PM10count = countP2;

// first, PM10 count to mass concentration conversion
double r10 = 2.6*pow(10,-6);
double pi = 3.14159;
double vol10 = (4/3)*pi*pow(r10,3);
double density = 1.65*pow(10,12);
double mass10 = density*vol10;
double K = 3531.5;
float concLarge = (PM10count)*K*mass10;
durationP2 = 0;

//Print and Send Data


//Reset Timer
starttime = millis();


Precedente Wind MAP & Forecast Successivo Tutorial: Arduino MKR1000 Display LCD HD44780