Friday, October 22, 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. 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 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.

Friday, October 15, 2010

Arduino : Make or Buy ?

As Arduino target a wide range of users from hobbyist to artists to fashion designers, you have a wide range of choices. As the hardware is "open source", you can buy the board directly from Arduino in Italy or some of its clones or Arduino compatible boards near to you.

As everyone have different requirements,  you can either buy an Arduino board and its wide variety of shields (the add-on board that sits on top of Arduino boards) or make it yourself in a DIY way by buying the ingredients like ATMEL AVR chip (with Arduino bootloader), resistors, capacitors, LEDs, hook up wires, sensors and of course the breadboard.

Buying the Arduino board and the ready made shields have its advantage as you can just focus on what you are trying to achieve, programming the board, making a data logger, controlling robots, expensive thermometers without worrying about soldering, electronic components, and parts with different voltages and connectors. Buying it would be more expensive but you do not need to worry about parts not working as most of the shields are usually tested and have the library to support it.

Some of the more interesting Arduino shields like LCD shields, motor shields, colour LCD shields, LED Matrix shields and proto shields. The proto shields are blank board that you can make your own shields
by soldering electronics parts and sensors on top of it.

The second option is to make your own parts, for example I made a LCD module by buying the LCD module, solder 16 header pins, hook it up with some jumper cables to monitor the light from a Light Dependent Resistor(LDR). Well, the function is the same but it looks a little bit messy.

Arduino with LDR and 2x16 LCD module

After trying out a few other sensors like LM35 temp sensors and LDR , I went a step further and ordered an ATMEGA 328 chip (with Arduino bootloader)  and make my own Arduino on a breadboard for a fraction of the price of the Arduino board. I did my research from scratch on what to do, what parts to buy, from the voltage regulator, the ATMEGA 328 pinouts to decoupling capacitors.

Arduino on breadboard with MAX232

This is the finished Arduino on a breadboard, the total cost is only a fraction of an Arduino board. I have an existing  USB-Serial adaptor and breadboard, so it would cost much less for me. The only thing I need to solder was the DB9, RS-232 female connector to connect to the MAX232 serial chip. The setup is very similar to older Arduino serial board like the Freeduino Serial below.

Serial Freeduino

Update : I've rearranged the MAX32 chip to be nearer to the ATMEGA 328 Rx/Tx pins and added a 2x16 LCD Module with some extra space on the breadboard for adding in sensors and speakers.

Arduino on breadboard with Sharp IR sensors and LCD module

For the breadboard above, I have a Sharp GP2D12 ( 10cm - 80cm) IR range sensors with a sketch to display the distance of the sensors and trigger an siren via the speaker when a predetermine range is reached. This is a standalone application without the PC or the USB port. It takes power from 7.5V to 12V power adapter.

Comparing to the first picture with Arduino Duemilanove, breadboard and LCD module, my breadboard version look so much neater with less jumper cables crossing over to each other. Besides the Atmel ATMEGA 328 chip with Arduino bootloader, all the other parts are easily found in Kuala Lumpur, Malaysia.

Tuesday, October 12, 2010

Arduino - Open source hardware

When we mentioned open source, most people will think of software like GNU/Linux, those free and open software where you have access to the source codes and you can make changes to the codes to suit your needs if you have the knowhow.

When we mentioned microcontroller (MCU in short) to non-engineers, most people will think of those chips and electronics inside a modern car that controls the air intake, fuel mixtures and other parts of the car or the chip in the washing machine that control the washing cycle. It is the intelligence that make the electronic appliance works and repeats over and over again with limited options or customisation. This is the hardware part I am taking about.

Arduino founders Massimo Banzi and David Cuartielles spend time and money to designed the board, make the actual hardware and sell it for a small profit. What they did different is that they published everything for everyone to take, the design files, schematics, software for the board. Anyone can built the hardware at the lowest cost, sell it and keep all the profits without needing to pay the founders any royalties. In an article from Wired magazine "Build It. Share It. Profit, Can Open Source Hardware work"  Banzi quoted "If you publish all your files, in one sense, you are inviting the competitors to come and kill you".

Enough of definition and history. One of the first questions a beginner will ask, what can I do or use Arduino for ? Is it easy to learn how to program and use ? How much does it costs ? I do not know electronics, will I be able to pickup all the necessary skills to make it work ? Where can I buy parts for my projects ? This is where this blog, Arduino for beginners will be different and will talk more about sensors and their usage instead of just howto and tutorials on projects.

Let me address them one by one... What can you use an Arduino for ? Well, you can use it to interface with the physical world. The most basic would be to control LEDs (not very useful with a single LED, just make it blink at different timing) but when you combined it with sensors and creative ideas, you can create lots of fun stuff  like mood lamp using a 3 colour LED, scrolling LEDs, distance finder, motion sensors, home made alarms, custom remote controllers and one of the most popular, make robot more intelligent with sensors, servos and logics.

