Pages: [1] 2   Go Down
Author Topic: voltages and pins and optoisolators  (Read 1328 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there, hopefully I'm making a noob mistake that someone can point out reqlly quickly and put me out of my misery.

I'm trying to drive an optoisolator off pin 8 on my UNO, but it's not working. I have pin 8 set as OUTPUT so I am expecting 5 volts on the pin when I set it HIGH, however when I hook up a multimeter I'm getting 1.4v. As a further test I put pin 8 into A0 and read the analog value - 285ish... nowhere near 1024.

I read somewhere about the internal pull up resistor making it put out 1.7v but setting the pin as an OUTPUT switches that off.

Interestingly (and probably a mistake) I hooked the ground wire to 5v and started reading -5v on the multimeter, and zero on the analog pin, Setting pin 8 HIGH then pulled zero volts on the meter and 1022 on the analog pin.

Anyhow, my question - why can't I get the 5V out of pin 8 (or 9, 10, 11 that I tried) I need to power my opto?

Any help much appreciated.
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did projects with opto-couplers.

First.
Can I see your situation ?  Schematic ?  Wiring diagrams ? code ?

Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 485
Posts: 18816
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Interestingly (and probably a mistake) I hooked the ground wire to 5v and started reading -5v on the multimeter, and zero on the analog pin ...

What ground wire? You connected 5V to ground?

(edit)

Tell us about any smoke you saw.
Logged


Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nick, No magic smoke escaped, all is still working smiley I connected the multimeter up in reverse.

I think the opto is a red herring here, or more likely my logic, either way, something is fishy (sorry). The Opto is where I started, and where I need to end up, but in eliminating all the bits to track down my problem, I got the simplest of layout:

Arduino pin 8 to multimeter +ve
multimeter -ve to Arduino GND

Here is my code:

Quote
#define LEDPIN 13
#define OPTPIN 8

void setup() {               
  pinMode(LEDPIN, OUTPUT);
  pinMode(OPTPIN, OUTPUT);
}

void loop() {
  digitalWrite(LEDPIN, HIGH);
  digitalWrite(OPTPIN, HIGH);
  delay(2500);
  digitalWrite(LEDPIN, LOW);
  digitalWrite(OPTPIN, LOW);
  delay(2500);
}

The multimeter switches between 1.4v and 0v. I was expecting 5v and 0v.

As far as the opto I would expect the continuity to be near instant, so a 100ms long HIGH on pin 8 should give a decently long continuity beep from a multimeter setup across the opto outputs, however it wasn't until the pulse got to about 250ms that I started to get measurable continuity. the multimeter is cheap, so is probably pretty slow so I'll check this with a little LED circuit set up over the outputs later. My real issue though is understanding why I don't get 5v out of the Arduino pin.

Thanks
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When you do that test, is the opto still connected?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think I tried it with, and then later without. Would it make a difference? The resistance across the voltmeter is (close to) infinately high so the load through the opto will be infinitesimally small and should not have a potentiometer effect, certainly not enough to draw nearly 70% of the voltage?

I remember testing it with the opto in place and the pin 8 output also going into an analog line for comparrison - still at 285/1025 which does corelate to the 1.4v I'm seeing on the multimeter.

I'll try it again tonight without the opto and report back.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well my digital pins source 5V (powered by USB) unless I pull enough current to lower that, it would quit 16 MHz operation maybe somewhere below or above 4V since the pin output V is the same as the board runs on AFAIK.

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

... unless I pull enough current to lower that...

Hmmm. Interesting point. So if there is not enough load in the opto, it would effectively be a short. Would that pull so much current so as to to drop the voltage? Should I add a resistor in the line then?
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can't pull that much current from one or two pins without burning them out. Recommend to pull no more than 20 mA from a pin though they can take more, less is desirable. I'd use less for signal to an opto, it's only going to drive a very small led inside. Overload that and what do you get?
The opto has power and ground to drive the outputs, normally you want to keep the opto output pins from using too much current as per the datasheet.
You can run the opto on external power, just make sure the external ground is connected to the Arduino ground. If you don't then take care how much current you pull from the Arduino.

How hard to disconnect the Arduino and make sure your #8 pin is still good? Or maybe test your 5V for 5V? Because whatever you get from that, you should from the digital pin?
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have checked pin 8 and it is still driving my LCD panel, and still works with my buttons so it looks good.

I wasn't sure if I needed a resistor in line. For example rotary encoders and switches/buttons basically short circuit a HIGH pin to ground so powering an opto on the way shouldn't cause a problem. I checked the data sheet (I think it's an LTV826) and it only pulls 2mA and has 100 ohms of internal resistance so I didn't think I need a resistor in there.

the PS2501 (I plan to use later) says it pulls 10mA, and has 100 ohms internally. I also read that due to pulling a maximum of 80mA a 70ohm resistor should be used, any idea what that's based on? Last time I played at this level, was at school... luckily post decimalisation smiley

thanks for all your feedback so far. Very much appreciated.
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oh no.  smiley-eek  Never, ever, ever just hook a switch between 5V and ground on Arduino!

You need to learn Ohm's Law. Not just the formula arrangements either but what they mean, how current flows.

You need to learn both Kirchhoff's circuit laws, current and voltage.

Look here, all 3 parts, to start: http://hyperphysics.phy-astr.gsu.edu/hbase/electric/ohmlaw.html

Or you could stay using 'cookbook recipes', following circuit diagrams down to the last detail.

Those laws are simple but the more complicated the circuit the more of them apply, not so simple.

Still, if you know Ohm's law then you can say 5V and needing 10mA (=.01A) you need 5V/.01A = 500 ohm resistance total. A 100 ohm resistance is not going to do by itself. And -if- that's 10 mA maximum then use more resistance as all those parts are +/- tolerance % which with cheap parts is 10% or more. If it will run at 5 mA then use 1k ohm total resistance.

Just throwing things in the pot type electronics cooking is a good way to end up with lots of 'cooked' parts. Cook em hot enough and you will get smoke. It's a great way to burn hairline traces off a PCB but that's about all.
Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't forgot the limiting resistor for the opto-coupler led.  Check the datasheet. It is better to control the opto led with a NPN transistor in my opinion.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, position update:

all pins report 5v when nothing attached and set HIGH.
No magic smoke has been lost.
Vague recollection of Ohms law returning.
Only example I can find with a shorted "button" is the rotary encoder example, so a slight over exaggeration on my part smiley

Thanks again for all your feedback, I think this proves that the Arduino is pretty idiot proof smiley

Techone. why would you use a transistor? Do the characteristics on the opto change?
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Techone. why would you use a transistor? Do the characteristics on the opto change?

I sudgested the use of a transistor to control the led inside the opto-coupler, because it will use less current by the digital pin ( with a base resistor of 1 K to 4.7 K, and in some opto-couplers, you may use more current to control the led. Why is that ? At lower frequency switching, a standard 330 to 470 is OK and the need of a transistor is optional. But at higher frequency, like 4800 baud and above, the output signal ( at the opto-coupler transistor )  is lower, so a brighter led inside help to get that signal a bit higher, than a transistor is use for switching the led (on/off). That transistor I use is the 2N3904. Very good switching characteristics.

To answer your question... no. 
Logged

Pittsburgh, PA, USA
Offline Offline
Faraday Member
**
Karma: 98
Posts: 4809
I learn a bit every time I visit the forum.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
At lower frequency switching, a standard 330 to 470 is OK and the need of a transistor is optional. But at higher frequency, like 4800 baud and above, the output signal ( at the opto-coupler transistor )  is lower, so a brighter led inside help to get that signal a bit higher, than a transistor is use for switching the led (on/off). 

The opto has 100 ohm in itself, put another 100 between that and the pin and it should draw 25 mA. Compare to 330 ohm resistor + 100 ohm opto at less than half the current/brightness. That is how it works? Current is the same all through?

Logged

I find it harder to express logic in English than in Code.
Sometimes an example says more than many times as many words.

Pages: [1] 2   Go Up
Jump to: