Arduino Forum

Using Arduino => General Electronics => Topic started by: DragoslaV on Mar 02, 2011, 10:14 pm

Title: Combining analog input
Post by: DragoslaV on Mar 02, 2011, 10:14 pm
Hey Guys,

I'm quiet new to Arduino and electronics and I am trying to build my own speedometer with LED's. Currently I have my LED's up and running. So now its time for phase 2, input  :)

First this speedometer is for a motorcycle bike and it needs to have to following input:
* Indicator left
* Indicator right
* Fuel Injection Sensor
* Speed sensor (magnetic)
* Temperature sensor (oil heat)

Fuel Injection Sensor
This is a very important step in the process of turning on my engine. I cannot turn on my engine before this sensor calculated how many fuel it needs to burn. Of course the electronics of the bike are turned on in this process.

My problem
Well to be honest 'my mistake'. I did not calculated all the pins and I eventual got stuck with missing 1 analog input. However I think its still beatable!

My indicators can only be turned on one at the time. So its physically impossible that both left and right are turned on at the same time. I want to use this with the Fuel Injection sensor, if both left and right are turned on then this will mean the sensor is calculating how much fuel it needs to burn. If its done calculating then it will turn off both left and right indicator.

The drawing
(http://test.aerosol.me/leds/analog-input.gif)

My question
Since I am quiet a noob and before I buy the components, do anyone see any problems?? Also thanks alot in advance.

Side notes:
Indicators: This input is 12v but I heard it can go up a bit during driving.
Resistors: (12v - 5.7v)/0.04 = 157.5 (closest 150?)
Diodes: Forward Voltage drop will be at 0.7v
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 02, 2011, 11:33 pm
Quote
do anyone see any problems

Yes you are connecting 12V into the arduino, you will blow it up.

You need either potential dividers or some sort of transistor to act as a buffer.

Once you take out the Aref none of the other analogue inputs will read anything meaningful.

Title: Re: Combining analog input
Post by: CrossRoads on Mar 02, 2011, 11:54 pm
Aside from feeding in 12V, I don't believe Aref is an input you can get readings from, and you seem to be after more digital type inputs.
Seems like its time to add a multiplex chip, or a shift in register that you read continually to see if anything has changed.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 03, 2011, 01:26 am
@Grumpy_Mike
Thanks, I was aware that I had to cut down the 12v to 5.7v but I thought that was done differently..  :smiley-zipper: What is your best practice for that then??

@CrossRoads
I looked a bit closer in the Reference page and yes I totally misunderstood it  :smiley-roll-sweat: I guess that gives me the problem of missing 2 pins. I also could use a shift register but I want to keep this project as simple possible and also I could drop the temperature sensor which only gives me the headache of how to convert the 12v to a 5.7 and eventually to 5v.

(http://test.aerosol.me/leds/analog-input-v2.gif)

@KE7GKP
1) Well I could free up a digital pin by swapping it with a LED column.
2) That is a nice technique too I'm ganna keep that in mind! Thanks for sharing :)
Title: Re: Combining analog input
Post by: MarkT on Mar 03, 2011, 12:27 pm
There is no 'A8' pin!
Title: Re: Combining analog input
Post by: MarkT on Mar 03, 2011, 12:29 pm
If you have more analog input devices than analog pins you need to multiplex, see this page: http://www.arduino.cc/playground/Learning/4051 (http://www.arduino.cc/playground/Learning/4051)
Title: Re: Combining analog input
Post by: DragoslaV on Mar 03, 2011, 02:00 pm
@MarkT
Good noticed, I made a typo; it should be A0, A1 and A2.
Also thank you for the link! I guess a multiplex is the best practice for my problem.

@All & KE7GKP
I'm sorry, I should have posted my entire schematics. :smiley-roll-blue:

