Embedded System's and Solar Pannel


Solar Power


In solar panel light energy of photon converted to electric current
Working of solar panel




Above is the bad diagram of solar cell.Here there is very low power and very low illumination as a result of very low illumination.In hazy environment these parameters further fluctuate.
Arduino Connection to Solar Pannel




Components Use
Solar Pannel—3.3V Pin of Arduino through Diode(to protect battery from draining at night)
Batteries-3.3V Pin of Arduino
DIP SWITCH-A0,A1,A3 pin (that allows the user to select one of eight different demonstration programs to run)
1000 OHM resistor-other side of pin of Arduino that further connected to gnd of solar panel
Output to Solarpannel (that allows the user to select one of eight different demonstration programs to run )-A4 pin of arduino
The software can then go to sleep, so the solar panel can charge the battery faster.
When night comes, the program wakes up, and starts making patterns on the LED lights that are attached to pins D2 through D12
Anyway Arduino is not the best choice as the little computer uses up almost 55 milliamperes of current even when it is asleep and not doing anything
solar panel produces 90 milliamperes when lying horizontally in the full sun
 If the computer is using up 55 miiliamps, that leaves only 35 milliamps to charge the batteries
Assuming six hours of sunlight per day
we get 210 milliampere-hours of charge
That can run the computer for less than 4 hours
BUT ANYWAY AFTER YOU READ ITS CODE.WE WILL DICUSS ABOUT BETTER OPTION WHICH IS MSP430 CHIP
Firmware of this task is written below
#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>

unsigned char values[14] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
unsigned int index = 0;

enum { DEMO, COMET, THROB, TWINKLE, STAR, TRAIN, BOUNCE, RANDOM_WALK, DAYLIGHT } mode;

enum
{
  WD_8S    = (1<<WDIE) | (1<<WDP3) | (0<<WDP2) | (0<<WDP1) | (1<<WDP0), // 8.000 seconds
  WD_4S    = (1<<WDIE) | (1<<WDP3) | (0<<WDP2) | (0<<WDP1) | (0<<WDP0), // 4.000 seconds
  WD_2S    = (1<<WDIE) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (1<<WDP0), // 2.000 seconds
  WD_1S    = (1<<WDIE) | (0<<WDP3) | (1<<WDP2) | (1<<WDP1) | (0<<WDP0), // 1.000 second
  WD_120MS = (1<<WDIE) | (0<<WDP3) | (0<<WDP2) | (1<<WDP1) | (1<<WDP0), // 125 milliseconds
  WD_60MS  = (1<<WDIE) | (0<<WDP3) | (0<<WDP2) | (1<<WDP1) | (0<<WDP0), // 64 milliseconds
  WD_30MS  = (1<<WDIE) | (0<<WDP3) | (0<<WDP2) | (0<<WDP1) | (1<<WDP0), // 32 milliseconds
  WD_16MS  = (1<<WDIE) | (0<<WDP3) | (0<<WDP2) | (0<<WDP1) | (0<<WDP0)  // 16 milliseconds
};

class Throb
{
  unsigned char brightness;
  unsigned char pin;
  unsigned char increment;
public:
  Throb( int b, int p ) { brightness = b; pin = p; increment = 1; pinMode( pin, OUTPUT ); } 
  void change( void )
  {
    if( brightness > 100 )
      increment = -1;
    else if( brightness <= 0 )
      increment = 1;
    brightness += increment;
    analogWrite( pin, brightness );
  }
  void stop( void )
  {
    analogWrite( pin, 0 );
  }
};

Throb *a, *b, *c, *d, *e, *f;
long int itrain = 0b11111;
int train_length = 5;
int how_many_pd_lights = 8;
int how_many_pb_lights = 6;
int total_lights = 8 + 6;
int x = 0;

void
setup()
{
  MCUSR &= ~(1<<WDRF);              // Clear the watchdog timer reset flag.
  WDTCSR &= ~(1<<WDE);             // Clear the Watchdog Enable bit.
 
  DDRD = 0b11111100;
  DDRB = 0b11111;
 
  PORTD = 0xFF;
  PORTB = 0xFF;
 
  PORTD = 0;
  PORTB = 0;
  pinMode( A0, INPUT_PULLUP );     // Use internal pullup resistor
  digitalWrite( A0, HIGH );        // Use internal pullup resistor
  pinMode( A1, INPUT_PULLUP );     // Use internal pullup resistor
  digitalWrite( A1, HIGH );        // Use internal pullup resistor
  pinMode( A2, INPUT_PULLUP );     // Use internal pullup resistor
  digitalWrite( A2, HIGH );        // Use internal pullup resistor
  mode = DEMO;
  a = new Throb( 5, PD3 );
  b = new Throb( 16, PD5 );
  c = new Throb( 32, PD6 );
  d = new Throb( 12, PB1+8 );
  e = new Throb( 40, PB2+8 );
  f = new Throb( 50, PB3+8 );
 
  // Power saving:
  // Disable the ADC by setting the ADEN bit (bit 7) to zero.
  ADCSRA = ADCSRA & 0b01111111;

  // Disable the analog comparator by setting the ACD bit (bit 7) to one.
  ACSR = 0b10000000;

  // We couls also disable digital input buffers on all analog input pins by setting bits 0-5 to one,
  // But we are using A0, A1, A2, and A4.
  // DIDR0 = DIDR0 | 0b00111111;
}

void
wdt( int flags )
{
  MCUSR &= ~(1<<WDRF);              // Clear the watchdog timer reset flag.
  WDTCSR |= (1<<WDCE) | (1<<WDE);   // Allow the next line to work
  WDTCSR = flags;                   // Set the timeout
  MCUSR &= ~(1<<WDRF);              // Clear the watchdog timer reset flag.
}

ISR( WDT_vect )
{
  MCUSR = 0;                        // Turn off the watchdog timer
  WDTCSR |= (1<<WDCE) | (1<<WDE);   // Allow change to WDTCSR
  WDTCSR = 0;                       // Watchdog stopped
}

void
power_down( int flags )
{
  wdt( flags );
 
  set_sleep_mode( SLEEP_MODE_PWR_DOWN );
  sleep_enable();
  sleep_mode();
                                        // The program will continue from here after the WDT timeout
  sleep_disable();                      // First thing to do is disable sleep.

  power_all_enable();                   // Re-enable the peripherals.
 
  // Power saving:
  // Disable the ADC by setting the ADEN bit (bit 7) to zero.
  ADCSRA = ADCSRA & 0b01111111;

  // Disable the analog comparator by setting the ACD bit (bit 7) to one.
  ACSR = 0b10000000;
}

unsigned char
getMode( void )
{
  if( digitalRead( A4 ) )
    return DAYLIGHT;
  unsigned char mode = digitalRead( A0 ) << 2;
  mode |= digitalRead( A1 ) << 1;
  mode |= digitalRead( A2 );
  mode = (~mode) & 0b111;
  return mode;
}

//
// Comet controls the brightness of 14 LEDs on a scale from 0 to 13.
// As the pattern moves right to left (or clockwise if the LEDs are arranged
// in a circle, the brightest LED is at the front, and subsequent LEDs are
// each one step dimmer, like the tail of a comet.
//
void
comet( void )
{
  int lights = 0;
  for( int x = 0; x < 50; x++ )
  {
    lights = 0;
    for( int y = 0; y < 14; y++ )
    {
      if( x < 1<<values[y] )
      {
        lights |= 1 << y;
      }
    }
    PORTD = lights & 0b11111100;
    PORTB = (lights >> 8) & 0b11111;
  }
  values[index]--;
  values[index++] &= 0xF;
  index %= 14;
}

