Aircraft rotating beacon simulator with an LED

Hi all! I am trying to simulate with a single LED an aircraft rotating beacon. If you look at an airplane's rotating beacon, as the bulb rotates around to shine in your direction, it will appear to gradually get brighter, then "pulse" suddenly. If you could imagine it as a line on a graph, the line would rise a little, then right before it's brightest moment, the line would spike to the top of the graph. I have a sketch for a pulsing LED, but it's missing the spike, if you will. Can somebody modify this, or create a code that does this? Thanks!

int led1 = 0;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

void setup() {
  pinMode(led1, OUTPUT);
  
}

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pins:
  
analogWrite(led1, brightness);
  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(15);

//ORIG
//int brightness = 0;    // how bright the LED is
//int fadeAmount = 5;    // how many points to fade the LED by  
  
}

You can use some mathematical function that looks like it might work, get away from the linear fade up and down.

I found this that looks promising. You want something that takes awhile to start a rapid upswing towards the peak.

An alternate would be to use an array of 50 values or so (based on your fade step pf 5, which will finich in 51 steps) and in every array element write what the intensity should be.

That would be the most flexible.

Ppl here will prolly want you to build a teeny rotating beacon. :expressionless:

a7

Thank you! Some of the language is a little too high-tech for me, but I will check these out. :slight_smile:

I took a link from that article, it has some code you could try and it would fit in your way of controlling the fade up and down sections:

I'm not in the lab just now, some of these look like fun to try.

a7

The code you posted the analogwrite-value goes up from 0 to 255 then down from 255 to 0.

a good aproximation will be to divide the function into four parts:

  1. from 0 to let's say 50 rise brightness slowly (big value for delay)
  2. from 51 to 255 rise brightness fast (small value for delay)
  3. from 255 down to 51 reduce brightness fast (small value for delay)
  4. from 50 to 0 reduce brightness slowly (big value for delay)

and then play with the parameters the number where the change slow/fast happens and with the values for delay()

A while ago I designed some model aircraft lights that creates the rotating beacon, strobes, navigation lights and landing lights. They can be switched with a spare channel from a RC receiver. It is intended for Attiny85, but also works on other Arduino's.

I poked the leds through a picture of a plane, to show the effect.

There is a long thread about developing it on this forum, but it is in Dutch. And there is a PCB now.

You can load this in your Arduino and you will see the rotating beacon on Arduino pin 6.

// constants won't change. Used here to set pin numbers:
const int beacon_led =  6;        // Rotationg Beacon, select a PWM ~ capable pin !!
const int strobe_led =  5;        // Strobe pulselight
const int landinglight_led =  4;  // Landing Light
const int navigation_led =  2;    // Navigation lights
const int servo = 3;      // Servo input

//*************** ONLY CUSTOMIZE THESE 2 VALUES BELOW *********************************

long beacon_interval = 1000;           // loop duration for the beacon to make 1/2 revolution
long strobe_interval = 1000;           // loop duration for the interval between strobe sequence

// value is in milliseconds, so with the default 1000 this is one revolution per 2 seconds for
// the beacon and one series of strobe flashes per second

//*************** ONLY CUSTOMIZE THESE 2 VALUES ABOVE *********************************

// Variables that will change:
int ledState = LOW;             // ledState used to set the LED
long currentMillis;             // time the system is on since power-up
long previous_beacon_Millis = 0;// will store last time beacon was at high or low
long previous_strobe_Millis = 0;// will store last time strobe sequence started
long beacon_timer = 0;          // time within one beacon loop
long strobe_timer = 0;          // time within one strobe loop
int brightness = 0;             // how bright the LED is
int updown = 1;                 // Slow led beacon increasing or decreasing
int ch1;                        // servo input channel value
int lighton = 1;
int landing = 1;

void setup() {
  // set the digital pin as output:
  pinMode(beacon_led, OUTPUT);
  pinMode(strobe_led, OUTPUT);
  pinMode(landinglight_led, OUTPUT);
  pinMode(navigation_led, OUTPUT);
  pinMode(servo, INPUT_PULLUP); // Set servo channel input
}

