/* Using the isr function lets the digi2 pin sense the RISING of the voltage upslope every time the
sensor goes above zero volts. The millis function counts the time from switch-on and thus the
difference between float count from start is the time interval between sensor triggering ie; once
per revolution.
The idea is to run all the instrumentation for a 1932 Austin Seven to save the great expense of buying original/unreliable dials.
The LCD affected the rpm results until a serial chip was added.
The triggering is from a hall-effect sensor and some powerful 3mm barrel magnets, currently one pass per revolution.
The temp probe is a DS18B20 which comes pre-packaged in a stainless steel waterproof bundle and is wedged into a
brass nut on the top of the cylinderhead water casting (so will still show "high" if all water is lost.
An led is triggered if the rpm falls into a known danger band but this could also be adapted to make a limiter indication for max revs.
Yellow=SCL, Orange=SDA, Orange temperature probe single wire=Pin9, Brown Servo wire=pin10, Blue hall-effect single wire=Digipin2(akaInt0)
Oilpressure gauge. 0.5v(analog102) is 0psi, 4.5volts(analog921) is 30psi
Rob Thomas, Dec 20, 2016.
*/
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <OneWire.h>
#include <DallasTemperature.h> //libraries for the temp probe
#include <Servo.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3 //Port numbers on the serial chip thingy
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define POL POSITIVE //Backlight polarity
#define ONE_WIRE_BUS 9 //onewire input through pin 9
Servo myservo; // create servo object to control a servo
float value = 0;
float rev = 0; //clock count from upslope
int rpm;
int dial;
int oldTime = 0; //previous count from upslope
int time; //difference between new and old count
int oilout = 1;
int oil = 1;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin,
Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin, 3, POL);
byte a[8] = { //manufacturing the 'degree' symbol
0b00010,
0b00101,
0b00101,
0b00010,
0b00000,
0b00000,
0b00000,
0b00000
};
byte b[8] = { //manufacturing the small "2" symbol
0b00000,
0b00000,
0b00000,
0b01100,
0b10010,
0b00100,
0b01000,
0b11110
};
void isr()
{
rev++; //increase clock count
}
void setup()
{
lcd.begin(16, 2);
lcd.setBacklight(HIGH);
lcd.print("Austin Seven"); //brief announcement of the type of vehicle
lcd.createChar(1, a);
lcd.createChar(2, b);
attachInterrupt(0, isr, RISING); //digital pin 2 (a.k.a "int0")
sensors.begin();
pinMode(13, OUTPUT);
pinMode(A0, INPUT);
}
void loop()
{
delay (1000);
oil = analogRead(A0);
oilout = ((oil - 116) / 2.65333);
detachInterrupt(0);
sensors.requestTemperatures();
time = millis() - oldTime;
rpm = ((rev / time) * 60000); //count of revolutions in 1 second during 'delay' assuming one magnet pass per revolution
oldTime = millis(); //resets elapsed time count
rev = 0;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("RPM= ");
lcd.setCursor(4, 0);
lcd.print(rpm * 10);
lcd.setCursor(0, 1);
lcd.print("H");
lcd.setCursor(1, 1);
lcd.write(2); //wrte the small "2" sign
lcd.setCursor(2, 1);
lcd.print("O=");
lcd.setCursor(4, 1);
lcd.print(sensors.getTempCByIndex(0));
lcd.setCursor(9, 1);
lcd.write(1); // write degree sign
lcd.setCursor(9, 0);
lcd.print("OIL");
lcd.setCursor(13, 0);
lcd.print(oilout);
lcd.setCursor(12, 1);
lcd.print(oil);
dial = map(rpm, 0, 500, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(dial); // sets the servo position according to the scaled value
delay(15);
if (rpm >= 2200 && rpm <= 2400) //Vibration band warning for Austin Seven engine
{
digitalWrite(13, HIGH); //White wire to 13, black to gnd.
}
else
{
digitalWrite(13, LOW);
}
attachInterrupt(0, isr, RISING);
}