Dec 16

Sketch 8: Controlling a Seven Segment Display

You will be writing a program to control a seven segment display. You can refer to Lab 8 so that you know what pins the segments on the display are connected to. That way, you will turn on the correct LED's in the seven segment display when you try to display a number.

Again, copy below the /*************/ into the arduino programming environment.


This program will tell the arduino how to display numbers on a seven
segment display. It goes with the laser tag course.
This code only comes with comments. It is intended to help the
reader understand what they need to tell the arduino to do
(Aka, what code to write)
Remember to add comments!

// Variables (nicknames for pins)
We will need a variable for each of the pins that we connect to the
seven segment display so that we can turn that pin on or off
depending on what number we want to display.
All of our variables will be integers, meaning they will start with
int (variable name) = (pin number);
with the stuff in () replaced with the variable name and pin number.

void setup() {
Now we need to tell the arduino if the pins that we are using are
inputs or outputs. We will be sending a signal out to light up
each of the pins of the seven segment display. You use the
pinMode() function to set whether a pin is an input or output.
pinMode() accepts two inputs, the pin number and whether it is an
for example: pinMode(pin_3, OUTPUT);
the command above would set pin 3 to be an output (assuming pin_3 is
a variable that you set to 3)

//now for the main loop da loop
void loop() {
we've told our arduino what pins we are using and whether those
pins are inputs or outputs. Now we need to tell it what to display.
Just for fun, we want to have the display switch between two numbers,
0 and 1. You will should program the arduino to turn off all of the
segments (maybe by writing a function to do that, since you will need
to do that twice...), and then turn on the segments that correstpond
to either 0 or 1. You can have it waid for 1 second between the digits.
Be sure to add comments to your code so that you know what it is doing.


Now we want to write a function that turns off all of the digits. Use
this function in the loop above so that you don't have to copy and
paste it every time you want to turn the segments off before
turning them on to display a new digit.

//Tlia. Xlex aew e psx sj gshmrk. Asyphr'x mx fi kviex mj csy hmhr'x lezi xs hs epp xlex asvo xs hmwtpec e ryqfiv?


Dec 17

Building a Sunrise Alarm Clock, 1

Sunrise Alarm Clock: 1

Have you ever woken up at 5:30 am to the most annoying sound on the planet? Yes, the sound that strikes fear in the most peaceful sleeper. The alarm clock sound. That dream crushing sound that jerks you back into reality. If only there was a smoother transition, one where I didn't wake up feeling angry that I was from my dreamscape so ungraciously taken. Enter the sunrise alarm clock.

Bill of Materials:

1. Arduino compatible (bare bones support for Atmega328p)

2. 12V 5A power supply (adafruit part number 352)

3. RGB LED strip (60 LED, adafruit 346)

4. TIP120 x3 (adafruit 976)

5. DS1307 Real Time Clock breakout board (adafruit 264)

Yes, I got a way beefier power supply than I needed. I could power a laptop off that thing. But then again, if I ever want more LED's, a motor, or a solenoid (hey, maybe I want my alarm clock to shoot socks at me in the morning out of my sock cannon? That'll wake me up.).

So, what is all this stuff and what does it do? Together, they make a sunrise alarm clock.

Adafruit has a lovely tutorial on hooking up the RGB LED strip here.

Adafruit has a wonderful tutorial on using the DS1307 real time clock here.

I'm using three PWM pins, 9, 10 and 11. 9 is connected to the green part of the RGB LED, 10 is red, and 11 is blue (see schematic). A diagram of what pins are what for the Atmega chip is shown on the arduino website: Atmega328 pin mapping.

If you follow the above Adafruit links, you will find everything you'd want to know on the parts. Now I need to wire it, code it, and test it.

May 01

Charlieplexing LEDs to control a lot of LEDs with a few pins

Ever wanted to control a bunch of LEDs and minimize the number of pins used without using something like an LED strip or LEDs that have processors so that you can address them using I^{2}C or some other protocol? Well then, meet Charlieplexing and a handy tutorial all about how a clever use of pins can turn on lots of LEDs with clever use of the diode part of the LED.

Apr 11

Lab 1

This is the first lab assignment in the laser tag course. This lab covers Ohm's Law, LEDs, buttons, breadboarding and schematics. The purpose of this lab is to help you to understand how voltage, current and resistance are interrelated, how to connect circuit elements on a breadboard and how to read schematic drawings.

Before you can build a circuit, you need to know how to connect the parts together. To do this, we are using a solderless breadboard, which is a prototyping tool that is used to connect parts together without permanently bonding them (not using solder, which is a metal that you melt onto wires to connect them). A solder less breadboard has holes in it where you put the wires in to connect them to each other. A picture of a breadboard is shown below to demonstrate how a breadboard is used to connect components together.

Figure 1: Picture of a Breadboard. Every wire is connected only to wires of the same color. (click on the picture to make it bigger)

In Figure 1 above, the wires are connected to all of the wires that are the same color. There are four rails (holes that are electrically connected) that go down the left and right sides of the breadboard. These rails are connected vertically. For example, on the left most rail, all of the red wires are connected to each other and all of the blue wires are connected to each other, but the blue wires are not connected to the red wires. These are usually where you place battery power, with positive voltage on the side of the rail with the red line (this has the red wires in it) and the negative voltage on the rail next to it (this rail has blue wires in it). The middle part of the breadboard has rails that electrically connect the holes horizontally (as the green and yellow wires show). This part of the breadboard is separated into two sections (the green wires are all connected, and they are not connected to the yellow wires). For a true test of connectivity, see if you can explain why all of the grey wires are connected to each other.

The materials that are required to do this lab are: a 9V battery, 9V battery clip, LED (any color), assorted resistors, solder less breadboard, wire, wire strippers (for cutting different lengths of wire). You need to connect the battery, LED, button and resistor on the breadboard so that electricity can flow from the positive terminal of the battery (red wire), through the button, then the LED (through the positive [longer] leg of the LED) to the resistor, and then to ground (negative voltage, or the black wire in Figure 2 below).

Figure 2: Lab 1 Breadboard Picture (click on the picture to make it bigger)


Lab Description:

Build a circuit to turn on an LED using a push button. Calculate the resistor value (how much resistance) that is required to have only 0.02 Amperes (20 mA) go through the LED. The circuit is shown on a breadboard in Figure 2 and the schematic is shown in Figure 3.

Extra Credit:

Find the resistance values you would need for the current consumption to be 5 mA, 10 mA, 15 mA. Build these circuits too and see how the light coming from the LED is effected. Why does this happen?