Hey Everyone,
I am wondering if there is a way to make a flex sensor with a range of 10k - 40k ohms act like a pot with a range of 0 - 10k ohms?
Thanks...
rr
Hey Everyone,
I am wondering if there is a way to make a flex sensor with a range of 10k - 40k ohms act like a pot with a range of 0 - 10k ohms?
Thanks...
rr
Basically no
You would have to convert the range you have into a voltage, then use an op amp to remove the DC offset and amplify the signal range to the voltage range you want. However turning this back into a resistance would probably take and Arduino and an I2C digital pot.
What do you actually want to do?
Hmm... converting the initial resistance to a voltage would be tricky... A voltage divider won't give you a linear relationship of voltage-resistance.
This I think would give you a linear relationship (@Grumpy: am i right?):
Your R and R1 would be the nominal value of your flex - in your case 10K
then Vout=A/4Vrefchange in flex
Well I can't see why it would not be linear. Using a bridge just gives you a mid reference point for the op-amp.
I think the clue here is what rr is actually trying to do. I suspect he just wants to connect it into the analogue input of the arduino and not have to bother about subtracting offsets so the maximum range of readings is achieved with a single flex. Well that's not easy to do and if you really need extra resolution you are better off with a higher resolution external A/D.
Hey,
Thanks for replying to my post so quickly... I am thinking there is a way to change the code around in order to use the flex sensor. I found some code on controlling RGB hue with one pot. I got it working great with a 10k pot, but now i would like to use the flex sensor in order to create a more interesting interface. I am thinking there is a way to change something in the code to make it work. I have tried messing with the numbers with no luck. I am just a bit confused.
Here is the code i am working with:
int potpin = 2; // Switch connected to digital pin 2
int rpin = 9;
int gpin = 10;
int bpin = 11;
float h;
int h_int;
int r=0, g=0, b=0;
int val=0;
void h2rgb(float h, int &R, int &G, int &B);
void setup() // run once, when the sketch starts
{
Serial.begin(9600); // set up Serial library at 9600 bps
}
void loop() // run over and over again
{
val=analogRead(potpin); // Read the pin and display the value
//Serial.println(val);
h = ((float)val)/1024;
h_int = (int) 360*h;
h2rgb(h,r,g,b);
Serial.print("Potentiometer value: ");
Serial.print(val);
Serial.print(" = Hue of ");
Serial.print(h_int);
Serial.print("degrees. In RGB this is: ");
Serial.print(r);
Serial.print(" ");
Serial.print(g);
Serial.print(" ");
Serial.println(b);
analogWrite(rpin, r);
analogWrite(gpin, g);
analogWrite(bpin, b);
}
void h2rgb(float H, int& R, int& G, int& B) {
int var_i;
float S=1, V=1, var_1, var_2, var_3, var_h, var_r, var_g, var_b;
if ( S == 0 ) //HSV values = 0 ÷ 1
{
R = V * 255;
G = V * 255;
B = V * 255;
}
else
{
var_h = H * 6;
if ( var_h == 6 ) var_h = 0; //H must be < 1
var_i = int( var_h ) ; //Or ... var_i = floor( var_h )
var_1 = V * ( 1 - S );
var_2 = V * ( 1 - S * ( var_h - var_i ) );
var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );
if ( var_i == 0 ) {
var_r = V ;
var_g = var_3 ;
var_b = var_1 ;
}
else if ( var_i == 1 ) {
var_r = var_2 ;
var_g = V ;
var_b = var_1 ;
}
else if ( var_i == 2 ) {
var_r = var_1 ;
var_g = V ;
var_b = var_3 ;
}
else if ( var_i == 3 ) {
var_r = var_1 ;
var_g = var_2 ;
var_b = V ;
}
else if ( var_i == 4 ) {
var_r = var_3 ;
var_g = var_1 ;
var_b = V ;
}
else {
var_r = V ;
var_g = var_1 ;
var_b = var_2 ;
}
R = (1-var_r) * 255; //RGB results = 0 ÷ 255
G = (1-var_g) * 255;
B = (1-var_b) * 255;
}
}
This is the circuit I have for the flex sensor. I am using a 10k resistor between the pin and ground.
Any help or pointing out where to find help would be great.
Thanks
rr
OK first off when posting code paste it between the square brackets you get when the hash icon is pressed in the reply box. You can go back and modify your post to include this. It makes it so much ease to read.
What you want to do is to use the map() function, see the reference section of the arduino help. This allows you to spread out a range of values into another range. It simply does some math that you should have done when your were very young.
Thanks Mike...