Society of Robots - Robot Forum

Software => Software => Topic started by: DiegoChavez on October 24, 2014, 11:11:18 AM

Title: Smart Solar Panel Not Working
Post by: DiegoChavez on October 24, 2014, 11:11:18 AM
Hey I am working on a smart solar panel that consist of 5 photocells placed at different angles then the input is interpreted by an Arduino and it tells a servo motor to what angle to move the solar panel. the only problem that I that I have is that the motor doesn't change position. I think it might have something to do with the code but I cannot find the problem, 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) {
 
  myservo.attach(9);

}
 
void loop(void) {
  photocell1Reading = analogRead(photocell1); 
  photocell2Reading = analogRead(photocell2); 
  photocell3Reading = analogRead(photocell3); 
  photocell4Reading = analogRead(photocell4); 
  photocell5Reading = analogRead(photocell5);   
 
  // Far left photocell
   if(photocell1Reading > photocell2Reading, photocell3Reading, photocell4Reading, photocell5Reading){
     myservo.write(25);
     }

  // 45 left photocell
   else if(photocell2Reading > photocell1Reading, photocell3Reading, photocell4Reading, photocell5Reading){
     myservo.write(45);
     }

  // Center photocell
   else if(photocell3Reading > photocell1Reading, photocell2Reading, photocell4Reading, photocell5Reading){
     myservo.write(90);
     }
     
  // 45 right photocell
   else if(photocell4Reading > photocell1Reading, photocell2Reading, photocell3Reading, photocell5Reading){
     myservo.write(135);
     }
     
  // Far left photocell
   else(photocell5Reading > photocell1Reading, photocell2Reading, photocell4Reading, photocell3Reading);{
     myservo.write(175);
     }


}[/font]
Title: Re: Smart Solar Panel Not Working
Post by: muilenta on October 24, 2014, 12:13:44 PM
Try starting with a simpler program where you just move the servo with no sensor reading.
Title: Re: Smart Solar Panel Not Working
Post by: DiegoChavez on October 24, 2014, 12:30:12 PM
tried it, it works just fine
Title: Re: Smart Solar Panel Not Working
Post by: DiegoChavez on October 24, 2014, 12:55:25 PM
also tried a simple program to see if the photocells work and they work just fine.
Title: Re: Smart Solar Panel Not Working
Post by: Fr0stAngel on October 28, 2014, 03:01:49 AM
Hello,
Try to serially print out the sensor values using the serial library and view the output on the serial monitor. Have a look at the values and see if they sensor values are as they should be or not.

You can also try to simulate the circuit on Proteus (TM) using the arduino support model and see how the code behaves.

Good Luck