Hello all, I have been trying to set up a monitor for taking readings while the start switch is being held in the cranking position on a diesel generator.
The reason for this is so that i can see what things are doing during the cranking phase and then decide what would be useful and reliable as a control/backup for the cranking phase of a generator auto start, besides an rpm device.
At the moment the only sensor that comes on the generator is an oil switch.(also 240v meter but don't know if I can get a reading from it)
For this test i am looking at using:
- Load sensor on the starter cable (amps)
- Voltage meter on battery (battery)
- Voltage meter on the generator output (genVolt)
- RPM Sensor? (rpm)
- Oil switch which is already on the unit (oilSwitch)
Process:
-Initialise and print "Ready for start cycle"
-Monitor starter switch
-> Start switch activated
-Print "Starting cycle"
-Reset timer to zero
-> readings() Enter readings loop
-Print time since loop starter cycle started
-Take readings and print them to serial
-Check that start switch is still activated
-If still active > repeat readings()
-If start switch has been released > return to monitoring switch.
If started switch is pressed again reset timer, take readings etc.
At the moment I seem to have the code close to what i was hoping for but the main two things that I seem to be having a problem with it is resetting the timer to zero on the next cycle starts, and keeping it in just the readings() loop while start switch is being held active.(will loop but keeps the counter going from the first cycle instead of offsetting back to zero)
Please find code below.
int startSig = 3; //Starter state
int battery = A0; //battery volts
int rpm = A1; //rpm
int amps = A2; //starter amp draw
int oilSwitch = 4; //oil switch state
int genVolt = A3; //240 volt reading
int OIL; //variable to store read value
long cycleStart;
long startTime;
long elapsedTime;
int fractional;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(startSig, INPUT_PULLUP); //Starter state
pinMode(oilSwitch, INPUT_PULLUP); //oil switch state
Serial.println("Pin Modes Set");
Serial.println("Ready For Start Cycle");
}
void loop() {
delay(5);
if (digitalRead(startSig) == LOW) {
Serial.println("Starting Cycle"); // display cycle start
cycleStart = millis();
startTime = millis() - cycleStart;
Serial.println(startTime); //zero timer and print once
readings();
}
}
void readings() { //start engaged take readings
// if (digitalRead(startSig) == LOW);{
int battRead = analogRead(battery); //battery volts
int rpmRead = analogRead(rpm); //rpm
int ampRead = analogRead(amps); //starter amp draw
int OIL = digitalRead(oilSwitch); //oil switch state
int genVoltRead = analogRead(genVolt); //240 volt reading
//Conversions
float Batt = battRead * (5.0 / 1023);
float RPM = rpmRead * (5.0 / 1023);
float AMPS = ampRead * (5.0 / 1023);
float GENVOLT = genVoltRead * (5.0 / 1023);
//Print Results
Serial.print("Battery: ");
Serial.print(Batt);
Serial.print(", ");
Serial.print("RPM: ");
Serial.print(RPM);
Serial.print(", ");
Serial.print("AMPS: ");
Serial.print(AMPS);
Serial.print(", ");
Serial.print("Oil: ");
Serial.print(OIL);
Serial.print(", ");
Serial.print("Gen Volts: ");
Serial.println(GENVOLT);
//Print Time
elapsedTime = millis() - startTime;
Serial.print((int)(elapsedTime / 1000L));
Serial.print(".");
fractional = (int)(elapsedTime % 1000L);
if (fractional == 0)
Serial.print("000");
else if (fractional < 10)
Serial.print("00");
else if (fractional < 100)
Serial.print("0");
Serial.println(fractional);
//start released stop readings
if (startSig == HIGH) {
Serial.println("END OF START CYCLE");
loop();
}
}
I haven't got the sensors yet so i have just got floating values from the analog pins. Figured I should wait until i find out what the input values to expect before trying to map them.
Also not sure what I am going to try for the rpm as yet.
BTW this is one of those cheap imported generators like picture below.
Cheers,
Mowby.