« the devil's chamber | Main | LED as light sensors »

servo lab

First order of business was to figure out what was the min and max of my servo. To find the min, I replaced the equation for pulse to be

analogValue = analogRead(analogPin);
pulse = 400 + analogValue;

analog-flex.JPG

and turned my pot until it was at a stable position. Did the same to find the max value, except I added 2000 instead. The min/max of my servo turned out to be 800/2400. I should find a sticker and note this on the servo.

Now the fun part - putting in a variable resistor other than a pot. I measured the resistance for my flex sensor with the analog in setup. It ranged from 120/450. Then I changed the pulse formula to be

pulse = (analogValue - 120) * 5 + minPulse;
if ( pulse < minPulse ) pulse = minPulse;
if ( pulse > maxPulse ) pulse = maxPulse;

the last two lines prevents the servo from trying to turn beyond its limit.

analog-pot.JPG