Monday, May 24, 2010

Ultrasonic Range-finder with LCD Character Display

I purchased a 'Ping)))' Sensor from Radio Shack today, and after soldering pins onto my 16x2 LCD character display, I set out to create an ultrasonic range-finder with my Arduino.  As far as the hardware was concerned, wiring the LCD panel took the most time.  I am quite pleased, though, with the level of contrast control obtained from the potentiometer (seen in the upper left corner of the breadboard).  This simple adjustment makes it easy to get a crisp character readout on the display.  The device runs on a nine volt battery and gives accurate distance readings from 2cm to about 3m at increments of 1cm.  You can power the device via USB instead of a 9volt battery and when connected to the computer in this way, range data is sent to the computer via virtual com port.  Below is the code being run.

/* Ping))) Sensor and LCD Readout

This sketch reads a PING))) ultrasonic rangefinder and displays the
distance to the closest object in range. To do this, it sends a pulse
to the sensor to initiate a reading, then listens for a pulse
to return. The length of the returning pulse is proportional to
the distance of the object from the sensor.

http://www.arduino.cc/en/Tutorial/Ping
http://glennlangton.blogspot.com

created by David A. Mellis and Tom Igoe
modified to include LCD readout by Glenn Langton
*/

// include the library code:
#include

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// pin number of the sensor's output:
const int pingPin = 5;

void setup() {
// set up the LCD's number of rows and columns:
lcd.begin(16, 2);
// set the cursor to column 0, line 0
lcd.setCursor(0, 0);
// Print inches to the LCD.
lcd.print("inches");
lcd.setCursor(0, 1);
// Print cm to the LCD.
lcd.print("cm");
// initialize serial communication:
Serial.begin(9600);
}

void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);

Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();

// set the cursor to column 8, line 0
lcd.setCursor(8, 0);
lcd.print(" ");
lcd.setCursor(8, 0);
lcd.print(inches);
// set the cursor to column 8, line 1
lcd.setCursor(8, 1);
lcd.print(" ");
lcd.setCursor(8, 1);
lcd.print(cm);

delay(500);
}

long microsecondsToInches(long microseconds)
{
// According to Parallax's datasheet for the PING))), there are
// 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
// second). This gives the distance travelled by the ping, outbound
// and return, so we divide by 2 to get the distance of the obstacle.
// See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
return microseconds / 74 / 2;
}

long microsecondsToCentimeters(long microseconds)
{
// The speed of sound is 340 m/s or 29 microseconds per centimeter.
// The ping travels out and back, so to find the distance of the
// object we take half of the distance travelled.
return microseconds / 29 / 2;
}

Monday, May 17, 2010

A Scouting Recap

A speech I presented at my Eagle Court of Honor:

Since starting as a Tiger Cub Scout in first grade, I have come a long way through Scouting to arrive where I am today. It has been an amazing journey through which I have struggled, endured hardship and laughed, but in every experience I learned something.

Throughout Cub Scouting, my den leader (a.k.a. Mom) provided Den 2 of Pack 104 with phenomenal field trips, getting us to go places and do things few people get a chance to do. We toured a land fill and radio station, raced cubmobiles, went grunion running, attended a city council meeting and backpacked all BEFORE I was a Boy Scout.

My transition into Boy Scouting wasn’t a hard one (even if I did have to let go of pinewood derby races) because my older brother had already told me about many of the activities I could expect in Boy Scouts. As long as he was in the troop he mentored me and we enjoyed many outings together.

I quickly learned the ropes (literally as well as figuratively), and acquired many Scouting skills I would need for future trips. My father became Scoutmaster not long after I entered the troop and served in that position for the majority of my Boy Scouting years. We enjoyed many engaging meetings and exciting trips together, while also sharing ideas for improving the troop.

Occasionally on outings, a Scout’s creativity can overflow. I’ve found that hiking sticks provide excellent leverage for launching dried cow patties, slippery grass on a dew-covered hill is the best surface for urban canoeing, and when trying to catch mini bears (i.e. chipmunks) you run the risk of them dashing through your tent.

Of all the outings I’ve been on, a few stand out from the others. Emerald Bay’s “Rugged E” was filled with cliff jumping, night kayaking, and war canoe trips. Philmont Scout Ranch included over 70 miles of backpacking, amazing campfires and a hilarious train ride. My participation in the 2001 and 2005 National Scout Jamborees allowed me to tour the east coast, meet Scouts from around the world, and applaud the President’s address to the Boy Scouts of America. These experiences have been some of the best in my life.

Scouting’s journey has impacted me, and not just Scouting in general, but specifically those people who taught, encouraged, disciplined, and supported me. I am grateful to my parents, Scout leaders and friends for all they have invested in me along the way. Your contribution has made me a better Scout and I will continue to grow and learn --being prepared to do my best and doing my best to be prepared.

Saturday, May 15, 2010

Hello World: Starting out with Arduino

I recently purchased an Arduino Duemilanove from http://www.adafruit.com/.  As my "Hello World" beginning code I modified a sketch to signal SOS in Morse Code from a blinking LED.  A picture of the Italian made open hardware micro controller and my code are below.

/* SOS Blink

Blinks LED in Morse Code "SOS", repeatedly.

The circuit:
* LED connected from digital pin 13 to ground.

Created 5.15.10
By Glenn Langton
http://glennlangton.blogspot.com

based on an orginal by H. Barragan for the Wiring i/o board

*/

int ledPin = 13; // LED connected to digital pin 13

// The setup() method runs once, when the sketch starts

void setup() {
// initialize the digital pin as an output:
pinMode(ledPin, OUTPUT);
}

// the loop() method runs over and over again,

void loop()
{
/* Code S */
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(300); // wait for 3/10 second
/* Code O */
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for 1 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for 1 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(1000); // wait for 1 second
digitalWrite(ledPin, LOW); // set the LED off
delay(300); // wait for 3/10 second
/* Code S */
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(100); // wait for 1/10 second
digitalWrite(ledPin, HIGH); // set the LED on
delay(500); // wait for 1/2 second
digitalWrite(ledPin, LOW); // set the LED off
delay(300); // wait for 3/10 second

/*Pause 2 seconds for next SOS sequence*/
delay(2000);
}

Friday, May 14, 2010

Eagle Project at the San Fernando Mission

To achieve the highest rank in scouting, Eagle Scout, you must plan and execute a service project.  Here's a description I wrote just after completing my project at the San Fernando Mission.

Project Description

Monsignor Weber is the administrator of the San Fernando Mission, and responsible for the Archival Center and Mission grounds. He is also in charge of the Mission Museum. Monsignor Weber told me of the need for the Mission Museum artifacts to be labeled. The majority of the artifacts on display have no labels. The labels that are in place are poorly written, made on deteriorating material, and are often incorrect. Unfortunately, there are no personnel at the Mission who can reasonably undertake this task.

There are many rooms that make up the entire Mission Museum collection; however, my project will only be encompassing the two rooms with the highest traffic and greatest need. These connected rooms will be referred to as the North and South Museum rooms and contain many items from the Pope’s visit to Los Angeles, Indian baskets from all parts of California, and items from when the Mission was first built and used.

How My Project will be of Benefit to the San Fernando Mission

Without anyone to undertake the job of creating labels for the museum artifacts, this job has been left undone for 30 years. The labeling of the many artifacts on display would help the Mission with a job that would otherwise never have been accomplished. Over 30,000 students a year visit the Mission on field trips as part of their study of California history. Labeling the artifacts on display would give a more interesting and comprehensive understanding of the Mission Museum. The San Fernando Mission is the most important landmark in all of the San Fernando Valley and surrounding area, being the first settlement in this area of California. The history of the Mission would be made more available to the community and students, who regularly visit the museum. Many of the 21 California missions, including the San Fernando Mission are in need of money for structural repairs and artifact preservation. There is currently legislation that, if passed, will support the missions with this much needed money, but there is controversy over the separation of church and state that is preventing these measures to be taken. This eagle project will help to preserve the history and importance of many artifacts at the San Fernando Mission.

Carrying out the Project

My project, being of an intellectual nature, required the help of adults capable of good writing and proofreading. While I was able to use fellow scouts and peers for such tasks as data entry, cleaning of cabinets, and cutting of mat board, I sought the more qualified help of adults to perform the intellectual tasks. I was able to gather support from adults in my church, school, and troop. This provided the unique experience of having to delegate responsibility and oversee a project in which most of those working under me were much older, unlike what I had experience doing with those mostly younger than me in a troop or patrol setting.

Labor

The total amount of labor invested was just over 600 hours. That amount of time was divided between 30 people over the course of approximately two years. I invested about 100 hours of my own time, half of which was spent on planning and the other half of which was spent distributing responsibilities and overseeing progress on my project.

Due to the nature of my project, though many people are involved in the label making process, the majority of the man hours contributed falls to a few individuals. At the start of my project, there were many tasks and responsibilities to be distributed such as making sure labels were written, data entry, proofreading, and etcetera. As the project continued, tasks became more specific and individual work such as specific basket research, or approval by the Monsignor was narrowed down to a few crucial people.