Vehicle rpm sequential shift lights

Hi all,

Have been working through this for a while now and am still finding some issues, so I was hoping a post might be able to shed some light on the problems I've been having. A quick bit of background.

The project I'm working on is for a set of sequential shift lights for my car that come on one by one as the revs (rpm) rises.

The circuit diagram is below, as is the code I'm using. Not shown on the diagram, but I'm using 1k ohm (I think) resistors with each LED.

I get a response from the Arduino and can upload the code, but the shift lights don't seem to be coming on when I rev the car. I was wondering if anyone has any ideas about the code and if they can see any glaring errors at all? Maybe the board isn't picking up revs correctly?

Anyway, here it is and thanks in advance.

Sean

int rev = 12;
int ledGr1 = 5;
int ledGr2 = 13;
int ledGr3 = 11;
int ledG1 = 6;
int ledRo = 3;
int ledBl = 10;
int ledAll = 8;
unsigned long duration;
unsigned long rpm;

void setup(){
Serial.begin(19200);
pinMode(8, OUTPUT);
pinMode(rev, INPUT);
}
void loop(){
Serial.print("Drehzahl: ");
Serial.println(rpm);
duration = pulseIn(rev, HIGH);
rpm = 30000000 / duration;

if (rpm > 11500 && rpm < 20000) {
digitalWrite(ledAll, HIGH);
delay(5);
digitalWrite(ledAll, LOW);
delay(80);
}
if (rpm > 5000) analogWrite(ledGr1, 5);
if (rpm < 4950 || rpm > 20000) analogWrite(ledGr1, 0);
if (rpm > 6500) analogWrite(ledGr2, 5);
if (rpm < 6450 || rpm > 20000) analogWrite(ledGr2, 0);
if (rpm > 8000) analogWrite(ledGr3, 5);
if (rpm < 5950 || rpm > 20000) analogWrite(ledGr3, 0);
if (rpm > 9000) analogWrite(ledG1, 7);
if (rpm < 89500 || rpm > 20000) analogWrite(ledG1, 0);
if (rpm > 10000) analogWrite(ledRo, 10);
if (rpm < 9950 || rpm > 20000) analogWrite(ledRo, 0);
if (rpm > 11000) analogWrite(ledBl, 5);
if (rpm < 10950 || rpm > 20000) analogWrite(ledBl, 0);
delay(50);
}

You are missing pinMode() calls for most of your output pins.

Hi John,

Thanks for your reply. Good spot. If I sort these out, do you think the rest of the code should work ok?

Thanks,

Sean

seancarsonuk:
do you think the rest of the code should work ok?

Seems unlikely to me. The analog values you're writing are all very low which means the LEDS will barely glimmer even when they're on, and the code to decide which ones to turn on and off looks flawed to me (the threshold for turning ledGr3 off looks wrong, and the threshold for turning ledG1 off also looks wrong). I don't know what you intend the ledAll output to do, but the duty cycle you're generating in lines 23 ... 28 is going to be extremely low.

You ask whether the sketch is working out the rpms correctly. I wondered that too. You have code in there to print out the calculated rpms. What does it tell you?

Hi,can you explain what you want the LEDs to indicate and what colour indicating what RPM condition.

Also do you have bypassing capacitors around the voltage regulator, if not, look up the spec sheet for it and they should have a simple connection diagram showing the values required, These should be mounted as close a possible to the volt reg pins.

Tom..... :slight_smile:

It's not clear to me why you have extra diodes going to some of the blue LEDs.

Do you often get RPM's over 20,000?

Could you say what you intend the display to look like at various RPM ranges? It's hard to say if the code will do what you want without knowing what you want.

I would have an array with an element for each LED. I would use the speed sensing to set appropriate values (HIGH or LOW) in the appropriate array elements.

Then I would have a separate function that just lights the LEDs according to the values in the array. That function would need no decision making logic.

...R

Hi, just found this topic :slight_smile:

This shiftlight was my first Arduino project, seancarsonuk contacted me for some information in a different forum, maybe his cars rpm signal is not compatible with my code, on my car it works quite well.

I'm a complete noob when it comes to programming stuff like this, hence the simple code.... but it works :wink:

Here is a video of the shiftlight: Arduino Micro - Sequential Shift Light - YouTube

If someone has a better idea how to pick up the rpm signal i would be thankful, my code works but is not very precise. If the signal would be a simple square wave it wouldn't be a problem but the ECU gives me i short pulse with every ignition, this gives me a inaccuracy with rising rpm when using "pulseIn".

Hafkai:
this gives me a inaccuracy with rising rpm when using "pulseIn".

If you want to know the frequency of a signal averaged over multiple pulses, it's better to count the number of pulses in a period rather than try to measure the pulse length.