To Servo with Love

This lab demonstrates how to manipulate a servo motor using sensor input. As force is added to the FSR, it causes the servo motor to rotate. The more force is applied, the more the motor rotates along its 180 degree path.


Here is the Arduino code:

[code lang="c"]#include 

Servo servoMotor;
int servoPin = 2;

void setup()
{
  Serial.begin(9600);
  servoMotor.attach(servoPin);
}

void loop()
{
  int analogVal = analogRead(A0);
  Serial.write(analogVal);
  
  int servoAngle = map(analogVal, 0, 1023, 0, 179);
  servoMotor.write(servoAngle);
}[/code]