Dear Arduino makers,
I'm still new in Arduino programming and hardware. Now I'm doing a project which needs to connect multiple (3) servo motors (MGR996R) with the Node MCU (ESP8266) and the PCA9685. Each servo motors are intended to rotates from 0 degrees to a maximum of 180 degrees. I'm using the external power supplies which set to 5.0 V since the servo motors will be working in range between 4.8V to 6 V.
However, the results are odd. All of the servo motors keep rotating continuously (360 degrees) even though it have been declared in the code to rotates until 180. I searched online for the datasheet of MG996R servo motors and all of the sources stated that it should rotates to 180 degrees max.
I also found another sources mentioned about the FREQUENCY, MIN_PULSE_WIDTH and the MAX_PULSE_WIDTH could determined the min and max degrees position for the servos motors to rotate. I have no clue on how to calculate exactly the MIN / MAX PULSE_WIDTH manually., so I simply adjusted it accordingly by increasing or decreasing the values but the servo motors keep rotating continuously.
Oh by the way, I'm using the Adafruit_PWMServoDriver as well as the Node MCU 1.0 (ESP - 12E Module) board tools in this project since the HCAPCA9685 is not working with servos that I'm using.
I would be much appreciated if anyone in the forums could help me on this.
#using-arduino:motors-mechanics-power-and-cnc #hardware #esp8266 #pca9685 #MultipleServoMotor
The code that I'm using as follows:
#include "Wire.h"
#include "Adafruit_PWMServoDriver.h"
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
#define MIN_PULSE_WIDTH 600
#define MAX_PULSE_WIDTH 2600
#define FREQUENCY 50
void setup() {
pwm.begin();
pwm.setPWMFreq(FREQUENCY);
// find MIN_PULSE_WIDTH: set angle to 0
// find MAX_PULSE_WIDTH: set angle to 180
pwm.setPWM(2,0,pulseWidth(180)); // 0 or 180
pwm.setPWM(3,0,pulseWidth(180)); // 0 or 180
pwm.setPWM(4,0,pulseWidth(180)); // 0 or 180
}
int pulseWidth(int angle) {
int pulse_wide, analog_value;
pulse_wide = map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
return analog_value;
}
void loop() {
}
Regards,