Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Arduino Boost Gauge

By: a guest on May 20th, 2014  |  syntax: C  |  size: 3.03 KB  |  views: 170  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Arduino-based Boost Gauge v3
  2. // Uses a SSCDRRN030PDAA5 Honeywell Pressure Sensor connected to an Arduino Uno
  3.  
  4. #include <LiquidTWI.h>
  5. #include <Wire.h>
  6.  
  7. int analogInPin = A0;           // Analog input pin that the sensor is attached to
  8. int sensorValue = 0;            // value read from the sensor
  9. int boost = 0;                  // boost value in psi
  10. int boostgraph = 0;             // boost graph value
  11. int calibrationint = 124;       // map boost to ECU MAP sensor
  12. int maxvalue = 0;               //peak boost encountered since last reset
  13. int minvalue = 0;               //peak vacuum encountered since last reset
  14. boolean minmax = false;         //flag for boost graph or max and min boost
  15.  
  16. // Connect via i2c, default address #0 (A0-A2 not jumpered)
  17. LiquidTWI lcd(0);
  18.  
  19. void setup() {
  20.   // set up the LCD's number of columns and rows:
  21.   lcd.begin(16, 2);
  22.   // initialize the serial communications:
  23.   Serial.begin(9600);
  24. }
  25.  
  26. void loop() {
  27.   //backlight on
  28.   lcd.setBacklight(HIGH);  
  29.   // read the analog-in value:
  30.   sensorValue = analogRead(analogInPin);            
  31.   // map sensorValue to boost with calibration  
  32.   boost = map(sensorValue, 0, 1023, -3000, 3000) * calibrationint / 1000;
  33.   // create boost bar graph value
  34.   if (boost < 0) {
  35.     boostgraph = map(boost, -150, 0, 0, 7);
  36.   }
  37.   else {
  38.     boostgraph = map(boost, 0, 200, 7, 15);
  39.   }
  40.  
  41.   // compute max and min
  42.   if (max(maxvalue, boost) > maxvalue) {
  43.     maxvalue = boost;
  44.   }
  45.   if (min(minvalue, boost) < minvalue) {
  46.     minvalue = boost;
  47.   }
  48.  
  49.   //set cursor and print first line to LCD, keeping decimal point in same place
  50.   lcd.setCursor(0, 0);
  51.   if (boost > 150) {
  52.     lcd.print("   WARNING!!!   ");
  53.     lcd.setCursor(0,1);
  54.     lcd.print("DANGERTOMANIFOLD");
  55.   }
  56.   else {
  57.   lcd.print("Boost:");
  58.   if (boost < -99) {
  59.     lcd.print("");
  60.   }
  61.   else if (boost < 0) {
  62.     lcd.print(" ");
  63.   }
  64.   else if (boost < 100) {
  65.     lcd.print("  ");
  66.   }
  67.   else {
  68.     lcd.print(" ");
  69.   }
  70.   lcd.print(boost / 10);
  71.   lcd.print(".");
  72.   int deci = boost % 10;
  73.   lcd.print(abs(deci));
  74.   lcd.print(" psi   ");  //extra space to clear any extra characters
  75.  
  76.   // set cursor to second line on LCD
  77.   lcd.setCursor(0,1);
  78.  
  79.   if (minmax == true) {
  80.   // print max and min boost
  81.   lcd.print(maxvalue / 10);
  82.   lcd.print(".");
  83.   int maxdeci = maxvalue % 10;
  84.   lcd.print(abs(maxdeci));
  85.   lcd.print(", ");
  86.   lcd.print(minvalue / 10);
  87.   lcd.print(".");
  88.   int mindeci = minvalue % 10;
  89.   lcd.print(abs(mindeci));
  90.   lcd.print("    ");   // extra space to clear any extra characters
  91.   }
  92.   else {
  93.     // print boost graph
  94.     for (int cursorpos = 0; cursorpos < boostgraph; cursorpos++) {
  95.       lcd.setCursor(cursorpos, 1);
  96.       lcd.print((char)255);
  97.     }
  98.     for (int cursorpos = (int)boostgraph; cursorpos < 17; cursorpos++) {
  99.       lcd.setCursor(cursorpos, 1);
  100.       lcd.print("-");
  101.     }
  102.   }
  103. }
  104.   // wait 2 milliseconds before the next loop
  105.   // for the analog-to-digital converter to settle
  106.   // after the last reading:
  107.   delay(2);                    
  108. }