Confusion with ULN2803 and IR sensor power

Support for Arduino in combination with Air Manager and Air Player

Moderators: russ, Ralph

Message
Author
Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Confusion with ULN2803 and IR sensor power

#1 Post by Kaellis991 »

The power setup for the darlington in the attached diagram shown on my iPad is easy to understand....I think.

In my circuit on the breadboard, the ULN relay Output connects to the LED GND through a 220 OHM resistor. The +5v from the LED power connects to the LED positive lead and connects to pin 10 on the ULN.
The arduino GND and the LED PSU GND connect to pin 9 on the ULN......which is how I understand this is supposed to work.

My circuit in this photo is partially built, but the concept is for the sensor to trip the relay input using the AM code on the arduino. The sensor output connects to D7 on the arduino.
When the sensor is activated it is supposed to send a high output from D8 to the #1 input on the ULN2803 relay (short orange wire) to connect the LED GND on the output side.

I think I have that part correct...right? However, I am confused about about how to provide power to the sensor.
Should the sensor power come from the Arduino or the remote power supply? I get confused about the GND connections and how they can intermix between two different power sources.

Edit: after thinking more about this, I realize that the sensor has to get it's power from the Arduino. DUH!! Because if the other side was a 12v circuit...then I think there would be some damage done to the sensor....
IMG_4925.jpg
Kirk
Last edited by Kaellis991 on Sun Aug 14, 2022 5:39 pm, edited 1 time in total.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#2 Post by jph »

Hi Kirk, what do you mean by a "ULN relay Output" ?
You mean the open collector ? -
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#3 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 5:37 pm Hi Kirk, what do you mean by a "ULN relay Output" ?
You mean the open collector ? -
Hey Joe,

I think that's what I mean. I get confused about emitters, collectors, bases, etc. All I can get my head wrapped around is that there is an input side and an output side on the ULN2803a.
ULN2803a pin 1 is an input (as are others on that side) and the corresponding output is pin 18. Which I understand allows for the GND connection to the LED to be connected.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#4 Post by jph »

Yeah, thats about right. Probably better to avoid the term 'relay' here unless you are actually using a relay. The 2803A doesn't really care what is on it's outputs.
If you think of how an NPN transistor works then all the outputs of the 2803 are are simply the collector of an NPN transistor that is connected to nothing - hence the term 'open collector output' . (ignoring the transient suppression / flyback diode)

Anything connected to the open collector output - in that case and with that pin it is 1C (c for collector) - will be grounded when a logic 1 is presented to 1B (b for 'base' ) of the transistor darlington pair.

Your circuit is fine as far as turning on the led goes and the led should light when the pin on the arduino connected to 1B is 'high'.

I just happen to have a breadboard at the side of me with a pi Pico and a ULN2803a on it as well. I have been using this most of the day experimenting with it as hardware PWM buffers. :D

a transistor is really simply in concept, well, a basic NPN. a little bit of current from the 'base' pin to the 'emitter' pin will cause a LOT of current to flow from the 'collector' pin to the emitter pin. Thats it really. in most cases with a transistor the 'gain' - how much base - emitter current causes a correspondingly larger collector to emitter current to flow is in the order of 50 to several hundred times greater, but by using 2 transistors in a darlington arrangement the 'gain' is massive, in the many thousands of times so we just think of it as a switch. a signal at B1 (pin 1) causes anything connected to C1 (pin 18) to be conducted to gnd.
Joe
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#5 Post by Kaellis991 »

If I have this wired correctly, then the sensor works backwards than when I had it hooked up to the LED without the ULN array.
While going through the ULN the LED stays lit when nothing is interacting with the sensor. When the sensor is activated, (second image) the LED goes off.
Backwards it seems....

Edit: But that makes sense when I read that these sensors are supposed to output LOW rather than HIGH when activated.
IMG_4926.jpg
IMG_4927.jpg

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#6 Post by jph »

That will just be the arduino code, post the code and I will have a look. You can invert the B1 output in code.

What is the state of the sensor output pin when uncovered and covered ? - the pin that goes to the arduino... (edit - yeah, just read your edit, that sounds right, its easy to invert in code)

