arduino to PWM vac solenoid - Page 1
Forum section: electronics / beginners

author: Jbates58
author_rank: Regular Contributor
timestamp: October 13, 2016, 11:28:38 am
content: hi alljust a quick question,i am wanting to use an arduino to control a solenoid through PWM. i have the code and the hardware theory worked out, but just want to check a few thingsi will use the arduino to control a transistor for the solenoidthe solenoid coil is about 15ohms and it draws a touch over 1A @12v.it will be running at a max of 15V and a min of 11V (as its in a car)i just want to know if there is anything special i need to know, or do i just need to make sure that the transistor i get can support that much current consistantly?i am at the moment unsure what frequency or duty cycle it will be running at as i need to make the hardware to test it; if that matters.Jason

author: Seekonk
author_rank: Super Contributor
timestamp: October 13, 2016, 12:59:40 pm
content: Keeping things standard, I would use pins 5 or 6 which are set to 980Hz as the other are 490. That can be raised in frequency, but I would avoid using 5 & 6 as that changes other parts of the program that use the timing of these counters. Assume you will use a flyback diode on the coil.

author: danadak
author_rank: Super Contributor
timestamp: October 14, 2016, 01:06:22 am
content: The solenoid is pretty seriously inductive in nature, so PWMing it willnot be a simple Iavg vs DC relationship. Furthermore your swing trans-istor will have to have robust safe area capability due to transients.Regards, Dana.

author: Jbates58
author_rank: Regular Contributor
timestamp: October 14, 2016, 05:53:25 am
content: Quote from: Seekonk on October 13, 2016, 12:59:40 pmso are you saying that i should or shouldnt use pin 5 or 6? i can use either, i was actualy hoping to down scale it from the arduino uno and hopefully get awat with something like a attiny 85.and yes, i forgot to mention that i will have a diode across the coil.Quote from: danadak on October 14, 2016, 01:06:22 amsorry, i dont understand what you mean. my plan was to use something like a 3A to220 transistor or something along those lines. am i barking up the wrong tree?Jason

author: danadak
author_rank: Super Contributor
timestamp: October 14, 2016, 10:12:26 am
content: You are going to see some large V transients because you are switching off an inductiveload, so a clamp must be employed. And transistor ratings have to handle this the safearea issues. As well as the current which you are already aware of.Note this also means you have to protect the UP output from these transients fed back viastray C coupling, and ground bounce.Put a scope on it, 10X probe, and look at transients. Also consider a diode clamp across thesolenoid for clamping turnoff transient.http://www.diva-portal.org/smash/get/diva2:18589/FULLTEXT01.pdfRegards, Dana.

author: Jbates58
author_rank: Regular Contributor
timestamp: October 14, 2016, 01:24:36 pm
content: Quote from: danadak on October 14, 2016, 10:12:26 amthat is where i was going to put the diode. would i need more than one?the transistor i was hoping to use is a TIP32CG, as i have a heap of them lying about in the electronics kit.Datasheet:http://www.onsemi.com/pub_link/Collateral/TIP31A-D.PDFit can handle 3A, so i thought it would suffice even with a bit of a spike.to protect the UC, would i use a diode of some sort on the output pin and then into a resistor to limit the current to the transistor and then to the transistor?havent done alot with transistors so its a learning curve.i have made a basic simulation of what i want to do, and coded it in 123circuits.io, in place of the solenoid, i have used an LED to indicate the PWM system. but i am unsure how to share it here.my theory was to basicly remove the LED, and replace it with the solenoid and a flyback diode to clamp out the spike.Jason

author: Ian.M
author_rank: Super Contributor
timestamp: October 14, 2016, 01:44:06 pm
content: Insufficient gain - the TIP32CG's mimimum HFEis 25, so for 1A Ic, you need a minimum of 40mA Ib which is more than an Arduino can safely provide. Use a Darlington pair or a MOSFET, but be careful - gate capacitance and I/O current capability will limit how fast an Arduino can switch a MOSFET and a Darlington has far higher voltage drop when on than a single transistor.

author: Zero999
author_rank: Super Contributor
timestamp: October 14, 2016, 01:53:29 pm
content: Quote from: Jbates58 on October 13, 2016, 11:28:38 amNo it doesn't. Look up Ohm's law.

author: Jbates58
author_rank: Regular Contributor
timestamp: October 26, 2016, 10:40:54 am
content: ok, so an update.i purchased some logic level mosfets and had a play and got it all working. i used the arduino pins 5/6 and found that they had a higher PWM frequency (and confirmed that on the arduino site relating to PWM) and then i swapped it to PIN 3 as it had a lower frequency (490HZ)and i discovered that the solenoid has a working range of aprox 20% - 60%but from the information i can gather, which is a little ambiguous but they all co-incide with each other, and they all state that the vehicles ECU runs it at 400HZ, so i am wondering if there is any problems with it running faster than it should?and i know that i can adjust the timers and whatnot to increase or decrease the frequency, but i am lost as to how to do the maths behind it, and then on how to implement it into the code.from what i have read, it will also effect how the rest of the code is executed by the arduino, but im also trying to gauge to how much it will effect it by.i hope that makes sense.Jason

author: Ian.M
author_rank: Super Contributor
timestamp: October 26, 2016, 11:07:36 am
content: The only down-side of driving a PWMed inductive component at a higher frequency, is higher switching losses and more EMI. A lower frequency could be problematic as you might hit a mechanical resonance. IMHO stay with 490Hz - its not worth changing it and unless you accept loss of resolution you cant get the exact frequency you want anyway. You should also note that Timer 2 is used for the PWM pin you have connected to, and if you change the frequency, it can mess up any libraries that rely on the 490Hz timer 2 interrupt rate.

author: Seekonk
author_rank: Super Contributor
timestamp: October 26, 2016, 12:26:59 pm
content: I suggested the higher frequency because some solenoids do not have enough inductance. I drive relays at 980Hz without issue. Again, avoid changing frequency of 5 & 6. For others who my follow this and may not understand the process.// This changes the frequency of PWM pins 11 & 3 ONLY// Fewer transitions = less heat created// Pins 11 and 3 for 16MHz clock// Settinng Divisor Hz// 0x01 1 31250// 0x02 8 3906// 0x03 32 976// 0x04 64 488// 0x05 128 244// 0x06 256 122// 0x07 1024 30// TCCR2B = TCCR2B & 0b11111000 | <setting>;TCCR2B = TCCR2B & 0b11111000 | 0x06;// PWM pins 9 & 10// TCCR1B = TCCR1B & 0b11111000 | <setting>;//TCCR1B = TCCR1B & 0b11111000 | 0x06 ;//Pins 5 and 6: Standard// changing this changes delay times AVOID//Setting Divisor Frequency// 0x03 64 976//TCCR0B = TCCR0B & 0b11111000 | 0x03 ;

author: Jbates58
author_rank: Regular Contributor
timestamp: October 27, 2016, 11:52:19 am
content: cheers,how can i determine wether or not it is been properly switched so as to decide if i need to change the frequency? i have a scope and a meter.what do i look for or test for?it seems to be working fine, but this is new ground to me, and im learning as i go.Jason

author: Seekonk
author_rank: Super Contributor
timestamp: November 02, 2016, 04:53:41 pm
content: You can look at the current. Once you see a change in slope the core is saturated. There will be an initial change in slope as the core pulls in and the inductance changes. This is a good way to see the speed of a relay or solenoid. Some good reading material is the app notes on a LM1949.