Core Electronics Forum

Solar Button Version 2

Update:
Device ran for 5 & 1/2 hours today (battery was not fully charged).
More than enough run time for a wearable piece of electronic bling.

Took about 1 hour to charge on Adafruit LiPo charger at 200mA.
(500mA setting would be too high for this 120mAh battery)
Device then ran for over 8 hours.

===========================
This is my second attempt to do something with the Solar Panel Skill Badge. ADA700
The power out of this device is pretty small, not really useful for charging anything or keeping something charged. So with this attempt it was only used as a light level sensor.

An A-Star 328PB drives a 8 pixel LED strip and is powered by a 120mAh LiPo. 328PB and battery on the back of the panel and LED strip on the front. A resistor divider is used to drop the 5V from the panel to a level acceptable by the micro, 3.3V.

The software reads the voltage from the panel and sets the brightness appropriately. It then randomly selects one of 5 patterns. Colour and duration are also randomly selected. I have not checked the life of the battery but it has run for over an hour ok.

Happy with the way this has turned out.
The pics do not do the project justice. In reality the LED display is quite good.

Cheers
Jim


My-Movie04

2 Likes

Schematic for the Solar Button.
Software is nothing special and uses Adafruit’s very excellent Neo Pixel library.

1 Like

What a neat use of a solar cell :slight_smile: Cool little setup!

1 Like

so intensity/brightness… could be adjusted. i thought voltage control …i am not familiar with his circuit that is driving it but there are plenty of underpopulated pins on his processor board…me thinking it cold be done either manually via an analog trim-pot…being voltage dependent…?.

Or via some code using a gpio pin analogue… varying the output to this pin if it is voltage dependent or if it is digital then use a digital gpio pinn…??.. i`m thinking it would give you a code programmable adjustment of brightness level… which ever pin does not actually power the unit is the one i think you need to use… to control the brightness …unless Ive got it al wrong…not knowing enough about the strip hardware,i did look at the schem data sheeet here on the core shop listing page… but it does not give the complete strip schematic.as a whole…??..that i can see…?..

so the basic aim is to give you control of the brightness or intensity…i see it both ways hence the unused pin 4 on the led it self could be an analogue control if you see it that way…

2 Likes

Any of the Core Electronic products that are manufactured by Adafruit usually have excellent detailed information on the Adafruit website. User guides and such. Sometimes you will find schematics, sometimes not. Depends on whether Adafruit deem it necessary or not.
The following link contains a detailed description of Neo Pixels, what they are and how to use them. These little devices are amazing for producing light displays. Smart LEDs if you want to call them that.
Regards
Jim

1 Like

Program code.

#include <avr/sleep.h>
#include <Adafruit_NeoPixel.h>

// GPIO pin defines
#define Neo_Pin         3                 // Data In pin of Neo Pixel 
#define SOL             A0                // Solar Panel input

#define Neo_Count       8                 // number of Neo pixels in strip
#define NeoBrightness   1                 // lowest brightness

uint8_t p[7][3] = {   255,  0,  0,    // Red          Tried difference numbers, dont really make a difference
                      255,255,  0,    // Yellow       255,255,0 255,128,0 128,255,0 all looked the same at low intensity as expected
                        0,255,  0,    // Green 
                        0,255,255,    // Cyan
                        0,  0,255,    // Blue
                      255,  0,255,    // Purple
                      255,255,255};   // White

// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel NeoStrip(Neo_Count, Neo_Pin, NEO_GRB + NEO_KHZ800);

//=================================================================================
void setup() {
//Serial.begin(115200);
//Serial.println("================");  
//Serial.println(" LED Blink ");
//Serial.println("================");

// === Setup Devices ===
  NeoStrip.begin();                             // INITIALIZE NeoPixel 8 LED strip
  NeoStrip.show();                              // Turn OFF all pixels
  NeoStrip.setBrightness(NeoBrightness);        // Set BRIGHTNESS of NEO pixels

  randomSeed(analogRead(1)+analogRead(2)+analogRead(3)+analogRead(4)+analogRead(5)+analogRead(6));

  Clear_NEO();
  delay(1000);
} 
//=================================================================================
void loop() {
  Set_Brightness();  
  uint8_t disp = random(5);
  switch (disp) {
    case 0:
      for (int i = 0; i < 7; i++) {
        ALL_Neo(i);
        delay(250);
      }
      for (int i = 5; i > -1; i--) {
        ALL_Neo(i);
        delay(250);
      }
      delay(250);
      break;
    case 1:
      for (uint8_t i = 0; i < 10; i++) {
        ALL_Neo(random(7));
        delay(500);
        Clear_NEO();
        delay(250);
      }
      delay(250);
      break;
    case 2: 
      Glow(random(7),0,random(1,4));
      delay(500);
      break;
    case 3: 
      Cylon(random(7),random(1,4),random(3,9));
      delay(500);
      break;
    case 4: 
      for (uint8_t i = 0; i < random(1,4); i++) {
        rainbow(5, 10);
        delay(50);
      }
      break;
    default:
      Glow(0,1,random(1,4));  // Red colour
      delay(500);
      break;
  }
  Clear_NEO();
  delay(100);
}
//=================================================================================
void Set_Brightness(void) {
  unsigned int solar = map(analogRead(SOL),0,1023,1,100);  
  NeoStrip.setBrightness(solar);
  return;
}
//=================================================================================
// LED move across strip
// c16 = colour to use, n = number of pixels to move 1 2 3, l = number of loops 
//=================================================================================
void Cylon(uint8_t c16, uint8_t n, uint8_t l) {
  uint32_t color = NeoStrip.Color(p[c16][0],p[c16][1],p[c16][2]);
  unsigned int t = NeoStrip.numPixels();
  if (n < 1) n = 1;
  if (n > 3) n = 3;
  for(unsigned int y = 0; y < l; y++) {
    for(unsigned int i = 0; i < t-n; i++) {
      NeoStrip.setPixelColor(i, color);
      if (n > 1) NeoStrip.setPixelColor(i+1, color);
      if (n > 2) NeoStrip.setPixelColor(i+2, color);
      NeoStrip.show();
      delay(100);
      Clear_NEO();
    }
    for(int i = t-1; i > n-1; i--) {
      NeoStrip.setPixelColor(i, color);
      if (n > 1) NeoStrip.setPixelColor(i-1, color);
      if (n > 2) NeoStrip.setPixelColor(i-2, color);
      NeoStrip.show();
      delay(100);
      Clear_NEO();
    }
  }
  return;
}
//=================================================================================
// Increase and decrease the brightness of all LEDs
// r = 0 random colour each loop, r = 1 use Colour, l = number of loops
//=================================================================================
void Glow(uint8_t Colour, bool r, uint8_t l) {
  for (uint8_t y = 0; y < l; y++) {
    if (!r) { Colour = random(15); }
    for (int i = 0; i < 100; i++) {
      NeoStrip.setBrightness(i);
      ALL_Neo(Colour);
      delay(5);
    }
    for (int i = 99; i > -1; i--) {
      NeoStrip.setBrightness(i);
      ALL_Neo(Colour);
      delay(5);
    }
    delay(250);
  }
  return;
}
//=================================================================================
// Set all pixels to off
//=================================================================================
void Clear_NEO(void) {
  for(unsigned int i = 0; i < NeoStrip.numPixels(); i++) NeoStrip.setPixelColor(i, 0);
  NeoStrip.show();
  return;
}
//=================================================================================
// Display same colour on all pixels
//=================================================================================
void ALL_Neo(uint8_t c16) {
  uint32_t color = NeoStrip.Color(p[c16][0],p[c16][1],p[c16][2]);
  for(unsigned int i = 0; i < NeoStrip.numPixels(); i++) NeoStrip.setPixelColor(i, color);
  NeoStrip.show();
  return; 
}
//=================================================================================
void rainbow(unsigned int wait, unsigned int rainbowLoops) {
  int fadeVal=0, fadeMax=100;

  for(uint32_t firstPixelHue = 0; firstPixelHue < rainbowLoops*65536; firstPixelHue += 512) {
    for(unsigned int i = 0; i < NeoStrip.numPixels(); i++) { 
      uint32_t pixelHue = firstPixelHue + (i * 65536L / NeoStrip.numPixels());
      NeoStrip.setPixelColor(i, NeoStrip.gamma32(NeoStrip.ColorHSV(pixelHue,255,255 * fadeVal / fadeMax)));
    }
    NeoStrip.show();
    delay(wait);

    if(firstPixelHue < 65536) {                              
      if(fadeVal < fadeMax) fadeVal++;                       
    } else { 
      if(firstPixelHue >= ((rainbowLoops-1) * 65536)) { 
        if(fadeVal > 0) { fadeVal--; }                            
      } else {
        fadeVal = fadeMax; 
      }
    }
  }
  return;
}
//=================================================================================
//=================================================================================
//=================================================================================

Sketch uses 5900 bytes (18%) of program storage space. Maximum is 32256 bytes.
Global variables use 67 bytes (3%) of dynamic memory, leaving 1981 bytes for local variables. Maximum is 2048 bytes.

Edit: fixed error in code. Before I posted the code I changed part of it and did not test compile it. (void int is not a valid function variable it should be just void in Set_Brightness)

1 Like

i can modd code i can apply code but i cannot write the code…thx for the tut…