08M2 + LM317LZ switching an NPN, noob, baffled, stuck.

caitlin

New Member
So I've done my best, but I'm very new to this.
Hopefully here's a picture:
circuit.png

When everything is powered from 3 AA batteries the circuit works as I expect. When pin 4 goes high, the transistor shuts off, when pin 4 goes low it switches back on.
I plan to read in a sensor value on a different pin and use that to decide whether to wiggle pin 4 or not, that transistor is hopefully going to poke a relay instead of an LED and thereby allow a bunch of current to flow to a motor.

The problem arises when I have the circuit as in the image, I've metered the output of the LM317LZ and it's almost bang on 5V.
The voltage around pin 4 is silly though and I don't understand enough of this to know why. I seem to be completely failing to isolate my voltages, and I fear I'm trying to sink 12V through pin4 which can only end badly.

Can anyone offer either advice, or a phrase I could web search on to try and understand this better. I'm not really here to ask for a magic fix, but also to try and increase my understanding of how these little wire bits fit together.
 

oracacle

Senior Member
you output should be between 12v and the transistor and the transistor and 0v.
you will need a back emf diode when you use a relay.
also add some capacitors around the regulator and close between the picaxe power pins
 

Pongo

Senior Member
The transistor is configured as an emitter follower. The voltage on the emitter will be no higher than the (voltage on the base - 0.7 volts) = max 4.3 volts, leaving 7.7 volts across the transistor. Unless you have a low voltage relay it would be better to ground the emitter, and connect the relay between the collector and the 12 volt rail (common emitter configuration).

I'm not familiar with the 08M2 but doesn't it need a resistor to ground on the serial input pin to function?
 

AllyCat

Senior Member
Hi,

Welcome to the forum. Yes at some time you should add capacitors across the supply rails or you may get very unreliable or unpredictable measurements or operation. But ....

When pin 4 goes high, the transistor shuts off, when pin 4 goes low it switches back on.
That's not what I would expect to happen, but what is making "Pin 4" go high and low? The diagram shows "Leg 4" (in PICaxe terminology) connected to the transistor, but that pin is "Input only". In program terms Pin 4 (strictly Port.pin = C.4) is Leg 3.

The voltage around pin 4 is silly though and I don't understand enough of this to know why. I seem to be completely failing to isolate my voltages, and I fear I'm trying to sink 12V through pin4 which can only end badly.
The transistor is wired as an "Emitter follower" which does not give any voltage gain, i.e. the emitter voltage roughly follows the input (base) voltage. If you need to control a 12 volt signal, the emitter should be connected to ground and the "load" (LED + resistor or a relay, etc.) between the collector and the 12 volt rail. If the load is inductive (e.g. includes a wound coil, like a relay) then check out the way to add a "flywheel" diode and decoupling capacitors before applying any power.

And yes, the PICaxe needs a pull down-circuit on the programming input (Leg 2).

Cheers, Alan.
 

caitlin

New Member
Apologies to all posters, that was a critical omission on my part, the microcontroller is on a prototype board which contains the support circuitry for the serial.
You will also be correct that it's C.4 (pin 3?!) which is connected in the circuit not literally pin 4, again this is because I have the chip in the programming board which is doing some redirection. The pin labelled '4' on that board runs to pin 3 on the chip.

So I've just re-jigged the circuit, and I now have a 0.1uF cap between Vin of the Lreg and ground and a 2.2uF cap between Vout and ground.
I tied the emitter of the BC557 directly to ground, and put the led and resistor between the collector and 12V

Now the LED permanently lights, but when the sensor pin is activated on the 08M2 I can see the brightness modulate as the C.4 pin is switched between low and high.

This constitutes a significant improvement, but obviously the desired behaviour is full shutoff of the transistor and I'm not sure how to achieve that.

I can redraw the circuit including these modifications and the support components on the programming board, if that would be useful.

I will certainly make sure I get a diode in the circuit before moving on to connect a relay.
 

AllyCat

Senior Member
Hi,

The BC557 is a PNP, which could certainly explain the LED only dimming (base-collector junction acting as a forward diode). Otherwise, what you describe (with a BC54x NPN or similar) should work, but there might be another "unknown" on the prototype board.

Cheers, Alan.
 

caitlin

New Member
Hi,

The BC557 is a PNP, which could certainly explain the LED only dimming (base-collector junction acting as a forward diode). Otherwise, what you describe (with a BC54x NPN or similar) should work, but there might be another "unknown" on the prototype board.

Cheers, Alan.
When you buy a load of components 3 years ago, and label them... then... when it's 3 years later, try looking up the part numbers rather than trusting the idiot who wrote 'NPN' on the pnp ones and 'PNP' on the npn ones.

I am in your debt, and can only apologise to the other people who have been so helpful in this thread.
I believe I now have a circuit that will do what I need it to.

I have some 1N4001 and some 1N4148 diodes, and a short web search suggests the former may work. So I think I'm covered for relay switching.

Thanks again everyone.
 
Top