Flex sensor
A flex sensor is a type of sensor that can detect the bending of a material. It is usually made of a flexible material like plastic and can be bent to a certain degree. When the flex sensor is bent, its resistance changes which can be measured by the Arduino board.
The flex sensor finds its application in various fields like robotics, medical devices, gaming, and musical instruments. In robotics, it can be used to control the movements of a robotic arm or hand. In medical devices, it can be used to monitor the movements of the human body or limbs. In gaming, it can be used as a controller to control movements of characters in the game. In musical instruments, it can be used to control the sound of the instrument.
Arduino code to glow the LED in proportion to the bending of the flex sensor:
Arduino Code
int FLEX_PIN = A0; // connect the flex sensor to analog pin A0
int LED_PIN = 11; // connect the LED to digital pin 11
int flexValue = 0; // variable to store the value of the flex sensor
void setup() {
pinMode(LED_PIN, OUTPUT); // set the LED pin as an output
Serial.begin(9600); // initialize the serial communication
}
void loop() {
flexValue = analogRead(FLEX_PIN); // read the value from the flex sensor
Serial.print(“Flex Value: “); // print the value to the serial monitor
Serial.println(flexValue);
flexValue = map(flexValue, 0, 1023, 0, 255); // map the value to a range of 0-255
analogWrite(LED_PIN, flexValue); // set the brightness of the LED based on the mapped value
delay(100); // wait for 100 milliseconds
}
In the code, the flex sensor is connected to analog pin A0 and the LED is connected to digital pin 11. The analogRead() function is used to read the value of the flex sensor which is then mapped to a range of 0-255 using the map() function. The analogWrite() function is used to set the brightness of the LED based on the mapped value. The delay() function is used to wait for 100 milliseconds before repeating the process. The serial communication is used to print the value of the flex sensor on the serial monitor.