Instructables

PUPPET CONTROLLER

FeaturedContest Winner

Step 6: A working thing!

Picture of A working thing!
Now we can put it all back together to make something that works! 

A few tweaks were needed:
  1. Now that the flex sensor is tapped to the hinge, it is always a little flexed so the impedance is lower.  I changed the resistor to 10K.  
  2. The mapping from sensor input to servo angle needed to be adjusted a bit.  
  3. I also flipped around the pacman animation in processing and made it bigger for the photos.
After these adjustments the whole thing works pretty well.  It is a bit jittery, but that can be fixed.... (but I'm not going to).

Video:




This shows the back a little




Code with all the peices working nicely:

note: using 10K pullup resistor 

////////// Arduino Code ///////////////
//This is from an example inluded with Arduino IDE download.
// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott
//MPC - added serial output 'n stuff

/*
Here is the wiring:

Wiring -
|------Arduino Gnd
Encoder |------Analog 0
|------Arduino 5V

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

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


*/
#include ; //use servo library

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

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

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.print(val);
//Serial.print("---");
val = map(val, 0,1023, 0,255);
if(val > 175){ //wide open
val = 185;
}
if(val <80){ //closed
val = 80;
}
if((abs(val-valOld))>7){ //filter out the jitter
valComp = val;
//Serial.println(val);//DEBUG
Serial.print(val,BYTE);//USE
delay(10);
val = map(val, 80, 255, 90, 179); // scale it to use it with the servo (value between 0 and 180)
valComp = map(valComp, 255, 80, 0, 90);
myservo.write(val); // sets the servo position according to the scaled value
delay(10);
otherServo.write(valComp);
delay(10); // waits for the servo to get there
valOld = val;
}
}

/*
//PROCESSING CODE
//pacman moouth opens/close with X input from arduino output (flex sensor)

import processing.serial.*;
Serial port;
float x = 0;
float val = 0;
int frame = 1000;

float easing = 0.5;
float xOld;

void setup(){
size(frame,frame);
background(100);
smooth();
println(Serial.list());
String arduinoPort = Serial.list()[1];
port =new Serial(this, arduinoPort, 9600);
}

void draw(){
if (port.available() > 0) {
val = port.read();
print(val);
//val = mouseX;
print("-----");
x = map(val,80,255,0.01,0.6); //translate values input to useful values/println(x);
println(x);
}
background(100); //clear last image
rotate(PI);
translate(-frame,-frame);
float targetX = x;
x+=(targetX - x)*easing;
arc(frame/2,frame/2,frame/2,frame/2,(x)*PI,PI+(1-x)*PI); //draw packman, using radians... p21
//x= xOld;
}
*/
 
Remove these adsRemove these ads by Signing Up
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!