Serial control of a servo motor and brushless DC motor using Arduino Uno

Hello,

New to this program and working on a watercraft project controlled by an arduino. Readings from sensors will be input from an external arduino to my Arduino Uno via a serial string of information. I am tasked with creating a program that will facilitate the simultaneous control of a servo motor for the rudder and an ESC to control the brushless motor for propulsion. I will attach what I code that I have been using below from http://forum.arduino.cc/index.php?topic=56575.0 [1]. My trouble is in adding in the code for the servo to react to serial communication. Thank you.

#include <Servo.h>
int MotorSpeed = 0;

Servo BrushlessMotor;

void arm(){
// Code modification necessary for use of ESC
setSpeed(30);
delay(1000); //delay 1 second, some speed controllers may need longer
}

void setSpeed(int speed){
// speed is from 0 to 100 where 0 is off and 100 is maximum speed
//the following maps speed values of 0-100 to angles from 0-180,
// some speed controllers may need different values, see the ESC instructions
int angle = map(speed, 0, 100, 0, 180);
BrushlessMotor.write(angle);
}

void setup()
{
BrushlessMotor.attach(12);
arm();
Serial.begin(9600);
pinMode(MotorSpeed, OUTPUT);
}

void loop()
{
MotorSpeed = Serial.read();
setSpeed(MotorSpeed);
delay(1000);
}

Code modified from user: “Acecombat” http://forum.arduino.cc/index.php?topic=56575.0

Hello and welcome to the forum. In the future, post code using code tags. What do you expect this code to do, and what does it do differently?

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

If you now want to control two things rather than just the one in your code you need to decide what format of messages you're going to send and then put some code in to read those messages and do something with them.

Which part of that are you having trouble with?

Steve

I don't see anything to do with a rudder servo in your code. ESCs are usually controlled with writeMicroseconds() from 1000 to 2000 with standstill about 1500 +/-. Post a link to your ESC so we can see how to properly initialize it, (I hate the word "arm").