How to interface linear actuator with D1-Mini

Hi all!

I wrote this tutorial:

I am now updating the linear actuators because, well, the last ones are GARBAGE and have both broken several times. So I bought these (data sheet) and am now getting around to hooking them up.

They have a builtin hall effect sensor so I can tell how far open or closed the gates are, and when to stop them / turn them on. I am having some issues with programming and hooking them up.

  • The hall sensor is powered by 5V, so I assume the hall outputs are 5V? Could I power it off of 3.3V? I didn't see that in the data sheet. I am controlling them with a Wemos D1-Mini, hence the 3.3V question for the hall sensor.
  • If the hall sensor only outputs 5V, how could I drop it to 3.3V for the wemos input?
  • How would I code for it in the first place? The hall sensor outputs 11,278 pulses per inch. The actuator moves at 0.51 inches per sec, so in 2 seconds, there would be 11,278 pulses.

Thanks in advance!

Maybe, but that wouldn't match the voltage specified in the data sheet, so no guarantee.

Voltage dividers. These are simply pairs of resistors, e.g. 4K7 & 10K.

Just like a rotary encoder.

Why do you need to tell how far open they are?

Thanks @PaulRB

Because I don't want them to open and close all of the way. That would break them. So I need them to start and stop in a certain place.

Haha, that's right.

A hint from my 12 year old Mighty Mule dual gate controller. The setup allows you to program the gate closed position and the gate open position. You will likely need to do the same.
The controller also monitors the motor current to stop the movement when the load (usually pushing snow) becomes too great. Also avoids law suits when some one or thing gets caught in the gate.

Yep, that's exactly what I'm doing.

That's awesome! I just finished designing a PCB with that feature included. I've already had several "accidents" from them not shutting off.

My controller has a pot to let the user set the overload point.

1 Like

Way too soon to even start designing a PCB!

I see a potential problem here. Can't they open all the way either? I mean until the limit switches are activated (I hope they have those in addition to the hall sensors)? Because when the Arduino is powered up (or reset) it won't know what position the gates are in. It will need to "home" to the fully open or closed position in order to know what position the gate is in.

Perhaps if the gates cannot open or close far enough to activate the limit switches in the motors, you will need to add a sensor to allow the gates to "home" to a known position.

I designed a new PCB a while back before I got these actuators. Now I'm going to modify it to work with these actuators, and then order it.

Very true. Actually, they can open all the way, but they just can't close all the way. So my idea, is when the gates are turned on, wait a couple minutes while they open all the way (there are builtin limit switches), and then are closed to the correct position.

No need to wait that long. The Arduino will be able to know very quickly when the limit switch is activated because the signals from the hall sensors will stop changing. If you are using a library for a rotary encoder, you can have your sketch monitor the encoder position value and if that does not change for one or two seconds, assume the gates are fully open, then reset the encoder position to zero ready for closing.

Rather than monitor the current through the motors to detect objects blocking the gate, you can use the hall sensors for this also: the rate of change of the encoder position will slow down or stop.

1 Like

Yeah. I didn't even think of that!

Also a great idea! That will just take a little bit more coding to figure out when a delay is too long. Like this:

void measureActDist(){
  goAgain:
  while (digitalRead(hall1) == LOW){
    acounter++;
    delay(0.01)
    if (acounter >= 9){ // normal is 8.86
      stopGates();
      return;
    }
  }
  if (digitalRead(hall1) == HIGH) {
    pulsecounter++;
  }
  if (pulsecounter != ppi*usedActStroke){  //ppi = 11,278 ; usedActStroke(inches of actuator used) = 5"
    goto goAgain;
  }
}

Right?

No, I was suggesting you use a rotary encoder library to keep track of the gate position for you, so you would not be reading the digital inputs directly.

Instead, you would make use of the encoder position value provided by the library. By checking that position once a second, and comparing it to the previous position, your code could work out the speed that the motor is moving at. If that speed falls to zero, you have hit the limit switch, or an object!

"goto"??? Hang your head in shame! :open_mouth: :wink:

Choosing the right rotary encoder library will be important here. The signals from your hall sensors will be very fast (~5000 pulses per second as you mentioned in your original post), so a library that makes use of interrupts will be required. But many such libraries may only work on AVR chips, and you are using ESP.

Is this a good library that includes interrupts?

Yeah, I was only using "goto" to simplify testing. :upside_down_face:

I am now updating the linear actuators because, well, the last ones are GARBAGE

How about updating the tutorial, so others aren't burned by following your bad advice?

Just did. Luckily I didn't recommend any actuator. I only mentioned once that I bought mine off of windynation.com .

It doesn't seem to use interrupts, no. Worth trying, but do not get too hopeful.

Oh. This one uses time interrupts, but it doesn't say anything about ESP:

I guess I'll have to try it, and see if it works.

I think it will fail to compile: "unsupported board".