Measure curvature with flexible sensor
In life, it is important to be flexible. But what do you do if you want to measure the curvature of an object? You use a flexible sensor. Such a sensor uses coal on a plastic strip to behave like a variable resistance or potentiometer (see exercise 8), but instead of changing the resistance by rotating the handle, you change it with a bend (curvature). The stress divider is used as in Exercise 8 and Exercise 9 to detect this change in resistance. the sensor bends in one direction and the more it bends, the higher the resistance - has an interval of about 10 kOhm at 35K Ohm. This scheme uses the curvature of a flexible sensor to control the position of the servo motor.
(NdT: If you don't have a flexible sensor in your kit, you can order one from Sparkfun or any other supplier. Look for a "flex sensor," it costs between €5 and €8.)
- Flexible sensor .
- Mini servo.
- Rider of three pins.
- 10 kOhm resistance (brown-black-orange).
- Connecting wire.
CIRCUIT DIAGRAM
CIRCUIT INSTALLATION
CODE
You can find this code in CIRC-13-code-flexsensor.js
var five = require("johnny-five");
five.Board().on("ready", function(){
var flexSensor = new five.Sensor("A0");
var myServo = new five.Servo(9);
flexSensor.on("read", function(err, value){
var servoAngle = five.Fn.map(value, 50, 300, 0, 179);
myServo.move(servoAngle);
});
});
EMERGENCY REPAIR
Servo doesn't move
?Even with colored wires, it's scandalously easy to insert a servo upside down. So it can be.
Servo doesn't move the way it should
The sensor is designed to work in only one direction. Try folding it the other way (with the stripe code facing the convex curve).
Servo motor moves only once
You may need to change the range of values when you call the map function.
CODE EXTENSION
Interval calibration
While your servo is moving now, chances are its spacing won't be perfect. To adjust the interval, you need to change the values of the map function:
five.Fn.map(value, fromLow, fromHigh, toLow, toHigh)
To calibrate our sensor, we can use the console to show values when the sensor is folded, and then take note of the interval of these values. Replace fromLow (default 50) with the value displayed when the sensor is not folded. Then replace the fromHigh value (300 by default) with the value when it is fully added.
Applications
With sensors, they really enjoy using it elegantly and unexpectedly, here are a few of our favorite applications:
Player's glove stone-paper-scissors
The glove that makes you play this game with yourself.
Electronic Plant Support
Check if the plant is turned to light and correct it. (Broken link, NdT).