PLEASE NOTE: This site is no longer being actively maintained. For frequently updated BeagleBone resources please visit

Wednesday, October 8, 2014

On 9:39 AM by Richard St-Pierre

RSTP - Ping Pong Ball grip controlled


This "gripping" project is a ball!  This project guide will inspire you with an unusual hands-on approach to controlling a fan motor. Squeeze hard and the ping-pong ball shoots up the tube. Release your grip and the ball falls. LEDs on the prototyping cape, provide feedback on your grip 'strength'.

A special, easy-to-build  "Grip-to-Voltage" converter circuit allows the BeagleBone to measure how hard you squeeze the handle bars. The BeagleBone measures the 'grip-voltage' and converts the signal to a PWM (Pulse-Width-Modulation) signal to control the speed of a cooling fan. Can you control the ball so it hovers in the middle of the tube?

Get friends involved, as you can include a partner to help you control the ball (holding hands in a circle).

What You Will Need

  • BeagleBone Black
  • BeagleBone expandable case Orange or Black (recommended)
  • AC adapter 5 Volts, 2 Amp (recommended)
  • A BeagleBone Protocape 
  • A "grip-to-voltage" converter and PWM driver (see circuit section)
  • Angstrom or Debian Linux
  • A high output (45 CFM) 24VDC Fan (ex: ComAir Rotron model:FN24B3)
  • 24-30V DC power supply
  • A Ping-Pong ball (40mm)
  • Clear T12 protective tube (48 inches, 1.2m)
  • Metal grips (Aluminum wind chime tubes work well)
  • Some 'hook-up' wire, solder, nuts & bolts
  • Base material (wood or plastic)
  • Plastic (apple) juice jar (or similar)
Materials are provided as a guideline (this is not an exact "kit").
Be inspired and creative with the materials you may find around your home.

Grip Controlled Ping-Pong using PWM - overall

STEP 1 - The Construction

First find a clear plastic container with an opening that will fit with the clear tube/guard.
A square container base is preferred, as it will allow the fan to seal better with the container.
(unless you use a round fan!)
PingPong Ball demo - RSTP

Cut a round opening at the bottom of the container to match the fan's active air flow area.
Punch four mounting holes for the screws that will secure the fan to the container. Grip controlled Ping Pong ball

The fan will need to be mounted on 'legs'. It is important that the air intake for the fan be sufficient to allow maximum output air flow. The fan should be mounted, in such a way as to allow lots of air in. Empty pen tubes were used for the prototype, as leg extensions.

Grip demo assembly - Logic Supply inspire tutorial

The grip handle assembly. An insulated (wood) base is used to mount the grip bars.

Grip Handle assembly details

A bolt is fed through the base with the nut facing up.  The grip tube is slid on to the nut -- fitting snugly. Wires are wrapped around the head of the bolt, making electrical contact with the bolt and the contact rods.

STEP 2 - The Electronic Circuit

There are two parts to the circuit. A fan PWM driver and a "grip-to-voltage" converter.
A BeagleBone prototyping cape is a great way to assemble this circuit.

Circuit Components

  • 1 Transistor (Q1) NPN (2N3904) or equivalent
  • 1 Transistor (Q4) N-Channel Mosfet (VN0104) or equivalent
  • 3 LEDs 5mm (D1-D3) (red, yellow, green) or a tri-color LED (common cathode)
  • 3 Resistors (R10-R12) 330 ohms 1/4 watt (Orange Orange Brown Gold)
  • 1 Resistor (R4) 100K ohms 1/4 watt (Brown Black Yellow Gold)
  • 1 Resistor (R1) 1000 ohms 1/4 watt (Brown Black Red Gold)
  • 1 Resistor (R3) 4700 ohms 1/4 watt (Yellow Purple Red Gold)
  • 1 Resistor (R2) 6800 ohms 1/4 watt (Blue Gray Red Gold)
  • 1 Capacitor (C1) (0.1uF)100nF (optional)
  • 1 Capacitor (C2) 4.7uF or 10uF Electrolytic
  • Metal tubes, wires, solder, nuts and bolts (for the grip handles)
  • 24-30VDC power supply (200mA)

The 'grip-to-voltage' circuit measures skin resistance. The greater the skin area in contact with the grip handles, the lower the effective resistance. A firmer grip and more skin moisture also lower the resistance reading. A lower resistance value (gripping harder) will increase the speed of the fan.

The analog input of the BeagleBone is 1.8V max. We must make sure not to exceed this voltage.
Since we are using 5V for the grip-to-voltage converter, a voltage divider is used to guarantee that the output will not exceed 1.8V (say-- if the grip bar were accidentally shorted together). AIN5 is the input ADC channel used. P9-42 is used for the PWM pin. Probe1 and Probe 2 are the grip handles.

The circuit can be build using the workshop cape as an example.

STEP 3 - The Software

