Optical Flex Sensor




Introduction: Optical Flex Sensor

PROBLEM: I needed ten or so reliable flex sensors for a project. The cheapest flex sensors on eBay are $10-$20 or more - so a project with 10 sensors becomes expensive.

SOLUTION: DIY (of course!) optical flex sensor.

This optical flex sensor has an LED at one end of a clear plastic strip, and an LDR (light-dependent resistor) at the other. As the strip is bent, the less light reaches the LDR through the plastic strip.

Provided you have access to a 3D printer, these work out at less than 2 dollars each.

Step 1: 3D Print the End Pieces

The end pieces hold the LED and the LDR against the plastic strip, and provide pins for connection. They are 3D printed using black PLA filament.

Attached are the .stl files.

The plastic strip is 0.5mm thick, but I had trouble accurately creating a 0.5mm slot using my 3D printer (even though it was calibrated quite well otherwise, the slots tended to be printed too thin). I had to create a 0.8mm slot in the .stl to get a 0.5-0.6mm slot in the print. Your printer may be more accurate, so I have provided OpenSCAD files. Just change the variable w, which is the slot thickness.

Step 2: Build the LDR End Piece

LDR Light Dependent Resistor G5528 (very small LDR 3mmx5mm in size)
2 pin header
Epoxy glue
Black insulation tape
Sensor End Piece (3D printed in step 1)


Cut the legs of the LDR so that they are the same length as the short pins on the header, then solder the LDR to the header as shown in the photo.

Wrap (loosely) a small strip of black insulation tape around the soldered joints. This is to try and prevent light leakage.

Insert the LDR into the large hole in the end piece so that it is hard up against the slot inside. Push the tape down into the hole to prevent light leakage as much as possible.

Epoxy over the header and end piece.

Step 3: Build the LED End Piece

White LED strip. This type has very small surface mount LED's and has 3 (SMD3528) LED's per segment.
2 pin header
Epoxy glue
Black PLA filament
LED End Piece (3D printed in step 1)


Scrape the surface off the LED strip as shown. Make sure that the two sections scraped are the two that connect to the two terminals of the LED.

Cut the short pins of the header shorter, and cut around the LED as shown - careful not to cut where the LED connects.

Solder the LED to the header. Test that the LED is working by applying 5v through a 100 ohm resistor to the header pins.

Insert the header and LED into the end piece. This needs to be the correct way up. If you place the end piece on the table so that the slot it nearer the top than it is to the bottom, then the LED will be inserted facing upwards. Ensure that the LED is seated properly, and that you can insert a 0.5mm thick piece of PET plastic into the slot. You may need to bend the LED downward slightly before inserting so that it does not stick up and block the slot.

Melt two small blobs of black PLA with a soldering iron either side of the header to prevent light leakage.

Epoxy the header to the end piece.

Step 4: Put It All Together

0.5mm thick PET plastic
10mm black heat-shrink tubing
Black insulation tape
Epoxy glue

A strip of 0.5mm thick PET plastic is used for the bendy part. Cut a strip 7-8mm wide and the length that you require (my prototype strip was 6.5cm long).

Optical fiber works because of 'total internal reflection' - even when the fiber is bent most of the light still reaches the far end by reflecting off the inside walls of the fiber. This is not what we want in this situation - we need less light to reach the far end when the plastic is bent. So roughen up (frost) the two flat sides of the plastic with a fine grid sand-paper.

Slide the plastic into the two slots of the end pieces (you may have to taper it slightly). Test that the LED and LDR are working by connecting 5v (through a 100 ohm resistor) to the LED and the LDR to a multi-meter. The strip should light up as per the photo, and you should get a reading on the multi-meter that varies as you bend the strip.

If all is good, then epoxy the ends of the plastic to the outside of the end pieces. Take note of the polarity of the LED so you can connect it up correctly later.

When it is dry, we need to light-proof the whole assembly.


A length of black insulation tape is wrapped width-wise around the plastic strip, and then another piece is wrapped around from the other side, so that it is totally covered. Small pieces are placed over the two headers, pushing the pins through the tape.

The end pieces are then covered with two short pieces of 10mm diameter heat-shrink tubing.
IMPORTANT: use gentle heat to soften the heat-shrink, as you do not want to soften the PLA or PET strip.

The sensor is now complete.

Step 5: Testing and Use

Connect the LED to a 5V power supply through a 100 ohm resistor, and connect the LDR to a multi-meter. You can now determine the resistance range of your sensor (from straight to 180 degee bend).

With the LED connected through a 100 ohm resistor, I got a resistance of around 50K when the strip was straight, and around 900K when it was bent to 90 degrees. Changing the value of the resistor will alter the range of resistance values that you obtain.


Using the sensor as part of a voltage divider, it can be read via an analogue input of an Arduino.

Connect the LED side of the strip to GND and 5V through a 100 ohm resistor. Connect the LDR side of the strip to 5V and to the analogue input A0. Connect a 100K resistor between A0 and GND. You can alter the value of this resistor to suit the range of values that you want to read. I good idea is to make it the same value as the strip when it is bent half-way. eg If your project will be bending the strip between 0 and 90 degrees, then match the resistor to the resistance of the strip at 45 degrees.

Run the following sketch and view the output on serial monitor as you bend the strip:

void setup() {

void loop() {
int sensorValue = analogRead(A0);

These were my readings:
0 degrees = 830
90 degrees = 200
180 degrees = 20

I found that the reading when straight was quite consistent and stable. The reading when bent was also quite consistent, but tended to vary slightly depending on where you made the bend. Overall I was happy with the result.

Sensors Contest 2017

Participated in the
Sensors Contest 2017

Be the First to Share


    • For the Home Contest

      For the Home Contest
    • Big and Small Contest

      Big and Small Contest
    • Make It Bridge

      Make It Bridge



    5 years ago

    Very elegant sensor and good explanation of the theory-of-operation.

    Thanks for sharing.


    6 years ago

    Thanks, very useful, I will try it