Machine or computer interface with human using sensors and everything we use today have many sensors in them. I'm not talking about temperature sensors in the aircon but most basic stuff like the keyboard I am typing this blog, it is a combination of many buttons sensors, mouse, an IR sensors. Apple macbook have tons of sensors (to make it more cool and intelligent) besides the keyboard, touchpad is a touch sensors, light sensors to dim the screen in dark room, proximity sensors to off the display when you close the lid, IR sensors to take input from the remote controller. With the iphone, they have sensors like accelerometers, touch screen, proximity and light sensors. Well you get the idea.

Arduino with its input and output pins, can be program to either read sensors using digital pins (on or off) / analog pins (voltage differences) or send an output to the output device like a LED, speakers, USB/serial port to the computer, LCD screen or turn on/off an electrical appliance using relays.

Please refer to Arduino Playground for more details like interfacing with hardware, software and other related information.

Wednesday, October 6, 2010

The breadboard

Anyone going into electronics will definitely need this : a breadboard. This is a historical name that stick till today because during the early days, they used to nail copper wires to a wooden board that used to cut ... well you would have guessed it... bread. Today, they are also called solderless breadboard or plugboard. ( source : )

The top and bottom two horizontal rolls (connected together inside the breadboard) are for power supply ( + and - ) and the two five rolls in between are connected vertically inside the breadboard. The groove in the middle is designed so that an integrated circuit (chips) with long legs on both sides can be plugged in between the groove. These are called DIP ( Dual In-line Package ) chips.

Electronic basic components - LED, resistors, transistors and capacitors

First thing to learn about electronics is what parts does what, I read thought several materials like books and webpages but find it a bit difficult to understand it completely. Later I discover that Makezine did a series of very clearly explained video on YouTube on the following components called Makezine presents :-


Light Emitting Diode (LED)




and last one is Integrated Circuits AKA microchips or "chips" in short.

As most of the electronic books explain the above components like a textbook style just to fill up the pages, the above video show it in a more lively way with some historical background about how the components was invented or discovered.

Buying electronics components

The nearest electronic components shop was located in SS2 in  Petaling Jaya, Malaysia. This shop have a wide variety of common electronics parts but you must know what parts you needed as they do not offer a "Starter Kit" to newbies. I had a long list of parts taken from the Make : Electronics book like resistors, transistors, LEDs, potentiometers (pot in short), capacitors, alligator clips, breadboard and jumper cables.

I had no idea how much it cost per parts so I buy in small quantities but found out they were really cheap especially the resistors. Some of the parts I needed they have no stocks and I have no idea what other parts can replaced it.

The biggest issue are the resistors and capacitors, I somehow ended up with those resistors and capacitors I do not need and the lab examples always needed some other parts that I do not have. Since they are kinda cheap, I ended up buying lots of different resistors ( 220R, 330R, 1K, 10K, 20K, 1M and many many more ) and different types of capacitors in different farad ratings. Here is a good link to the resistors colour codes calculator.

So the first thing as a beginner I learn about electronics or Arduino, get the Arduino Starter Kit and save all the hassle and trouble of making a few trips to the electronic components shop.

An electronic and Arduino blog for beginners by beginners

My target audience of this blog would be for people with almost zero knowledge of electronics and microcontrollers like Arduino. Like myself, I stumbled upon Arduino a few months ago but since I did not know anything about electronics, I did not pursue it further due to that barrier.

I was always curious about how consumer electronics work and since I was very young, I like to take apart old electronics appliance to see what is inside and hopefully find something useful I can salvage. During those days, I never figure out what are all those components are for and most electronics books are textbooks for Electronics Engineers (lots of maths and formulas). After I started using computer and doing computer stuff in my teenage years, I kinda left this electronics interest of mine in the back of my mind.

How I started learning electronics again is when I pickup this book called Make : Electronics, Learning by Discovery by O'Reilly. This book approach is really different from the other electronics books as it assume that the reader have absolute zero knowledge in electronics. The author even teach you how  "taste" electricity!!

After reading a few chapters, this is where the fun begins, buying electronic components for the first time. I did not buy any sort of starter kit (did not know it was available) so I have absolutely zero electronic parts except for a soldering iron and a mini analog multimeter.

The second highly recommended book is Getting Started in Electronics by Forrest Mims. This book is very unique as the texts was hand written and diagrams are hand drawn!!!! This book was quite old as the first edition was publish in 1983 but as most of the basic information does not changes that much and most of the information are still relevant and useful today.

Tuesday, October 5, 2010

Hello World (LED blink blink blink)

LED blink blink blink (loop forever). I learned that this is how you program "Hello World" in the electronics and microcontroller world... of course using an Arduino on pin 13.

That it for my first posting for Arduino Beginners Blog for Malaysia.


Related Posts Plugin for WordPress, Blogger...