Tuesday, November 2, 2010

Sensors part 2 - Environmental Sensors

Temperature Sensors
These are most common found in air-conditioning unit to lower the room temperature to the temperature set by the remote controller.  They are widely used in a lot of electrical appliance and PC motherboard to measure the temperature. There are analog and digital version of the sensors. The common ones are the LM35 (analog) and DS18B20 (digital) and thermistor.

I've compared three temperature sensors ( LM35, DS18B20 and DHT11 ) and my findings are as follows :-

DS18B20



DS18B20 1-wire parasite power


DS18B20 - These are the best, most expensive and harder to find locally. The DS18B20 uses a 1-Wire bus for data transfer (another wire for ground) and can be daisy chained together to draw power directly from the 1-wire bus "parasite power" with a 4K7 ohm pull-up (5V) resistor. They only use 1 digital pin on the Arduino and can support a lot of these sensors on a single pin as all the DS18B20 have unique address in them. Just need to load the libraries and call the function to retrieve the temperature from each of the sensors. Since the data is digital, these sensors are not dependent on voltage level and can go a further distance.

LM35

LM35 - These sensors are very common and easily found locally. They are analog sensor and need to be connected to Arduino analog pin to get the voltage level. If the power supply are not regulated at 5V and fluctuating between 4.8-5.5V,  these analog sensors could give a wrong readings as they are dependent on the voltage level. Even when I use analogReference(INTERNAL) using the internal 1.1V for the temperature calculations, with different power source, regulated 5V and USB 5V power, the temperature reading are off by 1C between them. In terms of accuracy, they are 0.5- 1.0C higher than the DS18B20 so you might need to do minor adjustment in the temp calculations. If you think the temp reading are off, always use a multimeter to check the power supply voltage.

Thermistor

A cheaper way to measure temperature is to use a thermistors together with a 10K resistors.

Gas Sensors

Smoke and gas sensors

These different sensors that can detect different gasses like CO, CO2, alcohol, LPG, smoke and air quality. A smoke detector usually works in conjunction with an alarm detect smoke using optical or ionization methods.

Relative Humidity Sensors
Humidity sensors also known as hygrometer, measure the relative humidity in the air. It measures both the air temperature and moisture. It is express as a percent, is the ratio of actual moisture in the air to the highest amount of moisture air at that temperature can hold. The warmer the air is, the more moisture it can hold, so relative humidity changes with fluctuations in temperature. 

DHT11 sensors

These sensors are always combined with a temperature sensors and give digital readings. The common ones are DHT that sense both relative humidity and temperature with digital output.

I've tested this sensor, DHT11, they are relatively cheaper than the SHT-11. The sensor are from Aosong AM2303 with range of 0 - 100% Relative Humidity and Temperature range of -40 to 125 Celsius. The accuracy are +/- 2% RH. The output from the sensor are digital but they are connected to an Analog pin from the Arduino. After initialising the sensor, you call a function to get four values from the sensor, relative humidity in percentage, temperature and the checksum. I find the temperature value is 1C higher than DS18B20.

Thursday, October 21, 2010

Sensors Part 1 - Interaction with the Physical World

We use sensors everyday and they are so common that we sometimes forgot about them or didn't even know they existing until the sensors stop working... here are some sensors that we encounter in our everyday life... let start with the most popular ones.

Button sensors


You might think this is not a sensor but just a button but it is the most important sensors to the computer. We input our characters via a keyboard, a collection of buttons! A few tricks can be performed by the button sensor to have different behaviors.

Big button sensors, push button and numeric pad


  • pushing a button to turn a LED on or off ( AKA on/off pushbutton switch )
  • holding a button will turn on the LED, releasing the button will turn off the LED
  • holding a button to adjust the brightness of the LED or two button volume control on laptops
  • double click the button to select a menu or just to the next sound track, this is commonly found on the mouse buttons or mp3 players to skip a track a song.
  • triple click on the button, this can be found on Apple iPhone headset/mic to play the previous sound track.
  • buttons arranged in four directions to navigate up/down/left/right
This will give you some idea on how you can program the behavior of just a simple button sensor. You can buy Arduino button sensors, a big yellow button for educational purpose. What you use it for is up to your creativity.


Rotary Sensors


This is probably the second most common sensors that are found anywhere from volume controls to old generation of iPad. Apple designers found out that it is much easier (and faster) to select songs using a rotary sensors that an bunch of arrow keys. All our mouse have a wheel in the middle made for scrolling functions. An earlier version of rotary sensors was found in the side of older Sony products called the jogdial, a single hand operation to combine the push button with a rotary sensors.

Rotary sensors

The above is the rotary sensors for Arduino to be used as input interface for your projects.

Touch Sensors
These sensors are found in all touch screen phones and touchpad below the laptop keyboard. The last few generation of iPod uses touch sensors as a replacement for rotary sensors.

The latest generation of touchscreen smartphones uses a capacitive touch screen while older touch screen phones uses a resistive touch screen that depends on the pressure of the stylus/pen. 



Range Sensors

Sharp IR range sensor

This sensors are activated when we shift to the reverse gear, they are called reverse sensors or parking sensors. Similar sensors are used in art gallery to detect when a person is near the art work or within the predefined range. For robotic, these sensors can be used to detect the distance of an object in front of the sensors.

Range sensors works by sending a source of light or wave and measuring the signal that was reflected back and comparing it with the energy that went out. The common ones are like Sharp GP2D12 (10 to 80cm) and other depending on the IR range.



Motion Detectors (PIR)
PIR sensor


These sensors are commonly used in burglar alarms, automatic lightning and those annoying sensors in 7/11 that plays a tune when someone walks into the store. They are use to detect presence of a person within a range. They are called Passive IR or just IR motion sensors. The white dome is a lenses that focus the energy to a pyroelectric sensors that detect changes in IR radiation. Ladyada.net have a detail article about the PIR motion sensors.




Photoelectric Switches

Photoelectic switches
These sensors are most commonly found on newer elevators that will stop the elevator door from closing when the beam is cut.

Laser and light dependent resistors (LDR)


A cheap and easy way to make one of these sensor is using a laser pointer and a light dependent resistors or photocell. Once the laser is cut, the photocell will detect the change in light and trigger an alarm. This is both fun and easy to make.







Saturday, October 16, 2010

Arduino Output : LED, roll of LEDs and LED Matrix

As a beginner, after getting an Arduino board, the first tutorial is to control a Light Emitting Diode (LED) to make it blink or fade at different voltage levels and different timing using the delay function.

For the tutorial, please refer to http://www.earthshineelectronics.com/ and click on the External Links - The Complete Beginners Guide to the Arduino by  Mike McRoberts.

*** Always put at least a 220R or higher resistor between the standard 5mm LED and the Arduino pin to limit the current flowing through the LED. This is to protect the LED and also limit the current flowing across the pin back to Arduino. Even if you are using the correct voltage for the LED, you still need a resistors to limit the current. A good article here talks about LED in details and even have an experiment of using very small resistors between the LED to measure the current flowing through it.

LED have two or more legs, the longer leg is anode (a or +) and the shorter leg is cathode(k or -).
How do you find out the different legs if you have cut both the legs to the same length to be inserted into the breadboard. The way to identify this is easy, the flat side is the cathode as per the picture below.


By now, you would notice that the LED will only light up if you connect them correctly, positive (+) to the anode and cathode goes back to the negative or ground. The resistor can be placed before or after the LED to limit the current of the entire circuit.




This is a very good tutorial to introduce programming to beginners but it isn't very useful in the real world just to make LED on and off over and over again... LED indicator are very useful tool for debugging and to "see" what is going on especially during data transmission and wireless stuff.



When you combined a roll of LEDs together, you can make more fun stuff like LED VU meters to response to audio input or LED chaser on the car from an old tv series called Knightrider. You can control the speed of the LEDs to make it more lively. This setup will take up 8 pins from the Arduino.
If eight rolls of LEDs are combined together, it become a LED matrix like the picture below.

LED Matrix

There are single colour LED matrix or multi colour LED matrix for different usage. One thing you notice is that to drive a 8x8 LED matrix, you will need 16 pins ( 8 top and 8 bottom pins ) and Arduino do not have enough pins for this purpose. The solution is to use a chip called shift registers.. the most popular one are the 74HC595 Shift Registers. Another note for beginners is that if you get a 8x8 LED matrix that is too big, it will NOT fit into the breadboard, anything 3 cm or larger will not fit a single breadboard. If you are buying LED Matrix, please get the common cathode version.

LoL shield


A 9x14 LoL (Lots of LEDs, not Laugh out Loud ) Shield is a nice and clean shield to have without all the messy wiring on the breadboard. The details to make one is here.

Big LED displays


Here are some interesting projects and products using LED matrix. Small Room Labs did a 16x16 LED matrix and Sparkfun did a 64x64 LED Matrix coffee table. If you are not aware, most of the LED monitors and LED TV are made up of very very small three colour LEDs combined to display the graphics in a high resolutions like 1920x1080 LEDs.

7 segment LED display


Another common LED is a 7 segment LEDs that use to display number from 0 to 9. There are single digit or multi-digits parts to choose from. For the 7 segment LEDs, please get the common cathode (CC) version (all the LED cathode pins are connected together) as it is easier to drive the display with either a 74HC595 shift registers or a 4026 or 4511 chips. Both the 4026 and 4511 have 7 segments LEd display drivers/output but the inputs are different.

The 4026 is a decade counter (0-9) that takes input electrical pulses ( for example, every press of a button will increase the digit by one ) and display the digit on the 7 segment LED. This can be used for making a digital clock by sending an electrical pulse to the 4026 every second for the second digit.

The  4511 take in 4-bit binary coded decimal from 0 (binary 0000) to 9 (binary 1001) and display it to the 7 segment LED. An example would be to read an input from a temperature sensors and display the three digits temperature to the 7 segment LED using three 4511.

These useful chips (74595, 4026, 4511) are all building block to make functional gadgets found in other webpages.

Add on : I was viewing a youtube video on Sparkfun founder's speech on a google event and he mentioned something about this giant 7 segment, 12 feet GPS wall clock and how to make one. Why use GPS as a clock source, because GPS have the most accurate clock down to 100 nano seconds.

Please refer to Arduino Playground on the section about LED for more details on all the above mentioned.