Brush-less Motor

I have recently bought a 12V DPDT relay and 12V Brush-less DC motor. I have tested both the relay and motor separately and both of them work. My issue is once I try to combine both codes to control the relay and motor individually, the components (relay and motor) no longer respond as needed. The relay would activate, but the motor does not start. Another issue is the relay does not respond when I try to de-energize it.
The code below is an initial attempt in writing the code for this system. Is there any issue with this code? Or something I should add?
The goal of this system is to reverse the direction of the motor using a relay.

Thanks
// Code

#include <Servo.h>
char val; // variable to receive data from the serial port
int ledpin = 11; // LED connected to pin 11 (on-board LED)
int value1 = 1500; // set values you need to zero
int value2 = 1500; // set values you need to zero
Servo firstESC;

void setup()
{
pinMode(ledpin = 11, OUTPUT); // pin 11 (on-board LED) as OUTPUT
firstESC.attach(9);

Serial.begin(9600); // start serial communication at 1151100bps

}

void loop()

{
firstESC.writeMicroseconds(value1);
if( Serial.available() ) // if data is available to read

val = Serial.read(); // read it and store it in 'val'

if( val == 'a' ) // if 'a' was received led 11 is switched off
{
digitalWrite(ledpin = 11, HIGH); // turn Off pin 11
value1 = Serial.parseInt();
}

if( val == 'd' ) // if 'd' was received led 11 on
{
digitalWrite(ledpin = 11, LOW); // turn ON pin 11
value2 = Serial.parseInt();
}

}

digitalWrite(ledpin = 11, LOW); Unusual

Is parseInt() timing out?

double checked the hardware?

Very confusing. You appear to be reading a couple of things from Serial but doing nothing with them. And I can't see any reference to a relay anywhere in the code. Also I don't know any way of reversing the direction of a brushless motor using a relay.

Perhaps if you provide details of exactly what motor/ESC/relay you are using and how everything is connected it would be easier to understand. Also what board you are using because the onboard LED is normally on pin 13 not 11.

Steve

I don't know any way of reversing the direction of a brushless motor using a relay.

Actually its fairly easy to do (exchange any two of the wires on the motor) but it is highly unlikely that the OP really wants to do that.