Moonlight code help.

I was putting this in an other part of the forum but maybe it was the wrong part for this so i put the same question up here and rely hope for some help on this.

Here is the actual thread and the questions.

If any one can assist me i will be so happy.

  • Suggestion:

Since the other thread just tells people to come back over here… I suggest you post the relevant information HERE, so people dont have to play the click game, going back and forth.

That being said… you havent really provided us with ANY information on what you want.

You did post a link to some lamp… and you did post a link to some Neopixel stuff…

but what do you want it to -DO-?

What kind of ‘controller’ are you looking to have made for you?

You want control over the color(s) the Neopixels will produce? (how do you want to control this?)

It should turn on at a specific time? Manually turned on/off?

I would suggest you post and talk about how you see this functioning/working… only at the point will other know if they can or want to step up to the task at hand.

Hi all.
Posting the information here so it get right.

As i am new to this and also to Arduino i have some questions.

I got my self an Arduino Uno Rev.3 that i want to have as a controller for the moonlight in my aquarium
I also was looking to have two of this NeoPixel Ring - 16
Or two of this NeoPixel Stick - 8

To simulate the moonlight after my regular lights turn off at night.
But dont know witch is best as it will be attached to my light fixture and it is a Kessil Gooseneck Kessil Gooseneck

And the second problem is that i rely dont know how to program it at all as i dont have that skills and not having any one around me that can help.

What i want it to do is not so easy to explain but i will give it a try.
I want it to act as a moonlight that starts on a time setting lets say that my regular lights go of at 10:30 PM and go back on at 11:00 AM during the time the lights is of i want the led for moonlight to start say 30 min before the regular lights go of and that the moonlight go of 30 min after the regular lights go on.

As the Adafuit NeoPixel is in RGB and Each LED is addressable i also want this to be in Blue color and also want the every second led to turn on when it starts the cycle and after 2 hour the rest turns on and after three more hours it shuts of the every second led again.
Also as the Led is really bright light i also want it to run on 50% of the capacity of the LEDs

Also if it is possible to add the code for a temp probe like this on Temp probe / Sensor
And also an code for an display like this one Display that can show the temperature wold be nice.
But this is not the priority for now as the moonlight is what i want at first.

I would appreciate it very much if any one can give me a hand and help me on this.
I also hope that if you dont understand what i want to explain send me an PM and i will try to explain it in the best way i can.

I'm not clear how the 'gooseneck' comes into play?

Are you trying to use that circuitry? or something?

Neopixels need/require a +5v voltage source... thought son how you plan on powering things?

For the most part..

you just need:

an RTC module
Some Neopixels..
and Arduino of your choice.. (maybe a pro-mini will help for size?)

you can then time things to 'trigger' when you want..

I mentioned the Goosneck for the light as i in the beginning was thinking of to put the Adafruit rings on the lamp it self, As you can see it got a frame round the light source Picture of the light! where i was thinking of to put it up.

But this is not so important.

The most important is to get a code that can work as i described earlier in the thread.

And i will power the led with a power supply adapter or if any one have an other tips on that pleas tell me what you think.

Ok, so threre's a couple of issues.

I want it to act as a moonlight that starts on a time setting lets say that my regular lights go of at 10:30 PM

The first issue is: how does the arduino know what time it is? One way to go would be to use a real-time clock module. Alternatively, you could rig up a light sensor.

But a simpler way that would probably work for you would be to plug your arduino power adaptor into a timer (you can get them anywhere, these days), and just have the arduino do the moonlight thing from whenever it gets turned on.

As the Adafuit NeoPixel is in RGB and Each LED is addressable i also want this to be in Blue color and also want the every second led to turn on when it starts the cycle and after 2 hour the rest turns on and after three more hours it shuts of the every second led again.
Also as the Led is really bright light i also want it to run on 50% of the capacity of the LEDs

Well, this is dead simple. Why have every second one turn on? Why not just tell the LEDs to be less bright? You can use the math sin() function to simulate rising and setting over a period of time. Heck - if you have a strip, you could even simulate the moon moving over the hour.

But - whatever. Having the neopixels run through a little sequence that starts when the arduino is powered up is pretty straightforward - you can just use delays to control the timing if you want.

