Thursday, September 23, 2010

Ducted Fan and Arduino

So I was looking for more of a breeze...




...seems like I've got some good breeze now with the 56mm ducted fan. Be careful, these ducted fans will slice your finger off!


Below is the sketch that works with the Great Planes ESC (adapted from other people's ESC sketches). It arms the ESC, then sweeps the speed up, stop, back to full speed, and sweeps back down to off.

#include <Servo.h>

Servo myservo;

void arm(){
// arm the speed controller, modify as necessary for your ESC
Serial.println("arming");
setSpeed(30);
delay(2000);
setSpeed(90);
delay(2000);
Serial.println("armed");
setSpeed(30);
delay(2000);
}

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,
int angle = map(speed, 0, 100, 0, 180);
myservo.write(angle);
}

void setup()
{
Serial.begin(115200);
myservo.attach(9);
arm();
}

void loop()
{
int speed;

Serial.println("Sweeping up");
for(speed = 37; speed <= 90; speed += 1) {
setSpeed(speed);
Serial.println(speed);
delay(100);
}
setSpeed(30);
delay(1000);
Serial.println("Sweeping down");
for(speed = 90; speed > 37; speed -= 1) {
setSpeed(speed);
Serial.println(speed);
delay(100);
}
Serial.println("30 halting...");
setSpeed(30);
delay(5000);
}

4 comments:

mohankumar said...

the code posted here makes the speed high and low.Can u please tell me how to modify this code to get a brushless motor running at constant speed?

t11s said...

mohankumar, simply call my "setSpeed();" command with a speed (valid ones are from 37 to 90 for this particlar fan), then don't call setSpeed again, and the speed should not change.

Bilal said...

Hi dear it is very useful .Thank you so much for share.Can we control Esc by serial port ? any idea?

t11s said...

Bilal, you could always use an Arduino or other microcontroller to convert a serial command to timed digital output.

Alternatively, you might be able to use RTS/CTS and DTR/DSR and direct digital outputs from an RS-232 port, but they may need to be level shifted to not blow out the ESC.

Here is an example:

http://www.the-control-freak.com/COMDIO/COMDIO.htm