Hi
To the Arduino Community, I'm new here and would like to say hello to you all..
A friend gave me this UNO and LCD and said here have a play
I came up with this idea of making a Turbo Timer Boost Controller in 1 unit.
I have been playing around with a UNO and made an Input from IGN and Output Relay
to IGN for turbo timer, output to solenoid for wastegate control and Pot to set Boost and Time from.
OK, I'm no programmer, just a bit of a hacker, but I had a go, I know its not clean and lean and would like any help in this area..
it almost works 100%..
The Turbo Timer bit of code I cant get the right statement to make it function
Thanks for reading and looking..
/*
Tony's Turbo Timer Boost Controller V2
Reads an analog input on pin A5, converts it to voltage.
Attach the center pin of a potentiometer to pin A5, and the outside pins to +5V and ground.
::Smoothing
Reads repeatedly from an analog input, calculating a running average
and updating the (average) statement. Keeps 5 readings in an array and
continually averages them.
Define the number of samples to keep track of. The higher the number,
the more the readings will be smoothed, but the slower the output will
respond to the input. Using a constant rather than a normal variable lets
use this value to determine the size of the readings array.
*/
const int numReadings = 5;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int voltage = 0; // create voltage from potPin
int BoostPin = 11; // set output pin for the wastegate boost control
int timerPin = 5; // set output Relay Turbo Timer count down, IGN Output pin.
int potPin = A5; // A5 Analog Pin potentiometer ref voltage
int ignPin = A4; // A4 Analog Pin IGN Sensing
int potValue = 0; // potentiometer input variable
int pwmValue = 0; // Output Duty Cycle PWM
int ignState = 0; // IGN On or Off
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 115200 bits per second:
Serial.begin(9600);
// initialize all the readings to 0:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
// Set Output Pins
pinMode(BoostPin, OUTPUT);
pinMode(timerPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the value from the potentiometer and Ignition:
int potValue = analogRead(potPin);
int ignState = analogRead(ignPin);
// Convert the analog reading from potPin (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = average * (5.0 / 1023.0);
// subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(potPin);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings)
// ...wrap around to the beginning:
readIndex = 0;
// calculate the average:
average = total / numReadings;
delay(1); // delay in between reads for stability
//Print to the serial port
// Serial.println(voltage);
// Turbo Timer - waits for ignState to go from HIGH to LOW then writes timerPin HIGH for selected time then goes LOW.
if (ignState > 1022) digitalWrite(timerPin, HIGH); // IGN On
else {
}
if (ignState < 1010) digitalWrite(timerPin, HIGH), delay(voltage * 1000 * 60) digitalWrite(timerPin, LOW); // IGN Off
else {
}
The above bit Turbo Timer just here is where I cant get the code to work
// My Version of Analog voltage to PWM, crude but works for this application
// send the square wave signal to the BD681 Darlinton Transistor:
if (average > 1010) digitalWrite(BoostPin , HIGH); // Max potValue average to hold open
else {
for(int pwmValue = 0; pwmValue <= 255; pwmValue +=50){ // Hz ?
digitalWrite(BoostPin, HIGH);
delay(average / 50); // closed to open moves around the pot span
}
if (average < 2) digitalWrite(BoostPin , LOW); // Min potValue average to hold closed
else {
for(int pwmValue = 255 ; pwmValue >= 0; pwmValue -=50){ //Hz ?
digitalWrite(BoostPin, LOW);
delay(1); //open to close
}
}
}
}