Schematics (without Multiplex)
(http://test.aerosol.me/leds/LED-technische-tekening-v4.jpg)
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 03, 2011, 04:45 pm
The row pins can only supply 30mA so you will have to split this amongst all the columns. You normally need some form of high sided driver like a p- channel FET or a PNP transistor.

Also the row resistors should be in the columns, otherwise the brightness will change depending on how many LEDs are on at the same time.

How will the software scan these?
Title: Re: Combining analog input
Post by: DragoslaV on Mar 03, 2011, 09:58 pm
@Grumpy_Mike
Yes, spot on, I totally forgot to update my schematics but I have 10 resistors on the columns and not on the 8 rows as shown in the image.
Also somehow I got my LED's working without the transistors and with a very good brightness. (LED's require 20mA). Does it harm anything if I continue without?

@KE7GKP
Haha yes I used all the pins  :smiley-roll-blue:  I would have done it differently now but I guess that is what learning is all about.. I totally dropped my first idea. That idea was the result of a noob trying to figure out a creative way around :smiley-roll-blue:

I think your multiplex is a really good idea so I'm gonna update the schematics with a 4051 between it.
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 03, 2011, 11:09 pm
If each LED requires 20mA then you are asking those anode pins to supply 200mA. So yes this will do harm seeing as 40mA is the absolute limit.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 03, 2011, 11:43 pm
That makes sense. I wish somebody told me that here (http://arduino.cc/forum/index.php/topic,52365.msg377084.html). But I'm glad I you told me this while its still on my breadboard :) I just dont get it why they didnt mention to put transistors between it in the playground example (http://arduino.cc/playground/Main/DirectDriveLEDMatrix).  :smiley-sweat:

So todo for now:
* Add transistor to the rows.
* Add a Multiplex. (4051)
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 04, 2011, 09:21 am
Quote
I just dont get it why they didnt mention to put transistors between it in the playground

Sadly it is not a very good example, you will note there is no resistors in although the text now tells you to do this after some badgering from a few members. The lack of resistors and overwriting of the outputs probably meant the display looked ok. There is a train of thought that goes, it is only a demonstration and people will not run it for long so overload dosn't matter.
However I think that it is important to get it right as people, like you, go on and use the circuit as a basis to expand into their own design. If you start off with the right idea you don't have to relearn old stuff.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 05, 2011, 03:00 am
Thanks everybody and thank you Mike for clarifying that out!

Based on your input and based on this schematic (http://www.instructables.com/file/FVO2UZAG3CAMAAN/), I have created a new schematic for myself including the multiplex and transistors. The transistors used in this schematic (http://www.instructables.com/file/FVO2UZAG3CAMAAN/) is a '2N3904'. Could I also use this for my setup??

Also I would love to hear if I made a(nohter) mistake in my schematics!  :D
Title: Re: Combining analog input
Post by: CrossRoads on Mar 05, 2011, 03:13 am
The big block labaled transistors represents 6 more of the NPNs above?
You are missing the resistors between the arduino and the base pins as shown in the example you cite.
Need them to limit current out of arduino pin.

You might also look at ULN2803, 8 transistors all packaged up with needed resistors.
High input pin, output pulls LED cathode low.
http://focus.ti.com/lit/ds/symlink/uln2803a.pdf
ULN2803 is 46 cents at dipmicro.com
Title: Re: Combining analog input
Post by: DragoslaV on Mar 05, 2011, 02:19 pm
Yeah, that block should have represented 6 more of the NPNs like above. To be honest the new program I was using is frustrating as hell to work with so I just made it one block  :smiley-roll:

Also thank you a thousand times for the ULN2803A tip! This will definitely save me time and wires! I'm now off to the store to buy the 4051 and the ULN
Title: Re: Combining analog input
Post by: DragoslaV on Mar 06, 2011, 04:59 pm
I heard there are no stupid questions compared with not asking at all so is the COM pin on the ULN2803A the same as the Emitter?

Or is this schematics correct?
(sorry the upload directory was full)
(http://test.aerosol.me/leds/speedometer.gif)
Title: Re: Combining analog input
Post by: CrossRoads on Mar 06, 2011, 06:10 pm
No, Ground is the pin that all emitters are connected to.
COM is the pin that would to go motor V+ if you had motors, or relay coils, etc.
You should be good as drawn.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 06, 2011, 06:17 pm
Ahh, I think I get it now.
Thank you CrossRoads!
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 07, 2011, 07:00 pm
My only reservations are all the sensors going into the 4051. These have to have an output that is less than 5V. If the output ever goes above this then it will fry something. Given that it is a 12V system there is a danger that this voltage will be present on the sensors.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 07, 2011, 10:53 pm
You're absolute right Mike, I should work out the v12 to v5.
This is my schematics of a single v12 input:
(http://test.aerosol.me/leds/v12-to-v5.png)
(hell yeah! I love Eagle already)

Quick question: are there any parts around that combine the voltage regulator and capacitors?
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 07, 2011, 10:56 pm
Do not use a voltage regulator to cut down a signal from a sensor into an arduino, it is totally the wrong thing to do.
You need to use either a potential divider, transistor or opto isolator.

Quote
that combine the voltage regulator and capacitors

No.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 07, 2011, 10:59 pm
Thanks alot for pointing out that noob mistake :smiley-sweat:
What is the best practice for a nooby?

Also let me remind you that the indicators are no sensor, just plain v12 battery going to a lamp.
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 07, 2011, 11:11 pm
Take the sensor output put it through a 10K resistor into the base of a transistor. The connect the emitter to ground and the collector to the input. Finally in the software enable the internal pull up resistor.
Title: Re: Combining analog input
Post by: jackrae on Mar 07, 2011, 11:22 pm
You might also want to consider fitting decoupling capacitors (0.1uF) across Vcc and Gnd on each of the chips to prevent noise affecting operation of the signals.  These should be fitted as near the chips as possible.
jack
Title: Re: Combining analog input
Post by: DragoslaV on Mar 19, 2011, 08:34 pm
Sorry I been away for a while. Thanks for the replies!
If I understand you correct Grumpy_Mike I will get the follow result (in a nutshell)?
(http://test.aerosol.me/leds/v12-to-v5-version2.png)


Code: [Select]

void setup() {
  Serial.begin(9600);
 pinMode(19, INPUT);
 digitalWrite(19, HIGH);
}
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 21, 2011, 01:45 pm
Yes that should do it.  :)

The transistor will get the pull up it needs through the multiplexer.

If it were me I would also put a 4K7 resistor from the  collector of the transistor to 5V but this is not essential. It is just it would make the transistor behave correctly even if it weren't switched through to the arduino.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 21, 2011, 09:47 pm
Alright! Thank you very much again for your help! :)

I will also put the 4K7 resistor between it. Also I was reading (http://arduino.cc/en/Main/ArduinoBoardNano) that only the digital pins has pull-up resistors? So its wise not to connect it on pin #19 but on #13 and below?
Title: Re: Combining analog input
Post by: Grumpy_Mike on Mar 21, 2011, 09:52 pm
Quote
only the digital pins has pull-up resistors

No all the I/O pins on the processor have internal pull up resistors, even the analogue ones.
You can also put external pull up resistors on analogue inputs.
Title: Re: Combining analog input
Post by: DragoslaV on Mar 21, 2011, 10:00 pm
Sweet  8) Thanks for the info! Time to get this working now :D
Title: Re: Combining analog input
Post by: cintax on Mar 23, 2011, 03:34 am
You can free up almost all the I/O you are using to drive the LED matrix with a MAX7219 or MAX7221 for each display.

http://www.maxim-ic.com/datasheet/index.mvp/id/1339

Also, keep in mind that you are not expressly using 12V here. Most charging systems actually sit around 14.5V to 15.5V. Motorcycles use a stator and rectifier which doesn't work in exactly the same as the alternator in your car to generate power. You will have voltage fluctuations at lower RPMs with charging (15.5V) occurring after 5000RPM.

Check your manual or measure voltage at different RPMs for exact values.