New Project ( can it be done)

Hey guys,

I'm new to the whole Arduino community and Arduino itself. I have had an idea for a long time now but i have never acted on it .

Firstly the question i have is, can the Arduino perform the project.

Ive seen various videos on youtube incorporating the Arduino to perform a similar project on a smaller scale:

I want to do it on a bigger scale. I want to have a strip of LED's either on the rear bumper or just under the rear bumper that will perform the same operation. Is there an issue with cable lengths or is it just something that nobody else wants as i haven't seen it been done.

I would be very greatfull for any info regarding this . im not looking for someone to code it and all for me(yet :slight_smile: :slight_smile: ) , i just want to know if it can be done and if i would face any complications

Sure it can be done. It can be done without a microcontroller, too.

So you are saying you want to create an array of LEDs that is sensitive to the car's RPMs?

There are two ways you can go about this. One is to tap into your car's crankshaft sensor and use the signal pulses from that to calculate the momentary engine revs. Which is more complicated than it sounds, because you will have to use a few clever bits of code that aren't immediately understandable to the beginner. Because the crankshaft sensor is usually a very fast signal, it'll come down to using timers on the Atmega/Arduino. Both digitalRead and pin change interrupts will just be too slow.

Another way, if you have a fairly new car with OBDII, is to get an OBDII shield or breakout module that will read out the car's OBDII data continuously, which also contains the car's momentary engine revs. You could then use the data retrieved from that to write code for which LEDs you want to light up at what engine speeds.

Personally, I'd go the crankshaft sensor route. A lot more research involved about the specifics of your car, but from a hardware standpoint, the easiest way because you will really only need your Arduino, an optocoupler, one resistor and a couple of (jumper) wires.

Also, if you want to attach LEDs to your car externally, make sure that that's street legal where you live. In a lot of countries, that counts as illegal vehicle lighting. Even if you mount LEDs under your bumper so they wouldn't be directly visible to traffic behind you.

I appreciate the reply's guys , id be interested to hear how it can be done without a micro controller jonah . i want to be able to turn it off aswell and maybe adjust the brightness of the LED's and maybe change when the LED's operate . as in when the first one , second one , third one etc come on with relevance to the RPM.

its just an idea that i have been thinking of for a while and i have a bit of time on my hands now. personally i wouldn't be running out to put it on my car . there is a big cars modification culture here in Ireland. once a year the donegal rally alone brings people from far and wide to the county(state) showing there cars and just cruising . id like to in the future maybe target that market because i think its something that they would love.

i dont know where i picked this info up from but i read somewhere that i could read the frequency from the car and use that as a guide for the controller. Alot more research and picking peoples brains needed on this though.

is there anywhere on the community or elsewhere that people go to, to get others to write code for them for $$$$

markmmaguire:
i dont know where i picked this info up from but i read somewhere that i could read the frequency from the car and use that as a guide for the controller. Alot more research and picking peoples brains needed on this though.

As I said, read out the frequency of the crankshaft sensor flywheel, and you're golden. Involves a bit of fiddling, first of all you would have to establish how many notches there are on your flywheel, as that differs from car to car. And then use that information together with your timers to work out the rpm by feeding the crankshaft signal into your Arduino. I have done precisely that kind of work on a trip computer for an MG F that I am working on at the moment. I'm not at home so you'll have to wait until I get back, but I would let you have that code snippet for free. You would still have to come up with the rest of the code though to tailor it to your specific application.

Draft last saved

Well, the tachometer on older cars is analog technique. I guess in the end the electronics create a voltage that twists the tachometer needle. Get that voltage and have leds turn on at different voltages. There are DIY voltage meters that show the voltage with similar led arrays. I don't know the circuits, I just know it can be done without digital microcontrollers.

The catch is going to be that every car manufacturer powers their rev counter differently. Technically, it will always come down to some sort of square wave or PWM coming from the engine control unit that will result in changing voltages with changing engine revs, and that then drives the tachometer.

You could then of course in a roundabout way just hook a series of LEDs up to your instrument cluster with different resistors so they will light up at different revs. And you will be able to have LEDs that way which will respond to changing revs. Provided they don't draw too much current away from the rev counter. But as those voltages will be different from car brand to car brand, this is really kind of a roundabout way of doing it.

A much more exact way is really to tap into a car's crankshaft sensor. Your key value is going to be how many teeth there are on the crankshaft flywheel of a particular car, and that info should be much more readily available.

As soon as I get home, I will post the code section that does this for me using the mentioned timers as part of my ongoing project of building a trip computer for one of my cars.

i appreciate your kind offer carguy, that would be great . i am before the beginner stage in regards to programming though :slight_smile: . if you could still post that snippet , that would be great . i am going to pick up a book tomorrow to start me off and i have a few youtube references i am working off aswell.

i can revert back to your code every now and again to get a grasp of what is going on and what standard is needed to perform an operation like that .

again thanks for all the help guys, my aim was to just find out if it was possible , you have gone beyond your call of duty and i appreciate that;

