Variable 5V input ...help

Hi all, I have run up against a block and I don’t know how to get around it.
Adrunio Uno board to run a ten light array connected to the cars Throttle Position Sensor, .5volts closed throttle and 4.5 volts full throttle.
I thought I had it figured out but when I hooked it to the car I only get the first 4-5 lights to work.
And can’t figure out how to write in a 5volt normally open switch to turn on a single led for the stop lamp.
I have gotten a simple switch to work for the clutch pedal input, yea I did something myself…
The customer is coming up on his race weekend and I still have a lot to do to the car and don’t want to scrap this project, too much time and money in it now to give up. So I am here to ask the experts for help

int potPin = 0;
int i = 0;

void setup()
{
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);

}

void loop()
{
for (i = 1; i<=10; i++);
digitalWrite(i, LOW);

int val = analogRead(potPin);
int count = map(val, 0, 1023, 0, 10);

for (i = 1; i<=10; i++)
if (i<=count)
{
digitalWrite(i, HIGH);
}
else
{
digitalWrite(i, LOW);
}

const int buttonPin =12;
const int ledPin =11;
int buttonState =0;

pinMode (buttonPin, INPUT);
pinMode (ledPin, OUTPUT);

buttonState= digitalRead(buttonPin);

if (buttonState==LOW)
digitalWrite (ledPin, HIGH);

else

digitalWrite (ledPin,LOW);
}

Hi

Without your circuit diagram or more detail am going to only be able to give some thoughts on where I'd look, but here goes.

It might be worth opening a serial session to output to the screen what value val is actually reading and count is calculated to. This may need a bit of a change in your code as the serial sits on pins 0 & 1 and I don't know what impact it will have with you trying to drive D1 for an LED. Just thinking we should rule out the possibility the values being received are being interpreted correctly as 4-5LEDs only.

That many LEDs should be powerable from the Arduino directly presuming they're standard 5mm types with the correct resistor value in series, but as a debugging step try to just drive the one that corresponds to count to see if the others come up live (will eliminate dud LEDs or an issue with your circuit as issues).

On the brake pin question make sure you've got a pull-down resistor in place so the value on that sensor pin doesn't float. Jeremy Blum's tutorial 3 covers many of these concepts EE Basics in Tutorial 3 for Arduino – JeremyBlum.com as a reference point.

Also I'm presuming you've put a multimeter on that brake switch to confirm it's controlling the +5V supply, and not switching the GND ?

Do let us know what you find - sounds like a very interesting project !

Cheers ! Geoff

This is the set up i am trying to use, of coure only 10 led's. did away with the dash pot/reostat and put the cars TPS straight to the A0
Hope this helps

trying to get the diagram to post not sure if it's going to work?

PotMeter_bb[1].jpg

Stick a delay(1000); at the end of loop. Since you set all leds off at the top of loop, your issue may simply be that they don't stay on long enough for your eyes to register it. This test will at least eliminate an issue with your wiring.

OK checked my wiring, swaped pin input, swaped Arduino boards...
The lights light up one at a time and stay on properly when hooked to the reostat...
Rechecked the voltage output from the TPS sensor, .5v closed throtle-4.5v full throttle, engine running or not.
Still only getting 6 of the leds to light when the car is not running and when I start the car, I dont get any movement of the lights???

Any ideas...I am stuck

Did a nother test with the board...hooked it to another non like vehicel (a cadillac esclade) TPS reads the same though.
Key on engine off, FULL array of lights all ten light up and go off in corespondance of the gass peddal... start the truck, the same :0

Seams to be more than just a simple voltage input to the cars ECM, is there some way to filter that junk out?
Should I just scrap this end of it?????????????????and make a nother "TPS" seperate of this project????

You are really not providing any usable details. We can't see past your screen. I'm sure referring to a car model, TPS, ECM, etc makes sense to you. Personally, I don't have any context for those things.

You also seem to be ignoring suggestions or at least providing feedback on those suggestions. The suggestion to add delays was already given. What was the result of that test? If the signal is fluctuating, you may not be seeing the LEDs change.

