# Flex sensor doesnt work

#### rocker123uk

Joined Dec 6, 2015
33
Hi all,

I have been struggling with this very basic circuit, basically i have to done the analog to digital conversion for a flex sensor where the digital value 0-1024 is shown on my LCD (easypic board).
i have done it with a potentiometer at first and it worked well. then i used an FSR and created a simple voltage divider circuit and it also worked fine. however when replaced the FSR with the flex sensor it all stops working (i used different flex sensors as well). the value shown on my LCD is approximately 600 after the analog to digital conversion occurs and it barely changes when the flex sensor is bent.

Last edited:

#### ericgibbs

Joined Jan 29, 2010
15,347
Hi 123,
Please post details or link to the Flex sensor that you are using.
E

#### rocker123uk

Joined Dec 6, 2015
33
hi
the flex sensor data sheet is here : https://cdn-shop.adafruit.com/datasheets/SpectraFlex.pdf
and the code im using is this:
C:
// Lcd pinout settings
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D4 at RB0_bit;

// Pin direction
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB0_bit;

void main() {
char *temp = "0000";
int a=0;
ADCON0 = 0b10010000; //AN2 analog channel selected
ADCON1 = 0b01001001;  //PORT configuratoin to AN2
TRISA = 0b00000100; //RA2 analogue input
Lcd_Init();
Lcd_Cmd(_LCD_CLEAR);
do {
temp [0] = adc_value/1000 +48 ; //add 48 to get the ascii value
temp [1] = (adc_value/100) %10  +48 ;
temp [2] = (adc_value/10) %10 +48;
Lcd_Out(1,11,temp);
Delay_ms(100);
Lcd_Out(2,1,"Too hard   ");
Lcd_Out(2, 1, "Hard       ");
Lcd_Out(2, 1, "Medium   ");
Lcd_Out(2, 1, "Soft     ");
Lcd_Out(2, 1, "Too Soft    ");
} else {
Lcd_Out(2, 1, "             ");
}

} while (1) ;
}
Mod edit: code tags

Last edited by a moderator:

#### Raymond Genovese

Joined Mar 5, 2016
1,653
Since you have tested the code with a potentiometer, that part may be ok. But you didn't show how you have the circuit hooked up. Specifically, you have not mentioned using an op amp (as an impedance buffer) as you can see on p. 2 of the document that you linked. That, along with an appropriate value for R2 would be reasonable places to look for a solution.

#### rocker123uk

Joined Dec 6, 2015
33
I have used an LM741 op amp and it didnt work either. i have the circuit connected in the image shown

#### Attachments

• 10.8 KB Views: 7

#### Raymond Genovese

Joined Mar 5, 2016
1,653
ok, I would suggest the following.

Measure the resistance of the flex sensor by simply attaching an ohm meter to the two leads. Lying flat it should be ~10K and bending it should increase the resistance. That will test the flex sensor itself. What happens in that case?

#### MrChips

Joined Oct 2, 2009
25,920
Pretty please, do tell us the part number of the flex sensor and the value of the load resistance (the external resistance you have added to form a voltage divider).

#### rocker123uk

Joined Dec 6, 2015
33
as the flex sensor bends, the resistance increases. when doing the analogue to digital converstion. it should shown on the lcd that as it bends the value increase from 0 to 1024 (like it did with fsr and potentiometer) however, it starts at about 600 and as i bend it, it actually reduces from 600 to a maximum of 400...this is were im confused

#### Raymond Genovese

Joined Mar 5, 2016
1,653
as the flex sensor bends, the resistance increases. when doing the analogue to digital converstion. it should shown on the lcd that as it bends the value increase from 0 to 1024 (like it did with fsr and potentiometer) however, it starts at about 600 and as i bend it, it actually reduces from 600 to a maximum of 400...this is were im confused
That is ok because of the way you have it hooked up. Look at this little reference. You have R1=10K and R2=flex sensor. Using the calculator on that page, look at what happens to the voltage out as R2 decreases. You are getting reasonable values as far as I can tell. If you use the flex sensor as R1 and the fixed resistor as a 10K, you will see the voltage increase and the value of the A2D conversion.