//
// Throb is a class that brightens and dims an LED in a cycle, so it appears to throb.
// The constructor takes an initial brightness, and a pin number as arguments.
// Calling the method change() causes the brightness to change.
//
// By starting each LED off with a different brightness, they will change out of sync
// with one another. By calling the change() method a different number of times for each LED,
// they will throb at different rates.
//
// Only six LEDs can be controlled: PD3, PD5, PD6, PB1, PB2, and PB3.
//
void
throb( void )
{
  delay( 20 );
  for( int i = 0, imax = random(8); i < imax; i++ )
    a->change();
  for( int i = 0, imax = random(8); i < imax; i++ )
    b->change();
  for( int i = 0, imax = random(8); i < imax; i++ )
    c->change();
  for( int i = 0, imax = random(8); i < imax; i++ )
    d->change();
  for( int i = 0, imax = random(8); i < imax; i++ )
    e->change();
  for( int i = 0, imax = random(8); i < imax; i++ )
    f->change();
}

//
// Star lights one LED at a time, in a series of 11 LEDs
//
void
star( void )
{
  int lights = 1 << (1 + ++x);
  PORTD = lights & 0b11111100;
  PORTB = (lights >> 8) & 0b11111;
  x %= 10;
  power_down( WD_60MS );
}

//
// Train moves five lights at a time from left to right, like a train.
//
void
train( void )
{
  itrain <<= 1;
  itrain = (itrain | (itrain >> total_lights)) & 0xFFFFFFL;
  PORTD = (itrain >> train_length) & 0b11111100;
  PORTB = (itrain >> (train_length + how_many_pd_lights)) & 0b11111;
  power_down( WD_60MS );
}

//
// This program lights up one LED after another, and then it reverses.
// It looks like the light is bouncing from one side to the other.
//
void
bounce( void )
{
  static unsigned long int lights = 1;
  static bool go_left = true;
  if( lights & 4 )
     go_left = true;
  else if( lights & (1<<12) )
     go_left = false;
 
  wdt_reset();
 
  if( go_left )
    lights <<= 1;
  else
    lights >>= 1;

  PORTD = lights & 0b11111100;
  PORTB = (lights >> 8) & 0b11111;
  power_down( WD_60MS );
}

//
// Random walk makes a light appear to walk randomly around in a string
// of 11 LEDs.
//
void
random_walk( void )
{
  static unsigned int lights = 1 << 9;
  static bool go_left = true;
  if( random( 100 ) > 50 )
    go_left = true;
  else
    go_left = false;

  if( lights & 4 )
     go_left = true;
  else if( lights & (1<<13) )
     go_left = false;

  if( go_left )
    lights <<= 1;
  else
    lights >>= 1;

  PORTD = lights & 0b11111100;
  PORTB = (lights >> 8) & 0b11111;
  power_down( WD_60MS );
}

void
twinkle( void )
{
  int lights = random( 65535 );
  PORTD = lights & 0b11111100;
  PORTB = (lights >> 8) & 0b11111;
  power_down( WD_60MS );
}

void
demo( void )
{
  PORTD = 0;
  PORTB = 0;
  for( int i = 0; i < 1000 && getMode() == 0; i++ )
    comet();

  PORTD = 0;
  PORTB = 0;
  for( int i = 0; i < 200 && getMode() == 0; i++ )
    throb();
  a->stop();
  b->stop();
  c->stop();
  d->stop();
  e->stop();
  f->stop();

  PORTD = 0;
  PORTB = 0;
  for( int i = 0; i < 100 && getMode() == 0; i++ )
    star();

  PORTD = 0;
  PORTB = 0;
  for( int i = 0; i < 206 && getMode() == 0; i++ )
    train();

  PORTD = 0;
  PORTB = 0;
  for( int i = 0; i < 200 && getMode() == 0; i++ )
    bounce();

  PORTD = 0;
  PORTB = 0;
  for( int i = 0; i < 200 && getMode() == 0; i++ )
    twinkle();

  PORTD = 0;
  PORTB = 0;
  for( int i = 0; i < 200 && getMode() == 0; i++ )
    random_walk();
}

void
daylight( void )
{
  PORTD = 0;
  PORTB = 0;
  power_down( WD_8S );
}

void
loop( void )
  switch( getMode() )
  {
    case DEMO:                    demo();         break;
    case COMET:                   comet();        break;
    case THROB:                   throb();        break;
    case TWINKLE:                 twinkle();      break;
    case STAR:                    star();         break;
    case TRAIN:                   train();        break;
    case BOUNCE:                  bounce();       break;
    case RANDOM_WALK:             random_walk();  break;
    case DAYLIGHT:                daylight();     break;
  }
}



Solar Pannel Using MSP430

Better Choice as the demo program uses less than six milliamperes to run
That leaves us 84 milliamperes to charge the battery
In six hours of sunlight, we get 504 milliampere-hours of power
That will last us 84 hours -- not only all night
but three and a half days in the dark

Here in this board whole circuit is similar and P2_7 pin to sense whether the sun is providing power



The Code we Use to drive above circuit is as follow
#include <Servo.h>
 
unsigned char values[14] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
unsigned int index = 0;
bool noisy = false;
 
enum { DEMO, COMET, TWINKLE, STAR, TRAIN, BOUNCE, RANDOM_WALK, SERVO, DAYLIGHT } mode;
 
Servo servo;
 
long int itrain = 0b11111;
int train_length = 5;
int how_many_pd_lights = 8;
int how_many_pb_lights = 6;
int total_lights = 8 + 6;
int x = 0;
 
void
setup()
{
  P2REN = 0b01111000;                     // Enable pullup / pulldown resistors on P2.3, 4, 5, and 6
  P2OUT = 0b00111000;                     // Make switches pull up, solar pull down
  
  P1DIR = 0b11111111;
  P2DIR = 0b00000111;
  
  P1OUT = 0;
 
  mode = DEMO;
 
  if( noisy )
  {
    delay( 500 );
    Serial.begin( 9600 );
    Serial.println( "Artists!" );
    delay( 500 );
  }
  
  servo.attach( P1_0 );
  
  x = 0;
}
 
enum { WD_60MS, WD_8S };
 
void
power_down( int flags )
{
  delay( 100 );
}
 
unsigned char
getMode( void )
{
  if( noisy )
  {
    Serial.println( "getMode()" );
    delay( 100 );
  }
  P2OUT |= 0b00111000;                     // Make switches pull up, solar pull down
  if( digitalRead( P2_6 ) )
    return DAYLIGHT;
 
  if( noisy )
  {
    Serial.print( "Switches are: " );
    Serial.println( (P2IN >> 3) & 0b111 );
    delay( 100 );
  }
  return (P2IN >> 3) & 0b111;
}
 
 
//
// Comet controls the brightness of 14 LEDs on a scale from 0 to 13.
// As the pattern moves right to left (or clockwise if the LEDs are arranged
// in a circle, the brightest LED is at the front, and subsequent LEDs are
// each one step dimmer, like the tail of a comet.
//
void
comet( void )
{
  if( noisy )
  {
    Serial.println( "Comet" );
    delay( 100 );
  }
  
  int lights = 0;
  for( int x = 0; x < 50; x++ )
  {
    lights = 0;
    for( int y = 0; y < 14; y++ )
    {
      if( x < 1<<values[y] )
      {
        lights |= 1 << y;
      }
    }
    P1OUT = lights & 0b11111111;
    P2OUT = (lights >> 8) & 0b111;
  }
  values[index]--;
  values[index++] &= 0xF;
  index %= 14;
}
 
//
// Star lights one LED at a time, in a series of 11 LEDs
//
void
star( void )
{
  if( noisy )
  {
    Serial.println( "Star" );
    delay( 100 );
  }
  
  int lights = 1 << x++;
  P1OUT = lights & 0b11111111;
  P2OUT = (lights >> 8) & 0b111;
  x %= 11;
  power_down( WD_60MS );
}
 
//
// Train moves five lights at a time from left to right, like a train.
//
void
train( void )
{
  if( noisy )
  {
    Serial.println( "Train" );
    delay( 100 );
  }
  
  itrain <<= 1;
  itrain = (itrain | (itrain >> total_lights)) & 0xFFFFFFL;
  P1OUT = (itrain >> train_length) & 0b11111111;
  P2OUT = (itrain >> (train_length + how_many_pd_lights)) & 0b111;
  power_down( WD_60MS );
}
 