void loop() {
  // check to see if the beacon loop interval has passed and need to restart
  currentMillis = millis();
  if (currentMillis - previous_strobe_Millis > strobe_interval) previous_strobe_Millis = currentMillis;
  if (currentMillis - previous_beacon_Millis > beacon_interval) {
    previous_beacon_Millis = currentMillis;
    updown = - updown;
    ch1 = pulseIn(servo, HIGH, 25000); // Read the pulse width of servo signal connected to pin D3
    if ((map(ch1, 1000, 2000, -500, 500)) < 200) lighton = 1;
    else lighton = 0 ;
    if ((map(ch1, 1000, 2000, -500, 500)) < -200) landing = 1;
    else landing = 0 ;
  }
  beacon_timer = currentMillis - previous_beacon_Millis;  // calculate milliseconds within beacon loop
  strobe_timer = currentMillis - previous_strobe_Millis;  // calculate milliseconds within strobe loop

  if (lighton == 1) {
    digitalWrite(navigation_led, HIGH);
    // depending on how far we are in the loop, led's are switched on or off.
    if (strobe_timer > 000 && strobe_timer < 101)  digitalWrite(strobe_led, LOW);
    if (strobe_timer > 100 && strobe_timer < 126)  digitalWrite(strobe_led, HIGH);
    if (strobe_timer > 125 && strobe_timer < 201)  digitalWrite(strobe_led, LOW);
    if (strobe_timer > 200 && strobe_timer < 226)  digitalWrite(strobe_led, HIGH);
    if (strobe_timer > 225 && strobe_timer < 301)  digitalWrite(strobe_led, LOW);
    if (strobe_timer > 300 && strobe_timer < 326)  digitalWrite(strobe_led, HIGH);
    if (strobe_timer > 325 && strobe_timer < 401)  digitalWrite(strobe_led, LOW);

    if (updown == 1) {
      brightness = map(beacon_timer, 0, beacon_interval, 1, 255);
    }
    else {
      brightness = map(beacon_timer, 0, beacon_interval, 255, 1);
    }
    analogWrite(beacon_led, (255 / brightness));
    digitalWrite(landinglight_led, landing);

  }
  else {
    analogWrite(beacon_led, 0);
    digitalWrite(strobe_led, LOW);
    digitalWrite(landinglight_led, LOW);
    digitalWrite(navigation_led, LOW);
  }
}

The formula for the rotating beacon is to have a brightness counter upcounting (0-255) and then downcounting (255-0) and then use a division to get the brightness spike. analogWrite(beacon_led, (255 / brightness));

Good luck!

The "rotating" is a reflector, around the beacon, not the beacon.

More like "was a reflector"
The majority is Led Arrays now.

1 Like

I am curious how these bad ideas get chosen. I would rather rotate a chunk of material than transfer electricity through a slipring (I worked with power and data through sliprings).

No moving parts. The LEDs are sequenced to give the appearance of a rotating lamp or reflector.

a7

1 Like

This forum keeps teaching me new stuff.

Thanks. In a traditional Grimes beacon, there are 2 bulbs mounted to a disk that rotates - basically.

Thanks, but I'm trying to simulate it with a single LED. The ideas are not "bad." People are just trying to help me.

Exactly! Thank you!

Edison, I, too, am uploading to an ATtiny85 (well... 45). Your video depicts what I'm after, and your "analogWrite(beacon_led, (255 / brightness));" edit did the trick in my sketch, so thank you very much! All I did was change "beacon_led" to "led1." My brother is going to be very happy, as this project is for his plane.

Thanks, Stefan. I think I got what I needed from another post, but just for testing, would you be able to modify my sketch with your idea, and post it? I'm having trouble getting it to work due to my lack of coding experience. Thanks!

Edison, would it be possible for you to make a version of your sketch, and remove all data relating to the servo, and post it? I presume that is for an incoming signal from your transmitter to turn the landing light on and off, but I'm just guessing. Thanks!

Dear @unor3man

my understanding of this forum is:

helping not making.

So make an own attempt.

Your attempt doesn't even have to compile. Just make an own attempt.
If you do so I will assist in modifying your sketch to make it work.

Dear StefanL38,
I may have been asking too much, but I have been working my eyes out "on my own" to make things work. You need to better understand that some of us aren't as saavy as some of you. I wouldn't call it "making." I would call it sharing. I don't know C+, or whatever the language is for IDE. I modify bits and pieces of code that people have shared with me. Isn't that what Open Source embodies? I will make an effort to learn more about it. I do greatly appreciate your offer to assist me. Thanks!

For convenience I re-post your code from post # 1

int led1 = 0;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

void setup() {
  pinMode(led1, OUTPUT);
  
}

// the loop routine runs over and over again forever:
void loop() {
  analogWrite(led1, brightness);   // set the brightness of pins:
  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
    fadeAmount = -fadeAmount;  
  }
  delay(15);   // wait for 15 milliseconds to see the dimming effect
}

The line

analogWrite(led1, brightness);

sets the brightness
In your code this value is counted up from 0 to 255 and then counted down from 255 to 0

This creates the fading in / fading out.

function loop is "looping
starts from here

void loop() {
  analogWrite(led1, brightness);   // set the brightness of pins:

executes down to

  delay(15);   // wait for 15 milliseconds to see the dimming effect
}

Now you have to replace this single loop created by loop() itself

with four particular for-loops

count up from 0 to 50 with long delay
count up from 51 to 255 with short delay
count down from 255 to 51 with short delay
count down from 50 to 0 with long delay

counting up with long delay

for (byte myCounter = 0; myCounter < 51; myCounter++) { 
    brightness++;
    analogWrite(led1, brightness);   // set the brightness of pins
    delay(50); // long delay
}

rewrite this pattern for the other three parts
If you have questions ask the questions