Introduction: Control an Arduino With Your IPhone

About: Creative Technologist.

Hey!

This Instructable shows you how to control an Arduino with an iPhone without having to program your own iOS application. We're going to flash an LED but you can do lots of other things with it too!

We will be using an Arduino compatible microcontroller called the LightBlue Bean. It connects to your phone over BLE and comes with an iPhone app that you can use to control it. You can order a LightBlue Bean here.

Step 1: Download Bean Loader App

First, make sure that you have the Arduino application installed on your computer. If not, install it!

The LightBlue Bean is programmed wirelessly using an OSX application called Bean Loader. Download it here and follow the installation instructions.

The first time you open the Bean Loader it will ask you to associate it with the Arduino app. When the notifier pops up click "Associate".

Step 2: Upload a Sketch

Copy and paste this code into an empty sketch in the Arduino app and hit "Upload":

/*
  XY Blink
 
  This sketch is intended to be used with the
  LightBlue Sandbox screen, particularly the
  X-Y trackpad screen.
  
  NOTE: This sketch is not a low-power sketch.

  This example code is in the public domain.
 */

void setup() 
{
  Serial.begin(57600);

  Serial.setTimeout(5);
}

#define XYPAD_X  8
#define XYPAD_Y  9

static uint8_t rate;
static uint8_t intensity;

void loop() {
  char buffer[64];
  size_t length = 64; 
      
  length = Serial.readBytes(buffer, length);    
  
  if ( length > 0 )
  {
    // There may be both X and Y values read in 
    // a single packet.  Handle this case.
    // Byte[0] : X/Y control #
    // Byte[1] : Value [0,255]
    for (int i = 0; i < length - 1; i += 2 )
    {
      if ( buffer[i] == XYPAD_X )
      {
        rate = buffer[i+1];
      }
      else if ( buffer[i] == XYPAD_Y )
      {
        intensity = buffer[i+1];
      }
    }
    // limit the rate
    if ( rate < 5 )
    {
      rate = 5;
    }
  }
  
    Bean.setLed( 0, intensity, 0 );
    delay( rate );
    Bean.setLed( 0, 0, 0 );
    delay( rate );
}

Open the Bean Loader application and connect you your Bean. Make sure to update the firmware if it tells you to.

Program the sketch and disconnect from the Bean when it's done!

Step 3: LightBlue IOS App

To control the LightBlue Bean, we will use the iPhone app LightBlue.

When you've downloaded the app, connect to your LightBlue Bean, click "Option" in the top right corner and choose "Sandbox view". Then go to the second view (labeled "B") and move around on the trackpad to change the intensity and rate of the LED!