Go Down

Topic: Linear resistance through optocoupler (Read 3201 times)previous topic - next topic

stoopkid

Oct 06, 2011, 08:42 am
I'm trying to control a 9v audio signal through a self made optocoupler(200k dark LDR and random blue LED, temporarily). They're all taped up together and dont seem to be getting any interference. The LDR is in parallel with a 10kohm resistor as I need a linear 0-10k resistance.

But I'm having a really hard time getting a nice linear fade in the resistance in the values I need. I tried to use logarithm and it helps a tad but I don't think I'm doing it right, and I seem to still be having other problems.

This is my equation
255-(log(256-i)*46))
I literally just added to it until I got about what I was going for. I assume it's not done correctly. I'm just looking for my 0-255 value to have a curve. It's still not curved enough according to my multimeter. But even more troubling is that it reports from 10k to IMMEDIATELY 5K when the LED PWM goes from 0 to 1 or 2. So I literally cannot get any more resolution out of that, and I need the 5k-10k to have at least close to as much resolution as 5k-0.

Code: [Select]
`int j = -1;void setup(){  pinMode(3,OUTPUT);  pinMode(5,OUTPUT);  Serial.begin(9600);  Serial.println("reset");}void loop(){  //analog input 0 connected to pot just for testing  int i = map(analogRead(0),0,1023,5,255);  analogWrite(3,255-(log(256-i)*46));//optocoupler LED  analogWrite(5,255-(log(256-i)*46));//test LED  if(i!=j){//Only print if value changes    Serial.println(255-(log(256-i)*46));//print value    j=i;  }  delay(10);}`

So basically I'm having nothing but trouble with this so I could really just any advice.

Thanks

Grumpy_Mike

#1
Oct 06, 2011, 10:53 am
Quote
But even more troubling is that it reports from 10k to IMMEDIATELY 5K when the LED PWM goes from 0 to 1 or 2.

That suggests to me that the LED is too bright. Try cutting down on the LED current by increasing the series resistor value.

I did say it was very non linear.

mmcp42

#2
Oct 06, 2011, 11:28 am
have you tried using PWM modulation, might give you more control, especially if the LED is enthusiatic!
there are only 10 types of people
them that understands binary
and them that doesn't

Grumpy_Mike

#3
Oct 06, 2011, 11:37 am
Well he did say:-
Quote
But even more troubling is that it reports from 10k to IMMEDIATELY 5K when the LED PWM goes from 0 to 1 or 2.

mmcp42

#4
Oct 06, 2011, 11:39 am
oops missed that
saw analog_write and assumed ...

will stand in corner for a while
there are only 10 types of people
them that understands binary
and them that doesn't

stoopkid

#5
Oct 07, 2011, 12:34 am
I've gone all the way up to 10k for the LED limiter and I still get an LDR jump from 9.8k to 8.9k when I go from off to PWM 1. I would keep going up, but when I get to 255 the LDR only gets down to 1.7k. I can live with 300ohms at the lowest, but not 1.7k.

Maybe put a 20k in parallel with the LDR so that I'm not actually aiming for the lowest end of the PWM spectrum? I sure don't like lowering my resolution like that, but do I have any other choice?

Grumpy_Mike

#6
Oct 07, 2011, 01:21 am
The other thing you can try is an optical filter between the LED and the sensor. A few cellophane wrappers from candy might do.

stoopkid

#7
Oct 07, 2011, 08:52 am
Would it help much to just get a real optocoupler? Would this work?

Grumpy_Mike

#8
Oct 07, 2011, 09:50 am
It would work but not as well as some other designed. If you want to do an analogue transfer through an opto then look at the sort with one LED and two transistors. The second transistor is used for feedback to keep the thing more linear.

http://www.ssousa.com/appnote060.asp

PaulS

#9
Oct 08, 2011, 02:17 am
Quote
oops missed that
saw analog_write and assumed ...

And assumed what? The analogWrite() function IS used for PWM.

stoopkid

#10
Oct 08, 2011, 02:27 am
I'm already going to have so much going on with this project(5 or 6 rotary encoders, a bunch of 10-seg bar graphs, hopfully an LCD text screen) I would rather calibrate the optocoupler ahead of time than constantly check it. In that case would my link do or is it still substandard?

Grumpy_Mike

#11
Oct 08, 2011, 11:08 am
Quote
In that case would my link do

Hard to say but it will still be very non linear. The approach I suggested uses no CPU time so I don't see why you would need to constantly check it.

stoopkid

#12
Oct 08, 2011, 11:43 am
I figured the second LDR is for feeding back into the arduino so that I can adjust until I get the correct value. Is that not correct?

Also it's \$5 and I need at least 5 so I sure like the 25 cent one I linked better. I know I'm being pretty picky here, but are there any other choices? Or could I make due with the one I linked? If I logged the values and the curve and adjusted in programming would I at least get fairly consistently repeatable resulted out of it? That's really all that's important as long as I don't get those huge jumps like with my rigged up scheme.

Grumpy_Mike

#13
Oct 08, 2011, 03:21 pm
Quote
the second LDR is for feeding back into the arduino so that I can adjust until I get the correct value. Is that not correct?

No it is for feedback to the op-amp driving the LED. Without it you tend to get the same sort of large steps you did with your home made stuff.

stoopkid

#14
Oct 11, 2011, 08:32 am
Is that the only model that does that or is there a way to find more because I can't hardly find anywhere that carries those and the places that do are expensive.

Go Up

Please enter a valid email to subscribe

To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy