149Views11Replies

Author Options:

How to control DIY linear actuator with end switches and sensor input? Answered

I want to build a DIY 12v DC linear actuator, using Arduino uno. The actuator is DIY so it does not have any position tracking.

I want to use 2 relays to control the direction of the actuator, two end switches, and one sensor input (preferably a photo resistor)

The sensor, and end switches are connected to Arduino UNO R3 as inputs and relays as outputs.

When the sensor is energized motor moves forward until it hits End Switch No 1 and stops;
When the sensor its not energized motor moves backwards until it hits End Switch No 2 and stops:

And be able to repeat this program whenever  the sensor is energized.

I would be greatly appreciate if someone can help me with this sketch, because i don't have any experience with Arduino code.
Thank you and have a grat day.

12 Replies

user
steveastrouk (author)2017-11-09

It can be very dangerous to use a microprocessor to control an actuator in the way you describe. It is ALWAYS better to make the relays cut the power when the actuator hits the limit stops IN HARDWARE.

Select as Best AnswerUndo Best Answer

user
catalin1704 (author)iceng2017-11-10

I intend to use a fuse, or a resetable fuse (i have one on the drill, wich is the source of the motor) to protect the motor burning up in case of malfuntion, and i don't know how to make the exact thing without using a microprocessor

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)catalin17042017-11-10

Its very easy, see my diagram

Select as Best AnswerUndo Best Answer

user
catalin1704 (author)steveastrouk2017-11-11

Thank You.

I will try this schematic

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)catalin17042017-11-12

With this circuit, you only need a photosensor circuit, no need for a microprocessor

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)catalin17042017-11-11

The circuit I've posted is ideal for a chicken coop.

Select as Best AnswerUndo Best Answer

user
iceng (author)steveastrouk2017-11-10

+1 Steve

I was opening my schema program when my iPhone signaled a comment and behold you saved me the effort !

Now, I don't need to produce.. My sky is depressing, cold, cloudy and dark.

Hope you have a nice weekend.

BTW catalin only needs a pair of 47K resistors and the normally open contacts of those limit switches to let his Arduino know when a limit is reached ;-)

Select as Best AnswerUndo Best Answer

user
steveastrouk (author)iceng2017-11-11

Ooh. Your little wrinkle at the end there should go in the diagram. I like that !

Also, I suppose at a pinch, you could use two relays. Relying on the XOR of the control signals would still be safe ?

In the 'teens (deg F) in State College today.

Select as Best AnswerUndo Best Answer

user
iceng (author)steveastrouk2017-11-11

Safe for a chicken maybe ;-)

Our mountain town changes 60 deg F twice a day..

Select as Best AnswerUndo Best Answer

user
catalin1704 (author)iceng2017-11-11

I rewrote a program based on a chicken coop door found on YouTube,

and looks promising:

int Sensor = 6; // LDR Sensor Pin

int ReedPin1 = 2; // Reed Switch 1

int ReedPin2 = 4; // Reed Switch 2

int MotorFW = 8; // Motor Forward

int MotorRW = 10; // Motor Backward

int Reed1 = 0;

int Reed2 = 0;

int Light = 0;

void setup()

{

pinMode (MotorFW, OUTPUT); // MOTOR PINS SET AS OUTPUT

pinMode (MotorRW, OUTPUT);

Reed1 = digitalRead(ReedPin1); // SET ALL SENSORS AS DIGITAL

Reed2 = digitalRead(ReedPin2);

Light = digitalRead(Sensor);

if (Reed1 != HIGH) // IF REED(1)IS NOT ACTIVATED

{

while (Reed2 != HIGH) // WHILE REED(2) IS NOT ACTIVATED

{

digitalWrite(MotorFW, HIGH); // MOTOR RUNS FORWARD

digitalWrite(MotorRW, LOW);

Reed1 = digitalRead(ReedPin1); // CHECK REED SENSORS POSITION

Reed2 = digitalRead(ReedPin2);

}

digitalWrite(MotorFW, LOW); // STOP MOTOR

digitalWrite(MotorRW, LOW);

}

}

void loop()

{

Light = digitalRead(Sensor); // SET LDR SENSOR AS DIGITAL

Reed1 = digitalRead(ReedPin1); // SET REED SENSORS AS DIGITAL

Reed2 = digitalRead(ReedPin2);

if (Reed1 = HIGH && Light == LOW) // IF SENSOR REED (1) IS ACTIVATED AND LDR IS OFF

{

delay(1000);

motordown(); // MOTOR RUNS BACKWARDS

}

else if (Reed2 = HIGH && Light == HIGH) // IF SENSOR REED (2) IS ACTIVATED AND LDR IS ON

{

delay(1000);

motorup(); // MOTOR RUNS FORWARD

}

}

// MOTOR FORWARD FUNTION

void motordown()

{

Reed1 = digitalRead(ReedPin1); // CHECK REED SENSORS POSITION

Reed2 = digitalRead(ReedPin2);

if (Reed2 = HIGH && Light == LOW)

delay(1000);

Reed1 = digitalRead(ReedPin1); // CHECK REED SENSORS POSITION

Reed2 = digitalRead(ReedPin2);

while (Reed1 != HIGH) // WHILE REED (1) IS NOT ACTIVATED

{

digitalWrite(MotorFW, HIGH); // MOTOR RUNS FORWARD

digitalWrite(MotorRW, LOW);

Reed1 = digitalRead(ReedPin1); // CHECK REED SENSORS POSITION

Reed2 = digitalRead(ReedPin2);

}

digitalWrite(MotorFW, LOW); // STOP MOTOR

digitalWrite(MotorRW, LOW);

}

//MOTOR BACKWARDS FUNCTION

void motorup()

{

Reed1 = digitalRead(ReedPin1); // CHECK REED SENSORS POSITION

Reed2 = digitalRead(ReedPin2);

if (Reed1 = HIGH && Light == HIGH)

delay(1000);

Reed1 = digitalRead(ReedPin1); // CHECK REED SENSORS POSITION

Reed2 = digitalRead(ReedPin2);

while (Reed2 != HIGH) // WHILE REED (2) IS NOT ACTIVATED

{

digitalWrite(MotorFW, LOW); // MOTOR RUNS BACKWARDS

digitalWrite(MotorRW, HIGH);

Reed1 = digitalRead(ReedPin1); // CHECK REED SENSORS POSITION

Reed2 = digitalRead(ReedPin2);

}

digitalWrite(MotorFW, LOW); // STOP MOTOR

digitalWrite(MotorRW, LOW);

}

Select as Best AnswerUndo Best Answer