Thanks PaulMurrayCbr for the respond.

I sent you an PM

In reply to the PM:

There’s two ways you can do this. You can get someone else to do you a sketch, or you can have a bash at learning to program.

I’d really suggest learning to program, and in the first instance I suggest you run your arduino on a timer plug from Home Depot, start it up at the right time, and just have it go through a fixed routine of moonlight. It’s simple, you’ll learn some stuff, and it might be as much as you want. I’ll just drop a sketch onto this thread that might do what you want.

If you want to do light sensors and RTC clocks, well - that means either learning a bunch of stuff or else finding someone to do it. Depends on whether your primary hobby is programming or fish.

Tell you what: here’s a simple sketch that just does a moon moving along the strip over 10 hours. It compiles (you need to install the neopixel library). I don’t know if it works - don’t have a neopixel strip with me at the moment.

The sketch is basically: “every minute, clear and redraw the strip”. To test it, set NIGHT_TIMEms to 30 seconds (10 * 1000L) and set REDRAW_DELAYms to maybe half a second (500). You don’t want to redraw too often, because a redraw can make the strip flicker.

#include <Adafruit_NeoPixel.h>


const int STRAND_SIZE = 30; // we have a 30-LED strand
const byte STRAND_PIN = 9; // putting the neopixels on pin 9
Adafruit_NeoPixel strand = Adafruit_NeoPixel(STRAND_SIZE, STRAND_PIN, NEO_GRB + NEO_KHZ800);

const int MOON_WIDTH = 5; // make our moon 5 pixels wide.

const unsigned long NIGHT_TIMEms = 10L * 60L * 60L * 1000L; // the night is 10 hours long - in milliseconds
const unsigned long REDRAW_DELAYms =  60L * 1000L; // redraw once a  minute - in milliseconds

unsigned long lastUpdate;

void setup() {
  strand.begin();
  // set the overall brightness of the strip to 160 out of a possible 255
  strand.setBrightness(160);
  updateMoon();
  lastUpdate = millis();
}

void loop() {
  // update every 60 minutes (meansured in milliseconds)
  if (millis() - lastUpdate > REDRAW_DELAYms) {
    updateMoon();
    lastUpdate = millis();
  }

}

// ok. This function does the job of drawing the moon, based on what time it is.

void updateMoon() {
  strand.clear();

  float now = ((float)millis()) / ((float)NIGHT_TIMEms); // "now" is a number between 0 and 1

  // the overall brighness of the moon depends on the time.
  float moonBright = sin(now * PI);
  if(moonBright <=0 ) return;
  

  float moonPos = now * (STRAND_SIZE - MOON_WIDTH);

  // I'll make pix slop over the end just a little.
  for (int pix = moonPos; pix <= moonPos + MOON_WIDTH + 1 && pix < STRAND_SIZE; pix++) {
    // ok! how bright should the pixel at moonPos be?

    // I'll use the sin() function to make a blob that's bright in the middle

    float bright = moonBright * sin((pix - moonPos) / MOON_WIDTH * PI);
    // 'bright' may be negative at the start and end of the edge of the moon
    if (bright > 0) {
      strand.setPixelColor(
        pix,
        // 200/200/255 should be a nice bluish white
        (int)(200 * bright),
        (int)(200 * bright),
        (int)(255 * bright)
      );
    }
  }

  strand.show();
}

Thanks.
I will try this as soon as i can.
Are waiting for some more stuff i ordered and on the Led to arrive to my local store. ´

I will post as soon as i got it all up and running.

Need to ask.

Is it possible to add one of this Mini RGB Led Amplifier
Between the Arduino board and the Led Stripe ?

wizz:
Need to ask.

Is it possible to add one of this Mini RGB Led Amplifier
Between the Arduino board and the Led Stripe ?

Well, it looks like that's what this thing is designed for. Issues are: will it be ok with a pulse-width modulated signal? Anyway - I thought your concern was that the moonlight should not be too bright?

Oh, and it's common anode. How is your LED strip set up?

They are “Neopixels”…

PaulMurrayCbr:
Well, it looks like that's what this thing is designed for. Issues are: will it be ok with a pulse-width modulated signal? Anyway - I thought your concern was that the moonlight should not be too bright?

