2010年6月8日火曜日

Sensor 02 Ping Ultrasonic Range Finder

http://arduino.cc/en/Tutorial/Ping

This experiment is based on Arduino webpage.

Ping Ultrasonic Range Finder is useful to detect a distance from the device and object.

For the art creation it must work as a good interactive device such as change the darkness of a movie that is projected by a projector or new interactive musical instrument.

This exercise enable you to understand about Arduino programing.

I am going to add little program to the original program, which is available on Arduino webpage, to make Theremin like function.

For this tutorial you need followings.

Requirements

Ultrasonic Ran Range Finder (from Parallax the company made Boe-Bot )

220 Ohm resistor

Buzzer

wires

Arduino




Circuit





Program

For this circuit, use the program that is on the Arduino webpage.

http://arduino.cc/en/Tutorial/Ping

Important things that to know are:


To set up device, "deigitalWrite(pingPin, LOW);" is written


A command "pulseIn" is used to get a length of the time that sound goes and back.

"puleIn" provide information of the time by microsecond.

It is very useful, "pulseIn" is not necessary but if we make a program that act like "pulseIn"is taking times and complex.

To make a similar function we need to use "while" command to loop until the sensor got returned sound and we need to make a counter by "increment" and "delaymicrosecond"  to make a function of stopwatch.

Basically, the digital input can deal with only 0 or 1 so that we are actually counting a time with arduino instead of measuring a distance with Ultrasonic device. And change the time to length with our scientific knowledge and mathematic.  It is conducted in a "function" of "long microsecondsToInches" and "long microsecondsToCentimeters".

More thing that we should know about this program is that the program uses "long" instead of "int" for the variable of duration inches and cm. Since "puleIn" return the time by micro-second the value will be huge if the object is located at a distant place so that the value will beyond the capacity of 32bit.


To add a function of Theremin add following program at the end of "void loop"


int frequ;

frequ = max(duration,3000);
int sound = map(frequ, 0, 3000, 100,800);

tone(8, sound, 300);

delay (200);


This program changes the value that is gotten from Ultrasonic device to certain amount(in this case from 0 to 3000). I use it for a value of frequency. However, frequency 0 is impossible to hear and frequency 3000 must be too high so that I use "map" to change the frequency to audible range. 






1 件のコメント: