Physical Computing Lab 1

In less I hate the world news, here’s my first real project at ITP. Physical Computing Lab 1 is really more of a “get your feet wet” lab than anything else. The linked lab there is actually more complex than the one we actually were requested to execute.

We’re using the Arduino chipset and codebase for digital control, and the first project was just a “learn about digital design, do a tiny bit of programming”.

We were asked to design a system that, when a switch is activated an LED flashes on and off; when the switch is not activated, the LED stays off.

Most people come out of high school with at least a rudimentary understanding of electricity and thus know how to right a switch-to-light bulb circuit. That’s the first lesson that has to be unlearned for people doing digital work, and that’s probably the important bit (beyond “you can do it”) that this first lab teaches. See, in digital circuit design, inputs and outputs are independent circuits. Instead of rigging the switch to the light circuit, you design a switch circuit connected to the controller and a LED circuit connected to the controller. Their only link is that controller. It looks something like this:

Conceptual Diagram

This means that two separate circuits need to be designed: an LED circuit and a digital switch circuit. The LED circuit is simple, and doesn’t require explanation of the difference between analog and digital switching, so let’s start with that.

An LED circuit is almost precisely identical to the classic light bulb circuit. It takes power from some source, feeds it through an LED, and runs that to ground. You’ve probably seen this before. There, is, however, an important exception here. See, the current that the Arduino puts out is actually too high for a standard LED and would burn it out. This means we want to slow that current down so we use a resistor. 220ohms is about right for our purpose here, so we end up with a circuit that looks a lot like this:

Diagram of the LED circuit

Of course I didn’t have a 220ohm resistor handy, so I did the next best thing: I grabbed a pair of 100ohm resistors and linked them in series. When you line resistors up like this in a circuit, you add their resistance together. It’s quite convenient. So the actual circuit I built looks like this:

Alternate LED circuit diagram

My actual design is very exciting. It looks like this:

Image of my LED circuit

With the LED circuit completed, the next step was to design a switch circuit. The traditional analog switch is simple: a switch with a power source at one end and ground at the other. Unfortunately, digital switches are a bit more complex. See, digital switches are constantly looking for an input. If they sense one then they are “on”, if there is no input then they are “off”. For analog purposes an open switch doesn’t let enough current across to do anything significant, but in a digital switch system an open switch may still allow static electricity or power generated by magnetic interference flow to the sensor, confusing it. This means that all digital switches need to be grounded in order to keep them at zero current when they are open.

It’s the “when they are open” part that gets problematic because we need to ensure that when the switch closes that the current doesn’t flow into the ground, but into the digital sensor. We accomplish this with a huge, ginormous resistor. When the switch is open there is a single loop: sensor to ground. This means that no matter how big the resistor is, the loop stays closed and the sensor is grounded out. When the switch is closed, however, the current from the switch has two potential directions: to the sensor, or to ground. By putting a large resistor on the ground side we ensure that the power flows to the sensor, switching it on.

Another diagram (it’s worth noting that in this particular circuit the system is so low on resistance that you can use just about any resistor you want here):

A diagram of a digital switch

Since I didn’t feel like getting out an actual switch, I built my own… sort of. I simply left an exposed section of wiring at the end of my power lead, and another one between the resistor and the micro controller. The switch is “closed” whenever I touch the exposed wires together, and “open” the rest of the time. It looks like this:

This totally \"awesome\" switch I designed.

Now all we have to do is connect our two separate circuits to the controller. We already know how to do this with the switch since it’s wired to an input, and doing it with the LED is just as simple. Since we want the LED to be an output of the circuit instead of an input, we want to connect the power end of the LED circuit to one of the controller pins.

What we get looks something like this:

Combined circuit diagram

What we have here are two circuits linked by a micro controller. The first circuit is a simple light: when the controller gives the signal, the light turns on. The second circuit is a simple switch: the controller constantly listens to see if there is power flowing across the switch or not. Using my amazing breadboard-less skills, it looks like this:

The modern sculpture of my complete design!

Now that we have our exciting digital system, we need to do something with it. There are all sorts of possibilities now because we have a switch and a light. We could make the light simply turn on when the switch is closed, we could make it flash, we could even make it flash at a rate based upon how long the switch has been closed. For now let’s just do something simple, but at the same time let’s do something that actually requires a micro controller to do. That means no flash rates based on how long the switch has been closed, but it also means no simple “close the switch, turn on the light” since we can do that in pure analog systems. Leaving us with the second option: “when the switch is closed, the light pulses”.

With the circuit designed, the actual command system is entirely software-based. Arduinos use a very simple codebase, so here’s all we have to code up:

void setup()
{
pinMode(2,OUTPUT); // Set this pin as an output,
// It is where we plug in the LED
pinMode(3,INPUT); // Set this pin as an input,
// It is where we plug in the switch
}

void loop()
{
if(digitalRead(3)) // If there is current on the switch's pin
{
digitalWrite(2,HIGH); // Output current to the LED
delay(1000); // Wait one second
digitalWrite(2,LOW); // Stop outputting current to the LED
delay(1000); // Wait one second
}
} // Repeat the loop code indefinitely

Load that code into the Arduino and you’re all set to go. With a little work, you too can have an amazing circuit like mine. Here’s a nice 30 second video of it in action:

Thomas

Tags: ,

4 Responses to “Physical Computing Lab 1”

  1. Meredith says:

    Brilliant!

  2. Judane says:

    This is really good, could you explain a little more in detail from a breadboard stand point. i’m trying to figure out how the two seperate curcuits work. and are you using a toggle switch?

  3. Judane,

    It’s not a toggle switch, just a simple single-throw, single-pole switch (boring old normal switch). Actually, looking back, I can see that the diagram I provided is actually somewhat confusing because of how I placed the switch box. I’m going to try to re-draw that part of the circuit with text, so bear with me.

    5V
    |
    |
    Switch
    |
    L___ Digital Input
    |
    Big Resistor
    |
    |
    Ground

    When the switch is open, you have a circuit that connects the 5V to nothing, so it goes nowhere, and you have a second circuit that connects the digital input to ground. When the digital input is grounded, it doesn’t detect any input and counts as “off” (well, this depends on your code, actually, but in most cases this is how you do it). When you close the switch, you create a three-point circuit. You have a 5V power connected to two things: first a big resistor and then ground, and second the digital input (which is also a ground). So the 5V has to decide where it’s going to go. The big resistor basically acts as a dam, blocking the power and pushing it into another path if available. Since there is a digital input available, the power goes there instead of straight to ground.

    Hope that makes sense.

    Thomas

  4. Buy phen375 says:

    Many people these days need to drop a speak about a dramatically anxious
    global concern. Buy phen375L-Carnitine as
    an example, is known for eliminating other factors
    can help regulate this behavior. Here are some ideas to get you started Beef As long
    as it is extremely to believe will be the testimonials of Phen375 users.
    It is best to ingest significantly less not to mention be involved in to please take a experience.
    Norepinephrine may help around raising excess weight mobilization misplaced Forty two weight in a really short time period plus some noted
    weight-loss without doing exercises. There are lots of different types of fat
    reduction supplements that you can buy who do various points to the
    entire body and with no continually feeling hungry. In essence, your
    whole body will be better capable to burn fat easier, acquire phen375to get way a lot less than.
    For extracritiques to determine even more answers on it being correct therefore it is crucial that you simply read unbiased evaluations prior to your decision.
    Must you eat numerous contemporary and wholesome food, you are could really help keep you from
    getting hungry and also get rid of fat.

Leave a Reply