Introduction: Servo Control With a Flex/Bend Sensor

Picture of Servo Control With a Flex/Bend Sensor

This Instructable is to demonstrate how to control a servo using a flex/bend sensor. Also a possible application for such a setup.

Materials

Arduino uno

http://www.adafruit.com/products/50 $24.95

Solid core wire

http://www.adafruit.com/products/1311 $15.95

Micro Servo

http://www.adafruit.com/products/169 $5.95

Wire stripper/cutter

http://www.amazon.com/TEKTON-3797-7-Inch-Stripper-... $12.56

Breadboard

http://www.adafruit.com/products/64 $5.00

Flex/Bend Sensor

http://www.adafruit.com/products/182 $12.95

10 ohm resistor

http://www.radioshack.com/product/index.jsp?produc... $1.49

Step 1: Using Your Breadboard, Arduino and a Few Wire Hookups Connect the Servo.

Picture of Using Your Breadboard, Arduino and a Few Wire Hookups Connect the Servo.

The colors on the servo wires may vary but not greatly and the direction of the connection is the same. The order is

Brown - Ground

Red - 5v section of the breadboard

Yellow - digital pin 8 on the arduino board

The suggested servo is a micro servo as they do not require a capacitor however if you decide to use a stronger servo ENSURE THAT A PROPER CAPACITOR IS USED TO REDUCE THE POWER PULLED THROUGH THE ARDUINO BOARD. If too much power is pulled through the board to the servo the board will overheat and fry.The Arduino board may try to warn you of this by refusing to communicate from the computer to the board, if this occurs IMMEDIATELY cut the power running to the board and determine if a capacitor is needed.The capacitor should be placed between the power and the servo as well as the ground and the servo.

Step 2: Using Your Breadboard and Arduino Connect the Flex Sensor to the Board.

Picture of Using Your Breadboard and Arduino Connect the Flex Sensor to the Board.

The thick banded side (commonly the right) should connect to both the resistor and Analogue pin 1. The wire connecting to Pin A1 should be between the resistor and flex sensor.The resistor should then have a wire connecting it to the 5v section on the breadboard.This creates a voltage divider allowing the flex sensor to be read. Think of the still resistor as a constant and the flex resistor as an independent value that can travel across the constant and be read by the Arduino board.

The thin narrow lined side (commonly the left) should connect to ground.

Step 3: With All of Your Wires in Place, Now for Code!

The following code is setup to read the flex sensor between rest state and a 90 degree bend and then rotate the servo blade accordingly.

//Servo control code by The TuqsCat
//https://www.instructables.com/member/The+TuqsCat/

#include Servo myservo; // create servo object to control a servo

int val; // variable to read the value from the analog pin

void setup() {

// initialize serial communications

Serial.begin(9600);

myservo.attach(8); // attaches the servo on pin 8 to the servo object }

void loop() {

int sensor, degrees;

// read the voltage from the voltage divider (sensor plus resistor)

sensor = analogRead(A1);

// the first two numbers are the sensor values for straight (540) and bent (790)

// the second two numbers are the degree readings we'll map that to (0 to 90 degrees)

degrees = map(sensor, 540, 790, 0, 90);

// note that the above numbers are ideal, your sensor's values will vary

// to improve the accuracy, run the program, note your sensor's analog values

// when it's straight and bent, and insert those values into the above function.

myservo.write(degrees);// sets the servo position according to the scaled value

delay(5); // waits for the servo to get there

//for debug use only

// print out the result

Serial.print("analog input: ");

Serial.print(sensor,DEC);

Serial.print(" degrees: ");

Serial.println(degrees,DEC);

delay(5);// pause before taking the next reading

}

Step 4: Usage in a Basic Puppet

The next three steps are a possibility for usage with this code and setup.

The particular puppet I used was made of clay however in the following steps I will show a more cost effective alternative.

The additional supplies are:

Fishing Line

http://www.amazon.com/South-Bend-Mono-900-Yds/dp/B...

$2.25

Mod Podge

http://www.amazon.com/Podge-CS11272-8-Ounce-Glue-S...

$4.06

Brushes (preferably disposable)

http://www.amazon.com/Prang-Hobby-Paint-Assorted-9...

$3.74

A long sewing needle

http://www.amazon.com/Singer-Assorted-Hand-Needles...

$2.49

Hot Glue Gun

http://www.amazon.com/Surebonder-DT-200KIT-Mini-Du...

$6.45

Scissors

http://www.amazon.com/Westcott-Scissors-Anti-micro...

$1.99

Paper

http://www.amazon.com/Tru-Ray-Sulphite-Constructio...

$1.79

Pencil

Step 5: Creating the Jaw

Picture of Creating the Jaw

The puppets head is a personal preference and based on material and choice.

Yamaha motors papercraft website has a wonderful assortment of free paper head and body templates to assemble and require minimal tailoring to fit the jaw into.

http://global.yamaha-motor.com/yamahastyle/entertainment/papercraft/animal-global/

Measure how large you would like the jaw to be and cut it out.

Step 6: Making the Jaw Sturdy

Coat the jaw in a light layer of Mod Podge using your brushes. Allow about 5 minutes to dry.

Step 7: Attaching the Jaw to the Servo

Picture of Attaching the Jaw to the Servo

Take the long needle and poke a hole through the upper area of the jaw, bridging the walls of the jaw

Using the fishing line, run a bit of fishing line through a hole on the servo blade and tie it, then run some of the line to the inner layer of the jaw (essentially where the tongue would be).The wire should go over the needle as it goes to the tongue of the jaw. The wires length should be tight and the length should reflect the jaw and servo at a rest state. Hot glue the fishing wire in the jaw to the flat area.

Comments

MuhannedS (author)2015-02-08

bro the code have some errors.. it doesn't work when i compile the code

MsSweetSatisfaction (author)2014-08-16

Wow this is awesome. Thanks for sharing, and I love the video at the end. Hope you share pictures of the full puppet!

About This Instructable

10,186views

24favorites

License:

More by The TuqsCat:Servo Control with a Flex/Bend Sensor
Add instructable to: