Green Energy

After using various wall wart adapters to power my different arduino projects, I decided to try something new.
Instead of the normal 230V, I wanted a solar panel, as it is the easiest to get started with.
On the seeeduino site I found the following:

And it was quite easy to get going.

All I had to do, was to connect the solar panel to the connector labeled “Solar” on the Lipo Rider, and connect the battery to the “BAT” connector.

To keep the battery in place, I just used some double sided tape, and attached it to the bottom side of the Lipo Rider

To connect it to my arduino, I took a cables from a usb enabled on/off switch, and soldered a little pin header on, so it could be connected to the 5V pin on the arduino.

Next up, was to test it. But it was dark and therefor the solar panel was useless, but the Lipo Rider got another neat feature, because it can also charge the battery with power from an usb port. So I left the solar panel on, and connected the Lipo Rider to my computer, and it started charging the battery.

After 45-60 minutes, the little red CH led turned off, and the green OK led turned on instead, and it was fully ready to run on battery.

On the first test, I left it over night, with the arduino just running the default blink sketch, and it succeeded perfectly.

Next day when I came home from work, I placed it in the window in my kitchen, and the CH led turned on again, and started charging the battery with the solar panel.

To op the challenge, I wrote a little sketch that flashes 6 leds, and continuous fades another up and down.

#define buttonPin 2 //button attached to pin 2

#define led1 13
#define led2 12
#define led3 11
#define led4 10
#define led5 9
#define led6 8

#define fled 3 //Led on digital pin 3

unsigned long btnMillis = 0; //clock value to be stored at the time milli() is called

//Fade a led without delaying the rest of the code
//START
unsigned long fadeMillis = 0;
boolean fadeUp = true;
int fadeValue = 0;
void analogFade()
{
  if (millis() - fadeMillis >= 2)
  {
    fadeMillis = millis();

    if (fadeUp == true)
    {
      if (fadeValue < 255)
      {
        fadeValue++;
      }
      else
      {
        fadeUp = false;
        fadeValue--;
      }
    }
    else
    {
      if (fadeValue > 0)
      {
        fadeValue--;
      }
      else
      {
        fadeUp = true;
        fadeValue++;
      }
    }
    analogWrite(fled, fadeValue);
  }
}
//STOP

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);

  pinMode(fled, OUTPUT);

  delay(5000);
  btnDown();
}

void loop()
{
  analogFade();

  if (btnMillis != 0)
  {
    unsigned long timePassed = millis() - btnMillis;
    int timeOn = 0;
    int timeOff = 0;

    //LED 1
    timeOn = 2453;
    timeOff = 4334;

    if (timePassed >= timeOn && timePassed <= timeOn+50)
    {
      digitalWrite(led1, HIGH); //turn off event1 pin
    }

    if (timePassed >= timeOff && timePassed <= timeOff+50)
    {
      digitalWrite(led1, LOW); //turn off event1 pin
    }

    //LED 2
    timeOn = 4347;
    timeOff = 8562;

    if (timePassed >= timeOn && timePassed <= timeOn+50)
    {
      digitalWrite(led2, HIGH); //turn off event1 pin
    }

    if (timePassed >= timeOff && timePassed <= timeOff+50)
    {
      digitalWrite(led2, LOW); //turn off event1 pin
    }

    //LED 3
    timeOn = 2489;
    timeOff = 6743;

    if (timePassed >= timeOn && timePassed <= timeOn+50)
    {
      digitalWrite(led3, HIGH); //turn off event1 pin
    }

    if (timePassed >= timeOff && timePassed <= timeOff+50)
    {
      digitalWrite(led3, LOW); //turn off event1 pin
    }

    //LED 4
    timeOn = 2347;
    timeOff = 9453;

    if (timePassed >= timeOn && timePassed <= timeOn+50)
    {
      digitalWrite(led4, HIGH); //turn off event1 pin
    }

    if (timePassed >= timeOff && timePassed <= timeOff+50)
    {
      digitalWrite(led4, LOW); //turn off event1 pin
    }

    //LED 5
    timeOn = 4568;
    timeOff = 9745;

    if (timePassed >= timeOn && timePassed <= timeOn+50)
    {
      digitalWrite(led5, HIGH); //turn off event1 pin
    }

    if (timePassed >= timeOff && timePassed <= timeOff+50)
    {
      digitalWrite(led5, LOW); //turn off event1 pin
    }

    //LED 6
    timeOn = 1367;
    timeOff = 4321;

    if (timePassed >= timeOn && timePassed <= timeOn+50)
    {
      digitalWrite(led6, HIGH); //turn off event1 pin
    }

    if (timePassed >= timeOff && timePassed <= timeOff+50)
    {
      digitalWrite(led6, LOW); //turn off event1 pin
    }

    //Longest off time, to re-enable the button
    timeOff = 9874;
    if (timePassed >= timeOff)
    {
      btnMillis = 0;
      btnMillis = millis();
    }
  }
}

void btnDown()
{
  if (btnMillis != 0) return;
  btnMillis = millis(); //Set eventtime1 to now + 500ms
}

Leave a Reply