Professional Documents
Culture Documents
FLEX SENSOR
Hardware connections:
Flex sensor:
The flex sensor has two pins, and since it's a resistor,
the pins are interchangable.
Servo:
Note that servos can use a lot of power, which can cause your
Arduino to reset or behave erratically. If you're using large
servos or many of them, it's best to provide them with their
own separate 5V supply. See this Arduino Forum thread for info:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239464763
#include <Servo.h>
Servo servo1;
void setup()
{
// Use the serial monitor window to help debug our sketch:
Serial.begin(9600);
servo1.attach(9);
}
void loop()
{
int flexposition; // Input value from the analog pin.
int servoposition; // Output value to the servo.
flexposition = analogRead(flexpin);
servo1.write(servoposition);
Serial.print("sensor: ");
Serial.print(flexposition);
Serial.print(" servo: ");
Serial.println(servoposition);
// Note that all of the above lines are "print" except for the
// last line which is "println". This puts everything on the
// same line, then sends a final carriage return to move to
// the next line.