Controlling a ducted fan

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Controlling a ducted fan

Postby ewokkillah » Wed Feb 06, 2013 3:31 pm

Hi There,
I'm trying to control a ducted fan with a brushless motor. What I want to have it do is when i press a button have it go full speed. I tryed modifying an existing sketch that sweeps the speed of the motor up and down, but I cant seem to get it to work. so any help or advice would be greatly appreciated.
Thanks
This is a copy of the sketch I'm working from:

[code#] 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);
} [/code]
ewokkillah
 
Posts: 9
Joined: Fri Nov 16, 2012 1:32 am

Re: Controlling a ducted fan

Postby adafruit_support_bill » Wed Feb 06, 2013 6:17 pm

Does the sweep sketch work? I don't see any button code. What have you tried that didn't work.
User avatar
adafruit_support_bill
 
Posts: 16640
Joined: Sat Feb 07, 2009 9:11 am

Re: Controlling a ducted fan

Postby ewokkillah » Wed Feb 06, 2013 7:31 pm

thanks for your reply. That's the original sketch it works to sweep the motor speed up and down.
this is my modification
Code: Select all
#include <Servo.h>

Servo myservo;

int switchPin = 8;

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);
pinMode(switchPin, INPUT);
arm();
}

void loop()
{
int speed;

Serial.println("GO");
if (digitalRead(switchPin) == HIGH);
{
  setSpeed(90);
  Serial.println(speed);
  delay(4000);
}

Serial.println("STOP");
if (digitalRead(switchPin) == LOW);
{
    setSpeed(0);
  Serial.println(speed);
  delay(100);
}
Serial.println("30 halting...");
setSpeed(30);
delay(5000);
}

It turns the motor on full speed then off, but no button functionality.
thanks.
ewokkillah
 
Posts: 9
Joined: Fri Nov 16, 2012 1:32 am

Re: Controlling a ducted fan

Postby adafruit_support_bill » Wed Feb 06, 2013 9:22 pm

What do you see in the serial monitor? Post the output.
User avatar
adafruit_support_bill
 
Posts: 16640
Joined: Sat Feb 07, 2009 9:11 am

Re: Controlling a ducted fan

Postby ewokkillah » Thu Feb 07, 2013 5:06 pm

arming
armed
GO
0
STOP
0
30 halting...
GO
0
STOP
0
30 halting...
GO
0
STOP
0
30 halting...
GO
0
STOP
0
30 halting...
GO
0
STOP
0
30 halting...
GO
0
STOP
0
30 halting...
ewokkillah
 
Posts: 9
Joined: Fri Nov 16, 2012 1:32 am

Re: Controlling a ducted fan

Postby adafruit_support_bill » Thu Feb 07, 2013 6:43 pm

How do you have your switch wired? Are you using a pullup or pulldown resistor?
User avatar
adafruit_support_bill
 
Posts: 16640
Joined: Sat Feb 07, 2009 9:11 am

Re: Controlling a ducted fan

Postby ewokkillah » Thu Feb 07, 2013 10:28 pm

Yes a 10k pull down resistor on the ground
ewokkillah
 
Posts: 9
Joined: Fri Nov 16, 2012 1:32 am

Re: Controlling a ducted fan

Postby adafruit_support_bill » Fri Feb 08, 2013 6:09 am

Code: Select all
    if (digitalRead(switchPin) == HIGH);


Get rid of the semicolons at the end of your 'if' statements. Those are statement 'terminators' so the code after the 'if' is not conditional.

http://arduino.cc/en/Reference/If
User avatar
adafruit_support_bill
 
Posts: 16640
Joined: Sat Feb 07, 2009 9:11 am

Re: Controlling a ducted fan

Postby ewokkillah » Sat Feb 09, 2013 3:16 am

That did the trick :D
Thanks.
ewokkillah
 
Posts: 9
Joined: Fri Nov 16, 2012 1:32 am

Re: Controlling a ducted fan

Postby ewokkillah » Sun Feb 10, 2013 12:01 am

i think I jumped the gun a little. There still seems to be a bug somewhere it doesn't work consistently. Sometimes I press the button the fan turns on, and sometimes no.
any Ideas?
Thanks
ewokkillah
 
Posts: 9
Joined: Fri Nov 16, 2012 1:32 am

Re: Controlling a ducted fan

Postby adafruit_support_bill » Sun Feb 10, 2013 7:13 am

You have a lot of delays in your code. If you press the button during a delay, it won't be seen.
User avatar
adafruit_support_bill
 
Posts: 16640
Joined: Sat Feb 07, 2009 9:11 am


Return to Arduino

Who is online

Users browsing this forum: No registered users and 11 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [114]

Raspberry Pi[82]
 
FLORA[24]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[12]
Arduino[60]
 
NETduino[14]
 
BeagleBone[23]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[39]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[9]


 
Breakout Boards[35]
LCDs & Displays[49]
Components & Parts[70]
Batteries & Power[54]
EL Wire/Tape/Panel[52]
LEDs[112]
 
Wireless[16]
Cables[66]
 
Lasers[6]
Sensors/Parts[147]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[41]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[25]


 
Stickers[41]
 
Skill badges[55]
 
Books[26]
 
Circuit Playground[7]
 
Gift Certificates[4]