»
Beautiful Bit Logo

Arduino Sensor Testing

Arduino
Arduino UNO Sensor Testing

Useful Sensors in the Arduino Starter Kit

1x Standard Temperature Sensor and 5x Photoresistor.

Get the temperature with the temperature sensor from the Arduino Starter Kit

Using the standard Arduino Temperature sensor requieres no library. Do the calibration yourself. Setup function looks pretty simple:

void setup() {
   Serial.begin(9600); //9600 baud for serial monitor
}

To get the temperature you have to convert the raw value to voltage first:

void loop() {
   Serial.print("Temperature: ");
   float value = analogRead(A0); //whatever analog pin you want to use
   float voltage = (value/1024.0) * 5.0;
   float temperature = (voltage - .5) * 100;
   Serial.print(temperature, DEC);
   Serial.print(" C");
   delay(1000);
}

Temperature and Humidity with one Sensor

There are two standard temperature sensors: DHT11 (the blue one) and DHT22 (the white one with more accuracy). The DHT22 can detect temperatures between -40 °C and 80 °C while it can detect humidity from 0 % - 100 %. Deviation for temperature is 0.5 and 2 % for humidity. I found a library that can control both of them on github. If you got an unsoldered version you need a 10k Ohm resitor. How to setup the DHT sensor by using a digital pin:

#include <DHT.h>

#define DHTPIN 8
#define DHTTYPE DHT22 //#define DHTTYPE DHT11 or DHT22

DHT dht(DHTPIN, DHTTYPE);

float h = 0;
float t = 0;

How to initialize the DHT:

void setup() {
   Serial.begin(9600);
   dht.begin();
}

How to display the DHT data:

void loop() {
   h = dht.readHumidity();
   t = dht.readTemperature();
   serial.print("Temperature: ");
   serial.print(t);
   serial.print(" C, ");
   serial.print("Humidity: ");
   serial.print(h);
   serial.print(" %");
   delay(1000);
}

The putput should look like this: Temperature: 21.00 C, Humidity: 41.00 %

Gas Sensors

One of the most important environmental aspects is the air surrounding us. Unfortunately the quality world wide is getting worse. In cities like Hong Kong or Los Angeles you will get heavy smog (smoke and fog) on regular bases. Monitoring the quality for your own use can be a very interesting thing.

  • MQ2 (Liquified Petroleum Gas)
  • MQ3 (Alcohol)
  • MQ4 (Methane)
  • MQ7 (Carbon Monoxide)
  • MQ131 (Ozone)
  • MQ135 (Air Quality)

Humans can of course smell certain gases without using a detector, but dangerous gases like carbon monoxide are scentless. Carbon monoxide can be a problem in underground parking garages because cars produce loads of it. Carbon Monoxide tends to bind oxygen which can cause suffocation.

ATTENTION: Keep in mind that humans can not smell when they are asleep!
Arduino UNO Gas Sensor Benchmarking

So I wanted to test the MQ 3's sensitivity to alcohol, but as you can see I had some weird readings. The MQ 4 seems to be more sensitive to alcohol than the MQ 3! I tested the gas sensors by dipping a cotton bud into 40% Obstler (unfortunately I do not have pure ethanol at home) for a few seconds and then placing the soaked cotton bud close to the sensors.

The MQ 4 datasheet says that it only has a low sensitivity to alcohol, so I started wondering. Since I could not find an explanation for the readings I can only guess. If you take a look at the chemical structure of methane (CH4) and methanol (CH4O) you can see that they are very similar. Methanol is a known byproduct in the production of alcohol. But because it is more poisonous than ethanol it is not allowed to be in drinkable alcohol! Usually methanol is used by criminals when adulterating alcoholic beverages to make more profit.

I wanted to make sure that there is nothing wrong with the MQ 4 sensor, so I added a second MQ 4 sensor to the setup. The result was that both of them reacted in the same way to another alcohol sample on a cotton bud!

The official arduino.cc website has some additional information about the MQ Series.

Orientation

HMC5883L Compass and GPS Module.

COMING SOON: Example code and example data

Infrared and Ultra Sonic for Human and Movement Detection

Very popular sensors for motion and human detection are HC-SR501 Pyroelectric Infrared (effectual angle: 120° with 7 m range) and HC-SR04 Ultra Sonic Detector (effectual angle: 15° with 7,6 m range). I tested both of them:

motion sensors

For a little test I connected 2 pyroelectric infrared sensors and 2 red LEDs to the Arduino UNO. Then I wrote a simple script which triggers one LED per sensor. If there is movement on the left side, LED 1 goes red. Movement on the right side triggers the other LED. Due to limited visibility at certain ranges and angles I added a piezo for audio feedback.

motion sensors