With a bit of a rocky start (having to install the arduino driver like 4 times in order for it to register), the rest of my first project went off without a hitch. The circuit diagram and the picture didn’t match up, but I think it makes sense to default to the circuit diagram (particularly when it works).
I enjoyed this project even though it was simple. A first glimpse into the power of making your own circuits and programming your own microcontroller!
Pardon the pictures, it seems that I need to buy some sort of mini-tripod to help with documentation in the future.
My Arduino (Duemilanove with an AT mega328) and my breadboard.
The project all wired up.
The Arduino runs on power from the USB cord plugged into both the computer and itself (far left on the picture). The red wires all represent +, ie power flowing from the Arduino to the breadboard (for anyone that does not know, this mode of Arduino board has both power and ground slots on the board itself, which are in the lower half of the left side of this picture). The black wire all represents, – or ground, the point of lowest electricity. The blue wires are used to connect the digital pins on the Arduino (binary switches basically, high/1/on or low/0/off).
The purpose of this project was to create a circuit and a program so that while the yellow/sort of green light runs while nothing happens, if you push the switch button (white and in the lower right side of the picture) the yellow light goes off and the red light goes on.
Here is what the code looks like (// = comments to let you know what the line of code means):
//declare variables
int switchPin = 2; //digital input pin for a switch
int redLedPin = 3; // digital output pin for an LED
int yellowLedPin = 4; //digital output pin for an LED
int switchState = 0; // the state of the switch
void setup(){
pinMode(switchPin, INPUT); //set the switch pin to be an input
pinMode(redLedPin, OUTPUT); //set the red LED pin to be an output
pinMode(yellowLedPin, OUTPUT); //set the yellow LED pin to be an output
}
void loop(){
//read the switch input:
switchState = digitalRead(switchPin);
if (switchState ==1){
// if the switch is closed:
digitalWrite(redLedPin, HIGH); //turn on the red LED
digitalWrite(yellowLedPin, LOW); //turn off the yellow LED
}
else {
//if the switch is open:
digitalWrite(redLedPin, LOW); //turn off the red LED
digitalWrite(yellowLedPin, HIGH); //turn on the yellow LED
}
}
Tada! I pushed the button, and the light switched.
Video:PComp first project
Like I said earlier, simple but powerful. Next weeks lab involves a potentiometer(a knob basically), but I might try it early. I want to use the potentiometer to adjust the colors of the RGB LED that came in the kit.
I’ll post the results of my experiments at some point. Next post should be concerning my ICM (Intro to Computational Media, ie computer programming homework).


