Light detector failure

Hello, I have Arduino mega 2560 and I tried to connect a solar panel to the arduino and so read the electric current which is an indication of light level.
This is the setup I did, I connected the positive wire of the panel to PIN 8 and the negative one to GND.
And that was the code:
int a = 0;
void setup() {
Serial.begin(9600);
pinMode(8, INPUT);
}

void loop() {
a = analogRead(8);
Serial.println(a);
}

The debug was incorrect, it started from 320 ish and went down to 318 and stopped, the current callouts was unresponsive to the flashlight that I used to light on the solar panel.
What is wrong with my setup/code?

a = analogRead(8); **

code tags.

// using code tags will stop that happening

What solar panel? How does measuring voltage "read the electric current"? You need a shunt
resistor load to measure current.

Solar panels need even illumination to work properly, and a lot of light (sunlight is thousands of
times brighter than a flashlight (unless you have a crazy powerful one)).

dindibo4:
This is the setup I did, I connected the positive wire of the panel to PIN 8 and the negative one to GND.

I hope it was a small panel (<5volt and/or <1mA), otherwise you might already have burned out your Arduino pin.
Leo..

Wawa:
I hope it was a small panel (<5volt and/or <1mA), otherwise you might already have burned out your Arduino pin.
Leo..

It's not a small one, but the Arduino seems to work great after that and also I have measured the voltage of the panel, it was roughly 2-3 V

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

With the panel in sunlight but not connected to anything, what voltage do you measure at its output terminals?

How big is big?
Some dimensions or a picture or a spec sheet or where did you buy it or do you have a part number would be nice.

Does it have any information printed near its terminals.

Thanks... Tom... :slight_smile:

Are you connected to pin 8 or A8 (62)?

edgemoron:
Are you connected to pin 8 or A8 (62)?

I thought that calling analogRead automagically assumes the analogue pins.
Better practice ofcourse to use "A8"
Leo..

I haven't yet figured this out. :confused:

This works on a Mega.

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(8)); // should use A8
  delay(250); // slows printing
}

@OP
Use a (4k7-10k) resistor between solar panel+ and pin, to protect the pin.

Add a load resistor across the solar panel if you want to measure cell current (sort off).
Then it might be better to use 1.1volt Aref.
Leo..

TomGeorge:
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

With the panel in sunlight but not connected to anything, what voltage do you measure at its output terminals?

How big is big?
Some dimensions or a picture or a spec sheet or where did you buy it or do you have a part number would be nice.

Does it have any information printed near its terminals.

Thanks... Tom... :slight_smile:

Hello, the solar panel is 11 x 4 cm I didn't found any part number and I just found it.
As I said it was about 2-3 volts at sunlight and there is the circuit drawing.

Hi,
Again.....

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

It will also show you how to post images.
OPs pics.
circuithh.jpg
Why are you trying to analogRead from a digital pin?
Pins A0 to A8 are the analog input pins on a mega.

Read post #9 with modified code.

Tom... :slight_smile:

circuithh.jpg

2-3V is very low for a solar panel when held in sunlight - which may mean it's broken. Normally solar panels are at least 5V, to be able to charge USB devices. Larger panels (yours is a small one) commonly put out 18V.

This way you're measuring voltage. An analog reading of 320 is 1.56V (5V full scale) which is lower than I'd expect based on the 2-3V you say your multimeter gives you.

TomGeorge:
Hi,
Again.....

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

It will also show you how to post images.
OPs pics.
circuithh.jpg
Why are you trying to analogRead from a digital pin?
Pins A0 to A8 are the analog input pins on a mega.

Read post #9 with modified code.

Tom... :slight_smile:

Hey Tom thank you very much for your assistance, now the light detector is working great!
Here is the setup I used: