Go Down

### Topic: Using an op amp as a voltage comparator (Read 3942 times)previous topic - next topic

#### AKRichard

#30
##### Apr 03, 2018, 07:52 amLast Edit: Apr 03, 2018, 08:11 am by AKRichard
Quote
You are trying to HIGH SIDE SWITCH so you will need a PNP and a NPN.
Like this;
TomGeorge,  I put the circuit together the way you had it drawn and the new transistors work like a charm,  the relays are working as they should.  In fact the entire circuit appears to be working as it should.  Thank you for that.

Quote
If you have an Ohm meter, you can measure the coil resistance of your relay.  The static coil current will be the vehicle's nominal system voltage, about 14.5 V when running, divided by this resistance.  I'd expect the coil resistance to be something like 50 to 100 Ohms, so a nominal coil current on the order of 200 mA.

One thing that follows from this is that a 2N3906 PNP transistor has specified performance to 100 mA, so you probably want to select a part with higher current capacity.
I am going to measure the resistance across the coil tonight and see if I can calculate what size of resistors I should be using.  Im going to hook the breadboard up to my bench motor and try it out.  If everything continues working as it should, then its on to the next step, add the circuitry to monitor the batteries so that it can figure out for itself when to start and stop the motor.  I have a few ideas on how I might achieve this end, so we will see.

Unless I have difficulty calculating the resistor sizes myself, Id have to say that my problem has been solved and I learned a little bit more along the way.  Id like to thank you all for taking the time to help out.  It is appreciated.  I have a included a schematic of the circuit as I have it now, it has a .fzz extension to it (created with the fritzing software).
Why do poptarts have artificial fruit flavoring if they have real fruit filling?

#### avr_fred

#31
##### Apr 04, 2018, 03:41 amLast Edit: Apr 04, 2018, 11:26 pm by avr_fred
LED3 and LED4 are wired incorrectly, you cannot mix your 12 volt and 5 volt supplies in that way. The LED's need to be powered from the 12volt rail with the appropriately higher value resistor. You've also omitted the very necessary free wheeling diodes across the relay coils. The PNP transistors may/will fail in short order, depending upon the device type.

PS: please don't promote bad schematic habits with Fritizing, like drawing diodes and ground symbols upside down. That software is a waste of everybody's time and energy. Either use a real schematic editor or draw them by hand which highly preferable over fritzzy silliness.

#### larryd

#32
##### Apr 04, 2018, 04:55 am
Click on the image for full resolution.
No technical PMs.
If you are asked a question, please respond with an answer.
If you need clarification, ask for help.

#### AKRichard

#33
##### Apr 04, 2018, 07:53 amLast Edit: Apr 04, 2018, 07:53 am by AKRichard
LED3 and LED4 are wired incorrectly, you cannot mix your 12 volt and 5 volt supplies in that way. The LED's need to be powered from the 12volt rail with the appropriately higher value resistor. You've also omitted the very necessary free wheeling diodes across the relay coils. The PNP transistors may/will fail in short order, depending upon the device type.

PS: please don't promote bad schematic habits with Fritizing, like drawing diodes and ground symbols upside down. That software is a waste of everybody's time and energy. Either use a real schematic editor or draw them by hand which highly preferable over fritzzy silliness.
I forgot to include the diodes in the schematic they are in the circuit though.  About the led's though, that brings up the question of I am powering the arduino directly off of the 12v batteries through the 2.5mm jack.  You mentioned I shouldnt mix the voltages like that, is that just for the positive side, the reason I ask is because everything goes to the ground rail on the breadboard (no matter if its being fed from the +5 or +12 supplies).  Even though the led's work the way I have them wired, I want to follow best practices.  So if I figiure 12v starting voltage down to 5v at about 20 ma Id need about a 350ohm resistor?

No problem about the schematic.  Ill look around for something better.
Why do poptarts have artificial fruit flavoring if they have real fruit filling?

#### MarkT

#34
##### Apr 04, 2018, 12:41 pmLast Edit: Apr 04, 2018, 12:43 pm by MarkT
Why not power the LEDs from the Arduino pin through a 1k resistor - you are allowed to drive both a
transistor and an LED from the same pin, so long as total current is within the limit.  You only need one
transistor per pin to drive the relay.

So pin -> 220 ohm resistor to NPN base, relay + diode between collector and +12V, emitter to ground.
(This is the standard circuit to drive a relay, lots of examples out there).
Add LED + its 1k resistor from the Arduino pin to ground.

Much simpler, and saves 4 resistors and 2 transistors!
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

#### AKRichard

#35
##### Apr 05, 2018, 05:36 am
Why not power the LEDs from the Arduino pin through a 1k resistor - you are allowed to drive both a
transistor and an LED from the same pin, so long as total current is within the limit.  You only need one
transistor per pin to drive the relay.

So pin -> 220 ohm resistor to NPN base, relay + diode between collector and +12V, emitter to ground.
(This is the standard circuit to drive a relay, lots of examples out there).
Add LED + its 1k resistor from the Arduino pin to ground.

Much simpler, and saves 4 resistors and 2 transistors!
I tried to get the one trasnsistor setup to work but never could get the full 12v out of it, but I didnt have it hooked up quite the way youre talking about, Ill give it a try tonight.  Anything that saves on parts and pieces would be a savings at this point.  The breadboard is already getting crowded and all I have is the circuitry in this post plus the battery monitoring circuitry that im tryin out
Why do poptarts have artificial fruit flavoring if they have real fruit filling?

