Linear Actuator H-Bridge

Hi there,

I am making a Solar Tracking System.

Basically what i have now is

- A Linear Actuator 12V DC
- 2 LDRs
- 1 Arduino Uno
- 1 H-Bridge L298N

I would like to control my Linear Actuator to move according to the light exposed to the 2 LDRs. I really have no idea how to continue.

I plan to have my starting position at the half way mark of the Linear Actuator and it will move according to the sunlight.

If east have more light, it will shift up.

If west have more light, it will shift downwards.

int ControlPin1 = 9; // 
int ControlPin2= 10; // 
void setup(){

Serial.begin(9600);
pinMode(ControlPin1, OUTPUT);
pinMode(ControlPin2, OUTPUT);
pinMode(BUTTON1,INPUT);

}

void InitialPosition(){
digitalWrite(ControlPin2, HIGH);
digitalWrite(ControlPin1, LOW);
delay(30000);
}

void retractActuator() {
digitalWrite(ControlPin2, LOW);
digitalWrite(ControlPin1, HIGH);
delay(15000); // max range is 30000, mid point is 15000
}

void stopActuator(){
digitalWrite(ControlPin2, LOW);
digitalWrite(ControlPin1, LOW);
delay(7000);
}

void loop(){

Serial.println( );// mid point is 15000s from max range.
//InitialPosition();
//delay(1000);
//stopActuator();
//delay(1000);
InitialPosition();
retractActuator();

stopActuator();

}

I use the delay to allow it to extend to max length , and retract to the minmum length. And the initial position i use (max length time - minimum length time)/2.

Is there any other way i can do it more efficiently, rather than depending on delays?

Most of the online examples uses Servo Motor which I don't intend to use.

Do advise.

"Do advise."

Use the forum Google search function in the upper right of this page to search for "solar tracker" and "linear actuator" and similar key words. You will probably find many previous project discussions and code using these devices.

zoomkat:
"Do advise."

Use the forum Google search function in the upper right of this page to search for "solar tracker" and "linear actuator" and similar key words. You will probably find many previous project discussions and code using these devices.

Hi, I have already use the search function and i could not find any discussion that I can relate to. Thankyou.

Do you have any links to the linear actuator that you are using? Please provide a connection diagram of the system that you are building, and photos if you have already built it.

Please take a look. Thank you.

Linear Actuator 12V : https://www.aliexpress.com/i/32825161763.html

xpassionzxc:
Hi, I have already use the search function and i could not find any discussion that I can relate to. Thankyou.

Well, that is not a good sign.

Excellent. Thank you for that information. Can you please go back and edit your original post, so that the code is placed in code tags, to follow the forum protocol?

OP's diagram:

aarg:
Excellent. Thank you for that information. Can you please go back and edit your original post, so that the code is placed in code tags, to follow the forum protocol?

OP's diagram:

Yup just did it. Sorry about that.

Please take a look at my code and predicament. Thank you

You say you use delay() to reach the endpoint. That's weird. Normally you would use a limit switch to detect when the actuator has reached the endpoint. Explain. Are you stalling the motor at the endpoint?

For tracking, you want some kind of feedback loop. Can you explain how you are doing this? Normally you would use the ratio of light between the 2 LDR's to steer the motor.

Also, so we don't have to ask for a more detailed diagram, has everything been tested and working independently?

aarg:
You say you use delay() to reach the endpoint. That's weird. Normally you would use a limit switch to detect when the actuator has reached the endpoint. Explain. Are you stalling the motor at the endpoint?

For tracking, you want some kind of feedback loop. Can you explain how you are doing this? Normally you would use the ratio of light between the 2 LDR's to steer the motor.

Also, so we don't have to ask for a more detailed diagram, has everything been tested and working independently?

Yes, I use delay() for me to let the actuator move at one direction for a specific time.

For example to fully extend the linear actuator : delay(30000)

For example to fully retract the linear actuator : delay(30000)

To reach the midpoint from the minimum point : delay(15000)

That's right. The main problem here is that I don't have a feedback loop. And I don't know how to implement one to this circuit.

Yes, everything has been tested and its working fine individually.

I'm using this kind of linear actuators.

You say you use delay() to reach the endpoint. That's weird. Normally you would use a limit switch to detect when the actuator has reached the endpoint.

This type of linear actuator have internal limit swicth. Sometimes theres is some extra wire available to get the feedback of theses switch. But not mine.

I also playing with delays at the begining to move the actuator.
But because my system must continue to work during the move, i use the millis function to calculate time spend in the main loop.

unsigned long timeSpend() {

unsigned long newtime = millis();

if ( newtime > mytime )
  return( newtime - mytime );
else
  return( newtime );

}

void loop() {
  mytime = millis();

// ... DO THings ..
  checkSensors();

  delay(2);

  beatime += timeSpend();
  
  if ( beatime > 3000 ) {
    heartBeat();
    beatime=0;
  }
    
}

So it's still timed based.

I'll to try to get the feedback of the limit switch , so i need to open one to show how it works internally.

To check specific position of the object move by the actuator, you must add some sensors ( mechanical or optical switch )

lijah:
I'm using this kind of linear actuators.

This type of linear actuator have internal limit swicth. Sometimes theres is some extra wire available to get the feedback of theses switch. But not mine.

I also playing with delays at the begining to move the actuator.
But because my system must continue to work during the move, i use the millis function to calculate time spend in the main loop.

unsigned long timeSpend() {

unsigned long newtime = millis();

if ( newtime > mytime )
  return( newtime - mytime );
else
  return( newtime );

}

void loop() {
  mytime = millis();

// ... DO THings ..
  checkSensors();

delay(2);

beatime += timeSpend();
 
  if ( beatime > 3000 ) {
    heartBeat();
    beatime=0;
  }
   
}




So it's still timed based.

I'll to try to get the feedback of the limit switch , so i need to open one to show how it works internally.

To check specific position of the object move by the actuator, you must add some sensors ( mechanical or optical switch )

Hi, so glad that I have someone that can feel my problems.

Actually, I have an idea on how to detect the position by creating my own algorithm.

Since we can move the linear actuator up bit by bit. Why not while its moving up bit by bit we add a variable.

For example : It takes maybe 300 times of movingup(); the movingup is totally up to you like the amount of time. For me it like moving 1cm per movingup(); so we assigned the value Position=1, inside the movingup loop we write Position=Position+1;

Do this for the Movingdown();
Inside the Movingdown();

void Movingdown
{
digitalWrite(ControlPin2, LOW);
digitalWrite(ControlPin1, HIGH);
Position=Position-1;
}

From there, we can find the specific position, whenever we want.

xpassionzxc:
Hi, so glad that I have someone that can feel my problems.

I don't lack any sympathy for your problem. I am just trying to get you to put all the information out here so people can adequately assist. Until now, you really didn't explain what your problem was. Do I now understand that it is, how to position the actuator in the middle? Why is that necessary for a solar tracker? Wouldn't the LDR sensors tell it where to go, with feedback? Usually, the LDRs are mounted so that the light that hits them changes as the actuator moves... that is the feedback loop. If the LDRs are completely stationary, trying to position the actuator without feedback is going to be a disappointment.

It seems a lot like you're using the "ready, fire, aim" approach.

Sounds good,

But you must consider an external sensor to confirm the "halfway" position.
Your system must "auto calibrate" at start and go to this position confirmed by a sensor. Then you can use timing to define the position.

It's mandatory to have a "home" position a reference and better if you can confirm this position with extra sensor , not only using one limit of the linear actuator.

There's 2 situations :

  • After power cut : when your system initialise you must be sure of the current position as reference to start timing based positionning.
  • Failure : if something wrong and the object doesn't move as expected, avoid any damage. Some linear actuator are very powerfull and can damage the mechanism.

Concern the sun search, how do you proceed? Is there a photo sensor to get the best position or is it only west-east switch postition ?

May be you can use the east/west sensor to guide you , and a sensor on the pannel to get the current value.

I mean :

From the Halfway :

If EAST > WEST -> move to east until panel sensor is at max ( move if increasing )
If WEST > EAST > move to west ..

Then during the day :

If EAST increase and WEST decrease -> Move to EAST
If WEST increase and EASTdecrease -> Move to WEST

the AND is very important to avoid moves because of one cloud.

Also don't use the immediate value of the photo sensors but calculate average during one delay ( 5 or 10 minutes ) to avoid too much move.