Oh, and it's common anode. How is your LED strip set up?

Yes thats right i dont want it to be so bright.

As i got two led stripes i was wondering if i can use the one I mentioned to the other one i got to an other project sorry for not mentioned that.

Have not got all parts for the setup of the moonlight but hope to get it today.

Hang on - I'm not sure that a strip light is the same thing as a set of neopixels. Actually - they are quite different. A strip light amplifier will almost certainly not work with a neopixel strip.

bingo!...

Ok thanks for the explanation.

Here’s an updated sketch. Works for me.

A strip amplifier won’t do anything.

It looks like it’s designed to switch R/G/B over the length of the strip. Neopixels just don’t work that way - each individual LED is as bright as you set it. All you need is to be sure that the +5v power is 5v and can handle the current. Maybe there’s an issue if you have a very long strip and are turning all the LEDs on. It might be sensible to feed +5v at intervals along it so that the earlier tracks on the board aren’t carrying all the current for the later ones.

But that’s not what this moonlight sketch does - it’s only turning on a few LEDs at a time.

#include <Adafruit_NeoPixel.h>

const int STRAND_SIZE = 24; // we have a 30-LED strand
const byte STRAND_PIN = 6; // putting the neopixels on pin 6
Adafruit_NeoPixel strand = Adafruit_NeoPixel(STRAND_SIZE, STRAND_PIN, NEO_GRB + NEO_KHZ800);

//#define DEBUG

#ifdef DEBUG

const int MOON_WIDTH = 5; // make our moon 5 pixels wide.
const unsigned long NIGHT_TIMEms = 10L * 1000L; // 30 seconds
const unsigned long REDRAW_DELAYms =  100L; // redraw twice a second
const byte STRAND_BRIGHTNESS = 32; // one eightth brighness
#else
const int MOON_WIDTH = 5; // make our moon 5 pixels wide.
const unsigned long NIGHT_TIMEms = 10L * 60L * 60L * 1000L; // the night is 10 hours long - in milliseconds
const unsigned long REDRAW_DELAYms =  60L * 1000L; // redraw once a  minute - in milliseconds
const byte STRAND_BRIGHTNESS = 64; // one quarter brighness
#endif

unsigned long lastUpdate;

void setup() {
  strand.begin();
  // set the overall brightness of the strip to 160 out of a possible 255
  strand.setBrightness(STRAND_BRIGHTNESS);
  updateMoon();
  lastUpdate = millis();

#ifdef DEBUG
  Serial.begin(57600);
#endif
}

void loop() {
  // update every 60 minutes (meansured in milliseconds)
  if (millis() - lastUpdate > REDRAW_DELAYms) {
    updateMoon();
    lastUpdate = millis();
  }

}

// ok. This function does the job of drawing the moon, based on what time it is.

void updateMoon() {
  strand.clear();

  float now = ((float)millis()) / ((float)NIGHT_TIMEms); // "now" is a number between 0 and 1

  if (now >= 1) return;

#ifdef DEBUG
  Serial.print(now);
  Serial.print('\t');
#endif


  // the overall brighness of the moon depends on the time.
  float moonBright = sin(now * PI);
  if (moonBright <= 0 ) return;

#ifdef DEBUG
  Serial.print(moonBright);
  Serial.print('\t');
#endif

  float moonPos = now * STRAND_SIZE;

  for (int i = -MOON_WIDTH / 2 - 1; i <= MOON_WIDTH / 2 + 1; i++) {
    int pix = moonPos + i;
    if (pix < 0 || pix >= STRAND_SIZE) continue;

    float bright = moonBright * cos((pix - moonPos) / MOON_WIDTH * PI);

    // 'bright' may be negative at the start and end of the edge of the moon
    if (bright > 0) {

      bright = bright * bright; // this changes the profile of the sin by a bit

      strand.setPixelColor(
        pix,
        // 200/200/255 should be a nice bluish white
        (int)(0xE0 * bright),
        (int)(0xE0 * bright),
        (int)(0xFF * bright)
      );
    }
  }

  strand.show();

#ifdef DEBUG
  Serial.println();
#endif
}

Thanks will try as soon as i can :slight_smile: