Vous êtes sur la page 1sur 7

06/09/13

Arduino - Control ESC/Motor (Arduino Code)

Fun Projects of Vari


Sidebar
Contact me
The Unpublished

search

Arduino - Control ESC/Motor (Arduino Code)


Summary

OpenCV - Canny Edge,

Android - An example a

This is only the Arduino sketch for the tutorial "Arduino - Control ESC/Motor Tutorial
[http://techvalleyprojects.blogspot.com/2012/06/arduino-control-escmotortutorial.html] ". This is a tutorial of how to control an electronic speed control (ESC) [http://en.wikipedia.org/wiki/Electronic_speed_control]

Android IOIO - Listen for

Android IOIO - motor co

and brushless motor


[http://en.wikipedia.org/wiki/Brushless_DC_electric_motor] using an Arduino [http://www.arduino.cc/] .

Arduino - Control

17

Arduino - Control

33

Arduino - Control

/* * This code is in the public domain. * (Do whatever you want with it.) */ // Need the Servo library #include <Servo.h> // This is our motor. Servo myMotor; // This is the final output // written to the motor. String incomingString;

C# - Using the Comma

PowerSwitch Tail

Android App - Ma

Maximum Data Rate of

C# Text Messages by E

Multiplatform Project

Send Email C# - Exam

// Set everything up void setup() { // Put the motor to Arduino pin #9 myMotor.attach(9); // Required for I/O from Serial monitor Serial.begin(9600); // Print a startup message Serial.println("initializing"); }

Computer Projects

ASP.NET - Add Member

MS SQL Server 2

Android - Use we

void loop() {
techvalleyprojects.blogspot.com.es/2012/06/arduino-control-escmotor-arduino-code.html 1/7

06/09/13

Arduino - Control ESC/Motor (Arduino Code)

Fill PDF forms in

The RC Car Hack - App

The RC Car Hack - Part

// If there is incoming value if(Serial.available() > 0) { // read the value char ch = Serial.read();

Send feedback

The RC Car Hack - Part

The RC Car Hack - Part

TVS diode and the dea

Arduino Vending

(Tablet + Elm327) / Blu

Project 1 - Arduino Acce

/* * If ch isn't a newline * (linefeed) character, * we will add the character * to the incomingString */ if (ch != 10){ // Print out the value received // so that we can see what is // happening Serial.print("I have received: "); Serial.print(ch, DEC); Serial.print('\n'); // Add the character to // the incomingString incomingString += ch; } // received a newline (linefeed) character // this means we are done making a string else { // print the incoming string Serial.println("I am printing the entire string"); Serial.println(incomingString); // Convert the string to an integer int val = incomingString.toInt(); // print the integer Serial.println("Printing the value: "); Serial.println(val); /* * We only want to write an integer between * 0 and 180 to the motor. */ if (val > -1 && val < 181) { // Print confirmation that the // value is between 0 and 180 Serial.println("Value is between 0 and 180"); // Write to Servo myMotor.write(val); }

techvalleyprojects.blogspot.com.es/2012/06/arduino-control-escmotor-arduino-code.html

2/7

06/09/13

Arduino - Control ESC/Motor (Arduino Code)

// The value is not between 0 and 180. // We do not want write this value to // the motor. else { Serial.println("Value is NOT between 0 and 180"); // IT'S a TRAP! Serial.println("Error with the input"); } // Reset the value of the incomingString incomingString = ""; } } } Posted 11th June 2012 by Sean OBryan
5

View comments

Wilhelm Kuckelsberg October 11, 2012 at 4:57 AM Hello, I'm a little desperate. I want to settle with my 4 brushless Duemillenova. 3 motors work that is no longer the fourth. ESC and motors are teste and OK. here is mey code: #include #include Servo rotor_1; Servo rotor_2; Servo rotor_3; Servo rotor_4; #define PINESC1 5 #define PINESC2 6 #define PINESC3 10 #define PINESC4 11 #define ARM_TIME 10000 typedef enum { STARTROTOR1, STARTROTOR2, STARTROTOR3, STARTROTOR4, } rotation_t; int rotorSpeed = 0; int rotorMillis = 0; unsigned long currentMillis = 0;

techvalleyprojects.blogspot.com.es/2012/06/arduino-control-escmotor-arduino-code.html

3/7

06/09/13

Arduino - Control ESC/Motor (Arduino Code)

void setup() { Serial.begin(9600); rotor_1.attach(PINESC1); rotor_2.attach(PINESC2); rotor_3.attach(PINESC3); rotor_4.attach(PINESC4); arm_esc(ARM_TIME); } void loop() { ReadKeybord(); start(); currentMillis = millis(); Serial.print("Current Millis - ");Serial.println(currentMillis); } void start() { static rotation_t rotation = STARTROTOR1; static int wait = 1; static unsigned long newMillis = 0; switch(wait) { case 1: newMillis = currentMillis; wait = 2; break; case 2: if (currentMillis - newMillis >= 25) { Serial.print("New Mills - ");Serial.println(newMillis); switch(rotation) { case STARTROTOR1: rotor_1.writeMicroseconds(rotorMillis); Serial.print("CW1 MS - ");Serial.println(rotorMillis); rotation = STARTROTOR2; break; case STARTROTOR2: rotor_2.writeMicroseconds(rotorMillis); Serial.print("CCW1 MS - ");Serial.println(rotorMillis); rotation = STARTROTOR3; break; case STARTROTOR3: rotor_3.writeMicroseconds(rotorMillis); Serial.print("CW2 MS - ");Serial.println(rotorMillis); rotation = STARTROTOR4; break; case STARTROTOR4: rotor_4.writeMicroseconds(rotorMillis); Serial.print("CCW2 MS - ");Serial.println(rotorMillis); rotation = STARTROTOR1; break; } wait = 3; }
techvalleyprojects.blogspot.com.es/2012/06/arduino-control-escmotor-arduino-code.html 4/7

06/09/13

Arduino - Control ESC/Motor (Arduino Code)

break; case 3: wait = 1; break; } } void arm_esc(int ArmTime) { delay(ArmTime); Serial.println("Sending lowest throttle Motor 1"); rotor_1.writeMicroseconds(1000); delay(2000); Serial.println("Sending lowest throttle Motor 2"); rotor_2.writeMicroseconds(1000); delay(2000); Serial.println("Sending lowest throttle Motor 3"); rotor_3.writeMicroseconds(1000); delay(2000); Serial.println("Sending lowest throttle Motor 4"); rotor_4.writeMicroseconds(1000); delay(2000);

Serial.println("Low throttle sent"); } void ReadKeybord() { int key = 0; if(Serial.available() > 0) { key = Serial.read(); switch(key) { case '2': rotorMillis = mapSpeedToMicrosec(rotorSpeed += 1); Serial.print(" - Speed steigern - ");Serial.println(rotorSpeed); break; case '8': rotorMillis = mapSpeedToMicrosec(rotorSpeed -= 1); Serial.print(" - Speed senken - ");Serial.println(rotorSpeed); break; case '5': rotorMillis = mapSpeedToMicrosec(0); rotorSpeed = 0; Serial.print(" - Stop - ");Serial.println(rotorSpeed); break; } } } int mapSpeedToMicrosec(int speed) { int _MS = 0;
techvalleyprojects.blogspot.com.es/2012/06/arduino-control-escmotor-arduino-code.html 5/7

06/09/13

Arduino - Control ESC/Motor (Arduino Code)

_MS = map(speed, 0, 150, 1000, 2500); Serial.print(" - setSpeed Millis - ");Serial.println(_MS); return(_MS); } Reply Replies Sean OBryan October 12, 2012 at 2:34 PM I'll take a look tonight. Are you using a shield? Just posted another example. It uses the Servo library but may help as another example. http://techvalleyprojects.blogspot.com/2012/10/arduinocontrol-escmotor-arduino-code.html Reply

proton_gt March 11, 2013 at 8:32 PM i have test with my RC CAR esc but it only can move forward when i sent "val" above 90. it just stop and not move reverse when i sent "val" below 90. how can i move it reverse?? Reply

Maciej Kost March 22, 2013 at 9:49 AM This comment has been removed by the author. Reply

Maciej Kost March 22, 2013 at 9:50 AM To turn on the ESC with this program. Fits 10 and nothing happens Reply

techvalleyprojects.blogspot.com.es/2012/06/arduino-control-escmotor-arduino-code.html

6/7

06/09/13

Arduino - Control ESC/Motor (Arduino Code)

E n t e ry o u rc o m m e n t . . .

Comment as: Google Account Publish Preview

techvalleyprojects.blogspot.com.es/2012/06/arduino-control-escmotor-arduino-code.html

7/7

Vous aimerez peut-être aussi