Arduino input using a transistor to drive LED

I have a project which uses 50+ (and growing) A1220LUA Hall effect sensors feeding an Arduino Mega or re-plugged using connectors (ATX 24 pin) to LEDs, the connectors also carry the appropriate power feed, only a few of the LEDs are on at any one time and both options work OK..
I would like the ability to combine both so that the LEDs operate at the same time as the Arduino. I’m not the brightest button when it comes to electronics and this is my first foray into transistors.
After some research I have come up with the following circuit (attached) which hopefully would work (see notes below) if the connection to the Arduino sensor was not included, I don’t know how to evaluate/design that final connection to ensure the LED works and the Arduino ‘sees’ the signal.
I currently use R1 rather than the Arduino pull-down due to distance and because of the LED circuit (when that is plugged), R2 is the LED resistor.
I’ve done quite a lot of research but only find cases where things are being driven by output pins and as single connections rather than as part of an input pin circuit (and involve splitting the signal).
The advantage (to me) of the above circuit is that the Arduino can be used in a passive way i.e. using it’s power supply only for build and test, the code for the Arduino (and RPi which it connects to) can be tested with known working circuits.
My question/problems are:

  1. Is my circuit viable or is my ignorance showing.
  2. What should R3 and R4 be and how are they calculated.
  3. What transistor should I use (I currently don’t have any).
  4. Can R4 be sufficient to protect the Arduino while building and testing.
    My current physical wiring is not fully compatible with the above circuit (i.e. the LED resistor is after the Hall effect switch and before the plug/socket) so I want to ensure that I don’t create even more rework for myself as I continue building.
    I would be grateful for any help and assistance but please keep it simple I haven’t got as far as theory yet (and I’m probably too old to do so).

Sorry, but I just do not understand most of your "tr-circuit".

I assume this for the A1220LUA Hall effect sensor, since no pin is labeled ...
a) Left most pin is +5 volts
b) Center pin is Signal Out
c) Right most pin is ground
d) R1 is the pull-up resistor

R1 could be, at least, 2 x ( 5 Volts / Max Output Current )

Q1) Where is the recommended 0.1uf bypass cap?
Q2) What is the purpose of the 9 Volts ?
Q3) What is the purpose of Resistor R4 ?
Q4) What is the purpose of Resistor R3 ?
Q5) What is the purpose of Resistor R2 ?
Q6) What is the purpose of the Transistor ?

OK, I think I see what you want to do.

R4, your "Protection Resistor", could be around 150 ohms.
R1, your "Pull-Up Resistor", could be around 10K = 5 Volts / 0.5 ma

I would flip the transistor 180°.
Put the Emitter at the Top and Collector at the bottom
And make it a PNP that can handle 20 Volts E-to-C and 100 ma Collector current, 2N3906 ?
Then use the Output of the Hall to Pull Low and turn Transistor and LED ON.

I assume the +9 Volts on your schematic, really means, LED then +9 Volts ? ? ?
Are you using one LED per Hall Effect Sensor?
R3, your Base Resistor, could be around 7.5K = 7 Volts / 1 ma
R2, your LED Resistor, could be around 360R = 7 Volts / 20 ma

Maybe, redraw your schematic to include the LED ?

and cut the wire across the transistor:

Many thanks for your ‘understanding’. It was a bit late last night and when doing the schematic from my scribbles managed to forget the LED and make the transistor look like a diode. I hope the revised schematic attached reflects what you said.
I have successfully driven both the Arduino and LEDs (independently) using the Hall sensors and experiment indicated that the uf was not required (the signals will be in a predictable sequence so if there are any spurious signals I can deal with them in the RPi) and yes, there is one LED per Hall sensor.
I like your formula for the resistors, even I can understand R=V/I versus the rather more complex calculations for the Base resistor that I have found, I assume your’s provides a good ballpark figure.
I have a couple of questions, purely for my own understanding:

  1. What is the (simple) rational for using a PNP rather than a NPN
  2. I assume your use of 7 volts allows for the voltage drop across the LED
  3. The 150 ohm R4 resistor, how did you come to that, experience? or could it be almost anything within a wide range?

Thanks once again, your input has given me enough confidence to try playing with some transistors and the circuit, I’ve just ordered 10 to play with.

I hope the revised schematic attached reflects what you said.

Nop.
No arrow on the emitter to show what type it is.

  1. What is the (simple) rational for using a PNP rather than a NPN

In that circuit it is simply a very bad design, it should be an NPN and the emitter and collector should be swapped over.

  1. The 150 ohm R4 resistor, how did you come to that

Calculation. You decide what current you want through the LED, normally 10 to 20mA but it could be something different.
You have an LED forward voltage drop from the data sheet but basically it goes off colour. The resistor takes the supply - what ever the LED drops. Then you calculate the resistor to give you the current you want with the voltage you have (ohms law)

Hi,

Why is OUT of the hall effect connected to gnd, and the Vss/gnd connected to arduino input.

Tom.... :slight_smile:

