I am trying to figure out how to use an Arduino Pro mini clone to run the compressor cycle in my 1998 Nissan Frontier pickup (D22 chassis, 2 wheel drive, KA24DE gas 4 cylinder/5 speed manual. It is also sold as the Navarra in some markets.). My plan is to use a 10k thermistor to sense the temperature of the evaporator core which will then cause the Arduino to cycle a relay on and off. With the way Nissan wired it, the air conditioning system has the compressor and idle speed compensator wired so that if one goes on the other does too. Therefore I plan to use this part of the wiring to run it as I see no reason not to. I tested it by temporarily bypassing the computer's air conditioning functions and it still works, as does the original binary switch that I ran in series to prevent excessive pressure. What doesn't work is the PCM's air conditioning control circuit that turns the compressor off when the ignition is on and on as soon as the ignition is turned off. Everything else still works though so I do not want to replace the expensive PCM, especially since the truck has 384,000 miles on it and is not driven regularly.
My issue is with how to write the loop. I need to have the compressor run until the temperature reaches 34 F and then shut off. I then want it to wait until the temp rises to about 38-40F, turn on the compressor clutch and repeat the cycle. It needs this shutdown period so that the evaporator core does not freeze and hinder airflow. I was planning to use a sample sketch I found to read a 10k thermistor that returns a temperature and just add the loop code to it once I figured it out. Unfortunately I do not seem to be able to find a sample code for this particular situation. I apologize if this is a simple problem but I am new to programming.
That is about what I want it to do. I just can't figure out how to get it to remain in that range. So it would be something like:
if temp > 38
switch on until temp < 34
if temp < 34
switch off until temp >38
It has to drop below 34 before switching off and then wait until it gets hotter than 38 before turning on again. I know how to get it to turn off when it hits 34, but then it would just turn on again the moment it gets the slightest amount higher than 34. This rapid cycling would not be good for the compressor or compressor clutch and would cause failure in short order. I also considered just using a simple counter but that wouldn't account for the way it acts in varying conditions. (In the rain on the highway, the condenser core at the front of the radiator cools far more efficiently due to the water passing through it than it would be on a sunny 95 degree day sitting in traffic, for example. So there is need for a variance. Alternatively, I could just use a thermistor to break the circuit when the temp gets down to the threshold temp and eliminate the Arduino but I just don't think that would work as well.) I seem to remember there being a "While" statement but I didn't see it on the main page for the Arduino programming language so I am not certain if it is valid. Maybe I can use something like "goto"? My fear is that all the Arduino will ever see is the if temp < 34 then turn on. I need to find a way to skip this statement in the loop until the statement below it is valid.
I'm just scratching my head wondering why this solution would be desirable, when a simple mechanical thermal switch would do the job perfectly (and does, on most cars....). They are cheap, available at virtually at set-point temperature and hysteresis desired.