Smart Solar Panel Not Working

Hey, I am working on a smart solar panel that follows the sun. I am using the input from 5 photocells an Arduino uno and a servo. I wrote the code myself but for some reason it is not working, help is highly appreciated.

Here is my code:

#include <Servo.h>

Servo myservo;

int photocell1 = 1;
int photocell2 = 2;
int photocell3 = 3;
int photocell4 = 4;
int photocell5 = 5;
int photocell1Reading;
int photocell2Reading;
int photocell3Reading;
int photocell4Reading;
int photocell5Reading;

void setup() {



void loop() {
photocell1Reading = analogRead(photocell1);
photocell2Reading = analogRead(photocell2);
photocell3Reading = analogRead(photocell3);
photocell4Reading = analogRead(photocell4);
photocell5Reading = analogRead(photocell5);

// Far left photocell
if(photocell1Reading > photocell2Reading, photocell3Reading, photocell4Reading, photocell5Reading){

// 45 left photocell
else if(photocell2Reading > photocell1Reading, photocell3Reading, photocell4Reading, photocell5Reading){

// Center photocell
else if(photocell3Reading > photocell1Reading, photocell2Reading, photocell4Reading, photocell5Reading){

// 45 right photocell
else if(photocell4Reading > photocell1Reading, photocell2Reading, photocell3Reading, photocell5Reading){

// Far left photocell
else if (photocell5Reading > photocell1Reading, photocell2Reading, photocell4Reading, photocell3Reading);{


Could you please post your code between

[code]and [/code]

tags. It makes it easier to read and easy to copy and paste for analysis.

Also you say "it is not working" Could you be more specific about what's happening.

if(photocell1Reading > photocell2Reading, photocell3Reading, photocell4Reading, photocell5Reading)

This format does not follow the acceptable syntax for the "if" statement.

Look up || and && under the reference section.

if(photocell1Reading > photocell2Reading, photocell3Reading, photocell4Reading, photocell5Reading){

I presume that you want this to succeed if photocell1Reading is greater than the other 4 readings. To do that you would have to use:

if(photocell1Reading > photocell2Reading && photocell1Reading > photocell3ReadingĀ  && photocell1Reading > photocell4Reading && photocell1Reading > photocell5Reading){

The others must, of course be changed in a similar way and you must remove the semicolon at the end of the last if statement.

It would be easier if you had used an array for the readings. You could then find the largest element in the array and go from there.


Thank you, it works now.

Hi, a picture of your working project might be of benefit for all, if you would be so kind as to post one please. We see so many pictures of projects that aren't working it would be nice to see a working one.

Tom....... :)