Rev limiter using arduino

Hello all,

I've been reading a lot on this forum and decided to make an account because i need some help with my rev limiter.

The rev limiter works with a relay which is connected to de igntion.

What i want to achieve with 1 momentery switch is when i press it once it should run my loop for lets say 3 seconds. But when I keep it pressed it should run the loop until I release the button.

I'm relatively new to programming and arduino so i don't know how to achieve this. I've tried putting some extra delays in the code but that didn't work.

I also read that it can be helpfull to take a look in the blinkwithoutdelay script and take a look into booleans but i still don't know how to fix this.

My code:

const int buttonPin = 2;
int buttonState = 0; 

void setup() {
  pinMode(3, OUTPUT);// connected to S terminal of Relay
  pinMode(buttonPin, INPUT);
 digitalWrite(buttonPin,HIGH);
}

int counter = 0;
void loop() {

buttonState = digitalRead(buttonPin);

if (buttonState == LOW) {
  digitalWrite(3,HIGH);// turn relay ON
  delay(45);// keep it ON for x seconds mcut 45

  digitalWrite(3, LOW);// turn relay OFF
 delay(20);// keep it OFF for x seconds mnot  20
}
}

It is for a toyota starlet 1.3 non turbo without a catalytic converter. For the people that are interested in a video https://www.youtube.com/watch?v=mpbB-SgGfMU

I still have to find the ideal amount of milliseconds to get it working better then this.

Do you already have a rev limiter and the relay connects to it somehow? (I can't watch the video 'cause I'm at work.)

delay() is milliseconds so 3 seconds is delay(3000). 45ms may not be enough time for the relay to activate.

Otherwise, I don't understand how this thing works so I don't know what the problem is...

You need the Blink Without Delay method (millis() timer) ONLY if you need to read the button during the delay time. If you just want to hold the relay on for 3 seconds after momentarily pressing the button you can use the normal delay().

For example, if you wanted to activate the relay when the button is pushed, then hold for 3 seconds after the button is released, you'd need to use the milllis() timer method so you can keep re-starting the timer as long as the button is pushed. ...If you use delay(), program execution pauses during the delay() time so you can't check the button state until after the delay time is up.

Can you tell if the relay is on? You can probably hear it click, but it's also good to check electrically. If you don't have a multimeter you can temporarily wire-up an LED (with the usual current-limiting resistor) to turn-on when the relay is on.

And for troubleshooting it's also helpful to send little messages to the serial monitor (like the Digital Read Serial Example). You can send messages like "Button pressed", "Relay Activated", "Timer Started", etc... Anything that gives you feedback about what the program is doing (when it may not be doing what you think it's doing).

First off all thank you for de information.

The relay and everything is connect and it all works when I keep the button pressed. So when I keep the button pressed, the relay clicks every 45ms(relay activated) and 20ms(not activated) . So it cuts the ignition for 45ms and activates it for 20ms over and over again.

However what I want to do is just press the button once to activate

if (buttonState == LOW) {
  digitalWrite(3,HIGH);// turn relay ON
  delay(45);// keep it ON for x seconds mcut 45

  digitalWrite(3, LOW);// turn relay OFF
 delay(20);// keep it OFF for x seconds mnot  20
}

^This part for 3 secondes

So what I want is to press the button 1 time or let's say max 200ms and it should active the 3 secondes

And when I press it for longer than 200ms it should keep working the same as now. So it should stop activating and deactivating the relay when I release the button.

It seems to me that you want to save a timestamp of when your ignition suppression has first been activated. Then when you test for the next loop of ignition suppression, if either the button is still pressed or the minimum elapsed time has not yet expired, execute the ignition suppression loop again.

Once both the elapsed time has expired and the button is no longer pressed, reset the activation timestamp.

Also remember that the timer might rollover during your session so you have to allow for situations when the present time is later than the activation time but the timer has a lower value than the timestamp.

edmcguirk: It seems to me that you want to save a timestamp of when your ignition suppression has first been activated. Then when you test for the next loop of ignition suppression, if either the button is still pressed or the minimum elapsed time has not yet expired, execute the ignition suppression loop again.

Once both the elapsed time has expired and the button is no longer pressed, reset the activation timestamp.

Also remember that the timer might rollover during your session so you have to allow for situations when the present time is later than the activation time but the timer has a lower value than the timestamp.

Relays will never work in the short periods of time you allow. Already mentioned above #1.

bluejets: Relays will never work in the short periods of time you allow. Already mentioned above #1.

The ignition suppression loop can activate whatever method is needed. Relays are not implied.

Tigiy: Hello all,

I've been reading a lot on this forum and decided to make an account because i need some help with my rev limiter.

The rev limiter works with a relay which is connected to de igntion.

Really....??

Not what it says above.

bluejets: Really....??

Not what it says above.

He claims the relay works in #2. I do not choose to argue he is wrong. He asks how to get long or short button press to change the output. I suggested a solution for that.

If he decides that he wants a different form of ignition suppression, that new form will go in the same place in the ignition suppression loop and it will work the same.

There are two pieces here. A hardware piece seems to work but is unlikely to be a good long term solution. A software piece controls the activation of the hardware piece. The question here was to improve the software piece.