Edited to add: I think if you measure the sensor alone, you will find that the resistance decreases when bent, not increases. That result is consistent with the data sheet and the results that you are getting based upon hooking up the circuit as per your jpg.

I am wrong, again, I got confused, the resistance of the sensor increases when bent, not decreases.

Last edited:

#### Alec_t

Joined Sep 17, 2013
12,734
If you've interchanged the sensor and series resistor as shown in post #5, then the reading would reduce as stress increases.

#### rocker123uk

Joined Dec 6, 2015
33
so the images attached shows that using a fixed 10k resister connected to the flex sensor, the analogue to digital conversion hardly changed when i use the fsr it works perfectly. iv read somehwhere that i have to use CCP1 PWM , what do you think?

#### Attachments

• 352.8 KB Views: 2
• 345.3 KB Views: 2

#### rocker123uk

Joined Dec 6, 2015
33
now i have literally just swapped the flex sensor with the fsr and it works perfectly!! its weird because they have very similar specifications

#### Attachments

• 89.6 KB Views: 3
• 328 KB Views: 3

#### Raymond Genovese

Joined Mar 5, 2016
1,653
so the images attached shows that using a fixed 10k resister connected to the flex sensor, the analogue to digital conversion hardly changed when i use the fsr it works perfectly. iv read somehwhere that i have to use CCP1 PWM , what do you think?
I think you need to get the basics down first. The sensor's resistance should decrease when bent and I think that you need to confirm that first. If, in fact, the resistance increases, then you do not have the part that you think you have based on the data sheet you posted. You need to resolve that first.

Then, I think you should make appropriate use of the simple voltage divider to understand what readings on the A2D that you are getting and to establish the range of readings that you need for the purpose of the circuit.

Then, use an op amp (LM358 or LM324 as suggested in the data sheet) as an impedance buffer and choosing the fixed resistor to maximize the range that you need.

Then see where you are at before jumping to other solutions. The flex sensor doesn't operate like the FSR that you used because it has different characteristics. When you have a good grasp on that, you will be able to see the next step more clearly - at least that is what I think.

EDITED: I am wrong and got confused - the datasheet says that the resistance when bent should increase, not decrease as I stated.

Last edited:

#### Raymond Genovese

Joined Mar 5, 2016
1,653
now i have literally just swapped the flex sensor with the fsr and it works perfectly!! its weird because they have very similar specifications
Terrific, do you have any idea why that is so?

#### rocker123uk

Joined Dec 6, 2015
33
so i have just started from the basics again. i found that with the sensor alone. the resistance increase as it shown on multimeter, but when i connect it with a 10k resistor. the resistance actually increases and from 5k to about 7k ohms when its fully bent. what could the problem be?

#### rocker123uk

Joined Dec 6, 2015
33

#### rocker123uk

Joined Dec 6, 2015
33
ok i figure out why when it bends, the resistance reduces. the supply was connected the other way round. but it still doesnt solve my problem

#### Raymond Genovese

Joined Mar 5, 2016
1,653
so i have just started from the basics again. i found that with the sensor alone. the resistance increase as it shown on multimeter, but when i connect it with a 10k resistor. the resistance actually increases and from 5k to about 7k ohms when its fully bent. what could the problem be?
I have had to edit my previous messages, the resistance of the flex sensor INCREASES when bent, not decreases as I said twice. I suppose that I can offer the excuse of too many windows and tasks simultaneously, but, nevertheless, the resistance increases when you bend it and that is what the data sheet says. That is what you are reporting.

When you put it in a voltage divider, the voltage out will depend on whether it appears as R1 or R2, see the tutorial that I linked to earlier.

Sorry, I could not be more helpful.

#### Raymond Genovese

Joined Mar 5, 2016
1,653
ok i figure out why when it bends, the resistance reduces. the supply was connected the other way round. but it still doesnt solve my problem
I already made a stupid error and I have to tap out or I will lose neurons and I clearly have precious few to spare. The resistance should increase when you bend the device and there should be no voltage attached to the device by you. Just attach the ohm eter leads directly to the device and measure the resistance. When lying flat and when bending it.