
Using a Flex Sensor — SIK Circuit 9
Use a flex sensor to control a servo motor. Bend the sensor to move the servo — combining analog input with motor control for gesture-based interaction.
Instructions
Parts & Introduction
Parts & Introduction
A flex sensor changes resistance when bent. Combined with the servo from Circuit 8, you can create gesture-based controls — bend the sensor to move the servo. This combines analogRead() with the Servo library.
Parts Needed
- 1x Arduino Uno + USB cable
- 1x Breadboard
- 1x Flex Sensor
- 1x Servo Motor
- 1x 10KΩ Resistor
- 11x Jumper Wires
Material untuk langkah ini:
SparkFun Inventors Kit - V3.21 kit
Arduino Uno R31 buah
Breadboard1 buah
Flex Sensor1 buah
Servo Motor1 buah
10K Ohm Resistor1 buah
Jumper Wires7 buahTools needed:
Hardware Hookup
Hardware Hookup
Wiring Instructions
Flex Sensor
- Connect one pin of the flex sensor to 5V.
- Connect the other pin to Analog Pin A0.
- Connect a 10K resistor from Analog Pin A0 to GND (voltage divider).
Servo
- Connect Red wire to 5V.
- Connect Black wire to GND.
- Connect White wire to Digital Pin 9.
Material untuk langkah ini:
Flex Sensor1 buah
Servo Motor1 buah
10K Ohm Resistor1 buah
Breadboard1 buah
Jumper Wires7 buahArduino Code
Arduino Code
Open the Arduino IDE and upload the following sketch to your Arduino board.
/*
SparkFun Inventor's Kit
Example sketch 09 — FLEX SENSOR
Use the flex sensor to change the position of a servo.
Hardware connections:
Flex sensor: one pin to analog pin 0 (with 10K to GND), other pin to 5V
Servo: RED to 5V, WHITE to pin 9, BLACK to GND
This code is completely free for any use.
*/
#include <Servo.h>
Servo servo1;
const int flexpin = 0;
void setup()
{
Serial.begin(9600);
servo1.attach(9);
}
void loop()
{
int flexposition;
int servoposition;
flexposition = analogRead(flexpin);
servoposition = map(flexposition, 600, 900, 0, 180);
servoposition = constrain(servoposition, 0, 180);
servo1.write(servoposition);
Serial.print("sensor: ");
Serial.print(flexposition);
Serial.print(" servo: ");
Serial.println(servoposition);
delay(20);
}Material untuk langkah ini:
Arduino Uno R31 buahTools needed:
Test & Experiment
Test & Experiment
What You Should See
The servo moves in response to bending the flex sensor. Open the Serial Monitor to see both the raw sensor value and the mapped servo position.
Troubleshooting
- Servo not moving: Check servo wiring — easy to plug in backwards.
- Sensor only works one way: The flex sensor bends in one direction. The striped side should face outward on a convex curve.
- Limited range: Adjust the
map()range values (600, 900) to match your sensor's actual readings from the Serial Monitor.
Experiments to Try
- Build a "robot finger" that mimics your finger bending.
- Replace the servo with an LED and control brightness by bending.
Materials
7- $105.00
- 1 buahPlaceholder
- 1 buahPlaceholder
- 1 buahPlaceholder
- 1 buahPlaceholder
- $3.00
CC0 Public Domain
Cetak biru ini dirilis di bawah CC0. Anda bebas untuk menyalin, memodifikasi, mendistribusikan, dan menggunakan karya ini untuk tujuan apa pun, termasuk komersial, tanpa meminta izin.
Dukung Maker dengan membeli produk melalui Cetak Biru mereka di mana mereka mendapatkan Maker Commission yang ditetapkan oleh Penjual, atau buat iterasi baru dari Cetak Biru ini dan masukkan sebagai koneksi di milik Anda sendiri.