Go Down

### Topic: Simulating resistance for buttons (Read 3032 times)previous topic - next topic

#### JayinMI

##### Dec 01, 2012, 04:01 am
OK. I'm trying to interface my Arduino with a circuit for the steering wheel controls in my car.
I wrote a sketch that reads the input voltage, compares it to values for Volume Up, Volume Dn and Mode.
If it sees any of those three it does one thing (currently printing Vol Up, Vol Dn, or Mode on the screen via Serial Monitor),
otherwise it passes the voltage out on pin 9 using analogWrite to send a PWM voltage out.

However, I'm either doing something wrong, or exceeding the current capacity of Pin 9's output.

Here's the original diagram, and the modified one I was attempting to use.

It seems that I killed pin 9 somehow.

Here's the sketch I'm using:

Code: [Select]
`int swcIn;                      //Set variable name for SWC readingint swcOut;                     //Set variable name for SWC outputint swcPinin = 3;               //Set pin for SWC readint swcPinout = 9;              //Set pin for SWC passthrough outputvoid setup()                    // run once, when the sketch starts{  Serial.begin(9600);           // Set up serial  }void loop()                     // run over and over again{  swcIn = analogRead(swcPinin); // look at SWC input pin, store it in swcInif ((swcIn >= 606) && (swcIn <= 609)) // is swcIn => 606 and =< 609?  {      Serial.println ("Vol Dn");  //Yes? Print "Vol Dn" to serial monitor  }else if ((swcIn >= 506) && (swcIn <= 509))  //Is swcIn =>506 and =< 509?  {      Serial.println ("Vol Up");  //Yes? Print "Vol Up" to serial monitor                                }else if ((swcIn >= 317) && (swcIn <= 320))  //Is swcIn => 317 and =<320?  {      Serial.println ("Mode");    // Yes? Print "Mode" to serial monitor  }else   {    analogWrite (swcPinout, (swcIn/4));  // otherwise pass signal to radio      {//        delay(25);                     // wait long enough for radio to read it        analogWrite (swcPinout, 255); // clear the pin so it doesn't keep sending the last command      }}   }`

The sketch seems to work fine.

Do I need to use different components?

I had thought about using an output per button, using a relay to simulate each button, but that wastes a lot of outputs. And I need something like 6 for the other part of the project.

When the wires were still intact, I measured the voltage for each switch. Here's what I got:

Vol Up  2.47V
Vol Dn  2.95V
Mute    1.99V
Mode   1.55V
Track Up  .42V
Track Dn  .95V
Hang Up   3.98V
Voice  3.46

When the voltage is passed through on pin 9 via PWM, it matches up (it's actually about .2V higher, but the 5V from the Arduino is about .2V higher than the 4.98V the radio supplies. I can adjust for it in software.)

Any ideas?

Thanks.

Jay

#### Osgeld

#1
##### Dec 01, 2012, 06:53 am
your steering wheel is probably on a can or lin bus and is actually sending data to and form the on board control systems, and your meter isnt fast enough to react to the individual pulses ... none are capable of that.

#### Grumpy_Mike

#2
##### Dec 01, 2012, 10:16 am
Pin 9 is giving out PWM signals. In order to make that look like an analogue signal you need a filter, I don't see one.
Also check with a meter if the voltage on what you want to connect to pin 9 is not being pulled up to a higher voltage than 5V. That would kill it. If so you will have to use a transistor to buffer the signal.

#### JayinMI

#3
##### Dec 01, 2012, 01:01 pmLast Edit: Dec 01, 2012, 01:30 pm by JayinMI Reason: 1
It is not being pulled higher than 5V, but it appears that the 5V coming out of the radio is overriding whatever voltage I try to send to it.
The SWC wires are not on a Can Bus or Lin Bus in this car.

Grumpy_Mike...can you point me in the direction of the filter I need?

Thanks.

Jay

Edit: You mean like a low-pass filter (inline resistor, cap across the two leads?)
Helps alot when you know what to search for. My previous efforts resulted in nada.

What it looks like is that I need to pass varying levels of ground, so whatever method I end up using I need to make sure that there is a path to ground for the circuit to work.

#### Grumpy_Mike

#4
##### Dec 01, 2012, 03:05 pm
Quote
but it appears that the 5V coming out of the radio is overriding

That would be because the pin is being directly connected to the 5V and not through a resistor as you showed. So when you output zero volts from the arduino you are trying to short out this voltage. That is a way to make things melt.

It is a low pass filter you need. The simplest form is a resistor and capacitor.

#### MAS3

#5
##### Dec 01, 2012, 10:31 pm
It looks to me like you did not completely understood the schematics.
You connected pin 9 to what looks to be a pull up resistor.
That is actually what is does, but only until a key is pressed.
In case a key is pressed, it is part of a divider.
The keys have an array of resistors, and that key that is pressed (in case multiple keys would be pressed, the one most to the right will set the value) connects to 0 volt (GND).
So in case the 5th key is pressed, you can add 1K5 + 1K + 1K + 680 + 470 (i'm guessing because i can't read all values) so that would become 4650 or 4K65.
You will have an array of resistors forming 4K65 and an other resistor of 4K7.
These two values have 5 volts across, and at their joining point you will have about 2,486 volts.
This is quite close to a value actually measured by yourself.
You cannot just make this measured value and insert it instead of the resistor/key.

I would just connect pin 9 to the input of the unit, without this 4K7 resistor to 5 volt.
Thus, put your analog output directly to the input (that arrow pointig out) but not to the existing resistor.

You still need to make the PWM output an actual analog output, because else it's still unlikely to work.
And of course you always need to connect the GND of your Arduino, to that of the unit you want to control.
Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

#### JayinMI

#6
##### Dec 02, 2012, 01:29 am

It looks to me like you did not completely understood the schematics.
You connected pin 9 to what looks to be a pull up resistor.

No, I got that. I figured it was a pullup resistor, but something I thought of today was that
there was a 470pf cap across the leads before the resistor ladder. So, I was wondering if the combination
of the 4.7k ohm resistor (inside the radio) with the cap (at the resistance ladder) was, in fact, functioning as
a low pass filter? And, since I interrupted the +5V line and didn't include a cap on the radio side of the cut wire
if I added it back in would it work? I'll keep looking.

That is actually what is does, but only until a key is pressed.
In case a key is pressed, it is part of a divider.
The keys have an array of resistors, and that key that is pressed (in case multiple keys would be pressed, the one most to the right will set the value) connects to 0 volt (GND).
So in case the 5th key is pressed, you can add 1K5 + 1K + 1K + 680 + 470 (i'm guessing because i can't read all values) so that would become 4650 or 4K65.
You will have an array of resistors forming 4K65 and an other resistor of 4K7.
These two values have 5 volts across, and at their joining point you will have about 2,486 volts.

2,486?!? I assume it is actually 2.486 (less than 2 and a half) volts?

This is quite close to a value actually measured by yourself.
You cannot just make this measured value and insert it instead of the resistor/key.

I would just connect pin 9 to the input of the unit, without this 4K7 resistor to 5 volt.
Thus, put your analog output directly to the input (that arrow pointig out) but not to the existing resistor.

I had thought of that. The resistor is inside the radio, and I cut a trace on the board that I thought would do exactly that, but I still have 5V out, so I assume I cut the wrong trace. I'll fix that tomorrow. I figured if I could keep the 5V output from getting to the point where the radio looks for the signal from the SW buttons, and feed my analong/PWM output directly to that point that it should work. If I use a LPF then I might be able to return the trace inside the radio to stock and do everything outside the unit. That would be a plus.

You still need to make the PWM output an actual analog output, because else it's still unlikely to work.
And of course you always need to connect the GND of your Arduino, to that of the unit you want to control.

I have a 7812 taking the voltage in the car down to a little under 12V so it doesn't exceed the input voltage capability of the Arduino.
Grounds are all common to the car.

Jay

#### Grumpy_Mike

#7
##### Dec 02, 2012, 01:40 am
The input voltage capability of 12V is only for the power. The signals are limited to 5V.

#### JayinMI

#8
##### Dec 02, 2012, 01:44 am
Yeah, I know that, but I read that I needed something like 9V or above to make sure I always got a consistent 5V from it.
It says it will work up to like 20 volts (input) but that anything over 12 can cause damage, so I used the 7812 to bring it into a safer level.

Jay

#### JayinMI

#9
##### Dec 02, 2012, 02:22 am
Here's a revised diagram. Would this solve my problem?

Jay

#### JayinMI

#10
##### Dec 02, 2012, 07:21 pm
I've read several tutorials on building RC LPF's. But, frankly, a lot of the terminology is over my head.
I was also wondering if it matters where the resistor is in relation to the cap. Does it need to come before, or can it come after?
I read Grumpy_Mike's PWM tutorial, and that was helpful, but I'm still at a loss on what to choose for frequency.
A friend of mine with a fair amount of electronics experience has proven to be less helpful than I had hoped. Usually the responses have been after I figured something out on my own (or with the help of arduino forums) and been something along the lines of "Yeah, that's probably how I would have done that."

I can really only work on this project on my days off, and I only have 1 more coming up before Christmas, so I'd like to get this mostly working so I can get back to the software end of it.

Any help is GREATLY appreciated.

Jay

#### Grumpy_Mike

#11
##### Dec 02, 2012, 11:30 pm
Quote
Would this solve my problem?

I don't think so because pin 9 is still going off into the unknown and you tend to fry pin 9 for a not yet explained reason.
One way to help might be to add a resistor in series with pin 9, try anything between 100R and 1K.

#### JayinMI

#12
##### Dec 03, 2012, 12:50 am
Is 100R 100 ohms? And will I perhaps have to adjust my voltage in software? Just wondering what to expect.
I appreciate the help. I soldered a bridge over the trace I cut, so it should be back to normal.

Thanks again.

Jay

#### Osgeld

#13
##### Dec 03, 2012, 02:46 am
Quote
Is 100R 100 ohms?

yes, when you dont use the word ohms 100O can be confusing, especially when writing it by hand