Relay Switching - [SOLVED]

I am building a cooling fan controller for my pickup, i need to switch 2 relays. Curious if the below diagram will work. Also not sure which transistors, diodes to use.
And what is the best way to regulate the vehicles voltage?(alternator generally produces charge around 13.6v) I am guessing i will need some sort of dc-dc regulator?
I do want to note that i am not using the Arduino, simply using the atmega328p which i do not believe can handle much more than 5v.

The relays are 12v 30amp Automotive Relays.

Removed Image: See below

The circuit you have should work if you provide the support circuits that the 386 needs and your relays work at 5V and considerably less than 500 mA.

You can use a linear 5V regulator to get 5V from your car power but it's likely to get HOT. A dc-to-dc converter would waste less power and get less hot.

Don't forget bypass capacitors at the 386.

You can leave Aref open, but AVcc should be connected to VCC. Even if you don't use the analog inputs.

A 7805 regulator can be used for the 5V. But it gets hot if the ATmega328p has to drive a high currents.

So the relays are able to switch 30A, but what current do they need ? Perhaps you can measure that.
You could use "logic level" mosfets, instead of transistors or darlington transistors.
A transistor needs current for the base, but mosfets don't need current to switch them on.

You are using the internal oscillator ? Since you have no crystal.
How will you program it ? You need a connector for that.

Krodal:
So the relays are able to switch 30A, but what current do they need ? Perhaps you can measure that.
You could use "logic level" mosfets, instead of transistors or darlington transistors.
A transistor needs current for the base, but mosfets don't need current to switch them on.

You are using the internal oscillator ? Since you have no crystal.
How will you program it ? You need a connector for that.

The Relays are 30amp, 12vdc Automotive Relays, I measured the current of the relay coil and the coil current is 183.9 milliamps.(each relay) The Relays current was 150mA with vehicle off) Would regulating the voltage to 12v before it enters the transistor work?realistic?
I prefer to use better components if possible, I don't know much about much about mosfets. Could you recommend a good choice for my application?
I was thinking possibly a tip102 would work ok? (not to sure how to read these but it looks as if the tip102 can only handle 80mA)Single Bipolar Transistors | Bipolar (BJT) | Transistors | Electronic Components Distributor DigiKey
I also measured the voltage of the vehicle and it voltage ranges from 10.9 cranking to 14.8 under load. Is this going to cause problems when using a 7805?

I am using the internal oscillator, and i have a ftdi cable. I have already successfully been able to program and have the chip function on the breadboard.

Thanks again.

The battery voltage changing from 10.9 to 14.8 is no problem at all. Not for the 7805 and not for the transistors and not for the relays.
But I would add a fuse. If your circuit accidently causes a shortcut, you don't want the wires to become hot glowing.

The TIP102 can do 8A continuously, and 15A peak according to the datasheet.
It is a darlington transistor, so it needs very little base current (good), but has a larger voltage drop (not a big problem).
You have to calculate the base resistor.
Suppose the load is 200mA. At 200mA the hFE is 900 (datasheet).
200mA / 900 = 0.22mA
For saturation 30% is added : 0.22mA * 1.30 = 0.29mA
The VBE could be 2.8V
So the resistor is (5 - 2.8 ) / 0.29mA = 7k6
Calculation (copy whole link) : (5-2.8)/(0.2/900*1.30) - Google Search
But since the base current is allowed to be 1A, I would choose a resistor of 4k7 (or even 2k2).

Any "logic level" mosfet that can handle the current will do.
You can search Ebay for : logic mosfet
I have a bunch of RFP12N10L for this kind of loads, because they were cheap at that moment.
It is best to have a resistor from the Arduino to the gate of 1k for the capacitance of the mosfet.
And a resistor of 10k from the Arduino to ground, to keep it low during power up.

Using a transistor or darlington transistor is simpler, so I advise to start with that TIP102.
You could also use the TIP120, it's about the same as the TIP102 : http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1218993473
I have checked the datasheet, and the base resistor calculation turnes out the be almost the same.

If you use a transistor or a mosfet, you need a flyback diode over the relay.

Thanks for all the great info. I think I will give it a go and repost an updated diagram before testing. Maybe someone can take a look before I burn something up.
Again thanks for everyone's help.

Ok, have almost everything working. Only problem is I need to analog read the voltage of the a/c compressor command from the vehicle.
The voltage will vary from 14.9 to 11.0 I only need to know if the vehicles output is High or low. I am assuming I can just install a resistor between the vehicles a/c command and the A0 arduino pin. What size resistor would allow safe operation without suppling to many volts to the atmega328p?

Use a voltage divider.
Like 10k to a/c compressor and 15k to ground.
Even if you only want to know high or low, you still can use an analog input with analogRead(). With an analog input, choose 10k and 22k.

Thanks :slight_smile: I appreciate all the help. I will probably just use a digital input anyway. Not sure why I said analogRead.

In case anyone was wondering and/or willing to take a look. Here is my final diagram, everything seems to be working, just curious if anything is incorrect or if different size/range resistors/capacitors would be better. Thanks again for everyone's help.

Let me know if anything is not clear with the diagram, my paint skills are not spectacular. :slight_smile:

See below post for updated Pic.

I don't know how the sensor is powered. Is that 10k going to ground, or should it go to +5V ?

You forgot the flyback diodes over the load.
http://www.siongboon.com/projects/2006-06-19_switch/ (search for flyback).
http://www.rentron.com/PICX6.htm (search for diode)

The 7805 needs 100nF on input and output.

The +5V has only 10uF and two 10nF. Can you make it 100uF and two 100nF ?
The 100uF can be shared by the 7805 and the ATmega328.
It might also be 22uF, but 10uF seems to me just a little to small.

I think D13 is not working. If the switch is to ground, the resistor of 10k should be a pull-up to 5V.

D12 has no pull-up? The internal pull-up is 20k. The switch will pull it down with 25k, the result is unpredictable.

I forgot the diodes in the diagram but used them in the actual board.

From what I understand I should switch out the 100uf and 10uf caps at the voltage regulator with 100nf caps.

the +5v you i am assuming is the output of the voltage regulator into the atmega328p, currently i have .01uf caps both on the left and right side of the caps -- should I change these to 100uf and 100nf caps? I believe I fixed the resistor at D13 and D12.

Sorry I am a newb. 1st project. Thanks again for your time. Here is a updated diagram.
Removed Image: see below

Use two 100nF next (close) to the 7805.
And one (better two) 100nF at the ATmega328.
Somewhere should be a larger capacitor. So 100uF at the 12V of the 7805 is good, but also 100uF at the +5V is needed.

Sorry, but the D12 and D13 are not fixed. Normally is switch to ground, and pull-up resistor to +5V.
At D13, both the resistor and the switch go to +5V.
Pin D12, I don't understand what you want there. I have attached a drawing, but I don't know if that is what you need.
Is Pin A0 getting the full +12V ? If so, the ATmega328 will be broken instantly.

If you make your drawing with a bottom line as ground. The picture will become three times as large, but better to understand.

input12V.png

I think I understand the capacitors, I updated a diagram and took your advice. All Grounds should be on the bottom now.
I also color coded everything:
Red = approx 12vDC - From Vehicle (varies with alternator output from 11 - 14.8)
Orange = 5vDC Regulated voltage
Black = Ground

I think i fixed D13 and D12 - I rerouted some ports on the atmega to allow for easier to read schematic.
Pin A0 only receives 5v or less regulated voltage from the vehicles engine computer.

I included a smaller and larger picture of the schematic as well as the fritzing file, if needed.

Does everything look good now? Thanks.

https://dl.dropbox.com/u/31940398/CarFinalR1.pngLarger Schematic Image
https://dl.dropbox.com/u/31940398/CarFinalR1.fzzFritzing File

My advice to have a single line at the bottom for ground was wrong. Sorry.
You use the ground symbol, that makes it a lot easier.

I still don't understand how you use the incoming signals.
The resistor at the /RESET line was to ground, it should be to Vcc.
You connected Aref to Vcc, but the most standard way is to keep that open, with a capacitor to ground.
The 7805 must have those 100nF capacitors close to it, so I placed them next to it in the drawing.

I tried Fritzing a few times, so I gave it a try.
Now the picture is a lot larger, but the layout is more standard.
You can use my fritzing file if you like it.

CarInProgress.fzz (52.6 KB)

Thanks again, really appreciate all the help. I soldered most of it up last night. I will give it a go tomorrow and see if I put it together correctly. :slight_smile:

Well it isn't the prettiest build ever but it WORKS!!(so far). All wired into the truck and it does its job.
Field testing this weekend, we will see if it stands up to the harsh off-roading and high temp conditions.
Thanks again to everyone that helped out the FNG! :slight_smile: