master and slave solar tracker

Asalamoalikum
hi guys
Im trying to make a solar tracking system using master and slave technique.
there'll be one master solar panel that align itself according to the position of sun using 4 LDRs and then send a signal to the slave solar panel to get it aligned as well.
for this i have used MPU 6050 angle sensors placed on both the panels the slave will continuously check its angle against the angle of the master panel and the servo motors of the slave panel will move if there's a difference in the angle.
this plan doesnt seem to work or maybe i have done some thing wrong in coding.
please suggest anything else that i can do to perform this task or any improvement in the current project
i have attached the code below
thanks in advance

2mpucheck.ino (8.04 KB)

for this i have used MPU 6050 angle sensors

An MPU 6050 is not an angle sensor. It's an accelerometer and gyroscope. The date from the device can be used to compute angles.

this plan doesnt seem to work or maybe i have done some thing wrong in coding.

The code you posted, without identifying whether that is the master code or the slave code, does something that you didn't describe. You expect it to do something, but you didn't describe what you expect. You can't really expect help.

#define motormoves void

Why?

  Wire.begin();

Why are you calling Wire.begin() more than once?

  Wire.beginTransmission(MPU_addr);
  Wire.write(0x6B);  
  Wire.write(0);     
  Wire.endTransmission(true);
  Wire.begin();
  Wire.beginTransmission(MPU_addr1);
  Wire.write(0x6B);  
  Wire.write(0);     
  Wire.endTransmission(true);

You have two MPU 6050s attached to one Arduino? Why?

 servovS=servovS++;

That produces undefined behavior. Do not do that. Use servovS = servovS + 1 or servovS++.

  servovS= --servovS;

Same incorrect mess.

the code is same for both master and slave both are controlled using same arduino.
just dragged two PWM wires to control the motors of the slave traker

You might find this useful:

      //Roll & Pitch Equations from accelerometers only
      // float roll2  = (atan2(-_ay, _az)*180.0)/M_PI;
      // float pitch2 = (atan2(_ax, sqrt(_ay*_ay + _az*_az))*180.0)/M_PI;

Then you will find those do not work well, jittery, so you'll come back looking to add a filter but you'd get a faster response by entering the words "Complementary Bandpass Filter Arduino" into your most favored search engine and get loads of links. You can if you want, omit the word "Bandpass" from the search but you'd get better results using a Complimentary Band Pass Filter. The trade off is the more options you want out of a filter the more costly in uController resources the filter becomes.

Then you may not be, initially, getting any useable data from the complimentary filter. The first place to look at, if the info seems wonky, is the way you are collecting and calculating time. You may need to use micros() instead of millis(), depending on how fast the calculations are done.

You might find this link useful:
https://os.mbed.com/users/onehorse/

Of course, you could just take the servo values from the master device and send them, over wire, to the slave device.

can you please guide me about how to send values from servo to the servo of slave, it'll simplify my task

shaikhhammadali:
can you please guide me about how to send values from servo to the servo of slave, it'll simplify my task

You'll want to choose a data transmission scheme, there is available serial, I2C, SPI, and CAN; in example. Each has its pros and cons, such as does the device I am using have a serial, I2C, SPI, or CAN controller built into the device? You, after doing some research will need to make a decision on which transmission scheme you are going to go with.

ok thanks ill work on it