// Logic Supply Tinkerer Workshop
// Author  : Richard St-Pierre
// Version : 0.0 Aug 25, 2014 Initial concept
//           0.1 Aug 29, Input & LEDS working
// --------------------------------------------
// This is a demo program that controls the  
// speed of a fan that moves a ping-pong ball 
// in a clear tube.  The speed of the fan is
// controlled using PWM (Pulse Width Modulation).  
// The input is a pair of grip bars (handles).  
// The user squeezes the bars to control the speed.  
// A circuit measures the strength of the grip and
// converted it to an analog voltage for the ADC.
// The tighter the grip the faster the fan spins.
// Three LED provide feedback (Low, Med, High, Turbo).
// --------------------------------------------
var b = require('bonescript');

// Declare pin assignment
var LED_red = "P9_14"; 
var LED_yel = "P9_16";
var LED_grn = "P8_19";
//var pb_sw   = "P8_26";
var adc_in  = "P9_36";      // AIN5
var pwm_pin = "P9_42";    

var grip_value = 0;
var LED_value  =0;
var fan_speed = 0;

// Set pinMode
b.pinMode(LED_red, b.OUTPUT);
b.pinMode(LED_yel, b.OUTPUT);
b.pinMode(LED_grn, b.OUTPUT);
b.pinMode(pwm_pin, b.OUTPUT);

function gripRange(x)
 LED_value =0;    
 if (x > 0.1/1.8) { LED_value = 1; }
 if (x > 0.2/1.8) { LED_value = 2; }
 if (x > 0.3/1.8) { LED_value = 3; }
 if (x > 0.4/1.8) { LED_value = 4; }    
 return LED_value;


Set_LED(0);                 // Turn OFF all LEDs
console.log("BeagleBone Gripping Demo");

setInterval( handler , 500 );

function handler()
grip_value = b.analogRead(adc_in);
LED_value = gripRange(grip_value); 
console.log('grip: '+ Math.round(grip_value*100)/100 + ' LED: ' + LED_value);
if (grip_value < 0.1/1.8) fan_speed =0;
else fan_speed = 0.3 + 3.0*grip_value;

if (fan_speed > 1.0) fan_speed = 1.0;
b.analogWrite(pwm_pin, fan_speed);

function Set_LED(){
         case 0:
            b.digitalWrite(LED_red, b.LOW);
            b.digitalWrite(LED_yel, b.LOW);
            b.digitalWrite(LED_grn, b.LOW);
        case 1:
            b.digitalWrite(LED_red, b.LOW);
            b.digitalWrite(LED_yel, b.LOW);
            b.digitalWrite(LED_grn, b.HIGH);
        case 2:
            b.digitalWrite(LED_red, b.LOW);
            b.digitalWrite(LED_yel, b.HIGH);
            b.digitalWrite(LED_grn, b.LOW);
        case 3:
            b.digitalWrite(LED_red, b.HIGH);
            b.digitalWrite(LED_yel, b.LOW);
            b.digitalWrite(LED_grn, b.LOW);
        default:                            // all LEDs ON (upper Grip limit)
            b.digitalWrite(LED_red, b.HIGH);
            b.digitalWrite(LED_yel, b.HIGH);
            b.digitalWrite(LED_grn, b.HIGH);

STEP 4 - Operation

Three LEDs help by providing feedback on the grip input.
  • Green LED   = Grip is detected - Squeeze harder
  • Yellow LED = Medium grip - Controlling ball
  • Red LED      = Strong Grip- Ball rising
  • ALL LEDs   = Turbo (Maximum) Power - Ball takes off (from rest)

Program Overview

First we request the use of the bonescript library, and declare the LED, control pins and program variables. We must set the pin-mode for the BeagleBone GPIO signals. Next we have a simple function that converts the grip reading to ranges for the LEDs. Let's turn OFF all the LEDs and send a quick message to the console to let the user know that the right program has started and is ready.

Every 500ms (half second) we read the analog input. (you can change the interval rate if you like). The main loop reads the analog voltage (grip) and converts it to a range and sets the LEDs accordingly. The readings are also displayed to the console. This can be useful during debug and setup. We can now set the PWM (Pulse Width Modulation) to control the fan speed. We have three ranges.
  1. No grip detected, turn OFF the fan
  2. Grip detected, turn ON the fan and scale the reading
  3. Heavy grip, set speed to maximum.
The Set_LED() function takes the input range we calculated and controls the digital output pins to light the LEDs as described above. This provides useful feedback that the grip is detected and working. All LEDs must be ON for the ball to initially 'take-off'. If you hands are quite dry you may need to increase the contact area with handle bars (or blow into your hands to add moisture).

Get some help, as you can include a partner to help you control the ball (holding hands in a circle).
With one hand, hold-hand with your partner--with the remaining free-hand each person holds one of the grips. Squeeze harder, the hand of your partner and the ball will go up. Is your partner helping or messing with you? Are two people better than one at controlling the ball?

Hint: It takes more force to move the ball up (fighting gravity), and much less with gravity helping the ball back down. Move the ball to the top and let it come down slowly.

STEP 5 - Going Further

Can you improve the design with a distance sensor?
Can you create a control loop to set and maintain the ball at a fixed height?
The BealgeBone Black is a great way to experiment and learn about practical control, software and algorithms.

Let us know what you create!