More work with analog and digital

When last we saw our hero (me), we had a sort of sketchy resistometer. The code is set up poorly and the LEDs don’t work properly. Let’s see if we can fix that.

The first thing we need to go over is the interaction of parallel and serial electric circuits. In our previous design the LEDs were all in parallel, and that parallel array is connected to a single resister. It looks something like this…

Diagram of parallel LEDs

Diagram of parallel LEDs

Here’s the problem: because behind each of these LEDs is the micro-controller, and each of the micro-controller pins provides separate power source, as each LED comes online the current flowing through the parallel circuits adds up as it hits the resister. While the voltage remained constant in theory, the increasing current across a single resister (thanks to Ohm’s law) pushed the voltage up. The single resistor creates a bottleneck that reduces the proportional power across the circuit as each LED comes online.

The solution is to give each LED its own resistor. Because I’m lazy and didn’t really want to cut a whole bunch of resistors, I scaled the design back from 8 LEDs to a mere 5. This meant rewriting the code with new intervals, but I had to do that anyway due to the greater-than/less-than confusion in the last version. So here’s my redesigned LED array:

LED array

LED array

Then I reconnected my input device, the potentiometer. Which excitingly looks like this:

The exciting new circuit

The exciting new circuit

Then the code needed to be rewritten, which was pretty easy:

void loop()
int inputValue = analogRead(5);

if(inputValue < 200) digitalWrite(6,HIGH);
else digitalWrite(6,LOW);
if(inputValue < 400) digitalWrite(5,HIGH);
else digitalWrite(5,LOW);
if(inputValue < 600) digitalWrite(4,HIGH);
else digitalWrite(4,LOW);
if(inputValue < 800) digitalWrite(3,HIGH);
else digitalWrite(3,LOW);
if(inputValue < 1000) digitalWrite(2,HIGH);
else digitalWrite(2,LOW);

And then we boot it up and we get this lovely little thing:

Exciting, right?

From here on out I'm going to be working on getting this thing converted from a resistometer to a deciblemeter which reads the volume of ambient noise. The output, and even the code, will probably be mostly the same. The hard part, or at least complicated part, is figuring out how to use a voltage-producer instead of a variable resistor as an input. I've got some emails out about that. We'll see what happens.



One Response to “More work with analog and digital”

  1. [...] Dump Inside the Mind of Thomas Robertson « Where’s my life More work with analog and digital [...]

Leave a Reply