Hello everyone! I need some help with an optocoupler. I seem to have had this working a few months back, and now for some reason I can't get it working again. I don't know what the problem is. I don't think the optocouplers are the issue, but I'm not sure. The first time I ever used them was in the creation of this project a few months back which I am just now finishing, so I don't have enough experience with these to figure out this situation.
I have five CNY17F-3 optocouplers. The INPUTs to the optocouplers is the voltage supplied to five LEDs on an audio meter device (one LED going to each optocoupler) - around 3ish volts each. The OUTPUTs of the optocouplers are the five analog inputs on the Arduino. Like I said, I had this going OK a while ago as I recall, but something happened somewhere. Seems like I am getting no OUTPUT from the optocouplers. No voltage. At all - nothing.
I am wondering if something was switched around with the wiring (which is on a protoboard). I have gone over the pinout several times and I THINK I have it correct. Pins 1 and 2 are the inputs from the LED on the audio meter. Pin 3 isn't used. Pin 4 should go to ground, and pin 6 should be +5v (from the Arduino). Pin 5 should be the output to the analog pin of the Arduino. I have swapped everything around that I can think of.... moving 5v to various pins, and ground to various pins, and metering off of the empty pin for some kind of voltage. I get NOTHING on the output side, regardless of where I have the voltage and ground setup. This is the case with ALL five of the optocouplers that I have setup. There is nothing appearing on the output side of any of them. Further, the Arduino is reading floating values (145.0-150.0), which are completely out of line with anything in the program. This further proves that there is no input at the analog pins when it performs a read.
Can ANYONE provide any suggestions here?? Or any way to test?? I have gone through the pinouts of the entire CNY17 family, and none of the configurations seem to produce a result. I have even hooked up a 3v and ground from the Arduino as a test load on the inputs, and I just don't seem to get ANYTHING on the other end. Something is very wrong with this picture!
Pin 4 should go to ground, and pin 6 should be +5v (from the Arduino). Pin 5 should be the output to the analog pin of the Arduino.
Pin_4 should go to GND. Pin_6 is not used.
Pin_5 should go to a digital input, pulled-up to 5V (use the Arduino internal pull-up.)
You could use the analog pins, too, I guess. But, in this case you should be reading for digital output (hi/lo) from the opto because the opto-transistor should saturate full-on when the input LED/IRED goes On.
I have swapped everything around that I can think of.... moving 5v to various pins, and ground to various pins, and metering off of the empty pin for some kind of voltage.
Really? Just swapping wires, at random, like a drowning man grasping at straw? Why was that necessary? What good could come of it?
Hahahaha - when in doubt, just randomly swap wires and plug things in anywhere?? No?? I could have sworn that's what I was taught somewhere.
The reason for using the analog pins is that I need to meter a full range (1023) of levels. The LED does not just go on or off, there are varying shades of illumination which are critical for this project, hence the use of the optocoupler. It would have been MUCH easier if I could have just use a simple on/off, but alas, nothing is ever quite that simple.
I will re-try the pinout give your suggestions, but I am a bit confused by the pullup you mentioned, as I did not use that method last time. I distinctly remember running +5v to pin 4 or 6 (I'm pretty certain it was 4), and then running pin 5 to the analog pin. Pin 5 and 6 are tied together I believe, although some pinout diagrams do not show it that way. I pulled 6 to ground and 5 to the analog pin. That is the way the breadboard is still configured (+5v to 4, gnd to 6, and data on 5) and like I said, it WAS working at one point. Hhhmmm.
I refer only to the pin-out of the device you specified.
Some "optos" have a pin_6 for base bias, the device that you specified does not. (At any rate, it's not an output.)
Some people's interpretation of "working" is much different than mine.
It seems to me that if you're trying to come up with a variable voltage on the opto output that Pin_5 should go to +5 and pin_4 should go to an analogRead pin. That way, the phototransistor is "emitter following", but I figure there ought to be a resistor to GND (1K-5K?), too.
WONDERFUL. Thank you for your suggestion. I will give that a run and see if I finally get some kind of output. I will toss a resistor on there as well. Perhaps, by some fluke, I had it wired completely incorrectly to begin with but was getting an output of some kind anyway. I have not tried the configuration that you suggested, so I will let you know.
As I feared, I get nothing. Well, actually I get a solid 5v which is a mirror of what I have applied to pin 5. I have 3v going into pin 1 and 2 (voltage and ground), and 5v going into pin 5. I used a multimeter to see what was going on with pin 4 when applied to an analog pin, and it is a solid 5v. It SHOULD be a duplicate of what is being applied on the input side (3v). Any thoughts??
I'm wondering if you're clear on the numbering of the pins on the device.
You can't have 3V on the input and get 3V on the output.
I've attached a pic of a sample circuit. I think cameras are everywhere. If you're not too swift with "Paint" and you don't have a flatbed scanner, you can put pen to paper and take a picture of that. With this circuit, when the input is high, the output is high, too. With input between 2-3V, the output ranged about 1-4V. Not very practical.
** input resistor = 1k, output resistor = 2K **
There's a narrow range of input current where you can effect a variable output.
I thought that your VU meter LEDs were part of something like an LM3915 where you'd only care if they're on/off and there's no range of brightness of the indicator LEDs.
I had a cassette deck (Optonica) that had VU-meters and an LED for each channel which glowed in relation to volume.
Anyway, I guess I'd like to see what you thought you had, perhaps you were satisfied with some effect by chance. No offence.
NO offense taken, trust me!! I'm here for help - so anything you can share is appreciated!
I am attaching a diagram with the original pinout that came with these chips.
I found a few notes that I originally took when I wired this up. I originally had it exactly as you drew it, but I ran into a problem with running pin 4 to ground AND to the input pin. I was getting strange voltages on the input. Instead I ran pin 6 to ground and kept pin 4 as the analog input pin and it worked fine. I had all 5 of these chips up and running and the output of the chip was almost a linear relationship to the input (1.5v-in, 1.5v-out, etc.). Whatever voltage the LED on the vu meter was giving off, the same voltage was being spit out to the analog pin. That is why I am confused now, because I literally had the whole thing up and running, working fine. I moved a few things around, some time went by, and now I am getting garbage (or nothing) through these chips.
The whole point of this is to measure ranges and produce actions based on when those ranges are hit. For example, a full 1.5v from the LED (full on), represents a certain decibel level, .75v from the led (half on) represents some lesser decibel level, etc. Given the voltage outputs of the various LEDs I am able to get a rough approximation of what the decibel level are from the various audio inputs and have the microcontroller react accordingly. That is the premise here. I originally tried connecting one leg of the LED to the input pins, and the other legs to ground, but by binding the individual ground legs the LEDs on the vu meter started acting odd (as in, short circuit). So it was suggested that I try an optocoupler as it isolates the inputs and outputs. It DID work fantastic!
Well you may be asking a simple opto to do more then it's capable of without adding more support components. Firstly a optocoupler can be operated in two different modes, digital or analog. In digital you just want to pass a two state logic value between two system where you don't want them to share a common ground. This is the most frequent use of a opto and there are many example circuits around. Basically you have to switch a limited current (not a voltage) through the input LED, most work with anything from around 3ma to around 20ma maximum for the ON state and 0 ma current for the off state. If you just wire a DC voltage, say +5vdc, across the diode terminals you will damage (burn out) either whatever is supplying that voltage and or damage the opto's LED. External current limiting is always required when driving a simple led whether it's an internal led in a opto or just a simple two terminal led.
The other mode, linear, is where you 'bias' the input led to a steady idle DC current of say 10ma and then you superimpose a AC current (or a variable DC current) onto that bias signal. That will cause the opto's output transistor to follow the AC (or variable DC) current. The output transistor also will require a collector pull-up resistor to convert the current signal to a voltage output signal that can then be wired on to whatever is going to 'read' this analog voltage. The signal might be passed through a series capacitor if you wish to remove the 'idle resting' voltage of the output transistor, on not, depending on the downstream circuitry requirements.
So I guess what I'm trying to say is that your application is a little more complex then it might appear to you and much more details about the upstream and downstream circuity is needed to really help you with how to utilize the optoisolator properly.
WOW, Lefty.... yes that is significantly more in depth than anything that I have ever been told. When I originally looked into this option the suggestion that I was give was basically to plug these two wires here, these two wires there, and this wire to the analog pin. I did, and like I said it worked, but I am wondering is something may have been damaged in the process which is why I can not seem to get it to work now.
I am OK with electronics, and OK with C, but I have to tell you that you lost me with your explanation. I think that the "linear" mode is the one which would be most appropriate to me since I need more than a simple on/off, but based on your description I would have NO idea of where to begin. Everything I am working with is DC, and all the vu-meter LED's are simply 5mm red LED's (5v max reading at full on brightness.... I was incorrect in my previous post where I said 1.5 - sorry). Likewise, the Arduino input side is relatively straightforward.
I'd configure op-amps (LM358) as non-inverting buffers, very easy, and run the outputs to the Arduino analog ins.
High-impedance, it won't load (affect) your vu-meter. Inexpensive, effective.
I delved into my super stack of stuff and found the service manual for that cassette deck. I don't have the deck anymore.
I've attached the circuit that it used for that "VU-LED".
My recollection was that it had two, but it had only the one (diode-OR'd).
It had the meters, but it was kind of cool having the LED going, playback and record alike. It just happened, no utility past coolness - it'd have been meaningful if the LED came on >= +3 to indicate clipping.
Anyway.
** With that, though, I could add another LED in series, locate that on my breadboard or whatever, and shine it on a CdS-photocell (in an "optically-sealed" environment, a tube wrapped with duct tape or what have you) which would yield first-rate analog output. **
You're saying it worked before but doesn't work now. Assuming you don't have an oscilloscope, did you meter and monitor the input of the arduino while the audio is playing to see if there is voltage coming out of the optocoupler, and that it varies in relationship to the input side of the optocoupler?
In other words, put your meter on the input of the optocoupler, and observe the voltage. It may be hard to read the meter, as it will be fluctuating depending on the audio level, but you should read something and it should be fluctuating.
Then, move onto the output side and see if you see the same pattern. That's probably the easiest way to check the hardware to see where the issue lies.
I can't see a reason for adding op-amps as buffers, as the arduino should not load down the optocoupler if you're using the output of the optocoupler only to feed the input of the arduino.
Anyway, check the voltages and see what you get. If the input and output are similar, then you have a problem in your code.
My 2 cent in this tread.... : Check the opto-coupler with only -> 330 ohms for the "inside" Led and a 10 K for the inside transistor.
Connect : +4.5 V ( Battery set of 3 AA)- 330 resistor - pin 1 - pin 2 of the GND ( negative side ).
+4.5 V ( an another battery set of 3 AA ) - 10 K resistor - pin 5 - pin 6 of the other GND ( negative side of the other battery set ).
Measure with : DVM at pin 5 and 6 - it should read a low voltage ( between 1 to 0 Volt ), next : disconnect the battery at the LED side, and read again pin 5 and 6 - it should read a "high" voltage ( between 5 to 3 Volt )
By doing that, you check the opto-coupler if it work or not. Working : read a change of voltage when LED is on or off. If you don't have those reading, well the opto-coupler is.... "bad".