Tuesday, May 11, 2010

Arduino Reading Optical

Here is what is currently in production for the Arduino project. It is a draft and not finished work.

Reading Optical

Many optical devices are analog and not digital. The task is often to convert the response of the analog device into a more-or-less digital response. In the application of the analog devices in this segment, the analog pins on the Arduino chip will be used. Pins 0, 1 and 2 will be used. The analog pins on the Arduino read the input voltage from the device and convert into a numeric value.

The Arduino reference manual states, “This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit.”

Note that the voltages are still between 0 and 5 volts. Be careful not to fry your Arduino.

The numeric values from the analog pins may then be tested and branched using ranges of values and a case statement; an “if” structure will also work. Synthesizing digital action from an analog device merely means that the voltage has crossed a certain threshold; the number returned from the pin has passed a certain value and a test becomes true of false accordingly.

Goal

Instruct the student on input sensors- light (including optical encoder), switches and potentiometer. Optical encoders and switches are the “more binary” devices in the group; other items are “more analog”

Prerequisites

No prerequisites beyond the basic Breadboard Arduino class. These programs cover new material for this class and do not build on previous material.

Method

Cover analog versus digital input. Reiterate voltage capacities of the Arduino (0-5 volts). More information is available through the serial output than with LEDs in this segment.

Notes

There are multiple circuits on this board. Neither takes up much breadboard space or pins on the Arduino. If the infrared rangefinder is the Sharp brand, then a connector will most likely need to be built. In this case, a three pin, 0.10 inch pitch header pin was soldered to the end of the special pigtail for the sensing unit. After soldering, insulation and stability were needed, so a blob of hot-melt glue was added to the header pin.

The Parallax PIR unit, without a pigtail will only fit on the corner of the board due to I/O pin placement and jumper pin placement. A couple of ling wires are needed to connect to the Arduino. Other components are fairly straightforward.

The programs have some serial output to be displayed on the computer monitor. Power indicators may be left off.

The Class

Optical sensors are sensitive to light. Infrared (IR) has been grouped into this segment as it is looked at as both heat and light. It is light that cannot be seen with the naked eye, but certain electronic devices are sensitive to it. The remote control for your television is an IR device. For some reason, cameras on cell phones are sensitive to IR light. If you aim your TV remote at your cell phone camera, you will be able to see the light produced by the remote. There is more going on than just an IR flashlight, but at least you can verify that the batteries are not dead.

In this class, there are three devices- a simple photo resistor that passes power as a function of the amount of light striking it. This particular device is translucent and as such, is also sensitive to some of the light striking the back of the device. As more light strikes the surface, the resistance lowers. When the resistance lowers, more voltage appears on the Arduino analog pin and the Arduino returns a higher numerical value.

The infrared rangefinder uses reflected infrared light to determine range up to about 50 inches. Since it is using light, it is also susceptible to interference- things that would also get in the way of visible light. It is also sensitive to the color of the reflective surface. If sensing people, different colored clothing will yield different responses. It is not an exact science.

The Passive Infrared (PIR) device works the same way as the motion detector lights that light your driveway when someone walks by. It has a series of Fresnel lenses over an IR-sensitive device. When the device senses IR moving from one lens to another, a signal is produced. This device is also sensitive to distance. This particular PIR is a Parallax device designed for hobbyists.


Monday, May 10, 2010

Package from Sparkfun redux

It came- hooray for Sparkfun! Well, it probably came on Friday, but I wasn't there to receive it. I had it shipped to work thinking for some reason that it would get int my hands faster. In reality, the opposite was true. I received five twenty-eight pin chips with the little red dot. Now, I have to find out how to return the non-arduino chips. I'm pretty sure they have a procedure for that.

So, the big lesson here is that Sparfun made a boo-boo. Hey- it happens. The important thing is that they corrected the situation in a timely manner. When you next need electronic components- how about checking http://www.sparkfun.com/ first?

I should get back to work.

Monday, May 3, 2010

Arduino Light Dependent Resistor

Well, tonight, the board has a light dependent resistor (LDR). Only two of the three leads are used, so it's a little tacky, but this is, after all, prototyping. It will be cleaned up later- functionality is the name of the game right now. The analog value returned from the LDR drops with the light level. Using this value will enable the implementation of a small night-light circuit rather easily.

