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>
05 #if defined (__AVR_ATmega168__) || defined (__AVR_ATmega328P__)
06    AltSoftSerial BLEMini;
07 #else
08    #define BLEMini Serial1
09 #endif
11 int StepPins[] = {4,5,6,7,10,11,12,13,14,15,16,17};
12 int pinCount = 12;
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]);
18  void setup()
19 {
20    for(int thisPin-0; thisPin < pinCount; thisPin++) {
21      pinMode(stepPins[thisPin], OUTPUT);
22    }
23    while (!Serial);
25    Serial.begin(9600);
27    CLEMini.begin(57600);
28    motorA.setSpeed(10);
29    motorB.setSpeed(10);
30    motorC.setSpeed(10);
31 }
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.

Figure 9: Sending commands via the Simple Chat app on an iPhone.


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.

The Author

Paul is a Canadian-based Automation/Controls guy. Outside of the home lab, he works as a Security Solutions Engineer for Lockheed Martin. In 2010, Paul was recognized as a young leader in engineering by Control Engineering magazine.

Buy this article as PDF

Express-Checkout as PDF

Pages: 7

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content