Step 6: 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).


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

void loop()
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
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;
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); // waits for the servo to get there
valOld = val;

//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(){
String arduinoPort = Serial.list()[1];
port =new Serial(this, arduinoPort, 9600);

void draw(){
if (port.available() > 0) {
val = port.read();
//val = mouseX;
x = map(val,80,255,0.01,0.6); //translate values input to useful values/println(x);
background(100); //clear last image
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;
Great example.
waka waka waka waka waka waka waka waka waka waka
so cute~
Love it.
GREAT instructable..<br>Really enjoyed it!<br><br>Just trying to think of what else could be done with it!
That is one of the coolest things I have seen. I really need to learn how to program.

About This Instructable




Bio: Married to Domestic_Engineer (but I call her Meghan).
More by marc.cryan:How to by a cell phone for an 11 year old girl Cheapest, Bestest computer around, in beginning of 2015 Cryan Family Gothic Green House 
Add instructable to: