Arduino: First Exposure

The day finally arrived last week Friday.

Lucy was at Grandma and Grandpa’s house for the day.  Katherine had no school, and I took the day off to be with her.  Katherine had no homework to do over the weekend, which meant Friday was prime for our first real dive into the electronics package for our strato-balloon.

But before I get into the day’s activities, let me provide a little context.

Katherine and I want to be able to collect temperature and pressure readings, GPS coordinates, and pictures during the flight.  All but the last would (ideally) be transmitted back to Earth.  I’ve had no micro-controller experience in nearly two decades, so not only was I rusty, I was WAY out of date.  What components would work well together?  Which ones wouldn’t cost me an arm and a leg?  These are the questions that I spent many nights fretting over.

Every search for a specific component seemed to yield another project that had done something similar, and were using a set of electronics that was completely different from everything I had already seen.  I finally decided that I simply had too many options, and I just need to pick one, put in the time to make it work, and hope for the best.

For the brains of the electronics package, I settled on the Arduino Uno.  This computer has a slight smaller footprint than a credit-card, and seemed to have enough computing power to handle everything we would need from it.  What really put me over the top in selecting this was the Trackuino project, which incorporates an Arduino Uno, a GPS receiver and a HAM transmitter – three of the major components we would need for our flight.  The Trackuino was designed for and used on many high-altitude ballooning flights, so this was a great fit.

The Arduino Uno it is.

Next I wanted to purchase at least a couple of the components we would use, so we could start putting the package together.  I settled on the temperature sensor, and the data logger.  That way, our starting point would be to 1) collect temperature data off of the sensor, and then 2) log it.  Sparkfun.com has lots and lots of Arduino-friendly components for sale, and they document like I do – wiring diagrams, sample C-code for running them on an Arduino, and more.  I purchased a TMP102 temperature sensor and an OpenLog Data Logger.  The latter would allow us to record the data to a microSD card, so I ordered one of those.

That was weeks ago, and it took Katherine and I until last week to find a day when we would both be available and relatively commitment-free to work on this.  Sheesh!

Our first step was to just get acquainted working with the Arduino.  Thankfully, the development environment comes with many sample programs, or "sketches".  We started with a simple sketch called "Blink" that would turn a light on for 1 second, then off for 1 second, then repeat.

The Arduino has several onboard LEDs, and one of them was hooked up to one of the external pins, pin 13.  It was that LED that we first got to blink.  Full disclosure – Blink is the default sketch loaded onto the board, so all we really had to do to get it working was plug the thing in, but hey – baby steps, remember?

The next step was to do something non-trivial (ok, slightly LESS trivial).  I have a small collection of LEDs in my electronics stash, so we hooked the board up to my breadboard, and hooked an LED up to pin 13 and ground.  We plugged the board in, and voila!  Both the onboard LED and the external one blinked in unison!

10

My original plan for the next baby step was to hook up a second LED to a different pin, and get that to blink, too.  We would modify the original Blink sketch to control both lights.

We hooked up the second LED to pin 12.

20

It took a little bit to figure out how to ground each LED properly, but after a couple of attempts we managed.  We left the red LED hooked up to pin 13.

22

And hooked the yellow LED up to pin 12.

24

We hooked both LEDs grounds together on the GND pin.

26

Next, it was time to modify the program.  The original Blink sketch defines a variable called "led" that is mapped to pin 13.

int led = 13;

We renamed it to "RedLight" so we could better distinguish it.

int RedLight = 13;

At that point, I asked Katherine to try compiling the program, knowing that it wouldn’t work.  The rest of the Blink sketch still referenced "led" as the variable name, so trying to compile the code in this state led to a compile error.

30

I wanted to show here what a compile error look like, how to read it, and how to fix it.  It didn’t take her long.

40

Then Katherine added another variable called "YellowLight".

int YellowLight = 12;

Next, we had to initialize the YellowLight pin so that it would be used as an output.  We followed the pattern that Blink used for RedLight.

void setup() {               
  pinMode(RedLight, OUTPUT);    
  pinMode(YellowLight, OUTPUT);
}

Then we had to add the code that would actually turn the light on and off.  Katherine started getting the hang of what we were doing, and she felt confident she could make the rest of the changes on her own.  I told her I was going to go rotate some laundry, but she should continue on.  Katherine was really starting to get into this because as I was walking away she exclaimed, "I can’t believe I’m PROGRAMMING!"  I came back after a couple of minutes to find this:

void loop() {
  digitalWrite(RedLight, HIGH);
  digitalWrite(YellowLight, HIGH);
  delay(1000);

  digitalWrite(RedLight, LOW);
  digitalWrite(YellowLight, LOW);
  delay(1000);
}

Everything looked fine, so we plugged the Arduino back in, and loaded up the new version of Blink.

50

Success!  Both lights were now blinking in unison.

I thought we would move on to the temperature sensor next, but Katherine had other plans.  She saw that I had red, yellow, AND green LEDs.  She immediately said, "let’s build a stoplight!"  That sounded like a great idea.

We had to think a bit about how to get three lights wired in, after a little tinkering, and trial and error, we came up with this.

60

We placed the three LEDs apart from each other, and then tied the ground wires for each into the GND pin on the Arduino.

62

We then wired the three lead wires for the LEDs into pins 13, 12, and 11, respectively.

64

Next, we needed to modify the program to turn them on one at a time.  When the next one in the sequence turned on, we also wanted the other two lights to be off.  Following the earlier pattern of "turn lights on, then wait", we arrived at this logic:

int RedLight = 13;
int YellowLight = 12;
int GreenLight = 11;

void setup() {               
  pinMode(RedLight, OUTPUT);    
  pinMode(YellowLight, OUTPUT);
  pinMode(GreenLight, OUTPUT);
}

void loop() {
  digitalWrite(RedLight, HIGH);
  digitalWrite(YellowLight, LOW);
  digitalWrite(GreenLight, LOW);
  delay(1000);

  digitalWrite(RedLight, LOW);
  digitalWrite(YellowLight, HIGH);
  digitalWrite(GreenLight, LOW);
  delay(1000);

  digitalWrite(RedLight, LOW);
  digitalWrite(YellowLight, LOW);
  digitalWrite(GreenLight, HIGH);
  delay(1000);
}

And here is the result:

 

***

Satisfied with that, we moved on to something more related to the balloon project – our temperature sensor.  I found a post on Bildr.org that explained how we could wire up the TMP102 to the Arduino, and provided code to pull data off: http://bildr.org/2011/01/tmp102-arduino/.  I didn’t want to actually solder the wires into the sensor yet, so we juryrigged it by wrapping wires around the five connections, and crimping them down.

70

The program worked as expected, dumping out readings from the sensor 5 times a second.  If we blew on the sensor, we saw the temperatures go up briefly, and then settle back down.

80

We also wanted Rainbow Dash to start getting comfortable with the equipment, so we had her take the sensor outside where it was sunny and relatively warm for a March day.

90

As well as test it indoors in our freezer:

100

After doing a little more research on the TMP102, however, I realized that it’s lower limit is -25 degrees Celsius.  We’re expecting much colder temperatures than that, so I think we’re going to try a different sensor from Sparkfun – https://www.sparkfun.com/products/245.

Overall, it was a very productive morning.

Advertisements

4 thoughts on “Arduino: First Exposure

  1. I don’t understand 95% of all that electronic mumbo-jumbo… but I LOVED that Rainbow Dash wore a scarf for the freezer test!! HAHAHAHA!

Comments are closed.