# New to Arduino, need some guidance

Hello everyone, I have just purchased an Arduino Leonado as my first board. :D I have been doing some reading and I want to make sure of the following.

All the inputs should received no more than 5v, Meaning that if i wanted to use an input to tell me if there is voltage drop from a 12v power source, I would need to convert those 12v to 5v and then connect them to the input?

Also, I am assuming that somewhere I would have to define that the 5v signal = 12v (100%). I am trying to warp me head around how this would work.

Here is the project:

I have a 12v power source of constant DC. However, there is a motor connected to the power source. When the motor turns on, it will draw power and there will be a slight change (drop) in voltage. I want the arduino to detect this and push power or a signal from another io to turn on an LED and power a relay to turn on another 12v device.

I would appreciate some guidance.

Basically you have to reduce the voltage going into the input to go from 12V to whatever you end up putting into the Arduino. Then you need to map the voltage and program that map into the arduino code.

Yes you have to reduce the 12v to a voltage < 5v. Typically this is done with a “voltage divider” (two resistors, look it up).

Rob

Suppose that you use the voltage divider to drop the 12v to 4v - dividing by 3.

Then the Arduino ADC will read 0v as 0 and 4v as 818 (1023/5*4). You know that 818 really means 12v so you do your maths accordingly. In reality you will need to measure the voltage and check the ADC value as it is not exact although, as far as I know, it is consistent.

Sometimes a 12v supply can be a bit higher, especially for short periods so make sure your voltage divider never has an output above 5v. Dividing by 3 would be safe for a voltage up to 15v.

...R

Bittsen: Basically you have to reduce the voltage going into the input to go from 12V to whatever you end up putting into the Arduino. Then you need to map the voltage and program that map into the arduino code.

Okay so just so what I understand fully. When you say "..to whatever you end up putting into the Arduino." you mean any voltage between 0-5v, because based on the specs I can power the board with 12V source (although not ideal). This applies to all inputs.

Robin2: Suppose that you use the voltage divider to drop the 12v to 4v - dividing by 3.

Then the Arduino ADC will read 0v as 0 and 4v as 818 (1023/5*4). You know that 818 really means 12v so you do your maths accordingly. In reality you will need to measure the voltage and check the ADC value as it is not exact although, as far as I know, it is consistent.

Sometimes a 12v supply can be a bit higher, especially for short periods so make sure your voltage divider never has an output above 5v. Dividing by 3 would be safe for a voltage up to 15v.

...R

Very useful info, thank you !!

I have been reading articles and watching videos the past hours.

The AREF pin will only read a max of 5v - which means that if I wanted I were to use 2 resistor to split the power of the 12v down to 5v the AREF would need to be fed from that same line if that is the voltage I want to monitor is that correct?

Here is what I am thinking and I want to know if I am thinking correctly.

I can supply the board with 12v for power 12v1 and I can then convert 12v2 down to the 5V the inputs need.
I am unsure If the ground connects to the ground next to the digital inputs and if the external AREF needs a ground also?

If this wiring is correct, then it just programing to get it to print the voltage.
My goal is to sense a change or drop in voltage from 12v2 to trigger another action.

aref doesn't need a specific ground, as far as I know.

Using aref helps balance an unstable input voltage when you are dividing the voltage of an astable power source.

Also, when the voltage is divided by 3 to get 4V, and reads 818, you can tell the arduino to read the 818 as 1024 giving you a broader range. Of course this is only useful as long as the voltage source is stable.

What do you mean by stable or unstable power source ? The 12v for the input will come from a regulated psu. Actually the one I have is 13.8v would you call that stable ?

yet there is a motor connected to the power source and there will be a power voltage drop of a few milivolts when the motor is turned on.

I want to pick up this change. So making the 8xx = 1024 to get a higher resolution would be ideal.

I want to know if the way I plan on wiring the board makes sense or works. (Or if my overall plan will work period)

Stable vs unstable...

If you were putting this into a car, for example, the voltage is unstable. It has a built in voltage regulator, sure, but the voltage still varies by a small amount depending on the power draw and the speed of the alternator. Unstable.

Stable is a fully regulated power supply such as a home current, which is heavily regulated and not (typically) subject to fluctuations in voltage. This, when stepped down to 12V (or 13.8) is stable. You can also, further, stabilize voltage by adding certain electronic circuitry to insure a steady voltage even if there are fluctuations.

.

The 12v to the analogue input looks all wrong to me.

You need two resistors to make a voltage divider. The divided voltage comes from the junction between the resistors. For example

Vhigh ---- R1 ---- R2 ----- Gnd | | Vdiv

So that Vdiv is about 1/3 of Vhigh, R1 should be (say) 10k and R2 should be 5k6. For Vhigh = 12v that will give Vdiv = 12/15.7*5.6 = 4.3v

If you want to measure the voltage at an Analogue pin there is no point feeding the same voltage to Aref because the ADC would always see the input as exactly the same as the reference.

(Unless I have missed something)

...R

It's one thing to talk about exercises in how you connect inputs to the Arduino and write sketches and such, but this is totally disparate from performing the actual function you appear to be requiring.

Given that you did arrange a system to detect a voltage drop on your "constant DC", it would be extremely unreliable in indicating whether a particular motor was drawing power since there will be other sources of fluctuation in the supply. The better whatever that supply is in terms of regulation, the more difficult it becomes to detect the motor being switched on or off, even presuming you are going to base this on transients rather than absolute voltage levels.

