Low-cost motor control by displaying coloured shapes on a phone or PC screen

Smart phones pack a lot of features (battery, display, sensors, audio i/o, wireless internet connectivity, computing power, etc) into a tiny, convenient, inexpensive package. A smart phone therefore makes a great robot brain and I’ve become fascinated by the idea of creating an ultra low-cost robot that’s really just a vehicle for an Android phone running an app that analyses the robot’s environment and controls its behaviour.

Obviously, the phone could dispatch orders to actuators via an RF link (e.g. bluetooth) or a cable to control the robot’s movement. However, the idea I’m investigating here is to use ordinary LEDs as photodetectors to repond to colour changes on different regions of the phone screen. Using this technique, the phone app couldn control actuators just by displaying coloured shapes on the screen.

The following video demonstrates the principle, using alternating black and white squares on a screen to switch a motor on and off:

It works fine with the phone screen too, but since I was using my phone to do the filming you’ll have to take my word for it!

My aim is to build the whole robot using easy to find components for a cost of €10 or less. I don’t have a complete robot yet, but the cost is currently within budget. What I have implemented so far (as shown in the video above) is:

  • A pair of reverse-biased green LEDs act as photodetectors, providing a single binary signaling channel between the screen of the controlling device (laptop / phone) and an MSP430 microcontroller.
  • The MSP430 microcontroller controls a single geared DC motor. It uses one digital input to detect the control signal from the phone / laptop and one digital output to control the motor via an NPN transistor.

The code running on the MSP430 is dead simple – it basically just relays the binary control signal from a digital input (P1.1) to a digital output (P2.4):

// LED photodetector motor control example
// Written by Ted Burke - last updated 28-2-2014
// Code is for MSP430G2452 or MSP430G2553
#include <msp430.h>
int main( void )
    // Stop watchdog timer to prevent time out reset
    // Set P2.4 as an output, other pins as inputs
    P2DIR = 0b00010000;
    P1DIR = 0b00000000;
        if (P1IN & BIT1) P2OUT = 0b00010000;
        else P2OUT = 0b00000000;
    return 0;

Here are some photos of my breadboard circuit (plus 4xAA battery pack and geared DC motor):

The circuit relies on a little-known property of ordinary LEDs: When reverse-biased, they act as (slightly inefficient) photodiodes and can therefore be used not only for display purposes, but also as photodetectors. I had completely forgotten about this phenomenon until I saw Frank Duignan using it for something ingenious a few months ago. What I like about this approach is that most electronics enthusiasts have at least a couple of LEDs lying around, so it makes photo sensing very accessible without needing to order components specially.


Click here to download editable SVG version of circuit diagram

In this case, I placed the two LEDs in series (both reverse-biased) between the supply rails, forming a voltage divider. The output of the voltage divider is connected to a high impedance digital input of the MSP430. The idea is to point each LED at a different region of the controlling device’s screen and turn one region white and the other black, causing the output of the voltage divider to be either high or low. Binary signaling is achieved by swapping the black and white regions back and forth.

  • When LED1 sees black and LED2 sees white, P1.1 is low.
  • When LED1 sees white and LED2 sees black, P1.1 is high.

I created the following animated GIF to test my circuit:


This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s