My first Arduino project and my head hurts. Any advice appreciated

I'm trying to build what i (as a mechanic) call a resistive multiplexed circuit to reduce the thickness and number of wires going to the handlebar controls of a motorcycle. Its the same as getting of a cars steering wheel controls for the audio on a few wires.

I've connected 3 10k ohm resisitors in series with the analog read input at the end and a pulldown resistor to ground . Then I have 3 switches that put 5volts at the divides between the resistors so that each switch returns a different value on an analog read pin when pressed.

This bit i get fine on the 3 switches I get 253, 338, and 509 on the serial monitor.

Now here's my problem, I want to turn on a digital output based on the value seen on the analogRead but because of the environment it will be operating in I want to give the arduino a value range so for example send a digital pin high if the analogRead value is between 225 and 265. This would compensate for damp switch contacts on the handlebars.Any help would be appreciated, I did have a go with an if statement with no luck.

I'm sure this is a very basic mistake but endless Youtube vids and tutorials have left me wanting to build a bonfire with this stuff.

Maybe something like

resistanceVal = analogRead(resistorPin);

if (resistanceVal > 450) {
   // do something A
}
else if (resistanceVal > 310) {
  // do something B
}
else {
  // do something C
}

...R

Why not make life easy and use one digital input per connection and say a thin multi core screened cable .
Be careful too - you don't want to be riding along and the Arduino crash and the lights go out , or the engine to cut in a corner.
The electrics on a bike are very noisy, and this is a good possibility. I would never use such a circuit in a safety critical application .

hammy:
I would never use such a circuit in a safety critical application .

Very wise.

...R

Something like this would also work

resistanceValue = analogRead(resistorPin);
If ((resistanceValue > 225) && (resistanceValue < 265))
{
//Do something
}
Else if ((resistanceValue > 300) && (resistanceValue < 400));
{
//Do something
}

And so on.. I'm sure you can figure out the rest. Sorry for my formatting, I'm doing this on mobile but if you're plamning on copying and pasting just click ctrl + T in the ide to auto format.
Good luck!! :slight_smile:

hammy:
Why not make life easy and use one digital input per connection

Also this is a good idea and certainly what I would do since you wouldn't have to deal with varying in the values. However, I'm assuming you spent a great deal of work already getting that to work and it would likely be a bigger pain to restart and go that route. Either way would work fine. It's up to you.

Thanks for all the replies,

NeilSawhney, your solution works perfectly. As for the safety side of things, I'm experimenting with employing the type of layout used on cars for years but you have raised a good point.

That said I'm going to work out a fail-safe so that a broken signal will turn everything on and I might use a latching relay for the kill switch so if there is a signal loss it can't cut the engine. Maybe separate left and right function and use a Nano for each.

I'm at the "is it possible" stage so if there's any doubt i just won't do it.

Thanks again.

Minty251072:
I might use a latching relay for the kill switch so if there is a signal loss it can't cut the engine.

Don't involve an Arduino in that circuit at all - too risky,

...R