The suggestion to enable serial debugging. What was the result of printing the analogRead() value? This will tell you if there is any noise.

If you need to filter out noise, you'll need to use a scope or spectrum analyzer and determine what kind of noise is on the signal before you can properly filter it.

Hi James, like you said you are lost when it comes to car, make, TPS, ECM...
when it comes to adding the delay, printing the "analogRead() values, and ... I am lost. I can build an engine, transmission, tell you how to add suspension tricks to your car, but when it comes to programing I AM LOST, this is why I am asking for help.

Adding the delay to the sketch/code, does this go in the setup or the loop?
I am not sure how a delay will work, cause some lights are coming on when the car is started and stay on. At .5v only one light should be lit and there are more. when the engine is off, things seem to be working right, this is whats got me confused??????????

delay goes in the loop

delay (1000);

is all u need
your not sure it will work?
well try it also
the serial monitor is a great idea also you should put it on all your stuff basically it makes it easier
open the analog read serial example.
it contains the needed code to get a basic serial feedback (put it in your loop)
if you have the serial monitor open ctl>shift>m u can see what your input is
if you do

Serial.begin(9600);   //setup

Serial.println("Pot value is: ");  //loop
Serial.println(potPin);

but you need a delay otherwise it can go so fast you dont see it.
also to insert code (make it easier on everyone)
where u write the post their is a # symbol on the lower right above the writeing box hit it and insert the code in between the inserted stuff.

The bigger issue with serial debug is that the original code is using pin 1. Pins 0 and 1 should be avoided since they are used for the serial monitor.

thebfs:
delay goes in the loop

delay (1000);

is all u need
your not sure it will work?
well try it also

Delay installed.

[/quote]the serial monitor is a great idea also you should put it on all your stuff basically it makes it easier
open the analog read serial example.
it contains the needed code to get a basic serial feedback (put it in your loop)
if you have the serial monitor open ctl>shift>m u can see what your input is
if you do

Serial.begin(9600);   //setup

Serial.println("Pot value is: ");  //loop
Serial.println(potPin);

[/quote]

What will I be looking for with the "serial monitor"?

[/quote]
The bigger issue with serial debug is that the original code is using pin 1. Pins 0 and 1 should be avoided since they are used for the serial monitor.[/quote]

Should I move it to another pin?

Tryed the delay at 1000, 500, 250 and 10, 10 is liveable
Maybe some pictrues
1- hooked up to the car, ignition on, NO throttle pedal input
2- full throttle
3- Key OFF, ON voltage to the Arduino board!

What will I be looking for with the "serial monitor"?

you will see the values read from the pot.

  • then u can see if they mapped corectly
  • if any are out of scope/range
  • if you are getting jumping values/nonlinear
    -if your input is floating.
    etc
    all these and more will confuse the input, and then your program and finaly your project

Should I move it to another pin?

i personaly don't have experience with that. but i can tell you it wont hurt.
try it, james seems to know what he is doing

Should I move it to another pin?

Yes, you'll need to if you use the serial monitor to output any of the values. The serial monitor needs D0 and D1 pins free for its use.

Also for the sake of putting all these debugging ideas in the one place for you:

const int potPin = 0;
const int buttonPin =12;
// note moved ledPin up to D13.  
// You won't need a resistor for this as it's already got one, and there's already a LED on the Arduino attached to this pin.
const int ledPin =13;
int buttonState =0;
int i = 0;

void setup()
{
// note I've shifted you up a few pins to leave D1 free for the serial monitor
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);  

  pinMode (buttonPin, INPUT);
  pinMode (ledPin, OUTPUT);

// start the serial monitor
  Serial.begin(9600);

}

