Home TI-Nspire Scripting HQ TI-Nspire STEM HQ Getting Started with TI LaunchPads TI LaunchPad Lesson 9


Lesson 9 - Build your own BLE Robot for under $USD40

Energia Reference page

Texas Instruments TI-Nspire Scripting Support Page

Download the supporting documents for this lesson.


STEM on a Budget (2)

How would you like to build upon the last lesson: if we can build a functional BLE motion detector, why not add a couple of servo motors and some LEGO and build a remote-controlled robot?

Of course, you COULD go and spend hundreds of dollars and buy one of the shiny, cool pre-made ones, but that would not be nearly as much fun as designing, coding and building your own.

The model shown below is fully kitted out - it has on-board speaker and ultrasonic distance module, as well as the essentials: LaunchPad board, power source, BLE module and two small servo motors.

To build the case and wheels, I used pieces of LEGO that my children had built with many years ago - and that the grand-children are now having great fun with! Fortunately, we had plenty to spare, so the grand-babies will not miss out.

If you don't have LEGO, then look for small boxes, or other creative design solutions. Note that the servos come with small discs and other attachments to which bottle caps can be glued or screwed to make functional wheels!

The single most useful resource that I have discovered are small inexpensive velcro picture hangers, available from the local supermarket: the glued side, once set, is very strong, and you can easily then attach and detach the various components to your casing (including my LEGO wheels!).

I also recently discovered a wonderful Australian resource in Robot Gear, where I was able to purchase some great wheels designed for the FS90R servo - and for just $AUD6.95, these make another nice-to-have for our project!



Texas Instruments MSP432 LaunchPad ($USD12.99)

Two servo motors - I used Feetech FS90R micro continuous rotation servo from eBay and paid around $AUD6 each (total around $USD10) - NOTE: NOT the identical-looking Feetech FS90 which will NOT work for our purposes!

Generic HM-10 BLE module (under $USD5)


You will also need a light-weight power source.


I found a great 2500 mAh power bank on eBay for $AUD15! (around $USD10)

The form factor is ideal for our robot -it actually sits neatly beneath the LaunchPad board.


Nice add-ons

Generic HC-SR04 ultrasonic motion sensor (under $USD5)

I used a Grove speaker but any small speaker will be fine (and much less expensive: under $USD5)

Pololu wheel are designedspecifically for the FeeTech FS90R servo motor.


Refer to the previous lessons for connection instructions for the BLE module and the ultrasonic distance module. The speaker can be run from any spare pin, along with a ground (GND) and a voltage (VCC) pin.

The LaunchPad board comes with several voltage pins, both 3.3V and 5V. The only module here which really insisted on 5V was the HCSR04 ultrasonic. The servos expect 5V but will run (a little more slowly) on 3.3V.

WARNING: My first servo purchase from eBay delivered some lovely black heavy-duty motors that actually drew too much current for the board to handle when connected to 5V - I started to smell burning and quickly disconnected. After some cautious experimentation, I found that these actually did work just fine from 3.3V instead of 5V. My recommendation, though, is for the lighter less hungry FS90R servos shown above.

If using the blue Feetech FS90R servos, then feel free to connect to one of the 5V pins; if trying another servo, be careful - but my experience has been that 3.3V is probably a safer choice. The FS90R comes with three leads - brown, red and orange. Brown is ground (normally black), red (as usual) is voltage, and orange goes to the pin assigned to that servo in your sketch. There are numerous servo types available, and they can behave quite differently - some, for example, take inputs for speed, others for angle of turn. The simple form we use here are just responding to forward and reverse speed instructions.

Note, too, that the design I have used here allows me to connect jumpers both above and below the board. Above is easiest, but if you are running short of voltage and ground pins, then you may end up connecting some underneath.


LaunchPad Sketch: Simple Two Servo controls
(Copy and paste into Energia)

Have a look through the sketch. There are several features thast you should note.

First, you will see that we include two standard Arduino/LaunchPad libraries - wire and servo.

We define two servos, calling them servoLeft and servoRight. I have chosen to use pins 29 and 30 for these servos, but you are free to use others.

As usual, we define Serial and Serial1 (our BLE port), and use recvChar to control our robot - a single character sent from our Lua script to move forward, back, left or right.

NOTE that I have define four separate functions (leftForward, leftBack, etc) which are outside the loop and setup functions. This is something new, and allows us to moake our sketch much simpler and easier to follow.

