Servo Motor with Arduino based PLC

October 18, 2024 by
Servo Motor with Arduino based PLC
Bernat Garcia

Introduction

In this post, we will control the speed of a servo motor 57HSE2N-D25. For this we will also need a driver, HSS57 Hybrid Servo Driver, for the servo motor that will be connected to our Arduino based PLC for the automation of the speed control. For the software, a pulses.h library is implemented  ( software without using pulses.h library is also attached).

Requirements

Connections


Servo Motor - Driver connections:

Red     ->       A+
Green      ->       A-
Yellow   ->       B+
Blue  ->       B-

Ethernet PLC - Driver connections: 

PIN 3   ->  PUL - (pulses)      
PIN2    ->  DIR- (rotational direction)
PIN 50 (MISO)  ->  ENA- (enable)                     
GND    -> PUL- , DIR - , ENA -

* Signals = 5Vdc

Servo Motor with Arduino based PLC Connections


*Remember to power supply the PLC between 12 and 24V.

*In this case we are using 5V signal, so, no resistors are needed between PUL+,ENA+, DIR+  and PIN2, PIN3, PIN50.

*Controller is M-Duino 21+

*Encoder is not used in this post


Software

Using this sketch you are able to control the speed of the stepper, direction and number of revolutions.

Change PIN2 to control the direction, change NUM_REVOLUTIONS to decide how many revolutions do you require and change FREQ to change the frequency (rotation speed).

Below is the code:

/*
   Copyright (c) 2018 Boot&Work Corp., S.L. All rights reserved
   This program is free software: you can redistribute it and/or modify
   it under the terms of the GNU Lesser General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Lesser General Public License for more details.
   You should have received a copy of the GNU Lesser General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include <Pulses.h>

#define PIN_STEPPER_PUL 3
#define PIN_STEPPER_DIR 2
#define PIN_STEPPER_ENA 50
#define STEPPER_PULSES_PER_REV 1600UL
#define FREQ (2000UL) // Hz
#define NUM_REVOLUTIONS 10
#define STEPPER_STEPS ((NUM_REVOLUTIONS) * (STEPPER_PULSES_PER_REV))
 
volatile uint32_t stepsCnt = STEPPER_STEPS;
ISR(TIMER3_COMPA_vect) {
  if (stepsCnt) {
    --stepsCnt;
    if (stepsCnt == 0UL) {
      stopPulses(PIN_STEPPER_PUL);
    }
  }
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
  pinMode(PIN_STEPPER_DIR, OUTPUT);
  pinMode(PIN_STEPPER_PUL, OUTPUT);
  pinMode(PIN_STEPPER_ENA, OUTPUT);
  digitalWrite(PIN_STEPPER_DIR, HIGH);
  digitalWrite(PIN_STEPPER_ENA, HIGH);
  // It depends on the PIN_STEPPER_PUL
  TIMSK3 |= 1 << OCIE3A;
  startPulses(PIN_STEPPER_PUL, FREQ, 3);
}
////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
}

 
 


Check our Case Studies :

Automation Case Studies >>>                                             

​Search in our Blog

Servo Motor with Arduino based PLC
Bernat Garcia October 18, 2024

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>