3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.

PUPPET CONTROLLER

Step 2Add a flex sensor

Add a flex sensor
The pot works well, but it is not much fun. 

So you can swap it out for different sensor.  I'm using a flex sensor from instructables.  The sensor changes resistance as it is bent.   It is from [##REF##].

The flex sensor is hooked up like this:
    
5V----------
                  |
Pin 0----- 100K ------ One end of flex sensor---------
                  |                                                                    |
                  |                                                                  Flex Sensor
                  |                                                                    |
Ground-------------------other end of flex sensor-----


The resistor value depends on the resistance of the sensor.  It should be in the same ballpark as the max resistance of the sensor.  You'll also have to tweak the code mapping the input values to the servo angle. 
Look for this line of code:
                         val = map(val, 40, 350, 90, 179); // scale it to use it with the serv

Here is a video:

Replace potentiometer with the flex sensor
-Adjust Analog input values so everything works right with the flex sensor.  It is okay to guess a little

-Here's the updated code

////////// Arduino Code ///////////////

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott
//MPC - added serial output 'n stuff
// With flex sensor
// -Tweak Val to Angle Map

/*
Here is the wiring:

Wiring -

Flex Sensor |------Arduino Gnd
Flex Sensor |------Analog 0
100K |------Analog 0
100K |------Arduino 5V


| Yellow ------ Digi 9 (PWM)
Top servo | Red -----------5V
| Brown -------Gnd

| Yellow ------ Digi 10 (PWM)
Bottom servo | Red -----------5V
| Brown ------


*/
#include

Servo myservo; // create servo object to control a servo
Servo otherServo ;

int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
int valComp;

void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
otherServo.attach(10);
Serial.begin(9600);
}

void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
Serial.println(val);
valComp = analogRead(potpin);
Serial.println(val);
val = map(val, 40, 350, 90, 179); // scale it to use it with the servo (value between 0 and 180)
valComp = map(valComp, 350, 40, 0, 90); //other servo does oposite
myservo.write(val); // sets the servo position according to the scaled value
delay(15);
otherServo.write(valComp);
delay(25); // waits for the servo to get there

}
 
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
42
Followers
18
Author:marc.cryan
Looking for access to land or water in Boston Metrowest area.