You should also note the line in setup that can be used to rename your BLE module: so instead of BT05 or CC41-A, or HMSoft, for example, your robot can be identified by name! You will need to switch the power to the board off and on again, and give it a minute or so to reset itself, but this will make your life much easier if, like me, you have several BLE devices broadcasting.


#include <Wire.h>
#include <Servo.h>

Servo servoLeft; // create servo object to control a servo
Servo servoRight; // a maximum of eight servo objects can be created
int servoLeftPin = 29;
int servoRightPin = 30;
int pos = 0;

void setup() {

// delay(1000);
// Serial1.println("AT"); // just a check
// delay(2000);
// Serial1.println("AT+ROLE0"); // set up as Slave
// delay(2000); //wait a couple of seconds
// Serial1.println("AT+NAMEMyRobot"); // Uncomment these lines to rename your BLE module!

void loop() {

char recvChar;

recvChar = Serial1.read();
recvChar = Serial.read();


case 'f': //(f)orward

case 'b': //(b)ack

case 'l': //(l)eft

case 'r': //(r)ight

case 'n':



void leftForward() {
Serial.print("ServoLeft: ");

void rightForward() {
Serial.print("ServoRight: ");

void leftBack() {
Serial.print("ServoLeft: ");

void rightBack() {
Serial.print("ServoRight: ");


Interactive Script Exploration

This page has been enhanced using JavaScript so that we can focus easily upon the various elements of our script.

  • Click the 'init' button to see the initial variable definitions in the script window below for our robot.

    NOTE: the name of the BLE module you are using is entered in the variable 'nameList'. Feel free to change this as required.

    Included here is on.construction, with elements that are called just once. Note the use of 'pcall' (protected call - just in case you are on a platform that does not support this function). Note also that refreshMenu is called just once in a script.

  • To see on.resize and on.paint functions, click 'Layout'.

    NOTE: I have also added a small utility function to check the size of the font - this script will not work on the handheld (BLE requires the iPad app) but this is a handy thing to include in any script).

  • For menu, keyboard and mouse controls, click 'Menu'.
  • For BLE functions common to many scripts, click 'BLE General'.
  • For BLE functions specific to this script, click 'BLE Specific'. This section is much shorter than usual, since we are not looking for any feedback from the bLE connection - we are simply writing commands to it and letting the sketch do the hard work.
  • To see the entire script (and copy to paste into the TI-Nspire Script Editor), click 'Full Script'.

    platform.apilevel = '2.5'

    screen = platform.window
    w = screen:width()
    h = screen:height()
    local hh = platform:isDeviceModeRendering()
    local ipad = platform:isTabletModeRendering()

    pcall(function () require 'bleCentral' end)

    require "color"
    local myColor = color.lightgray
    local alert = ''
    local myChar = nil
    local startX,startY,width
    local bleState = ''
    local bleStatus = 'Tap here to scan'
    local peripheralList = {}
    local myUUID = 'FFE1'
    local nameList = {'myRobot'}

    function on.construction()

    w = screen:width() or 841
    h = screen:height() or 567

    pcall(function() ble.addStateListener(listenerCallback) end)






Congratulations! You now have a functional and cool BLE robot.

Based upon previous lessons, you might like to go ahead and add extra functionality to your robot - ultrasonic distance is a great way to monitor and control your device, and you have all that you need from the previous lessons to enhance your sketch to include this and other sensors, if desired.

The download for this page includes two sketches - the simple one shown above and an extensive one that includes a range of different applications. As well as the SimpleRobot.tns document, you will also find Robot_BLE.tns which adds the capability of linking to other BLE devices - control your robot using the accelerometer on your SensorTag, or your Vernier Go Wireless Link!! There is also the generic BLExplorer.tns document for taking it all to the next level.

The Robot_BLE.tns document - when used in conjunction with the LP_Robot.ino sketch - even offers the facility to make your robot self-driving!! It measures the distance to near objects and, when getting too close, will actually reverse and turn to avoid obstacles! Explore how this can be easily achieved in the Lua script.

If you run into problems, or you try new things, please feel free to drop me a line and I will happily do what I can to help you to get started.


Back to Top


Home TI-Nspire Scripting HQ TI-Nspire STEM HQ Getting Started with TI LaunchPads TI LaunchPad Lesson 9