1x switch & 3x LED's. Light one at a time in a sequence then loop to start???

Hi,

I am a complete noob when it comes to arduino. I have read some info on both this website and others to try and learn some of the basics.

I wonder if somebody could offer any advice on whether an Arduino could help with a project I am thinking of trying (if it is possible and not too far beyond my ability to learn the required skills).

Project description:

I have an electronic control unit, it has a single connection (wired) that senses voltage on the wire between 0 and 5v.
It sees 0v as an 'option 1', 5v as an 'option 3' and a mid point circa 2.5v (it is adjustable) as an 'option 2'.
Essentially it is just a way of selecting 3 different modes and by having a 3 way switch connected to earth, earth via a resistor and to nothing it sees the required voltages.
That part is the straight forward bit.

What I would like to do if it is possible would be some or all of the following.

I would like some form of identification to show which 'mode' has been selected.
I realise I could just wire a lamp to each mode switch position but I wouldn't need an Arduino for that.

I wondered if I could utilise a small LCD display and have the mode and/or mode details show as text on the display?

Also, instead of using the planned 3 position rotary switch to select between the modes could I utilise an Arduino and a single momentary push switch such that pressing the button would cycle through the 3 modes over and over?

Appreciate any help given. :slight_smile:

I would like some form of identification to show which 'mode' has been selected.

The Arduino has multiple analog inputs and you can use one to read the voltage.

The [u]Analog Read Serial Example[/u] should get you started.

The voltages won't be exact and you may get some noise/variation over time. The "trick" is to look for a range of voltages.* For example maybe less than 1/2 volt is treated as 0V, 1.5V - 3.5V is treated as 2.5V, and anything greater than 4.5V is treated as 5V. Of course, you should experiment to see how much variation you're getting so you can set your tolerance appropriately.

Your software doesn't actually have to read "Volts". You can use the ADC reading directly. For example, the ADC reads 512 at 2.5V (with the default 5V reference).

I wondered if I could utilise a small LCD display and have the mode and/or mode details show as text on the display?

There is an LCD library and some examples. That's probably the hardest part of your project.

Also, instead of using the planned 3 position rotary switch to select between the modes could I utilise an Arduino and a single momentary push switch such that pressing the button would cycle through the 3 modes over and over?

Yes, and that's probably better than checking the analog voltage. But, you'll have to replace the rotary switch with "something"... Probably 2 or 3 relays depending on what the actual circuit looks like.

You can simply count button-presses in a loop, and reset the counter to one** (with an if-statement) every time it counts to 4.** You'll need to debounce your switch... Mechanical switches bounce when they open/close, so the microcontroller may count several button-pushes in a few milliseconds when you push the button once.

  • If you look at the ATmega chip specs (or any other digital chip) you'll see that's how normal digital works too. Greater than a certain voltage is treated as a logic "1" and less than a certain voltage is treated as logic "0". There is a voltage range in-between that's undefined.

** It's actually more "traditional" in programming to start counting at zero. If you do that, you'd have positions 0, 1, 2, and then reset to zero as soon as you count to 3.

Thanks DVDoug for the swift and comprehensive reply, 8)

So in essence you believe that an Arduino should be capable of what I am asking of it?

And from your info could a single switch connected as in input then output a zero volts, 2.5v or 5v signal to the ECU?
Is that how it would work?
I presume that it would always default to mode zero on power on?

In it's simplest form is it a case that switch position zero (power on) would register as Mode 0 and therefore output an output to the ECU to signal 0v, a second press would then output a different output and signal to the ECU mode 1 (2.5v approx), then the third press would be mode 2 and signal 5v. At this point the ECU is seeing all 3 selected modes. Another press would then return to mode zero?

I saw a tutorial on using debounce so thanks for the pointer. That should work fairly easily I think.

You could use colored leds to indicate mode. Or even an RGB led with diffuser (plastic the led lights up from below/behind) or a cheaper 3-color led (red, green or together-as-amber) that needs no diffuser.

It might be possible to use two pins and some circuitry to make the ECU see 0V, 2.5V, or 5V though if diodes are needed the 2.5V and 5V would become less, .3V less with Schottky diodes or .7V less with plain old diodes.

The trick is that Arduino pins can be LOW, HIGH or effectively neutral and switch between almost instantly. One pin could be 0V or 5V and the other pin could drain some of the 5V through a resistor, turning on a voltage divider to the 5V.

That with a turn-pot selector could run off a stand-alone $1 or so 8-pin ATtiny chip.

Thanks GoForSmoke for the reply.

I don't know if I would be better to output High, Low and a high through a resistor (to get the 2.5V) via Diodes to the Ecu wire to simulate the 0v, 2.5 and 5v or to use PWM on 3 outputs.

If I used a single switch could I just have the sketch look for sequential switch presses, starting at 0 and output say 0v, then on button press one output 1 (Pwm at 2.5v) and then button press two output 5v?

Perhaps I am not understanding this correctly.

I have been reading some information on the Arduino to try and understand how it could work.

However you do the user input, the sketch should read that as one task (not getting down to actual code yet) and interpret that.

I have a couple of 3-way rocker switches but when I checked allelectronics.com for a link to show they appear to have no more. They do have 3-position slider switches though. A turn pot should be simple to code for, even a salvaged volume dial. 3 buttons would do or 3 IR reflector sensors or beam interrupts, you have an amazing number of input choices to choose from. Capacitive touch buttons need no moving parts and you can make your own or buy them. This is something you should explore.

The sketch should read the buttons, interpret the input and then change the output. The user should not have to know how it's done and the input method should be as easy and mistake-proof as possible.

If PWM will work then yes, 1 pin to the ECU will simplify the wiring and simplify the output code.

Thanks again for the reply :slight_smile:

I have been reading various sketches and trying to fathom out how it even works.

I see that using State change detection (edge detection) for push button switches from this site

The above code appears to be on the right lines. However the code illuminates the LED every 4th press.

I am trying to work out how I could modify the code to instead output to 3x LED's with each button press i.e. Position 0 would be LED1 on, position 1 would light LED2 but turn off LED1 and then position 3 would light LED3 turning off LED2. 4th press would return to position 0 and start all over again in a loop.

I'm guessing it must be a series of 'if' and 'else' statements but I am yet to work out how to set it out.

Once I have worked this out I could then substitute the LED's for the output wires to the ECU. I figured I could feed the 5v and the resisted 2.5V via a diode each to separate the flow to the ecu.