View Single Post
Old 06-28-2025, 08:28 AM   #17
1960BreadTruck
Junior Member
 
Join Date: May 2025
Location: Fairland, Indiana
Posts: 13
Default Re: The Bread Truck Rebuild

Parts list first, you get any of these anywhere:
Processor: Arduino Nano, or whatever compatable arduino board you wanna use
Display: 12864 128x64 LCD with blue backlight
Temp sensor: DS18B20 I2C sensor, they were cheap
Oil pressure sensor: 0-100psi Stainless pressure transducer from the jungle website
Fuel Sensor: Universal Doorman level sensor with 33-330 ohm range

The voltage sensor is just a voltage divider at 5:1 so 12v comes in at around 2.4v.
The fuel sensor is about the same, use two 1k ohm resistors to reduce the current through the circuit, and get the differential reading on an analog input.
I can post wiring diagrams too if you need, but it can be inferred. Heres my code:

#include <Wire.h>
#include <U8g2lib.h>
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2 // Temp sensor
#define FAN_PWM_PIN 6 // Fan control output
#define MODE_BUTTON 3 // Mode toggle button
#define UP_BUTTON 4 // Manual fan speed up
#define DOWN_BUTTON 5 // Manual fan speed down

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
const int oilpressin = A0;
const int fuellevelin = A1;
const int voltagein = A2;

U8G2_ST7920_128X64_F_SW_SPI u8g2(U8G2_R0, 13, 11, 12, U8X8_PIN_NONE);

bool manualMode = false;
int fancommand = 0;
int fanperc;
unsigned long lastDebounce = 0;

void setup() {
Serial.begin(9600);
sensors.begin();
u8g2.begin();

pinMode(MODE_BUTTON, INPUT_PULLUP);
pinMode(UP_BUTTON, INPUT_PULLUP);
pinMode(DOWN_BUTTON, INPUT_PULLUP);
pinMode(FAN_PWM_PIN, OUTPUT);
}

void loop() {
sensors.requestTemperatures();
float temp1 = sensors.getTempFByIndex(0);
int oilin = analogRead(oilpressin);
int fuelin = analogRead(fuellevelin);
int battin = analogRead(voltagein);

int oilscaled = map(oilin, 0, 1024, 0, 100);
int fuelscaled = map(fuelin, 0, 1024, 1, 48);
float battscaled = (battin / 1023.0) * 25;

// manual auto mode
if (digitalRead(MODE_BUTTON) == LOW && millis() - lastDebounce > 250) {
manualMode = !manualMode;
lastDebounce = millis();
}

if (manualMode) {
if (digitalRead(UP_BUTTON) == LOW && fancommand < 255) {
fancommand += 20;
delay(100);
}
if (digitalRead(DOWN_BUTTON) == LOW && fancommand > 0) {
fancommand -= 20;
delay(100);
}
} else {
// Auto mode logic
if (temp1 < 50) fancommand = 0;
else fancommand = map(temp1, 50, 90, 0, 255);
}


analogWrite(FAN_PWM_PIN, fancommand);

//draw the frame
u8g2.clearBuffer();
u8g2.drawLine(0, 32, 128, 32);
u8g2.drawLine(73, 0, 73, 64);
u8g2.drawRFrame(0, 0, 128, 64, 8);
//engine temp
u8g2.setFont(u8g2_font_DigitalDiscoThin_tf);
u8g2.setCursor(3, 29); u8g2.print(temp1);
//fan mode and command reading
u8g2.print(manualMode ? " M" : " A");
u8g2.print(fanperc = map(fancommand, 0, 255, 0, 100));
u8g2.setCursor(4, 13); u8g2.print("Eng Temp");
//oil pressure
u8g2.setCursor(7, 45); u8g2.print("Oil Press");
u8g2.setCursor(20, 60); u8g2.print(oilscaled);
u8g2.print("PSI");
//fuel
u8g2.drawBox(75, 20, fuelscaled, 10);
u8g2.setCursor(119, 17); u8g2.print("F");
u8g2.setCursor(76, 17); u8g2.print("E");
u8g2.drawLine(76, 30, 124, 30); u8g2.drawLine(125, 29, 125, 20);
u8g2.setCursor(87, 13); u8g2.print("Fuel");
//voltage
u8g2.setCursor(75, 45); u8g2.print("Voltage");
u8g2.setCursor(85, 60); u8g2.print(battscaled);

u8g2.sendBuffer();
delay(100);
}


You'll need to download the included libraries too, let me know if you have any questions!
1960BreadTruck is offline   Reply With Quote