Mega 2650 solar tracker LDR Relay

int powerPin = 3;
int ledPin = 13;

int motoraPin = 40;
int motorlPin = 41;
int motorrPin = 42;

int motorzPin = 50;
int motoruPin = 51;
int motordPin = 52;

int upSunPin = 2;
int downSunPin = 3;
int leftSunPin = 4;
int rightSunPin = 5;

void setup() {
// Serial.begin(9600);
pinMode(motoraPin,OUTPUT);
pinMode(motorlPin,OUTPUT);
pinMode(motorrPin,OUTPUT);

pinMode( motorzPin,OUTPUT);
pinMode( motoruPin,OUTPUT);
pinMode( motordPin,OUTPUT);

delay(3000);

}

void loop() {
// Int vall = analogRead(leftSunPin);
int valr = analogRead(rightSunPin);
int valu = analogRead(upSunPin);
int vald = analogRead(downSunPin);

int scaleLeft = map(vald, 0, 1023, 0, 10);
int scaleRight = map(valr, 0, 1023, 0, 10);
int scaleUp = map(valu, 0, 1023, 0, 15);
int scaleDown = map(vald, 0, 1023, 0, 15);

//Serial.print(vall);
Serial.print("-");
Serial.print(scaleLeft);
Serial.print("LEFT,");

//Serial.print(valr);
Serial.print("-");
Serial.print(scaleRight);
Serial.print("RIGHT;");

//Serial.print(valu);
Serial.print("-");
Serial.print(scaleUp);
Serial.print("UP:");

//Serial.print(vald);
Serial.print("-");
Serial.print(scaleDown);
Serial.println("DOWN.");


if   ( scaleLeft  ==  scaleRight) digitalWrite ( motoraPin, LOW);

else digitalWrite ( mototaPin, HIGH);

if (scaleLeft < scaleRight) digitalWrite ( motorrPin, HIGH);

else digitalWrite ( motorrPin, LOW);

if (scaleLeft > scaleRight) digitalWrire ( motorlPin, HIGH);

else digitalWrite ( motorlPin, LOW);

if (scaleUp == scaleDown) digitalWrite ( motorzPin, LOW);

else digitalWrite ( motorzPin, HIGH);

if (scaleUp > scaleDown) digitalWrite ( motoruPin, HIGH);

else digitalWrite (motoruPin, LOW);

if ( scaleUp < scaleDown) digitalWrite ( mototdPin, HIGH);

else digitalWrite (motordPin, LOW);

delay(100);

}
Sorry about the mess. what part of the code should I have before Setup. Now I got errors when up loading the code, Hope some one have the time to put me in the right direction. Kind Regards Botvid.!
In function void loop motor pin was not declared in this scope.
digitalWrite was not decared in this scope,

The IDE provides a control to copy the error message.
The error message also usually points pretty accurately at the location of the problem.

Please remember to use code tags when posting code

Right there.

See, when you post what you think you read, you just waste time

The compiler appears to have caught the disease.

Hi, @botvid
To add code please click this link;

Can you please post a circuit diagram?

Have you written your code in stages?
That is;
Have you written code just to control a motor?
Have you written code just to read the buttons?

If you have written this code all at once and it won't compile.
Can I suggest you write it in stages and prove each stage before attempting to combine them.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

Hi Tom thanks for your info about how to ask help. I will get back to you,must learn to put things in the right way.
Kind regards Botvid

Hi Tom I yes I have written the code all at once, have tried to do it in stages but no luck,
The code is for the Arduino Mega AT 2560 to controll two linear actuators for solar tracker,using relays and LDR
I hope this will come out, so you can understand what I'm trying to do.
Look forward to hear from you.
Kind regards botvid.


I still got error, digitalWrite was not declared in this scope.``

[code]
int powerPin = 3;
int ledPin = 13;

int motoraPin = 40;
int motorlPin = 41;
int motorrPin = 42;

int motorzPin = 50;
int motoruPin = 51;
int motordPin = 52;

int upSunPin = 2;
int downSunPin = 3;
int leftSunPin = 4;
int rightSunPin = 5;

void setup() {
// Serial.begin(9600);
pinMode(motoraPin, OUTPUT);
pinMode(motorlPin, OUTPUT);
pinMode(motorrPin, OUTPUT);

pinMode( motorzPin, OUTPUT);
pinMode( motoruPin, OUTPUT);
pinMode( motordPin, OUTPUT);

delay(3000);

}

void loop() {
// Int vall = analogRead(leftSunPin);
int valr = analogRead(rightSunPin);
int valu = analogRead(upSunPin);
int vald = analogRead(downSunPin);

int scaleLeft = map(vald, 0, 1023, 0, 10);
int scaleRight = map(valr, 0, 1023, 0, 10);
int scaleUp = map(valu, 0, 1023, 0, 15);
int scaleDown = map(vald, 0, 1023, 0, 15);

//Serial.print(vall);
Serial.print("-");
Serial.print(scaleLeft);
Serial.print("LEFT,");

//Serial.print(valr);
Serial.print("-");
Serial.print(scaleRight);
Serial.print("RIGHT;");

//Serial.print(valu);
Serial.print("-");
Serial.print(scaleUp);
Serial.print("UP;");

//Serial.print(vald);
Serial.print("-");
Serial.print(scaleDown);
Serial.println("DOWN.");

if ( scaleLeft == scaleRight) digitalWrite ( motoraPin, LOW);

else digitalWrite ( motoraPin, HIGH);

if (scaleLeft < scaleRight) digitalWrite( motorrPin, HIGH);

else digitalWrite ( motorrPin, LOW);

if (scaleLeft > scaleRight) digitalWrire ( motorlPin, HIGH);

else digitalWrite ( motorlPin, LOW);

if (scaleUp == scaleDown) digitalWrite ( motorzPin, LOW);

else digitalWrite ( motorzPin, HIGH);

if (scaleUp > scaleDown) digitalWrite ( motoruPin, HIGH);

else digitalWrite (motoruPin, LOW);

if ( scaleUp < scaleDown) digitalWrite ( motordPin, HIGH);
else digitalWrite (motordPin, LOW);

delay(100);

}
[/code]Arduino: 1.8.16 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\bosse\Documents\Arduino\BareMinimum\BareMinimum.ino: In function 'void loop()':

BareMinimum:73:33: error: 'digitalWrire' was not declared in this scope

if (scaleLeft > scaleRight) digitalWrire ( motorlPin, HIGH);

                             ^~~~~~~~~~~~

C:\Users\bosse\Documents\Arduino\BareMinimum\BareMinimum.ino:73:33: note: suggested alternative: 'digitalWrite'

if (scaleLeft > scaleRight) digitalWrire ( motorlPin, HIGH);

                             ^~~~~~~~~~~~

                             digitalWrite

exit status 1

'digitalWrire' was not declared in this scope

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Arduino: 1.8.16 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\bosse\Documents\Arduino\BareMinimum\BareMinimum.ino: In function 'void loop()':

BareMinimum:73:33: error: 'digitalWrire' was not declared in this scope

   if   (scaleLeft > scaleRight) digitalWrire ( motorlPin, HIGH);

                                 ^~~~~~~~~~~~

C:\Users\bosse\Documents\Arduino\BareMinimum\BareMinimum.ino:73:33: note: suggested alternative: 'digitalWrite'

   if   (scaleLeft > scaleRight) digitalWrire ( motorlPin, HIGH);

                                 ^~~~~~~~~~~~

                                 digitalWrite

exit status 1

'digitalWrire' was not declared in this scope



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

type or paste code here

Hi,
Please post your code in tags so that we can read and check it easily.
To add code please click this link;

What does this tell you?

if (scaleLeft > scaleRight) digitalWrire ( motorlPin, HIGH);

                            ^~~~~~~~~~~~

                             digitalWrite

Does that look like how an if statement is constructed.
https://www.arduino.cc/reference/en/language/structure/control-structure/if/

What happened?
Did you write code for the actuators and get them running?
Did you write code to read the LDR and serial print data?

What are the specs on your relays, please post link to data/specs?
Are you sure you have the connections right to your relays.
It looks like pin 7 and pin 2 on each is the common for the switches, but you don't use them.

You only need two relays per actuator, on to turn power on and off, the other to change direction.

Have you a DMM?
Tom... :grinning: :+1: :coffee: :australia:

1 Like

You're going to have to start paying more attention to your spelling.

Read it again, and stop paraphrasing - it wastes time.

Please remember to use code tags when posting code

Hi Tom and thanks for your patient, have done my spelling miss take and up load work fine. Now I will connect it all, and try it out.
I have write the code to read the LDR and serial print data. The relays is Finder 40.62. www.tme.com/au/en/details/40.62.9.012.0000/miniature-electromagnetiv-relays/finder
Pin 7 and 2 are not connected in this experiment.
If DMM is multimeter yes I got one.
Kind regards Botvid

Hi,
Relay Specs;

relay

If you use your symbol for the relay, 7 and 2 are the common.
When 3 and 6 really are.
Your schematic is correct just a bit misleading.
7,2,6,3 etc, I believe are socket terminal numbers?

As I said you can get away with two relays per actuator, rather than 3.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Hi,
Have you sorted your if statements out.
Have you got the LDRs and relays connected?

Ready to test?

Tom... :grinning: :+1: :coffee: :australia:

Hi yes I have connected the lot and it works fine in the shed,
now I will fit the frame work on the roof and see if it will work with the sun. My if statements spelling stuff up is embarrassing.
Thanks for your patient to teach me.
Kind regards Botvid.