New to Arduino, need some guidance

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

You are seriously going about this the wrong way!

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!

a change is resistance is not correct ?

No, a "power rail" is essentially a piece of wire, and while it does have a resistance it's pretty unlikely that's what you where measuring, and anyway it would not have changed with a slight change of current.

I assume you actually measured voltage. Where exactly did you place the two probes to make the reading?

But anyway as Paul said, you are barking up the wrong tree here, if you can't somehow access the control signal then measuring the current through the motor's power wire is the most foolproof method.


Rob

^ yes you guys are correct.

Here is the scenario,
I am working on an train layout, and just wanted the arduino to tell me when the train was on a specific section of rail… the rails have power all the time… so as you guys can’t see, it can’t really hook up to the motor inside the model train.
So I am now thinking or using some sort of reflectance sensor to “see” the train pass on top. Not sure if this will work.

But in regards to what I was measuring, I had the multimeter in ohms 20K and I had the red probe on one end, and the black one of the other end of the rail. When I touched one of the leads of the motor to this, I would see the reading go from 0.000 to 0.001.

I am sorry, I am new to electronics, and I will be taking a class at the local community college in June. I am fascinated by electronics etc. - back to what I was doing, I though I was measuring the resistance.

It's always a good idea to say what the overall project is about.

If you have different track sections you could probably use the Arduino to detect whether current is flowing thorough the motor of a loco on any particular section, but there would be a lot of wiring. And you would probably have no position indication for a stationary loco unless you created some system to send short pulses which could be used for detection but wouldn't be sufficient to move the motor.

I am planning to use Light Dependent Resistors (LDR) embedded in my sleepers to detect my trains. They are very cheap and easy to interface to the Arduino. And from tests I have done they will work perfectly well with ambient light.

...R

If you were to start by describing what you really need, rather than some idea that has occurred to you that just might be the answer, you are likely to get a solution much quicker.

Detection of a train on a track segment is - of course - a very old requirement both on "real life" railways and models. It is usually performed by using an AC circuit versus the DC feed for traction, with inductors used for isolation of each track segment.

Since contrary to your original explanation, you can insert circuitry in line with each track segment, the outright simplest way to do this is to insert a pair of "back to back" power diodes in series at each section, and monitor the voltage across these - most easily with a pair of transistors whose emitters connect to the supply and bases - through a 1k resistor - to the track side. This allows for both positive and negative supply to the track. (I have left out a few details here.)

In order to detect stationary locomotives, you simply ensure that the controller always supplies a minimum of about 2V to the track.

I know guys, I am sorry for now being straight forward from the get go. Will that next time, you are right, this way you are better able to help.

Re:

Robin2: ..If you have different track sections you could probably use the Arduino to detect whether current is flowing thorough the motor of a loco on any particular section, but there would be a lot of wiring....R

This is essentially want I want to do, but I have not idea how, other than connecting to the L and R rail, but then all I am able to get is the 12v from the rails, and its very jumpy.

This is why I was thinking ( with my limited knowledge) of how to detect resistance or current as mentioned. The other question is, wouldn't I need to break the rail in order to measure the current running through it, or now that I think about it, could I tap into the negative wire feeding the neg track and plug that into a digital input ? with hopes that when the locomotive is places on that section of track, the input wire can sense a change in current.