The easiest approach is to take the value returned from the LDR and feed it into an analogWrite command and use PWM to alter the brightness of the LED. Doing this directly would normally dim the LED as the light was dimmed. The LED was reversed and now operates as the inverse of the value read from the LDR. That is, as the light dims, the LDR returns a lower value, that value is fed into the analogWrite command and as the value drops, the LED gets brighter. Quick, easy, effective.

Here is the code in action:



Here is the board in action:


Happy breadboarding!

Sunday, May 2, 2010

Arduino Infrared

OK-
Nothing from Sparkfun yet, but weekend delivery was not expected- They need time to respond. So the next best thing was to borrow an Arduino off another board and get moving again.

The current project is an optical board with Arduino. Starting with infrared which may not actually be classified as optical, but it will be for this board. Passive Infrared (PIR) coupled with an infrared rangefinder makes sort of a neat human detector (or dog, cat, rats, what-have-you). Currently, the two items operate independently, but the code will be changed to let the PIR drive. If a heat source is sensed, then the rangefinder will be engaged. Perhaps. There are other approaches.

For your viewing pleasure, here is a picture of the board so far. It's a little blurry, but you should be able to get the point.


The PIR is at the bottom right, the IR rangefinder is at the upper right with the cable pinned under the breadboard. The LEDs indicate the power is on for the PIR and it has sensed motion, and power is on for the IR rangefinder and it has not yet been engaged.

More news as it happens.

Friday, April 30, 2010

Another Sparkfun Response

OK- from the previous post, it would seem that Sparkfun made a boo-boo and is doing the right thing to fix it. Hurray for Sparkfun!

While I am composing the last post, this email comes in (I left off the email headerinformation because it was a pain to post as it kept gagging the HTML):

Hello Bruce,

Our returns department finished testing the ATmega328s you returned to us, and found that they had somehow made it out without the Arduino Bootloader having been loaded. I have placed a new order, # 21xxxx, which contains five ATmega328, DEV-09217.

Please let me know if I can help with anything else, and have a great day!

Best,

L (Sparkfun rep name)
Customer Service
SparkFun Electronics

Now- I have not yet returned anything, but they have tested them.  I think I will wait and see what comes in the mail. Sparkfun may be experiencing growing pains- that's OK; it happens. Let's see how they handle it. I believe they will make everything right, it just may take another pass at the problem to get there.

Sparkfun Response

Received from Sparkfun:

Subject: Re: [FWD: SparkFun Order 21xxxx]
From: Tech Support
Date: Fri, April 30, 2010 10:16 am
To: "Your Host"


Hi Bruce,


I talked to customer service, they should be sending you out 5 replacement ATMega328s with the bootloader and a return label for the 5 unprogrammed ones. Sorry for the inconvenience this has caused.


Thanks,


P (Sparkfun rep name)

Monday, April 26, 2010

Sent to Sparkfun

Subject: [FWD: SparkFun Order 2xxxxx]
Date: Mon, April 26, 2010 11:39 pm
To: customerservice@sparkfun.com

Good day.

I received my latest order from Sparkfun. I had some spark, but unfortunately, no fun.

On my previous order, I received Arduino 328 chips. All were marked with a red dot but one. I had my doubts, so I reserved it. When attempting a project with the unmarked chip, it would not load. OK, I still needed some more Arduino chips, so I ordered four more- Order 2xxxxx. I received the four chips I ordered, but none were marked. I removed one from the package and tested it- it would not load.

Here is what I did to test:

1) Took a known good circuit and removed the Arduino
2) Installed the unmarked Arduino
3) Recompiled the code
4) Attempted to download
5) Received the following error:
avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51
6) Powered down
7) reinstalled the known good chip
8) Powered up, recompiled code
9) Downloaded code
10) Code executed as expected

I think none of these chips has the Arduino bootloader loaded on, even though my packing list has a certification of compliance signed by the Customer Service Manager. What do you think?

I am attempting to write a class using Arduino chips, but that is rather difficult when they are not the correctly configured chip and my deadlines are slipping. I now have 5 chips that are not what I purchased. What can you do to rectify this situation?

Sincerely,