ok here is my code for the calculation of engine rpm based on pulses from the crankshaft sensor. I have isolated the lines of code that are relevant to your application from a sketch that does many more things than just rpm calculation, and have made pretty much a complete, ready to use sketch for you.

As another note - crankshaft sensors usually feed right into a car's engine control unit. Which means you can typically get the signal from one of the ECU pins. It's best to use an optocoupler for minimal interference with your crankshaft signal, because your ECU will need this signal to be as clean and proper as possible to function properly. It should not be tampered with more than necessary.

From the schematics to my trip computer:

So now here's the code:

int rpm;
unsigned long final_counts;
unsigned long timeDifference;
unsigned long microsNow;
unsigned long microsStart;

void setup() {

  // Timer1 setup for RPM signal
  TCCR1A = 0; //initialize Timer1
  TCCR1B = 0;
  TCNT1 = 0;

  // Digital pin 5 is going to be our input for the crankshaft signal
  pinMode(5, INPUT_PULLUP); //external source pin for timer1
  //set external clock source pin D5 rising edge
  TCCR1B =  bit (CS10) | bit (CS11) | bit (CS12);

  /*LED pins... for argument's sake, let's say each LED represents 1000 additional rpm,
    hence seven LEDs (~7000 rpm being the maximum of many petrol engines).
    Your seven LEDs will be connected to the following digital pins on the Arduino: */

  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop() {

  microsNow = micros();

  // ------------------ RPM calculation every two seconds

  if ((timeDifference = microsNow - microsStart) >= 2000000) {

    TCCR1B = 0; //stop counter
    final_counts = TCNT1; //frequency limited by unsigned int TCNT1 without rollover counts
    TCNT1 = 0;

    /* There are 32 teeth on my car's crankshaft sensor flywheel, which means 33 rising edge pulses
      are one crankshaft revolution. Therefore, you have to divide your number of measured
      rising edges per two seconds by 33. And then multiply the result by 30 to get
      the crankshaft revolutions per 60 seconds, i.e. your rpm figure.
      Your car will very likely have a different number of teeth on its crankshaft sensor flywheel.
      Find out that number and substitute my number with it. */

    rpm = (final_counts / 33) * 30;

    TCCR1B =  bit (CS10) | bit (CS11) | bit (CS12); //restart external clock source

     // resetting two-second time interval for next rpm pulse count
    microsStart = micros();
  }

  // And now use that rpm figure to drive your LEDs.  
  byte myLEDs = (int) (rpm / 1000);

  for (byte x = 1; x <= 7; x++) {

    byte whichLED = 5 + x;
    
    if (x <= myLEDs) digitalWrite(whichLED, HIGH);
    else digitalWrite(whichLED, LOW);
  }
}

This in one way of doing it which gives you pretty much all you need.

Another way to do it would be to use a multiplexer. But this usually has the disadvantage of only letting you switch on one LED at a time.

Another way to count the RPM is to use a signal from one phase of the alternator. The tachometer on my old Chevy Diesel operated that way.

Paul

If you are looking to develop something that will fit a range of different cars, as OP seems to want to do, you are going to run into problems though, because you would first have to work out for every single car, sometimes even for different engine trims of the same model, how many turns of the alternator equal how many turns of the crankshaft. This would require either access to in-depth technical data, again for every model and engine trim, or ages of trial and error work.

Info on how many teeth a particular crankshaft flywheel has is much more readily available; either from model specific web forums or just by going to a junkyard or calling a parts dealer and having them count the teeth on a particular flywheel for you... :smiley:

Also, the wiring will be much more neat, as many cars have the engine control unit inside the cabin behind a bunch of carpets or something.

The only problem with the crankshaft sensor alternative is that you are going to have to be very careful so as not to disturb the signal in any way. An engine desperately needs a correct crankshaft sensor signal, because it is the basis for almost its entire injection and engine management software. If your circuit draws too much power or you've got loose connections, that can screw everything up.

going down the crankshaft route does seem like it could fail straight away . it doesnt have to be precise at all really . all i need is a different LED to activate in increments of 1000rpm.

you'll have to excuse my rookie knowledge but would it be possible to place some small leds on the rev counter and something that will receive light on the needle so when it passes each LED it would send a signal to the arduino. it sounds stupid even typing that :slight_smile: :slight_smile:

im gonna take a step back from this project until i get more experience and knowledge on the arduino and the programming . i think im in over my head with that project

markmmaguire:
you'll have to excuse my rookie knowledge but would it be possible to place some small leds on the rev counter and something that will receive light on the needle so when it passes each LED it would send a signal to the arduino.

Since you're at hacking the rev counter, just get a jumper cable at the right pin inside the rev counter, the one with the voltage that twists the needle.

markmmaguire:
going down the crankshaft route does seem like it could fail straight away .

Crankshaft sensors can be fickle, yes. They must be treated with care, as their signal is the foundation for almost the entire engine management system. The engine control unit must know the crankshaft position at all times without fail.

But it can be done. With the right resistor values and solid connections, it should normally work.