Advertisement
Guest User

test sensors

a guest
Nov 29th, 2015
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. #include <Wire.h>
  2.  
  3.  
  4.  
  5. int oilpres;
  6. int temprF;
  7. int temprFIAT;
  8. const int fanOut = 2;
  9.  
  10. void setup() {
  11. // Start i2c master
  12. Wire.begin();
  13. // initialize serial communication at 9600 bits per second:
  14. Serial.begin(9600);
  15. pinMode(fanOut, OUTPUT);
  16. }
  17.  
  18.  
  19.  
  20.  
  21. // the loop routine runs over and over again forever:
  22. void loop() {
  23.  
  24. tempCoolant(); // Calls on Coolant temp sensor that is in the Intake manifold.
  25. Serial.println("CLT Temp:");
  26. Serial.println(temprF);
  27.  
  28. //tempIAT(); // Calls on IAT sensor in Manifold
  29.  
  30. oilpressure(); // calls for OilPressure calculation
  31. Serial.println("Oil Pressure:");
  32. Serial.println(oilpres);
  33.  
  34. delay(1000);
  35. //fanControl(temprF); // controls fan
  36. // batteryVoltage(); // 1m to 100k voltage divider 1k to ground, 1m to source, measure from middle to ADC.
  37. // Wire.beginTransmission(9); // transmit to device #9
  38. //Wire.write(oilp); // sends oil pressure
  39. //Wire.write(temprF);
  40. //Wire.endTransmission(); // stop transmitting
  41. }
  42.  
  43.  
  44. float tempCoolant()
  45. {
  46.  
  47. float array[44] = {
  48. // Voltage From Sensor on left // Corresponding Temprature on right ,
  49. //You find this by using voltage divider forumla. Current set is for a 4.7k ohm R1 and R2 is your ACdelco Temp Sensor
  50. 2.429165 , 15 ,
  51. 2.137986 , 20 ,
  52. 1.864576 , 25 ,
  53. 1.613833 , 30 ,
  54. 1.38795 , 35 ,
  55. 1.188159 , 40,
  56. 1.013571 , 45,
  57. 0.8626761 ,50,
  58. 0.734253 , 55,
  59. 0.6246509 , 60 ,
  60. 0.5314699 ,65,
  61. 0.4536661 ,70,
  62. 0.3876349 ,75,
  63. 0.3317441 ,80,
  64. 0.286803 ,85 ,
  65. 0.2446477 ,90,
  66. 0.2110208 ,95,
  67. 0.1824518 ,100,
  68. 0.1582331 ,105,
  69. 0.1376963 ,110,
  70. 0.1201279 ,115,
  71. 0.1050845 ,120,
  72. };
  73.  
  74. // read the input on analog pin 0:
  75. float sensorValue = analogRead(A0);
  76.  
  77. // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  78. float voltage = sensorValue * (5.00 / 1023.0); // change for differant base voltage
  79.  
  80.  
  81. float tempr ;
  82.  
  83. if ( voltage >= array[0] )
  84. {
  85. tempr = array[1] ;
  86.  
  87. }
  88. else if ( voltage <= array[42] )
  89. {
  90. tempr = array[43] ;
  91.  
  92. }
  93. else
  94. {
  95. for ( int i = 1 ; i < 44 ; i++ )
  96. {
  97.  
  98. int ii = 2 * i ;
  99.  
  100. if ( voltage <= array[ii] && voltage >= array[ii + 2] )
  101. {
  102. tempr = array[ii + 1] + ( (array[ii + 3] - array[ii + 1]) * ( voltage - array[ii] ) / ( array[ii + 2] - array[ii] )) ;
  103. break ;
  104. }
  105. }
  106. }
  107.  
  108.  
  109.  
  110. temprF = tempr * 1.8 + 32;
  111.  
  112.  
  113.  
  114.  
  115. return temprF;
  116.  
  117.  
  118.  
  119. }
  120.  
  121. float oilpressure()
  122. {
  123.  
  124. float array[12] = {
  125. // Voltage From Sensor on left // Corresponding Temprature on right ,
  126. //You find this by using voltage divider forumla. Current set is for a 330 ohm R1 and R2 is your VDO Oil Pressure sensor
  127.  
  128. 2.105263 , 0.1,
  129. 1.944444 , 14.5,
  130. 1.764706 , 29,
  131. 1.5625 , 43.5,
  132. 1.071429 , 72.5,
  133. 0.4141189 , 100,
  134.  
  135. };
  136.  
  137. // read the input on analog pin 1:
  138. float sensorValue = analogRead(A6);
  139.  
  140. // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  141. float voltage = sensorValue * (5.00 / 1023.0); // change for differant base voltage
  142. //Serial.println(sensorValue);
  143.  
  144. float oilp;
  145.  
  146. if (voltage >= array[0])
  147. {
  148. oilp = array[1];
  149.  
  150. }
  151. else if (voltage <= array[10])
  152. {
  153. oilp = array[11];
  154.  
  155. }
  156. else
  157. {
  158. for (int i = 1; i < 12; i++)
  159. {
  160.  
  161. int ii = 2 * i;
  162.  
  163. if (voltage <= array[ii] && voltage >= array[ii + 2])
  164. {
  165. oilp = array[ii + 1] + ((array[ii + 3] - array[ii + 1]) * (voltage - array[ii]) / (array[ii + 2] - array[ii]));
  166. break;
  167. }
  168. }
  169. }
  170.  
  171. int oilpres = oilp;
  172.  
  173.  
  174. return oilpres;
  175.  
  176.  
  177.  
  178.  
  179.  
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement