Skip to content

Lab 4: Analog In with an Arduino

June 13, 2009

Finally getting into playtime with sensors.

Some people have asked me what the heck I’ve been talking about, so a little background to start: up until now, we’ve only been working with digital input.  Many sensors give back analog output, and the Arduino’s microcontroller, being a digital creature, needs to have this converted into 0’s and 1’s.  What makes the Arduino so breathtakingly pleasurable to use is that this conversion is handled by an ADC, or analog-digital converter, piggybacked onto the same board.  This converter assigns a number between 0 and 1023 to the signal coming in, and then that signal can be utilized to drive something else, from an LED to the Mars Rover.  “Driving something else” is output, and will be covered in the next lab.  1023, by the way, is the equivalent of 4 bytes of information (4 groups of 8 0’s and 1’s).

If you’re asking yourself, “What’s a sensor?”, you’ve certainly seen a thermostat at home that both senses the temperature and controls–or purports to control–the boiler and radiators.  There are hundreds if not thousands of other kinds that sense flex, vibration, pressure, light, chemicals, alcohol gas, barometric pressure, acceleration, distance by infra-red light or ultrasonic sound, color, magnetic north, etc.  And I’d bet we’ve only seen the tip of the iceberg.  There’ll be many many more on the way, and they’ll only be getting more and more sensitive.  They don’t all produce analog output, and there are other ways to communicate with them, but more about that later.

With all this being said, I will confess to going a little light on this lab as the Midterm has been all-consuming: I just used a potentiometer to see how an Arduino takes in an analog signal right now, and held off on hooking up a sensor for later.  A potentiometer, or “pot”, is a simple variable resistor, and is what’s used for a volume dial on your radio, or a dimmer switch for a room light, for example.  As it is rotated it develops more or less resistance, letting through less or more voltage respectively.

Here I’ve prepped the breadboard.  The LED is just showing that there’s power in the circuit.  The potentiometer is at the bottom, not yet hooked up.


Here everything’s hooked up, but powered down:


And here, powered up, with the pot turned all the way up:


The red power LED stays at the same intensity as it is not on the same circuit as the pot.  The yellow LED is controlled by the pot.  Here’s the circuit diagram from the Lab:

arduino_analog_input_schemAnd here’s the code:

No Serial Monitor

When you turn the pot, the Arduino reads the amount of voltage being sent to it, converts that into a number between 0 and 1023, and then sends a serial signal back to the laptop.  This would be reading out on the bottom of the screen, but I forgot to push the Serial Monitor button at the top right, so here we go again:


Serial Monitor 0

The pot is turned all the way down, and the yellow LED is off: the reading is 0.  The next two images show a mid-range readout of 452, and then an “all on” of 1023:

Serial Monitor 452

Serial Monitor 1023

Onwards to Output!

  1. Ralph permalink

    I am new to Arduino and Programming, but even at 64 years old I am having fun. My problem is that I cannot read the “Code” on the screen captures in this blog entry. Is it possible to receive the code as a discrete file?

    Thanks for your work.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: