Over the last few months I've been building a self-leveling PID system with 2 brushless DC motors connected to basically a teeter totter. Recently I've been having trouble with the control of the motors. So, I wrote a very basic program to take input from a potentiometer and map it to a range of 1000 to 1050 microsecond PWM signal and send it to each motor.
The issue I've been having is that when I upload the code to the Arduino the motors both go full throttle instantaneously despite the 5 second delay in setup() and the fact that I have the potentiometer set to a 1000 microsecond pulse width which shouldn't allow the motors to move.
The setup is identical to the schematic I uploaded except I'm using an Arduino Nano, a different gyro sensor (which in this case doesn't matter as I'm only dealing with the motors), a 14.8V LiPo battery, and the correct ESCs for the battery.
Here's the code:
#include <Servo.h>
#include <Wire.h>
// Servo motors
Servo right_prop;
Servo left_prop;
void setup() {
Wire.begin();
Wire.beginTransmission(0x68);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
left_prop.attach(3);
right_prop.attach(5);
Serial.begin(115200);
delay(5000);
}
void loop() {
int throttle = map(analogRead(A0), 0, 1023, 1000, 1050);
Serial.println(throttle);
left_prop.writeMicroseconds(throttle);
right_prop.writeMicroseconds(throttle);
delay(10);
}
