Motor Control Issues

I currently have a esc that is connected to a motor. I can make the motor go forward and backwards. However, when I put the backwards and forward commands it will go backward and forwards the first iteration through the loop. The second time it will just go forwards and skip the backwards command. I think this may because I am not interfacing with the esc correctly. Please let me know what you think. Code is attached below.

MotorTest.ino (2.26 KB)

Several things.

  • Go read through the How to use this forum - please read sticky post at the top of every forum. It covers a lot of great material new forum members like you need. Number 7 talks about how to post code using code tags.
  • Use CTRL-T in the IDE to autoformat your code. Formatted code is easier to read and much easier to troubleshoot. Mismatched curly brackets are easy to find this way.
  • You have variable and defines with nearly the same name. This certainly confuses me. Consider using one or the other.

Now, your code. Remove the pieces that don’t affect the motor. Test out what values make it stop, go backwards and go forwards. Maybe you already did this. It looks like you are using
stop 1500 (as a variable)
BACK 1350 (as a define)
GO 1600 (as a define)

Can you write a small sketch to just test those values?

Something like this:

#include <Servo.h>    //Servo library, included with the Arduino IDE

Servo motor;

void setup() {
  // put your setup code here, to run once:

void loop() {

  motor.writeMicroseconds(1500); //stop for 1 second

  motor.writeMicroseconds(1350); //back for 2 seconds

  motor.writeMicroseconds(1500); //stop for 3 seconds
  motor.write(1600); //forward for 4 seconds


See that I have a different delay for each to help identify where in the loop you are.
Let us know if this (untested) code works and what it does.