The obvious answer is - just go and arrange a connection to whatever is switching the motor. If that is really impractical, then the detection function can be performed by a current shunt.

In any case, this is an interfacing question between your current detection circuit and your control relay for the "slave" device(s) and has nothing really to do with an Arduino. :astonished:

Bittsen: Stable vs unstable...

If you were putting this into a car, for example, the voltage is unstable. It has a built in voltage regulator, sure, but the voltage still varies by a small amount depending on the power draw and the speed of the alternator. Unstable.

Stable is a fully regulated power supply such as a home current, which is heavily regulated and not (typically) subject to fluctuations in voltage. This, when stepped down to 12V (or 13.8) is stable. You can also, further, stabilize voltage by adding certain electronic circuitry to insure a steady voltage even if there are fluctuations.

.

You make complete sense about the AREF and power supply. I was doing a quick test with a multimeter and some resistors and I noticed that the voltage was not moving at times at all.

Paul__B: You are seriously going about this the wrong way!... In any case, this is an interfacing question between your current detection circuit and your control relay for the "slave" device(s) and has nothing really to do with an Arduino. :astonished:

Paul sorry to be so annoying. I appreciate the responses and let me say that while it realized the voltage sensing will not work for the same reasons you mentioned, it was a good exercise to go through. Yes this is an interfacing question; interfacing the object I wanted to use with Audrino. Therefore I do think is it related. I think that if I can understand the physical aspect of the "Circuit" when I am much better off when it comes to putting the sketch together. Unfortunately, I did not choose to go to college to be an electronics engineer; I choose something else. But I am determined to make this project work and I really appreciate everyone assistance and advice.

You guys know more then me when it comes to this, and for now I am in a position to learn before I can give back. (just like with everything).

Thank you!

Hello everyone,

I was able to get the 13v from the circuit I want to sense down to 4v via some resistors. When I connected the motor to the circuit, the Arduino was able to see a slit voltage drop and I turned on an LED and displayed some text on the screen.

On the program side (sketch) I was using a conversion factor to convert the 1023 bites to display the volts I was getting. I realized one important challenge that I need some help with. I am currently using a 13.4v PSU. What if I want to use a 9v PSU without having to edit the sketch?

I don't necessarily care about the actual voltage value, but I want the led to go on if there is a slight drop. 0.001 (which I am able to detect with the current set up.

I am thinking something like of a statement that says and I am looking for some help writing the syntax please.

"if value of input A0 is less than its original input by 0.005 (meaning if it decreases by more than 0.005), then Pint 13 output HIGH) "

What time should there be between the “original” voltage and the “dropped” voltage?

Perhaps you could read the voltage in setup() and save it in a global variable. Then at later time(s) you could read the voltage and compare it with the first value?

…R

Just analogRead the voltage in setup and store it in a global variable. In loop, read it again into a local variable and compare the difference; the abs function may be handy here. If the difference is greater than your threshold, turn the led on, otherwise, turn it off. Just make sure the motor is off when you start the system.

Don't bother converting the analog reading to volts - work with the raw 0-1023 you get. As a side effect of this, you won't need to change the sketch when you change voltage, although you may need to change the resistors in the voltage divider.

Your threshold value is an issue though. O.005 is at the limit of resolution on the ADC and it is likely that you will get false positives if you rely on it. Try running the system without the motor and see what readings you get. You'll likely find that it isn't that stable and you'll need to make your threshold larger.

Thank you both for the suggestion.

@wildbill that is right, I don't really need the voltage, I just want the raw the 0-1023. Regarding the resitors on the divider, I can always say that the systems will work within a range 9v-14v. Of couse the voltage in at the Io will be lower at 9v, but if set up the comparison to look an explicit change of 0.025 volts for instance, it won't really matter what the voltage at the Io is - at least I think.

regarding the code:

``````variable = analogRead(analogPin);
``````

after defining "variable" and "analogPin"

wildbill: Just analogRead the voltage in setup and store it in a global variable. In loop, read it again into a local variable and compare the difference; the abs function may be handy here. If the difference is greater than your threshold, turn the led on, otherwise, turn it off. Just make sure the motor is off when you start the system.

Don't bother converting the analog reading to volts - work with the raw 0-1023 you get. As a side effect of this, you won't need to change the sketch when you change voltage, although you may need to change the resistors in the voltage divider.

Your threshold value is an issue though. O.005 is at the limit of resolution on the ADC and it is likely that you will get false positives if you rely on it. Try running the system without the motor and see what readings you get. You'll likely find that it isn't that stable and you'll need to make your threshold larger.

I realized that even with just reading the raw input its not very stable. The number jump very much 2-3 integers. I wonder if there is any other way I can sense that the motor is on the these rails I am sampling with the arduino. I can see a very clear 0.01 change in resistance in my multimeter on either the positive or negative rail. How can an arduino input see this? The arduino cannot measure resistance on its own and I would have to use a formula, but I am then depending on the signal generated by the voltage..

If V=R*I , then R=V/I

crullier: I can see a very clear 0.01 change in resistance in my multimeter on either the positive or negative rail. How can an Arduino input see this?

Change in resistance? Are you sure that is what you mean?

Perhaps - if you are serious about actually doing this, and not just seeing it as an interesting "exercise", you might need to do what I actually recommended in my previous post!