Just to show you are not the only one with a 2803 on his lap today haha :lol: - a little 4 euro PICO running at a staggering 240MHz ! with Hardware PWM on all GPIO pins. - this is going to a 2803 acting as a PWM buffer / driver for dimming bulbs etc.
pico.jpg
Joe. CISSP, MSc.

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#7 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 5:53 pm Yeah, thats about right. Probably better to avoid the term 'relay' here unless you are actually using a relay. The 2803A doesn't really care what is on it's outputs.
If you think of how an NPN transistor works then all the outputs of the 2803 are are simply the collector of an NPN transistor that is connected to nothing - hence the term 'open collector output' . (ignoring the transient suppression / flyback diode)

Anything connected to the open collector output - in that case and with that pin it is 1C (c for collector) - will be grounded when a logic 1 is presented to 1B (b for 'base' ) of the transistor darlington pair.

Your circuit is fine as far as turning on the led goes and the led should light when the pin on the arduino connected to 1B is 'high'.

I just happen to have a breadboard at the side of me with a pi Pico and a ULN2803a on it as well. I have been using this most of the day experimenting with it as hardware PWM buffers. :D

a transistor is really simply in concept, well, a basic NPN. a little bit of current from the 'base' pin to the 'emitter' pin will cause a LOT of current to flow from the 'collector' pin to the emitter pin. Thats it really. in most cases with a transistor the 'gain' - how much base - emitter current causes a correspondingly larger collector to emitter current to flow is in the order of 50 to several hundred times greater, but by using 2 transistors in a darlington arrangement the 'gain' is massive, in the many thousands of times so we just think of it as a switch. a signal at B1 (pin 1) causes anything connected to C1 (pin 18) to be conducted to gnd.
Joe
Joe,

So when I read in the descriptions about this darlington transistor it is often referred to as "ULN2803 Relay Driver". Is that technically incorrect?

Kaellis991
Posts: 581
Joined: Mon Sep 07, 2020 8:49 am

Re: Confusion with ULN2803 and IR sensor power

#8 Post by Kaellis991 »

jph wrote: Sun Aug 14, 2022 6:06 pm That will just be the arduino code, post the code and I will have a look. You can invert the B1 output in code.

What is the state of the sensor output pin when uncovered and covered ? - the pin that goes to the arduino... (edit - yeah, just read your edit, that sounds right, its easy to invert in code)

Just to show you are not the only one with a 2803 on his lap today haha :lol: - a little 4 euro PICO running at a staggering 240MHz ! with Hardware PWM on all GPIO pins. - this is going to a 2803 acting as a PWM buffer / driver for dimming bulbs etc.
pico.jpg
The code prints false when the sensor is activated....i.e. covered.

P.S. what you are working on is way beyond my pay grade....
image.png

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#9 Post by jph »

Yes, technically it is incorrect, it is a 'darlington driver array'

One of its many features is certainly for driving inductive loads - such as relays - as it has the built in flyback diodes on the 'com' rail so saves adding one for each inductive load. You can see on the list of 'suggested' uses it can be used for anything really.
I found a box of 50 genuine toshiba ones in a box under the bench the other day, I bought them in the UK and had them on the boat so they have to be over 20 years old now. Amazing device. Really useful.
For AM, for the smaller hardware boards, I would stop buying anything apart from the PICO as they are just light years ahead of the competition and cheaper. If you ever play around with the arduino IDE they are truly awesome bits of kit also. The leonardo, nano, micro etc are history really. Crazy cheap.

Here's a bit from the thing you don't like - the datasheet haha - well, one of them, there are loads but they are all basically the same This datasheet is actually from TI.
Image1.jpg
Joe. CISSP, MSc.

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Confusion with ULN2803 and IR sensor power

#10 Post by jph »

oh, for the code, I was thinking it was arduino, but its lua lol,
in the function that receives 'state' you can remove the print for testing (or leave it) and add (in Air Manager)

log(state)
state = state ~ 1
log(state)

You can remove the 'log()' s later as well after debug

the state = state ~ 1 simply inverts the 'state' so if its a 0 its now a 1 and visa versa

it is just a bitwise exclusive or (XOR)

it saves using if else etc..

Joe
Joe. CISSP, MSc.

Post Reply