Wednesday, 29 October 2014


  Small Solar Panel (5v)

Arduino Light Sensor

I think this retro-design could be used for a cool visual of a solar array functioning.



 How it works.

The solar panel puts out 5 volts when working well with lots of light. Be aware if the voltage goes above 5v you may damage your Arduino. In that case use a voltage divider. The voltage output (0 to 5v) is measured by the analogue pin on the Arduino. Some code below converts this to a series of pulses on digital pins to light an LED bar.

As light intensity grows (that's me moving the lamp over the panel), the LEDs pulse faster and show that the voltage output from the panel is increasing. If the panel fails, or the light goes out a buzzer sounds or pin 13. You could also use that concept to trigger events if panels are undercharging or overcharging.

I think this retro-design could be used for a cool visual of a solar array functioning. Its reminds me of those old films where the reactor is about to go critical or when they are have to push the power output of warp engines to the limit. In fact, I may add some sound effects code too ! :)

 Code:--------------------------------------------------------
// Initialise Global variables
int startPin = 2; // starting pin don't use 0 or 1 because they are Rx and Tx.
int LEDnum = 12; // highest pin No. 12 -2 = 10 LEDs
int lightPin = A5; //A5 for sensor: 5v max output from the solar panel

// use a 10K resistor as well, in series, to limit the current
int lightLevel = 0;
int myDelay = 0;
int buzzPin = 13; // alarm pin for buzzer

void setup()
{
  pinMode(buzzPin, OUTPUT);

  for (int PINi = startPin; PINi < LEDnum; PINi++)
  {
    pinMode(PINi, OUTPUT);

  }
  Serial.begin(9600);
}

void loop()
{
  lightLevel = analogRead(lightPin); //Read the level


  myDelay = 100 - (lightLevel / 10) ; // set delay according to light level

  Serial.println(myDelay); // debug in terminal window

// if lightlevel is very low ie delay is big, switch off all led and Alarm
  if (myDelay >= 85)
  {
    for (int PINi = startPin; PINi < LEDnum; PINi++)
    {
      digitalWrite(PINi, LOW); 
    }

    digitalWrite(buzzPin, HIGH);
    delay (500);
    digitalWrite(buzzPin, LOW);
    delay (500);
  }
 
// Display charging on LED bar
  else{
    for (int PINi = startPin; PINi < LEDnum; PINi++)
    {
      digitalWrite(PINi, HIGH);
     
      delay(myDelay);
      digitalWrite(PINi, LOW);.
     
    
    }
  }
}

end code:--------------------------------------------------------------

No comments:

Post a Comment