loading

Arduino using solar panel?

Hey guys. Im trying to have a fading led that only turn on when there is no light sensed by a solar panel that would probably be attached to an Analog Input. I'm trying to figure it out but I just can't seem to find a way to make it work. I also need to figure out how I'm supposed to plug a solar panel into an arduino UNO since it is not like a battery and only has a + and - wire. Heres my program:

int light = A0;    //light acivated part
int led = 9;           // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);

}

// the loop routine runs over and over again forever:
void loop()  {
 
  // if there is light, dont run code
  if(analogRead(light) == 0){
    // set the brightness of pin 9:
  analogWrite(led, brightness);   

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
  }    
  // wait for 30 milliseconds to see the dimming effect   
  delay(60); }   

}

Why a solar panel? Why not a LDR (Light Detecting Resistor)? Not only is an LDR much cheaper, with an LDR you can set up a simple Dark Detecting circuit that can be used with the Arduino to fade the LED as you wish.

If you want to use the solar panel as a sensor than put the negative wire to ground and the positive wire to your analog pin. Be sure the panel will only produce 5V or less. If it's a more powerful panel you'll need to use a voltage divider to prevent the voltage from exceeding 5V and burning out the analog pin.

the_joker_ (author)  mpilchfamily3 years ago

one problem. I plugged the solar panel to the arduino like you said and told it to print "input on" if the analogRead value was greater than 50, true, or greater than zero in different attempts but it always printed no input. Any ideas?

+1