go away spammer

Author Topic: Smart Solar Panel Not Working  (Read 2636 times)

0 Members and 1 Guest are viewing this topic.

Offline DiegoChavezTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Smart Solar Panel Not Working
« 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]

Offline muilenta

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Re: Smart Solar Panel Not Working
« Reply #1 on: October 24, 2014, 12:13:44 PM »
Try starting with a simpler program where you just move the servo with no sensor reading.

Offline DiegoChavezTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Smart Solar Panel Not Working
« Reply #2 on: October 24, 2014, 12:30:12 PM »
tried it, it works just fine

Offline DiegoChavezTopic starter

  • Jr. Member
  • **
  • Posts: 33
  • Helpful? 0
Re: Smart Solar Panel Not Working
« Reply #3 on: October 24, 2014, 12:55:25 PM »
also tried a simple program to see if the photocells work and they work just fine.

Offline Fr0stAngel

  • Full Member
  • ***
  • Posts: 96
  • Helpful? 3
  • [O_O] what??
Re: Smart Solar Panel Not Working
« Reply #4 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
'crazy' is the new hype! =)

 


Get Your Ad Here

data_list