wrinkly_bob:
Many thanks for your ‘understanding’. It was a bit late last night and when doing the schematic from my scribbles managed to forget the LED and make the transistor look like a diode. I hope the revised schematic attached reflects what you said.
I have successfully driven both the Arduino and LEDs (independently) using the Hall sensors and experiment indicated that the uf was not required (the signals will be in a predictable sequence so if there are any spurious signals I can deal with them in the RPi) and yes, there is one LED per Hall sensor.
I like your formula for the resistors, even I can understand R=V/I versus the rather more complex calculations for the Base resistor that I have found, I assume your’s provides a good ballpark figure.
I have a couple of questions, purely for my own understanding:

  1. What is the (simple) rational for using a PNP rather than a NPN
  2. I assume your use of 7 volts allows for the voltage drop across the LED
  3. The 150 ohm R4 resistor, how did you come to that, experience? or could it be almost anything within a wide range?

Thanks once again, your input has given me enough confidence to try playing with some transistors and the circuit, I’ve just ordered 10 to play with.

You 2nd Schematic is not exactly what I was thinking ...

  1. AL1220UA - Left Pin is Vcc

  2. AL1220UA - Center Pin should be Vout, not Vss

  3. AL1220UA - Right Pin should be Gnd, not Vout

  4. When flipping the Transistor I had R2 between Collector and Ground.

  5. R1 could eventually be eliminated by using the Internal Pull-Up Resistor inside the Arduino

  6. R4 could eventually be eliminated after your "experimentation" phase is complete

  7. PNP Transistor should have an arrow pointing IN.

With R1 & R4 eliminated, leaves just R2 & R3 = quite simple.

Why PNP Transistor ?

  • I assumed Low Active when Hall Effect Sensor is ON
  • The Hall Effect Sensor will Sink Current when ON
  • Hall Effect On (Low Active) -> Transistor On -> LED On

If I am wrong about Low Active then ...

  • use your original NPN with emitter to ground circuit.
  • Math for R1 an R3 will be different -> must keep the Transistor ON
  • Hall Effect Sensor would then turn off the transistor, can only Sink 25 ma MAX

Why 150 ohms for R4 ?
5 Volts / 150 ohms = 33 milliamps
Absolute Maximum Rating for a Digital I/O Pin is 40 milliamps
33 milliamps is less than 40 milliamps

I am sure you can get either circuit working whether you select
the new Low Active Circuit #2 or
the original High Active Circuit #1.

@mrsummitville ,
Given the schematic on page 10 of the datasheet I linked, can you give any reason why the OP's circuit is necessary and why he shouldn't be using the schematic given on the datasheet (page10 figure 1-B) ?

raschemmel:
A1220LUA Hall Effect Sensor Datasheet (click Allegro PDF link-5th and 6th links)

SEE PAGE 10 Figure 1-B

I don't know where the OP got that design from (I think he just made it up) but it didn't come from the datasheet. As far as I can tell, he needs no support components. It is a standalone sensor and requires only 5V.(dc) and a 0.1 uf decoupling cap.

You are not understanding that the OP is using the Hall Effect Sensor to control BOTH the Digital I/O and
an LED via a +9 Volt supply.

I don't see any led in the OP's schematic

Why not use an NPN to sink the led current with a base resistor driven by the Out pin of the sensor ?
(with the led powered by the 9V with the proper current limiting resistor)

raschemmel:
@mrsummitville ,
Given the schematic on page 10 of the datasheet I linked, can you give any reason why the OP's circuit is necessary and why he shouldn't be using the schematic given on the datasheet (page10 figure 1-B) ?

Because I do not see an LED on page 10 figure 1-B.
Do you see BOTH a Digital I/O with a 5 Volt Pull-Up Resistor and an LED to +9 Volts on Page 10 figure 1-b?

Did you read the title of thread that states "Arduino input using a transistor to drive LED"?
Did you read OP's original message that states Digital Input and LED?

wrinkly_bob:
Many thanks for your ‘understanding’. It was a bit late last night and when doing the schematic from my scribbles managed to forget the LED and make the transistor look like a diode. I hope the revised schematic attached reflects what you said.
I have successfully driven both the Arduino and LEDs (independently) using the Hall sensors and experiment indicated that the uf was not required (the signals will be in a predictable sequence so if there are any spurious signals I can deal with them in the RPi) and yes, there is one LED per Hall sensor.
I like your formula for the resistors, even I can understand R=V/I versus the rather more complex calculations for the Base resistor that I have found, I assume your’s provides a good ballpark figure.
I have a couple of questions, purely for my own understanding:

  1. What is the (simple) rational for using a PNP rather than a NPN
  2. I assume your use of 7 volts allows for the voltage drop across the LED
  3. The 150 ohm R4 resistor, how did you come to that, experience? or could it be almost anything within a wide range?
    There may be an issue with my suggested Low Active circuit since you are using +9 Volts for the LED, not +5 Volts. A +5 V Pull-Up on teh base may not turn-off the transistor. Sorry.

Thanks once again, your input has given me enough confidence to try playing with some transistors and the circuit, I’ve just ordered 10 to play with.

mrsummitville
Thanks, the Low Active didn't work but did cause the LED to dim.
I managed to get hold of a npn S8050 and using the original, appropriate corrections and your comments got it to work fine, the Hall sensor both turning the LED on/off and Arduino sensor registering the state change. :slight_smile: :slight_smile: