Sunday, May 3, 2009

Making a strobe light with a Duemilanove 328 Arduino, should work with any arduino though



***EDIT The code in this kind of sucks so I corrected here. July 13th 2009***

Caveat: If you have the new Duemilanove you need to go to tools and set it for the ATMEGA 328 chip instead of the Duemilanove. Otherwise it will say something to the effect of: Programmer is not responding.----This may only be a mac problem.

I made this strobe, using a sketch from the "Getting Started with Arduino" book. On the arduino the connections are to GND, 5V, and Analog 0. Here is the orignal sketch code:


#define LED 13 // LED connected to digital pin 13

int val = 0;
void setup()
{
pinMode(LED, OUTPUT); // sets the digital pin as output
}

void loop()
{
val = analogRead(0);
digitalWrite(13, HIGH); // sets the LED on
delay(val); // waits for a second
digitalWrite(13, LOW); // sets the LED off
delay(val); // waits for a second
}


Here is my finished sketched code:


#define LED 13 // LED connected to digital pin 13

int val = 0;
void setup()
{
pinMode(LED, OUTPUT); // sets the digital pin as output
Serial.begin(9600);
}

void loop()
{
val = analogRead(0);
if (val < 50) {
val = val + 60;
digitalWrite(13, HIGH);
delay(val);
Serial.print(val);
Serial.print('\r');
digitalWrite(13, LOW);
delay(val);
Serial.print(val);
Serial.print('\r');
} else {
digitalWrite(13, LOW);;
}

}


So my interesting idea for this project, was what if you hooked a motor to it, and programmed it to only move when it was going to wards light and rather than usb powered, used solar power, then you would have created something that has a will to survive.

1 comment:

Nyx said...

Wow pretty amazing, I've always wanted to learn how to do random things like this ^^