I had an Adruino kit lying around for a long time but never did anything with it. Few days back I bought a few sensors and started to build a pollution sensor system consisting of atleast two sensors for now and multiple ways of monitoring. I don’t know any programing and most of the code is copied from different sources and modified wherever required to suit my requirements. As I worked, it became clear that it is not as easy job, so this project is going to be split in to multiple steps.

This project uses two different sensors, a simple MQ135 and a Sharp GP2Y1010. Data sheets are easily available on internet, but for quick reading here are short descriptions:

MQ135: It is a simple sensor used to measure presence of some common pollutants like NH3, NOx, Alcohol, Benzene, Smoke, CO2.  It has 4 pins, two for power supply and 2 for analog and digital readings.

Sharp GP2Y1010 is an optical dust sensor which measures the volume of suspended dust particles in air by using a LED and phototransistor. It has 6 pins.

Adruino pollution sensor project with MQ135 and Sharp GP2Y1010

BASICS:

1 POWER SUPPLY: As of now, Adruino is powered by a USB cable connected to PC. I also have a 9V compatible power supply which can be used once it’s disconnected from PC. I have a old powered USB hub which I plan to use in order to supply a 5V supply later to some components which will be added later. This may be necessary as some components seem to require a bit more power than what is good for accurate readings.

2. ADRUINO : A basic Adruino Uno board.

3. BASE: As of now, I am using breadboard for prototyping stage. If everything goes well, I may rebuild it in a more permanent way.

4. OUTPUT: All the output is being sent to Serial Monitor of Arduino programming interface. A LCD screen and an internet server interface will be added later.

Sharp GP2Y1010 Configuration

  • Pin 1 – Connected to +ve of 220 microF capacitor. -ve of capacitor connected to ground. A 150 Ohm resistor connected to 5 V.
  • Pin 2 – Connected to  -ve of capacitor
  • Pin 3 – Connected to D11 on Adruino
  • Pin 4 – Connected to ground.
  • Pin 5 – Connected to A0 on Adruino
  • Pin 6 – Connected to 5V

CODE:


int measurePin = 0; // Connected to pin 3
int ledPower = 11;  // Connected to pin 5
 
int samplingTime = 280;
int deltaTime = 40;
int sleepTime = 9680;
 
float voMeasured = 0;
float calcVoltage = 0;
float dustDensity = 0;
 
void setup(){
  Serial.begin(9600);
  pinMode(ledPower,OUTPUT);
}
 
void loop(){
  digitalWrite(ledPower,LOW); // power on the LED
  delayMicroseconds(samplingTime);
 
  voMeasured = analogRead(measurePin); // read the dust value
 
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH); // turn the LED off
  delayMicroseconds(sleepTime);
 
  // 0 – 5V mapped to 0 – 1023 integer values
  // recover voltage
  calcVoltage = voMeasured * (5.0 / 1024);
 
  // linear eqaution taken from http://www.howmuchsnow.com/arduino/airquality/


  dustDensity = 0.17 * calcVoltage – 0.1;
 
  Serial.print(“Raw Signal Value (0-1023): “);
  Serial.print(voMeasured);
 
  Serial.print(” – Voltage: “);
  Serial.print(calcVoltage);
 
  Serial.print(” – Dust Density: “);
  Serial.println(dustDensity);
 
  delay(1000);
}


OUTPUT:
NORMAL

  • 20:41:58.934 -> Raw Signal Value (0-1023): 180.00 – Voltage: 0.88 – Dust Density: 0.05
  • 20:41:59.950 -> Raw Signal Value (0-1023): 190.00 – Voltage: 0.93 – Dust Density: 0.06
  • 20:42:00.967 -> Raw Signal Value (0-1023): 175.00 – Voltage: 0.85 – Dust Density: 0.05
  • 20:42:01.981 -> Raw Signal Value (0-1023): 182.00 – Voltage: 0.89 – Dust Density: 0.05
  • 20:42:02.996 -> Raw Signal Value (0-1023): 175.00 – Voltage: 0.85 – Dust Density: 0.05
  • 20:42:04.009 -> Raw Signal Value (0-1023): 174.00 – Voltage: 0.85 – Dust Density: 0.04
  • 20:42:05.025 -> Raw Signal Value (0-1023): 173.00 – Voltage: 0.84 – Dust Density: 0.04
  • 20:42:06.036 -> Raw Signal Value (0-1023): 162.00 – Voltage: 0.79 – Dust Density: 0.03
  • 20:42:07.081 -> Raw Signal Value (0-1023): 176.00 – Voltage: 0.86 – Dust Density: 0.05
  • 20:42:08.096 -> Raw Signal Value (0-1023): 170.00 – Voltage: 0.83 – Dust Density: 0.04

