Wednesday 21 November 2018

Particulate meter - PPD42NS (Part II)

Relative to the previous post (Particulate meter - PPD42NS) now I can show the real results (effective datas) measured in my room in an period of 233 mins(3 hours and 53 mins).

To do this I had to modify the Arduino code in this way:
/*
 Interface to Shinyei Model PPD42NS Particle Sensor
 Program by Christopher Nafis 
 Modified to convert 0.01 cf to liters by Remo Tomasi
 Written April 2012
 Re-written November 2018
 
 http://www.seeedstudio.com/depot/grove-dust-sensor-p-1050.html
 http://www.sca-shinyei.com/pdf/PPD42NS.pdf
 
 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 = 60000; // 60 sec
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;

void setup() {
  Serial.begin(9600);
  pinMode(8,INPUT);
  starttime = millis(); 
}

void loop() {
  duration = pulseIn(pin, LOW);
  lowpulseoccupancy = lowpulseoccupancy+duration;
  if ((millis()-starttime) >= sampletime_ms)
  {
    ratio = lowpulseoccupancy/(sampletime_ms*10.0);  
    concentration = (1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62)*3.534; // * 3.534 to liters
    Serial.print("Concentration = ");
    Serial.print(concentration);
    Serial.println(" pcs/l");
    lowpulseoccupancy = 0;
    starttime = millis();
  }
}

Therefore, I introduced the conversion from cf (cube feet) to l (liters) and then I increased the sampling time from 2000 ms (= 2 secs) to 60000 (= 60 secs = 1 min).

Our unite measurement is, exactly, 0.01 cf = 283 ml = 0.283 l

So,
 

I multiply the formula of concentration for this last number.

Once I started the acquisition by arduino I had to redirection datas from the output device (on Ubuntu) which was COM3 that correspond to the device ttyACM0. To do this I simply wrote the following command on the command line (bash on Ubuntu 18.10):

cat /dev/ttyACM0 > log.txt

cat show to the monitor datas from COM3, but using '>' we redirect this information to a file called "log.txt" updated every 60 secs (the same time datas arrive). In this way we obtain a list of values like this: 

98726.26 pcs/l
35037.72 pcs/l
38756.15 pcs/l
27820.51 pcs/l
14590.92 pcs/l
17182.41 pcs/l
13278.62 pcs/l
8403.57 pcs/l
31862.78 pcs/l
...

Please Note: I had to launch this commmand before the capture:

ttylog -b 9600 -d /dev/ttyACM0

Why? Beacause the capture command seems doesn't work well and the previous command it's like a configuration of the channel. If you don't find this command you can install through this:

sudo apt-get install ttylog

I opened the log file into a spreadsheet software to manipulate the datas...and finally I've plotted the values obtaining the following graph:

Values of pcs/l plotted.
That's all folks!

Tuesday 20 November 2018

Particulate meter - PPD42NS

One of my dreams was to measure particulate in the air and make this operation simple.
Thanks to the PPD42NS sensor this is possible. Obviously we have to use an Arduino (UNO in my case) to connect to and to abtain datas.

PPD42NS particulate meter.
The connection is very fast and simple (the following project was made by me using Fritzing IDE):
Connection schema between PPD42NS device and Arduino UNO

I opened the Arduino IDE to write the code, in reality I found this code online, I copied it and pasted on the IDE:
/*
 Interface to Shinyei Model PPD42NS Particle Sensor
 Program by Christopher Nafis 
 Written April 2012
 
 http://www.seeedstudio.com/depot/grove-dust-sensor-p-1050.html
 http://www.sca-shinyei.com/pdf/PPD42NS.pdf
 
 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; 
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;

void setup() {
  Serial.begin(9600);
  pinMode(8,INPUT);
  starttime = millis(); 
}

void loop() {
  duration = pulseIn(pin, LOW);
  lowpulseoccupancy = lowpulseoccupancy+duration;
  if ((millis()-starttime) >= sampletime_ms) //if the sampel time = = 30s
  {
    ratio = lowpulseoccupancy/(sampletime_ms*10.0);  
    concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62; 
    Serial.print("Concentration = ");
    Serial.print(concentration);
    Serial.println(" pcs/0.01cf");
    Serial.println("\n");
    lowpulseoccupancy = 0;
    starttime = millis();
  }
}
 

I found the code here :
http://www.howmuchsnow.com/arduino/airquality/grovedust/

As you can see in the following pictures (and as written in the code) the yellow wire is connected to the pin 8: this wire contains the information about the  of particulate.

The particulate was positioned vertically.

Following the previous schema I connected Arduino to the sensor.

The project has brought out the following results.

Obsviously we need to calibrate everything not to having had a reference emission source.

Here you can see the related video on my personal YouTube channel:




Results:
Results on Arduino IDE monitor.


Concentration values were taken in the following unit of measurement:


pcs / 0.01 cf

where pcs stand for pieces and cf for cubic feet (0.01 cf = 283 ml).


Next steps: 
  • transform of the unit measure in ml;
  • sampling at the rythm of 5 mins;
  • export datas on an electronic sheet;
  • visualization in real time of the datas and graphic them;
  • comparison of data with those of the CNR (!!).
That's all folks! ...for the moment! 

Monday 12 November 2018

Optimal transport and Mechatronics

Image result for optimal transport

Yesterday I was discussing with my sister's boyfriend about a machanical matter: how to know where a moving object will be instant by instant from a point to another if looking at it was a robot.

It's not so simple as we might be tempted to think: the robot moves and at the same time sees something moving. It could usefull for the problem of a car guided by an AI.

Today I though of Alessio Figalli (the second italian winner of the Field Medal 2018): optimal transport, shift an object from a point to another at the lower cost.

A light bulb lit up in my mind: could it be everything connected with the optimal transport or at least with a simplified version?

...help!