Monday, June 8, 2015

The Arduino Powered Lighthouse

I was helping a friend build a 3' lighthouse, and he felt it could use some "animation". I suggested a Arduino controlled beacon. We didn't want to go to the hassle of building a motorized unit, so I designed a simulated rotating beacon. I picked a 3 watt white LED, but since the Arduino can't control that much current by itself, I used a IRL520 MOSFET. A MOSFET requires a 10k resistor from the gate to ground to turn it off when it's not active. I connected it to a PWM pin, so I could control the brightness of the LED.

Warning! A 3w LED can pull about 700ma of current at 3.3v, so even though we are only PWM'ing at 50% (except for that 50ms 100% pulse), you should have a separate 1a 3.3v supply.

The sketch below fades the LED in and out, and gives a super bright flash between the ramp up and ramp down, simulating the affect of being in the direct line of the bulb on a rotating beacon,

Enjoy!




int cycle=30;
int strobe=cycle*10; // calculate strobe delay
int maxFade=100; // maximum brightness before strobe
int ledPin = 11;    // MOSFET connected to digital pin 11

void setup() {
  // nothing happens in setup
}

void loop() {
  // fade in from min to max in increments of 2 points:
  for (int fadeValue = 0 ; fadeValue <= maxFade; fadeValue += 2) {
    // sets the value (range from 0 to maxFade):
    analogWrite(ledPin, fadeValue);
    // wait for "cycle" milliseconds to see the dimming effect
    delay(cycle);
  }
analogWrite(ledPin, 255); // simulate a rotating beacon catching your eye
delay(strobe); // hold full brightness for strobe delay
analogWrite(ledPin, maxFade);
  // fade out from maxFade to min in increments of 2 points:
  for (int fadeValue = maxFade ; fadeValue >= 0; fadeValue -= 2) {
    // sets the value (range from 0 to maxFade):
    analogWrite(ledPin, fadeValue);
    // wait for "cycle" milliseconds to see the dimming effect
    delay(cycle);
  }
}



No comments:

Post a Comment