Hey guys I'm in school for mechanical engineering and have done a bit of electronics but nothing with an arduino or other micro controller. What i am asking if this is even possible?
I want to control a linear solenoid rated at 14V, 0-3 amps. Internal resistance is 5 ohms.
I will have 3 inputs:
1-pwm input (166Hz) controlling ground of the solenoid (low side trigger)
2-analog 0-5V
3-analog 0-5v for psi
What i want to do is copy the pwm input if input 2 is above 0.42V and use input 3 as the setpoint (target for output) to 2.15V (40psi) if a button is pressed.
I also want a lcd display of the duty cycle, the analog 3 input in psi, and if the circuit is copying the pwm input or if the arduino program is controlling the solenoid.
This can easily be done.
I'd use the arduino to generate the PWM signal, it's much easier to do than copy it (the analog output of an arduino is actually a PWM signal). This makes it possible for the arduino to change the duty cycle, which is what you need for controlling something. To drive the solenoid you need some mosfetish circuitry, google around for that. Make sure to isolate the solenoid's circuit from your arduino with an optocoupler, just in case something goes wrong. If both the analog inputs are coming from the same sensor, i'd use only one input.
The tricky bit is actually choosing the right controller algorithm and parameters. But I guess that's the purpose of this problem, learning how to do that.
Input 2 and 3 are from 2 different sensors. I know they are not a psi input but if you multiply the voltage by 19 that gives you psi. I hope that makes sense.
I will explain what i am trying to do. I am trying to build a controller for the turbo veins in my truck to create an exhaust brake. I need the truck to still think it is controlling the solenoid but in reality my controller is. I want to copy the trucks pwm signal under normal driving conditions. When i step off the throttle pedal (one of the inputs, 0% throttle = 0.42V or less) that is when i want the controller to create its own pwm signal to create more back pressure by extending the solenoid andtherefore closing the veins. I want to make 40psi of back pressure (second sensor input, 40 psi=2.15V) so i need the controller to adjust the pwm duty cycle to make 40 psi of back pressure and hold it there until i step on the throttle (sensor 1 goes above 0.42V).
I know i will need to use mosfets to drive the solenoid and i will look into optocouplers as well. I hope this cleared things up a bit and thanks again for your input!
I have attached a rough diagram to hopefully make things easier
Perhaps you could feed the truck's original PWM through an AND gate (or similar) which could be turned on (to allow the signal) and off (to stop it) by the Arduino. Then a second AND gate could be used to feed the Arduino PWM into the truck circuit and to cut that off when you want to use the truck's PWM.
That way there is no need to copy anything and minimal disruption of the truck system.
The problem is the truck still has to "think" the solenoid is still there otherwise it throws a code and the truck goes into limp mode.
The truck controller is low side triggering the solenoid(ie controlling the ground). I have tested by cutting the ground wire between the solenoid and truck controller by running 14v through a 4.5ohm resistor to simulate the solenoid and it did not throw any codes or anything. Ill attach a picture of this.
The pwm signal to the solenoid is 14v high 0v low. The arduino analog input can only handle 5v. Can i just put a resistor in like in my picture?
Also can the arduino handle 14-15v for a supply voltage?
mitchedwards:
and it did not throw any codes or anything.
I don't know if this means it worked, or it didn't work?
If you mean that it worked ...
If the truck senses the solenoid by measuring the current flow then, obviously, you need to simulate that. Can you detect the pulses across the resistor and feed them, suitably amplified, to the solenoid? If so then you could use the mechanism I suggested earlier (or a close cousin of it) to feed the original signals or the Arduino signals. The same amplifier could probably serve the Arduino signal and the truck signal.
If I was to use the Arduino to "copy" the truck signals I would feel the need to do a lot of testing to be sure my Arduino program was doing what was needed. Feeding the original signals seems easier.
It would probably be a good idea to have some system to detect the sorts of solenoid failure that the truck's system is designed to detect and to have some means for the Arduino to "notify" the truck in the event of a solenoid failure - perhaps open a relay in the truck-to-resistor circuit.
You should also consider what's the worst case scenario if the system goes wrong. In particular could the engine go out of control causing a crash or causing damage to the engine. And also be sure to check with your insurer - they won't pay up if there is an unapproved modification (perhaps even if it is harmless) and your insurance premiums will be wasted.
Ok guys so i did some rethinking and came up with a new schematic. It uses a dpdt relay so the arduino never sees the signal from the truck and doesnt have to copy it which will simplify the code a bit. When the relay is closed(no power applied) the truck is in control of the VGT solenoid. If the TPS sensor falls below 0.42V, the arduino turns on the relay which in turn sends the truck computer a fake signal to make it think the solenoid is still there and the arduino is now controlling the vgt solenoid.
I am trying to write a PID code that uses the EPS sensor for feed back and the setpoint (setpoint=2.15V). I need the pwm signal to be between 0 and 45% duty cycle at around 166Hz.
Here is my code so far
#include <PID_v1.h>
const int tps = A0; //Throttle Position Sensor Input
const int eps = A1; //Exhaust Pressure Sensor Input
const int rly = 7; //Turn on/off Relay
const int sol = 6; //PWM Output To Solenoid
double pressure;
// Tuning Parameters
float Kp=1; // Initial Proportional Gain
float Ki=1; // Initial Integral Gain
float Kd=1; // Initial Derivative Gain
double Setpoint, Input, Output;
PID mypid(&Input, &Output, &Setpoint, Kp, Ki, Kd, Direct);
const int sampleRate = 1;
void setup(){
pinmode(7,OUTPUT)
pressure = analogRead(eps);
Input = map(pressure, 0, 1024, 0, 114); //Get Setpoint From EPS
Setpoint = 440 // Setpoint 2.15V=40psi
}
void loop(){
analogRead(tps); //86 = 0% throttle
if(tps<86){
digitalWrite(rly, High) //turn on relay
Setpoint = 440
pressure = analogRead(eps); // Read Exhaust Back Pressure
Input = map(pressure,0, 1024, 0, 114);
my.PID.Compute();
analogWrite(sol,OUTPUT);
}
}
mitchedwards:
Ok guys so i did some rethinking and came up with a new schematic. It uses a dpdt relay so the arduino never sees the signal from the truck and doesnt have to copy it which will simplify the code a bit. When the relay is closed(no power applied) the truck is in control of the VGT solenoid. If the TPS sensor falls below 0.42V, the arduino turns on the relay which in turn sends the truck computer a fake signal to make it think the solenoid is still there and the arduino is now controlling the vgt solenoid.
That may work, however during the period when the relay is switching over, there will be no current flowing from the solenoid driver if it is trying to turn the solenoid on, and it may decide there is a fault condition. I guess you'll need to try it.
An alternative would be to use three mosfets: one to connect the solenoid to the driver, one to connect the dummy load to the driver, and one to connect the solenoid to ground. The first two act like one of the poles of your SPST relay, and the third controls the solenoid PWM from the Arduino. You'll need to ensure that the flyback diode is connected across the solenoid, and not between the driver output and +12V (or add your own flyback diode).
One thing you need to be very careful with is that the Arduino cannot affect the TPS sensor signal even if it malfunctions. A 100K resistor between the TPS signal and the analog input may be sufficient, along with a 22nF capacitor between the analog input and ground to preserve the accuracy of the reading.
I suspect a relay would be an unreliable way of switching a logic signal. As well as the risk of the relay failing there is a risk of contact bounce affecting the signal.
I would also worry that switching the truck PWM signal (which has a significant current) from A to B while it is working could lead to errors in the truck circuits even using mosfets. Perhaps you could arrange for the switch to happen during an idle period in the PWM pulse, but that seems complicated.
Looking at the complexity required to merge two pulse sources together or switch seamlessly between them, it seems to me that the approach suggested previously of intercepting the original signal with a device which sends a modified signal to the actuator would actually be the simpler solution.
A natural way to implement that would be to run a pair of new wires down to the actuator - one bringing the original signal back to your new controller, the other one returning the modified signal. That way your original wire remains largely undisturbed and in place in case you ever want to reverse the mod.
I prefer the solution of gating the original signal to the solenoid - because that way, with judicious use of pullup and pulldown resistors on the mosfet gates, it becomes possible to revert to the original behaviour automatically when the Arduino is powered down.
Thanks for the replies guys! Instead of switching the signal bewteen the trucks computer and the arduino would it be better to make the arduino copy the trucks signal and use the programming to change between copying and making in its own?
Can an arduino handle 14-15v supply voltage for a long period of time?