Switching a 12V Relay from an Atmel AT89s52, when the P0.0 port goes 'low' - 0V

Status
Not open for further replies.

wicus

Junior Member level 1
Joined
Apr 16, 2009
Messages
15
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Cape Town, South Africa
Visit site
Activity points
1,407
I'm still struggling with this. My AT89S52 Switches to LOW (0V) to activate the output, which is connected at this stage via an LED to +v5. I need to replace the LED with a 12V relay, and assume I will have to use a small PNP Transistor i.e 2N2907/BC177 combined with a NPN TIP31C/TIP41C etc to switch the relay
.
I've done it like in the attached image but cannot get the 12V relay to switch. It works as soon as I take out the relay and transistors, and replace it with a 1.4V LED and resistor, to show that my ATMEL is programmed correctly

Any ideas what could be wrong here ? ?
 

Attachments

  • AT89-PNP.jpg
    104.5 KB · Views: 186

hai

1. Add a resister from +5V to base of Q1 (let the resistance be higher or equal to R9).
2. Add a resister from collector of Q1 to GND (resistance be higher than R18)

Thanks
 

Thank you karthikkrv85. I've changed as suggested - with a 1K resistor between Collector Q1 and GND, and Resistor between Base of Q1 and +5V - Will the 1K be ok as shown in the attachement ?

 

Attachments

  • AT89-PNP-modified.jpg
    126.4 KB · Views: 150

Still no joy at all. I've tested the TIP31C (NPN) and the 2N2907 (PNP) and it's ok - not faulty. I anyway replaced them with 2 brand new ones, but still the same . I've also verified the Pin Layouts , which is also OK. The 12V from the L7812 and the 5V from the L7805 is also correct.

---------- Post added at 15:43 ---------- Previous post was at 15:25 ----------

This is my complete circuit - The idea will be to have a 12V relay on each of the ports of P0.0-7. When I test with LED's it's fine, but I don't get the Relay's to switch.
 

Attachments

  • Complete_Circuit.jpg
    201.9 KB · Views: 188
Last edited:


Hai... port 0 need external pull up. Have you tried with external pull up resister? The internal pull up will be activated only external memory access mode.
 

Do you know how much current your relay coil draws?
I think the problem is because of the resistor R26 which is not allowing sufficient current. Remove R26 and connect that end of the relay directly to +12v. That should do it.

Hope this helps.
Tahmid.

---------- Post added at 11:49 ---------- Previous post was at 11:47 ----------

You should also have a diode across the relay. Maybe you're damaging the transistor. The anode of the diode should be connected to the collector of Q9, the cathode should be connected to +12v.

Hope this helps.
Tahmid.
 

The general idea of the circuit is not wrong.
I used using it (with minor modifications) in most projects I need driving a relay.
First, I measure the DC resistance of the relay coil, say R_coil.
Ic9 of Q9 = Vcc / R_coil
I start with Ib9 = Ic9 /20 to let Q9 saturated
I usally don't leave a transitor base floating, so from Q9 base to ground I add a resistor Rb9 so that its current 0.7 / Rb9 is not less than Ib9 / 10
Now the current in R18 is equal to Ib9 + 0.7 / Rb9 (R34 is not needed) which could be labelled as Ic1.
The same reasoning can be followed to calculate R9 (between Q1 base and 5V) and R9 (between Q1 base and MCU pin).

This works but it may be not enough in some important projects in which the relay should stay off till the MCU gets all control of the board. This depends on the rise time of the 5V supply. The ratio of the R9 values at the Q1 base can be adjusted so that Q1 will not turn on till Vcc (5V) reaches about 2.7V or higher (below which the MCU pin could be at zero volt), otherwise adding a capacitor may be needed (and possibly a discharging small diode when Vcc is off... this is another story).

So let us start, as our friend Tahmid already pointed it out, by measuring the DC resistance of the relay coil :wink:

Kerim
 

To avoid high voltage spikes when turning off the relay, a freewheeling diode across the relay coil is needed (if not integrated into the relay itself). Otherwise this spike can create problems in the microcontroller (e.g. reset or changes of RAM cells). Another option is to use an integrated relay drive (**broken link removed** ).

Enjoy your design work!
 

Add one 10Kohm Resistor in P0.0 pin with other connected to 5V, Second remove R26, you are not required that one, Also add one general purpose diaode with the Relay, Diode Cathode should be connected to coil end which is connected to +12V and Anode must be connected to coil other end.

It will work fine, try this
 

I've tried all the advice give, with no joy, BUT I think I found the problem

The +12V I'm using is coming from a source which I don't any control over. It's part of an existing power supply which is a given, and not something I can change. I discovered that as soon as the relay try to operate, the +12V drops to +9.2V, which is not sufficient to operate the relay, and that is why it's working when I replace the Relay with LED's , because the LED's don't use as much power as the Relay. So, the circuit is working with LED's but not using the relay. This relay uses about 1.2A (1200ma) to operate, and the existing 12V source can only handle 300ma, and this is where the problem comes in.

I'm busy building an irrigation computer where each of the 32 output ports of the AT89S52 will drive a 12V Relay, which itself switch through 220V/5Amps on the relay contacts.

My other option is to use a SCR i.e C106D which i can connect to the AT89S52, and which can switch through th2 220V 5Amp. From what I understand about SCR's - NEVER worked with them before - is that the microcontroller will be able to switch it on/of as it requires very little Amps to the gate to be able to activate/deactivate it.

Question: Like I've said, I never worked with SCR's before. What can be used between the AT89S52 and +5V (p0.0 is ON when it is at a low) that can operate from the +5V, and also be able to switch through about 5A for the irrigation pumps ? SCR or triac or Thyristor ? I don't know what is the best option to be able to google it myself

Any feedback highly appreciated
Kind Regards
 

The best and most easy way is add an opto coupler in paralel or series to your led and the output transistor will take care off everthing
dont need any more calculations or resistors or considring other problems like noise spikes or what ever.
if u use darlington opto its better and then add opto in series to led
good luck.
 

For 5A 220V as load, being controlled by a +5V source (microcontroller), I think it's best if you can use a triac. Direct driving a triac is a hassle especially for beginners, so it's better that you use an opto-isolator such as MOC3021, MOC3041 to drive the triac. Select the required opto-isolator depending on how you'll drive the triac. Before starting on this, you need to read quite a bit about triacs and opto-isolators. So start there.
Or you could buy a ready-made solid-state relay. Although these will be much more expensive, they'll be easier for you to use.

Hope this helps.
Tahmid.
 
Reactions: wicus

    wicus

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…