//
// This program lights up one LED after another, and then it reverses.
// It looks like the light is bouncing from one side to the other.
//
void
bounce( void )
{
  if( noisy )
  {
    Serial.println( "Bounce" );
    delay( 100 );
  }
  
  static unsigned long int lights = 1;
  static bool go_left = true;
  if( lights & 1 )
     go_left = true;
  else if( lights & (1<<10) )
     go_left = false;
  
  if( go_left )
    lights <<= 1;
  else
    lights >>= 1;
 
  P1OUT = lights & 0b11111111;
  P2OUT = (lights >> 8) & 0b111;
  power_down( WD_60MS );
}
 
//
// Random walk makes a light appear to walk randomly around in a string
// of 11 LEDs.
//
void
random_walk( void )
{
  if( noisy )
  {
    Serial.println( "Random Walk" );
    delay( 100 );
  }
  
  static unsigned int lights = 1 << 9;
  static bool go_left = true;
  if( random( 100 ) > 50 )
    go_left = true;
  else
    go_left = false;
 
  if( lights & 1 )
     go_left = true;
  else if( lights & (1<<10) )
     go_left = false;
 
  if( go_left )
    lights <<= 1;
  else
    lights >>= 1;
 
  P1OUT = lights & 0b11111111;
  P2OUT = (lights >> 8) & 0b111;
  power_down( WD_60MS );
}
 
void
move_servo( void )
{
  if( noisy )
  {
    Serial.println( "Servo" );
    delay( 100 );
  }
  
  for( int x = 0; x < 190; x += 5 )
  {
    servo.write( x );
    P1OUT = x & ~1;
    delay( 50 );
  }
  
  for( int x = 190; x >= 0; x -= 5 )
  {
    servo.write( x );
    P1OUT = x & ~1;
    delay( 50 );
  }
}
 
void
twinkle( void )
{
  if( noisy )
  {
    Serial.println( "Twinkle" );
    delay( 100 );
  }
  
  int lights = random( 65535 );
  P1OUT = lights & 0b11111111;
  P2OUT = (lights >> 8) & 0b111;
  power_down( WD_60MS );
}
 
void
demo( void )
{
  if( noisy )
  {
    Serial.println( "Demo" );
    delay( 100 );
  }
  
  P1OUT = 0;
  P2OUT = 0;
  for( int i = 0; i < 1000 && getMode() == 0; i++ )
    comet();
 
  P1OUT = 0;
  P2OUT = 0;
  for( int i = 0; i < 100 && getMode() == 0; i++ )
    star();
 
  P1OUT = 0;
  P2OUT = 0;
  for( int i = 0; i < 206 && getMode() == 0; i++ )
    train();
 
  P1OUT = 0;
  P2OUT = 0;
  for( int i = 0; i < 200 && getMode() == 0; i++ )
    bounce();
 
  P1OUT = 0;
  P2OUT = 0;
  for( int i = 0; i < 200 && getMode() == 0; i++ )
    twinkle();
 
  P1OUT = 0;
  P2OUT = 0;
  for( int i = 0; i < 200 && getMode() == 0; i++ )
    random_walk();
}
 
void
daylight( void )
{
  if( noisy )
  {
    Serial.println( "Daylight" );
    delay( 100 );
  }
  
  P1OUT = 0;
  P2OUT = 0;
  power_down( WD_8S );
}
 
void
loop( void )
  switch( getMode() )
  {
    case DEMO:                    demo();         break;
    case COMET:                   comet();        break;
    case TWINKLE:                 twinkle();      break;
    case STAR:                    star();         break;
    case TRAIN:                   train();        break;
    case BOUNCE:                  bounce();       break;
    case RANDOM_WALK:             random_walk();  break;
    case SERVO:                   move_servo();   break;
    case DAYLIGHT:                daylight();     break;
  }
}



Comments