void loop()
{
  delay(10);   // the delay duration you were happy with
// Note: I deleted the ; off the end of this next line.  With it there it did nothing.  Now it will blank out the LEDs
  for (i = 2; i<=11; i++)     
    digitalWrite(i, LOW);
  
  int val = analogRead(potPin);
  int count = map(val, 0, 1023, 0, 10);

// debugging to Serial monitor...delete this block when done debugging if you like
  Serial.print("val = ");
  Serial.print(val);
  Serial.print(", count = ");
  Serial.print(count);
  
// small change in the next block to just drive the ONE LED based on count's value
// have left the original if statement as a comment so you can reinstate it later
// note the changed for loop to reflect the new LED pin numbers
  for (i = 2; i<=11; i++)
//  if (i<=count)
  if(i== count) digitalWrite(i, HIGH);
  else digitalWrite(i, LOW);
   
  buttonState= digitalRead(buttonPin);
  if (buttonState==LOW) digitalWrite (ledPin, HIGH);
  else digitalWrite (ledPin,LOW);

// more debugging to Serial monitor
  Serial.print(", buttonState = ");
  Serial.println(buttonState);
}

That is of course untested, so I hope I've not introduced any ugly typos.

Since you've got a camera handy, any chance you can take a shot of the Arduino and breadboard in better light so we can eyeball what you've got there? They're a bit indistinct in the images so far.

Cheers, Geoff

Hi Geoff,

Got a chance this morning to down load the code and tryed it.
It looks like it will work!
I am going to try it in a car that I can drive on the street to check it out more, but THANK YOU!
Here is a pic of the Ardunio and breadboard.

Dont know why but when I have the board hooked up Led #2 & 11 are not lighting up? and to get the progression of lights we just have to change "i==" line?

Thanks Mate!

Linc

Linc:
It looks like it will work!

That's always a relief :wink: But read on and you'll see why I'm glad you think so!

Linc:
Dont know why but when I have the board hooked up Led #2 & 11 are not lighting up? and to get the progression of lights we just have to change "i==" line?

Actually that's entirely my fault. I changed everything but the remapping of count, which still has the old range. Make it instead:

  int count = map(val, 0, 1023, 2, 11);

...and that should work a little better than before.

All the best with your test,
Geoff

Hi Geoff,
Well after putting it on three differant cars...no good ]:slight_smile: I guess there is other comunication going on that circuit, that my DVOM just doesnt see.
So guess i am back to make a seperat reostat for the input.
That is unless you can think of something more to try.

Linc

Linc:
Well after putting it on three differant cars...no good ]:slight_smile: I guess there is other comunication going on that circuit, that my DVOM just doesnt see.

That's a real shame. In the case of the brake pedal I don't understand why it might be more complex than a switch - what does your multimeter tell you ?

On the accelerator I'm not at all surprised, especially if it's a newer car. Don't know if you've seen articles like this one http://www.instructables.com/id/Hacking-Automotive-Ultrasonic-Sensors/ which talk about all the cool traffic going on inside a GM vehicle on what appears to be a very busy serial data bus. I'd not expected there to be a point-to-point analog circuit to the engine management if it's a newer vehicle (sorry don't know the cars you mention above).

Some kind of reostat, rotary encoder etc might be in order to step outside the car's systems, agreed.

Geoff

Yea I use a lot of GM sensors for other projects I do. I race a 1975 Honda Civic 1200 with fuel injection on it and I have used lots of GM sensors.

I have a friend that is an instructor at the local uni here, I am going to ask him if he could hook up a Honda CRX to see if he can find the frequencies they use for the TPS signal, the car I am working on is a 1988 Honda CRX.

The brake switch is a normal open switch, 12 volts when closed so I will need to go with a voltage divider to bring it down to the 5 volts required. The code…it should be an analog input or digital seeing as how it’s a simple ON/OFF input? Your thoughts…
Or just use the 12 volts, a resistor and the LED

Linc

Hi Linc

Scary to find another Hondaphile. I used to drive an 89 Civic hatch, which over here was closely related to the CR-X. I couldn't tell you how the throttle was connected. I do know it was electronically controlled, with vaccuum actuation on dual carbs. A kind of halfway step to PGM-FI that was just too scary for me to ever pull apart :astonished:

I'd have thought for a vehicle of that age the brake pedal would be a simple switch, so yes a voltage divider down to 5V for the Arduino digital input will do the trick. Using (say) 10k and 15k as your resistor values will get you down to 4.8V which is right in the zone you need.

Sounds like you're well on the way now.
Geoff