// Arduino-based Boost Gauge v3 // Uses a SSCDRRN030PDAA5 Honeywell Pressure Sensor connected to an Arduino Uno #include #include int analogInPin = A0; // Analog input pin that the sensor is attached to int sensorValue = 0; // value read from the sensor int boost = 0; // boost value in psi int boostgraph = 0; // boost graph value int calibrationint = 124; // map boost to ECU MAP sensor int maxvalue = 0; //peak boost encountered since last reset int minvalue = 0; //peak vacuum encountered since last reset boolean minmax = false; //flag for boost graph or max and min boost // Connect via i2c, default address #0 (A0-A2 not jumpered) LiquidTWI lcd(0); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // initialize the serial communications: Serial.begin(9600); } void loop() { //backlight on lcd.setBacklight(HIGH); // read the analog-in value: sensorValue = analogRead(analogInPin); // map sensorValue to boost with calibration boost = map(sensorValue, 0, 1023, -3000, 3000) * calibrationint / 1000; // create boost bar graph value if (boost < 0) { boostgraph = map(boost, -150, 0, 0, 7); } else { boostgraph = map(boost, 0, 200, 7, 15); } // compute max and min if (max(maxvalue, boost) > maxvalue) { maxvalue = boost; } if (min(minvalue, boost) < minvalue) { minvalue = boost; } //set cursor and print first line to LCD, keeping decimal point in same place lcd.setCursor(0, 0); if (boost > 150) { lcd.print(" WARNING!!! "); lcd.setCursor(0,1); lcd.print("DANGERTOMANIFOLD"); } else { lcd.print("Boost:"); if (boost < -99) { lcd.print(""); } else if (boost < 0) { lcd.print(" "); } else if (boost < 100) { lcd.print(" "); } else { lcd.print(" "); } lcd.print(boost / 10); lcd.print("."); int deci = boost % 10; lcd.print(abs(deci)); lcd.print(" psi "); //extra space to clear any extra characters // set cursor to second line on LCD lcd.setCursor(0,1); if (minmax == true) { // print max and min boost lcd.print(maxvalue / 10); lcd.print("."); int maxdeci = maxvalue % 10; lcd.print(abs(maxdeci)); lcd.print(", "); lcd.print(minvalue / 10); lcd.print("."); int mindeci = minvalue % 10; lcd.print(abs(mindeci)); lcd.print(" "); // extra space to clear any extra characters } else { // print boost graph for (int cursorpos = 0; cursorpos < boostgraph; cursorpos++) { lcd.setCursor(cursorpos, 1); lcd.print((char)255); } for (int cursorpos = (int)boostgraph; cursorpos < 17; cursorpos++) { lcd.setCursor(cursorpos, 1); lcd.print("-"); } } } // wait 2 milliseconds before the next loop // for the analog-to-digital converter to settle // after the last reading: delay(2); }