#### MarkT

#36
##### Apr 05, 2018, 01:51 pm
I tried to get the one trasnsistor setup to work but never could get the full 12v out of it, but I didnt have it hooked up quite the way youre talking about, Ill give it a try tonight.
Then you probably were using the wrong circuit or not providing enough base current.  Switching
uses the common-emitter configuration, and base current needs to be 5 to 10% of load (collector) current
with a BJT.
[ I DO NOT respond to personal messages, I WILL delete them unread, use the forum please ]

#### gmcmurry

#37
##### Apr 06, 2018, 08:40 am
Go on Ebay and buy a couple of  ZVN4206A relay drivers.  They work like an npn transistor (2N2222) but don't need any additional components.  No resistors, no diodes.  All that stuff is built in.

Then go back to Ebay and buy a couple 12v auto relays with sockets.  They are real easy to hook up.

As the previous post suggests, I don't understand why you think you need a comparator.

Just hook up your relays to the Arduino using the ZVN4206A relay drivers.  If you can't figure that out, I would be happy to make you a drawing.

I think the best free software to draw schematics is ExpressPCB.  You can download both PCB layout software and Schematic software for free.  All you need is the schematic software (but you will get both)

The schematic software will allow you to export the drawing as a BMP file.  Bob's your Uncle..

Greg

#### AKRichard

#38
##### Apr 06, 2018, 01:58 pm
Quote
Just hook up your relays to the Arduino using the ZVN4206A relay drivers.  If you can't figure that out, I would be happy to make you a drawing.
I just looked up the spec sheet for the ZVN4206A and have just a few questions.  One the pins are labeled dgs  is that for drain, ground, and source.  hook up would be source to +12v, drain to relay coil, and ground to one of the arduino pins? assuming that is correct I would shut it down by switching the pin its on to high? and I can turn it completely on/off with the 5v from the arduino?

If thats the case, Ill by them right now (pack of 50 for 20 bucks heck ya).

Quote
Then go back to Ebay and buy a couple 12v auto relays with sockets.  They are real easy to hook up.
I already have the relays Im going to use wired in under the dash,  Ive been using them for a few years now, but I have the run relay wired to a toggle switch, and the start relay is controlled by a momentary contact button that is supplied with power through the aforementioned toggle switch.

Quote
I think the best free software to draw schematics is ExpressPCB.  You can download both PCB layout software and Schematic software for free.  All you need is the schematic software (but you will get both)

Ill check them out, thanks for the info.

Quote
Then you probably were using the wrong circuit or not providing enough base current.  Switching
uses the common-emitter configuration, and base current needs to be 5 to 10% of load (collector) current
with a BJT.

I didnt have a chance yet to try it out the way you are talking yet, I will as soon as I get a chance life is just getting in the way at the moment and demanding most of my time.

Why do poptarts have artificial fruit flavoring if they have real fruit filling?

#### gmcmurry

#39
##### Apr 06, 2018, 04:18 pm
Here is the Application Note for the ZVN4206

http://www.gregssandbox.com/arduino/ZVN4206AV%20relay%20mosfet%20Application.pdf

Yes you hook it up as an open collector device.  D=Collector G=Base S=emitter

+12 to the relay coil
D to the relay coil
G to the Arduino Pin  (High will turn it on)
S to ground

Hold the device with the flat side towards you and the legs down.

S G D

#### AKRichard

#40
##### Apr 25, 2018, 11:23 am
Hello again all,

Thanks for all the help yall have givin so far.  The project is up and running correctly.  I have the basic board built and running on the test bench and fixing to install it in the vehicle.  I have it running correctly using the transistors to run the relays.  The software side of it has been completely refactored and I wrote a little program in visual studio to monitor everything since all it has are the leds for visual indicators (and it will change the various settings while it is in operation without recompiling and uploading to the arduino). I will upload a schematic, the sketch, and the monitoring program a little later.  However, Id like to change it.

The project as it sits now, how 4 leds to show the various states it is in, and two buttons to effect changes, but using the two buttons to make the changes makes it difficult to make those changes (especially with just the leds for indicators).  Id like to have multiple buttons but dont want to take up a bunch of the arduino pins, so I was thinking what if I took a series of buttons, hook the first straight to the +5v supply, and run the power in series from there with resistors between each so that when it was pushed each button would show a different voltage at the pin.  I could theoretically have 1000+ buttons on a single pin then.  However, I ran a quick test on the concept and am running into the problem that the same button doesnt allways show the sasme reading (in fact sometimes I has a difference of 20+).  Im thinking that is probably because it depends on how many of the pins are allready outputting part of the current and not leaving me with the full at the supply pin, or am I missing something?  as it stands now I could still use it but Id have to leave a pretty wide set of readings for each pin (you know check for say between 651 and 680 for one button and between 681 and 710 for the next), or run a dedicated power supply just for the buttons that way it shouldnt fluctuate.

So basically Im just asking for yalls thoughts, multiple buttons would make it easier to change the settings, and the way I have the program working at the moment it requires both buttons to be pushed at times, is their a way to achieve that with the way Im talking about having all the buttoins go to the same pin?
Why do poptarts have artificial fruit flavoring if they have real fruit filling?

#### AKRichard

#41
##### Apr 25, 2018, 06:01 pm
Here is the current schematic of the circuits I have built and operational so far, as well as both the code for the sketch and the visual studio project for monitoring the sketch and changing various elements in the sketch.

Why do poptarts have artificial fruit flavoring if they have real fruit filling?

Go Up