As the voltage level fluctuates the dust density readings change accordingly. I burnt a small piece of paper to see if reading schange and they did.


MAXIMUM VALUE 

To get maximum values, I inserted a piece of rolled paper to block the sensor. Voltage readings jump to their maximum value, 3.69 volts and output dust reading is 0.53 at it’s maximum corresponding value.

  • 20:43:33.582 -> Raw Signal Value (0-1023): 755.00 – Voltage: 3.69 – Dust Density: 0.53
  • 20:43:34.598 -> Raw Signal Value (0-1023): 756.00 – Voltage: 3.69 – Dust Density: 0.53
  • 20:43:35.645 -> Raw Signal Value (0-1023): 755.00 – Voltage: 3.69 – Dust Density: 0.53
  • 20:43:36.659 -> Raw Signal Value (0-1023): 755.00 – Voltage: 3.69 – Dust Density: 0.53
  • 20:43:37.673 -> Raw Signal Value (0-1023): 755.00 – Voltage: 3.69 – Dust Density: 0.53
  • 20:43:38.688 -> Raw Signal Value (0-1023): 756.00 – Voltage: 3.69 – Dust Density: 0.53
  • 20:43:39.704 -> Raw Signal Value (0-1023): 755.00 – Voltage: 3.69 – Dust Density: 0.53



MQ135 Pollution Sensor Configuration

  • Vcc – To 5 V
  • GND –  To Ground
  • A – To A1
  • D – Not connected

CODE:


int sensorValue;
int digitalValue;
void setup()
{

Serial.begin(9600); // sets the serial port to 9600
}
void loop()
{
sensorValue = analogRead(1); // read analog input pin 1
Serial.println(sensorValue, DEC); // prints the value read
Serial.println(digitalValue, DEC);
delay(1000); // wait 100ms for next reading
}


OUTPUT

  • 22:40:14.593 -> 105
  • 22:40:14.593 -> 1
  • 22:40:15.608 -> 105
  • 22:40:15.608 -> 1
  • 22:40:16.589 -> 105
  • 22:40:16.589 -> 1
  • 22:40:17.607 -> 104
  • 22:40:17.607 -> 1
  • 22:40:18.589 -> 104

RESULTS:

By themselves, both sensors work fine. The readings seem to be consistent with environmental conditions and change with changing level of pollutants like smoke.

TO BE DONE:

  1. Attach a LCD screen and output the reading directly to it without use of PC.
  2. Adding and configuring a WiFi module to upload data to an online monitoring application.

PROBLEMS TO BE SOLVED:

  1. There is a noticeable change in readings if both sensors are used at same time. Adruino doesn’t seem to be able to supply same amount of voltage to multiple components. It will affect readings adversely when more components like LCD screen are added. Perhaps use of a separate power source, like a powered USB hub supplying 5 V will help.
  2. I don’t know of any way to properly calibrate the sensors. These are just the raw readings and may not be entirely accurate. I have not figured out a way to address this issue yet.

More in next post.

Few days back I noticed that my Raspberry Pi 3 is running quite hot. Sometimes crossing 80 degrees. This is  quite rare but since it is running for days without a break in this hot weather, I planned to do something to bring temperature lower. But problem is that Raspberry Pis don’t come with any kind of cooling kits which are easily available. Most of the options commercially available are quite useless for the price. I didn’t want to spend too much for it, so started with some DIY cooling kit and ran stress tests to check which work and are worth the effort to keep.

I found a simple script for stress testing online. It just runs CPU under full load and takes temperature readings every few seconds. Full script:

Ammunition box with all of Raspberry pi setup inside

Ammunition box with all of Raspberry pi setup inside

#!/bin/bash
vcgencmd measure_temp
sysbench –test=cpu –cpu-max-prime=20000 –num-threads=4 run >/dev/null 2>&1
vcgencmd measure_temp

In spirit of full disclosure, all these tests were done over the course of 4 days. They were all hot with outside temperatures during day time around 40 degrees but air conditioner was on for most of them time. Still, the room temperature was not constant for more than 4 tests at a time.  The data below is not 100% reliable and just gives an indication about the general characteristics of each cooling method based on my observations.

EQUIPMENT USED:

  1. A 80 mm cooling fan from an old PC case. I spliced a USB cable on to it (red and black wires) and powered it using an old tablet charger (5 Volt, 2 Ampere). The fan is rated for 12 V, runs a bit slower. It is not ideal solution but works for now.
  2. Very cheap thermal paste.
  3. A 1 Rupee coin with one side filed smooth as a test heat sink.
  4. Cheap and small aluminum heat sinks supposedly designed for Raspberry Pi. They had some sticky “thermal paste” on bottom which looked more like a sticker. So I removed that used my own.
  5. All of this Raspberry Pi setup is inside an old ammunition box salvaged from a junkyard. It has a power supply extension board, a powered USB hub, a USB wifi dongle, a USB harddisk (connected to Raspberry Pi itself, not hub), a 80 mm fan as described in point 1 and OSMC operating system with Kodi.


TEST RESULTS:

1.These are temperature readings without any type of cooling.

TEST 1

temp=60.7’C

Passive cooling with heatsink, cheap thermal paste and a filed coin

Passive cooling with heatsink, cheap thermal paste and a filed coin

temp=73.6’C
temp=74.1’C
temp=75.2’C
temp=75.8’C
temp=75.2’C
temp=75.8’C
temp=75.2’C
Difference in starting and peak temperature : 15.1
TEST 2
temp=50.5’C
temp=75.2’C
temp=79.0’C
temp=83.3’C
temp=83.8’C
temp=82.7’C
temp=82.2’C
temp=83.8’C
Difference in starting and peak temperature : 33.3
Result: Peak temperature varies between 75 and 84 degrees. But hovers around 83 for most part when air conditioner was off. Quite hot.

2. With only coin on processor. No thermal paste or fan

TEST 1
temp=54.8’C
temp=69.8’C
temp=71.4’C
temp=72.5’C
temp=72.5’C
temp=73.1’C
temp=73.1’C
temp=73.1’C
Difference in starting and peak temperature : 18.3
TEST 2
temp=60.7’C
temp=77.4’C
temp=79.0’C
temp=77.9’C
temp=83.8’C
temp=80.6’C
temp=79.5’C
temp=79.5’C
Difference in starting and peak temperature : 23.1
TEST 3
temp=52.1’C
temp=65.5’C
temp=66.6’C
temp=66.6’C
temp=67.7’C
temp=67.1’C
temp=69.8’C
temp=69.3’C
Difference in starting and peak temperature : 17.7
TEST 4
temp=60.7’C
temp=83.8’C
temp=84.4’C
temp=84.4’C
temp=84.4’C
temp=84.4’C
temp=84.4’C
temp=84.9’C
Difference in starting and peak temperature : 24.2
Result: With a filed coin acting as a heat sink, there is a small drop of 2 to 4 degrees. Not much to be useful.

3. With the fan blowing air directly on processor.

TEST 1
temp=49.9’C
temp=59.1’C
temp=59.1’C
temp=58.5’C
temp=58.0’C
temp=58.0’C
temp=56.4’C
Difference in starting and peak temperature : 8.1. It is great as the peak temperature was only 58.
TEST 2
temp=52.6’C
temp=69.8’C
temp=69.8’C
temp=67.7’C
temp=68.8’C
temp=69.3’C
temp=69.8’C
temp=65.0’C
Difference in starting and peak temperature : 17.2
Result: Idle temperatures are lower by 10 degrees and peak temperatures by 19 – 20 degrees with fan blowing air directly on processor. Differences in starting and peak temperatures also show a lot of improvement as the peak temp stays closed to 70.

4. With fan facing up.

This was an experiment to check if the reverse air flow would be as effective in cooling.
TEST 1
temp=47.2’C
temp=64.5’C
temp=64.5’C
temp=64.5’C
temp=65.0’C
temp=64.5’C
temp=65.0’C
temp=65.5’C
Difference in starting and peak temperature : 18.35
TEST 2
temp=52.6’C
temp=69.8’C
temp=67.7’C
temp=68.8’C
temp=67.7’C
temp=67.1’C
temp=69.8’C
temp=69.8’C
Difference in starting and peak temperature : 17.2
TEST 2
temp=49.4’C
temp=66.6’C
temp=67.7’C
temp=66.6’C
temp=69.8’C
temp=68.8’C
temp=68.8’C
temp=66.6’C
Difference in starting and peak temperature : 20.4
Result: This result is interesting as the peak and idle temperatures are quite close to those with opposite airflow.

5. Coin with thermal paste, no fan.

I applied a thin layer of thermal paste on coin and ran test without the fan
TEST 1
temp=45.6’C
temp=60.1’C
temp=61.2’C
temp=61.2’C
temp=61.2’C
temp=61.8’C
temp=62.3’C
temp=62.3’C
Difference in starting and peak temperature : 16.7
TEST 2
temp=52.1’C
temp=73.1’C
temp=76.3’C
temp=79.0’C
temp=82.2’C
temp=82.7’C
temp=82.7’C
Difference in starting and peak temperature : 30.6
TEST 3
temp=58.0’C
temp=77.4’C
temp=78.4’C
temp=81.7’C
temp=80.1’C
temp=83.8’C
temp=84.9’C
temp=82.7’C
Difference in starting and peak temperature : 26.9
Result: Seems like thermal paste I got is fairly useless. I ran the test 3 times to be sure.

6. Coin with thermal paste and fan blowing on it

TEST 1
temp=46.2’C
temp=59.1’C
temp=59.1’C
temp=59.6’C
temp=59.1’C
temp=59.1’C
Difference in starting and peak temperature : 13.4
TEST 2
temp=50.5’C
temp=60.7’C
temp=61.2’C
temp=62.8’C
temp=63.4’C
temp=63.9’C
temp=63.4’C
temp=64.5’C
Difference in starting and peak temperature : 14
Result: There is some improvement from direct fan without a heat sink and quite a bit improvement from running with only coin with thermalpaste.

7. With aluminum heatsink, no fan or thermal paste

These tests were done with the small aluminum heatsink.

TEST 1
temp=61.2’C
temp=79.5’C
temp=83.8’C
temp=83.8’C
temp=83.8’C
temp=83.8’C
temp=83.8’C
temp=84.4’C
Difference in starting and peak temperature : 23.2
Result: This heatsink has minimal effect in cooling the processor. It is too small and even the fins don’t help much compared to a simple coin.

8. With aluminum heatsink and fan blowing on it

temp=51.5’C
temp=62.8’C
temp=62.8’C
temp=63.4’C
temp=63.4’C
temp=60.7’C
temp=64.5’C
temp=62.3’C
Difference in starting and peak temperature : 13
temp=51.5’C
temp=66.1’C
temp=65.5’C
temp=66.1’C
temp=66.6’C
temp=66.6’C
temp=68.8’C
temp=67.7’C
Difference in starting and peak temperature : 17.3
Result: Somewhat surprisingly, this is better than direct air flow on processor.

9. With aluminum heastink and thermal paste

temp=60.1’C
temp=78.4’C
temp=83.8’C
temp=83.8’C
temp=84.4’C
temp=83.8’C
temp=83.8’C
temp=84.9’C
Difference in starting and peak temperature : 24.8
temp=53.7’C
temp=76.8’C
temp=78.4’C
temp=83.8’C
temp=83.8’C
temp=84.4’C
temp=83.8’C
temp=82.7’C
Difference in starting and peak temperature : 30.7
Result: This thermal paste seems to be quite useless.

10. With aluminum heastink, thermal paste and fan

temp=49.4’C
temp=64.5’C
temp=69.8’C
temp=66.1’C
temp=65.5’C
temp=66.1’C
temp=66.6’C
temp=69.8’C
Difference in starting and peak temperature : 20.4
temp=47.8’C
temp=62.3’C
temp=62.3’C
temp=62.3’C
temp=62.3’C
temp=62.8’C
temp=63.4’C
temp=64.5’C
Difference in starting and peak temperature : 16.7
Result: In this case, temperatures are around 2 degrees higher than without thermal paste.

11.With aluminum heastink, thermal paste and coin.

I put the coin on top of processor. Applied some thermal paste on it’s other side and put the heatsink on it. This test was without fan. I thought extra metal will help cooling.
temp=54.8’C
temp=74.7’C
temp=79.0’C
temp=83.3’C
temp=83.8’C
temp=83.8’C
temp=84.4’C
temp=84.4’C
Difference in starting and peak temperature : 29.6
Result: There is a difference of only 1 -3 degrese less if only one of either heatsink or coin was used. For some reason, extra metal made no difference.

12. With aluminum heastink, thermal paste, coin and fan.

Same set as above but with fan blowing air on top of it.
temp=50.5’C
temp=63.9’C
temp=62.8’C
temp=62.8’C
temp=62.8’C
temp=63.4’C
temp=62.8’C
temp=62.8’C
Difference in starting and peak temperature : 12.9
Result: This is slightly better than using either coin or heatsink and 4-5 degrees better than direct airflow.

Conclusions:

For some test runs, using the filed coin was better than the heat sink. Cheap thermal paste is next to useless in this case here. Only active cooling with fan provides any kind of appreciable cooling. Passive cooling will probably work if the heatsinks are bigger. But I don’t have any lying around and there will laso be the issue of bigger heatsink touching and shorting other components on the board.

Other posts related to Raspberry: