Digital – Analog – Mechanical
Final Prototype
By using the free RedBearLabs BLE controller app for iOS [9] (or Android [10]), I was able pair the BLE Mini with my Apple iPhone and send serial commands via the Chat application. My code in Listing 3 takes a series of integers representing the motor and degrees of turn and parses out the associated data, dividing it back into steps and sending the step data to the appropriate stepper motor driver.
Listing 3
Incorporating the BLE Mini
01 #include <Stepper.h> 02 #include <Arduino.h> 03 #include <AltSoftSerial.h> 04 05 #if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__) 06 AltSoftSerial BLEMini; 07 #else 08 #define BLEMini Serial1 09 #endif 10 11 int StepPins[] = {4,5,6,7,10,11,12,13,14,15,16,17}; 12 int pinCount = 12; 13 14 Stepper motorA(512, StepPins[8], StepPins[9], StepPins[10], StepPins[11]); 15 Stepper motorB(512, StepPins[4], StepPins[5], StepPins[6], StepPins[7]); 16 Stepper motorC(512, StepPins[0], StepPins[1], StepPins[2], StepPins[3]); 17 18 void setup() 19 { 20 for(int thisPin-0; thisPin < pinCount; thisPin++) { 21 pinMode(stepPins[thisPin], OUTPUT); 22 } 23 while (!Serial); 24 25 Serial.begin(9600); 26 27 CLEMini.begin(57600); 28 motorA.setSpeed(10); 29 motorB.setSpeed(10); 30 motorC.setSpeed(10); 31 } 32 33 void loop() 34 { 35 if (BLEMini.available());{ 36 delay(5); 37 int tMotor = BLEMini.parseInt(); 38 int rot = BLEMini.parseInt(); 39 int steps = rot / 0.72; 40 String test = "Steps: "; 41 test += steps; 42 switch(tMotor){s 43 case 1: motorA.step(steps); BLEMini.print(test);break; 44 case 2: motorB.step(steps); BLEMini.print(test);break; 45 case 3: motorC.step(steps); BLEMini.print(test);break;} 46 } 47 }
The Simple Chat interface from RedBearLabs takes my series of integers, parses it, and translates the data into steps for the stepper motor driver (Figure 9); however, I'm in the process of building a standalone iPad app that will leverage the RedBearLab BLE Mini library and allow me to manipulate the environmental controls in a more intuitive manner.
Conclusion
In this proof of concept, I have shown how to create signals in an iOS app that are communicated through Bluetooth as serial data to an Arduino Mega, which signals a motor driver that, in turn, runs stepper motors.
The next step is to create the iPad app, then 3D print a case to house the unit and connect the stepper motor arms to the manual turn dials for the fan, louver position, and temperature control.
Infos
- Stepper motor: http://www.adafruit.com/product/858
- RedBearLab BLE Mini: http://redbearlab.com/blemini/
- L293D: http://www.ti.com/product/l293D
- Arduino Mega: http://arduino.cc/en/Main/arduinoBoardMega
- Installing the Arduino IDE: http://arduino.cc/en/Guide/HomePage
- BLE Mini firmware: https://github.com/RedBearLab/Biscuit/tree/master/release
- Additional Arduino libraries: http://arduino.cc/en/Guide/Libraries
- BLE Mini library: http://redbearlab.com/rbl_library
- BLE controller app for iOS: http://redbearlab.com/app/ios
- BLE controller app for Android: http://redbearlab.com/blecontroller.apk
« Previous 1 2 3 4 Next »
Buy this article as PDF
Pages: 7
(incl. VAT)