how to blink a light

i'm fairly new to microcontrollers, i took 1 coarse where we made a digital clock but there was no programming involved, just a microcontroller and a pulse signal that we used as a counter. i'm looking to control a load lets say its an LED. i need to turn the led on for aproximately 1 second then off, then on for 2 seconds then off and not have it repeat. but i need to adjust the time down because it won't be exactly 1 or 2 seconds. it will be a trial and error, any ideas on how i could do this? if you can tell me how to do this i also need to program it into a stand-alone circuit if someone could help me with that as well. i've ordered my arduino and i'm expecting it soon i was hoping to get started as soon as i get it. any input is appreciated

chevyboy: i'm fairly new to microcontrollers, i took 1 coarse where we made a digital clock but there was no programming involved, just a microcontroller and a pulse signal that we used as a counter. i'm looking to control a load lets say its an LED. i need to turn the led on for aproximately 1 second then off, then on for 2 seconds then off and not have it repeat. but i need to adjust the time down because it won't be exactly 1 or 2 seconds. it will be a trial and error, any ideas on how i could do this? if you can tell me how to do this i also need to program it into a stand-alone circuit if someone could help me with that as well. i've ordered my arduino and i'm expecting it soon i was hoping to get started as soon as i get it. any input is appreciated

Well the first project just about all of do is the blink example (http://arduino.cc/en/Tutorial/Blink). There are two delays in the code, the first delay is how long the LED is lit, and the second delay is how long light is off. A usual way to tune the two delays is bring up the code in the IDE, just change the values, and reload it to the Arduino.

The next step might be to attach two potentiometers to two analog inputs and use the values the potentiometers return to feed the two delays in blink. That way you can change the values just by turning/sliding the potentiometers. This tutorial shows how to read a potentiometer: http://arduino.cc/en/Tutorial/AnalogReadSerial.

this is a must reader - http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay -

what about making it standalone? this is one very small project i wanted to start off with, i don't want to lose a 40 dollar arduino board just for this small circuit

well once you have your arduino you can use it to program other AVR chips, even as small at a 8 pin device (look up arduino tiny), so yea it should be simple, little tiny25/45/85, led, maybe a pot to trim timing values and either regulated power, or a simple 3 pin regulator

though it could be done with a 555 timer for about the same size and effort

Thank you so much you've all been a great help, one last question. I want this circuit to happen once, as in I push a button it runs through the sequence one time then stops. I don't want it to constantly loop. Can I just add a break at the end of my sketch?

Break won’t do it - just put this at the point you want your program to stop:

while(true)
  ;

Or put your code in the setup(), and nothing in the loop()

what about making it standalone? this is one very small project i wanted to start off with, i don’t want to lose a 40 dollar arduino board just for this small circuit

It’s probably not worth the trouble to make a “stand-alone” circuit if you are going to use a microcontroller… That’s up to you, bit I think it’s really cool that the Arduino comes on a fully-functional circuit board with USB and a voltage regulator, boot loader, and all that. I might have a custom PC board made if I needed to save space or if I was manufacturing a product for sale. But for a one-off hobby project, I’m going to use the pre-assembnled board.

A microcontroller is total is overkill for blinking an LED. The “blink LED” example serves two purposes… It introduces you to programming with the simplest possible program (sketch), and it helps you to confirm that the complier is working and that you can upload your program to the Arduino. (It also assures you that the Arduino is working.)

When you take a “regular” programming class, your 1st program is “Hello world!”. All it does is display “Hello world!” on the screen. Since the Arduino doesn’t have a screen, we blink the LED.

Even if you already know how to program, whenever you get a new compiler (or new development system), or you are learning a new programming language, you always try to get “Hello world!” working first, before any real programming.

A [u]‘555’[/u] sells for less than $1 USD. It doesn’t use programming/software/firmware, and you don’t need a microcontroller/microprocessor. The timing is controlled by resistor & capacitor values (R-C time constants*).

It can be used as a “one shot” or as a multivibrator (continuous oscillator).

i need to turn the led on for aproximately 1 second then off, then on for 2 seconds then off and not have it repeat.

I’m not sure I understand… If it doesn’t repeat, how can it be off for only one second? …It’s off “forever” (or until triggered), on for 2 seconds, and then off “forever” again.

Or, is that a delay? i.e. It’s off and you trigger it… One second later it comes on for two more seconds? For that, I think you’d need two 555 timers (or a 556, which as two 555s built into one package). You might also need a couple of “logic chips” (and-gates, or-gates, flip-flops). …No, I think it can be done with one timer and some logic, but I can’t design it in my head.

I assume you learned enough from your digital class to do that… It should be really “simple”, but not as simple as copying an example sketch, if you are a beginner in electronics & programming.

  • R-C time constants are not as accurate as the crystal oscillator in a microcontroller. So for example, if you are blinking once per second, and it’s really important to blink exactly 3600 times in one hour, an R-C oscillator won’t cut-it. You can use a cristal oscillator with simple logic circuits (instead of something like a 555), but they don’t come in “slow”, so you need a divider (more logic circuitry) if you’re going to use a megahertz crystal to blink an LED at 1 Hz.

A picAxe, could do this, too: http://www.picaxe.com/

An 08M2 and two resistors is all you need besides your LED's and stuff.

i need to turn the led on for aproximately 1 second then off, then on for 2 seconds then off and not have it repeat.

I'm not sure I understand... If it doesn't repeat, how can it be off for only one second? ...It's off "forever" (or until triggered), on for 2 seconds, and then off "forever" again.

Or, is that a delay? i.e. It's off and you trigger it... One second later it comes on for two more seconds? For that, I think you'd need two 555 timers (or a 556, which as two 555s built into one package). You might also need a couple of "logic chips" (and-gates, or-gates, flip-flops). ...No, I think it can be done with one timer and some logic, but I can't design it in my head.

I assume you learned enough from your digital class to do that... It should be really "simple", but not as simple as copying an example sketch, if you are a beginner in electronics & programming.

  • R-C time constants are not as accurate as the crystal oscillator in a microcontroller. So for example, if you are blinking once per second, and it's really important to blink exactly 3600 times in one hour, an R-C oscillator won't cut-it. You can use a cristal oscillator with simple logic circuits (instead of something like a 555), but they don't come in "slow", so you need a divider (more logic circuitry) if you're going to use a megahertz crystal to blink an LED at 1 Hz. [/quote]

i need the circuit to stay off permanently until its activated manually with a button, when i press the button i want it to turn on for 1 second, off for one second, on for 2 seconds then turn off and remain off until the button is pressed again. does that make it more clear?

A picAxe, could do this, too:

Or an Attiny85, no external components needed

would the attiny put out enough power to latch a 5v relay?

chevyboy: would the attiny put out enough power to latch a 5v relay?

That depends entirely on the relay's requirements.

Typically, though, you would just drive a transistor to latch a relay.