I want to link my Arduino to Processing to make speed modified train sounds on my model railway. I have no problem connecting the Arduino up if the loco is going forward as I can easily adjust the input voltage to suit. The problem I have is when I put the loco in reverse. How do I read this negative voltage. Must I use diodes to make it positive to read. If this is the case would I lose the first part of the voltage and so would my train set off before the sound.
I am sorry if this has been asked before but is it possible with resistors?
Use a normal voltage divider to drop 13volt to 5volt.
Then add a third resistor from the analogue pin to VCC (5volt pin),
to pull the pin to ~2.5volt when there is 0volt on the voltage divider input.
Then you can measure from -13volt to +13volt.
0volt giving an A/D value of about 512.
Leo..
Thanks for that. Looks like if got a bit of a clue now.
I am going to put whistle buttons in for train departures and measure rate of decrease and close to 0V for braking sounds. I will also have switchable idling sound.
I assume you have the Arduino,what model?, monitoring the voltage going to the track.
What scale railway?
What track controller are you using?
What type is it?
Depending on its construction there may be an easy solution.
Can you please post a copy of your connection circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Showing your power supplies, controller, Arduino and track connections.
It sounds like you want to control your railway using an Arduino following commands from your PC, then you try to have the Arduino sense the power on the railway tracks (that it controls itself) to react to what is happening (its own controls), and tell the PC (where the commands come from in the first place) to make the appropriate noises. That's a terrible roundabout way.
garethwilkins:
Thanks for that. Looks like if got a bit of a clue now.
Was after midnight when I wrote post#2.
Here are the calculations, assuming the Arduino supply is 5volt and the train is +13volt and -13volt.
13 - 5 = 8volt falls across the top resistor (input) of the divider, 5volt across the resistor to ground (the Arduino).
So the divider ratio is 5:8.
If you pick 10k for the resistor to ground, then the top/input resistor calculates to 8/5 * 10k = 16k (E24 value).
The resistor from pin to VCC (5volt) must be the same value as the first two in parallel.
(10*16) / (10+16) = 6k15.
6k2 is a standard E24 value, and close enough.
Leo..
Well, then my original question still stands: what controls the trains? Because that could be a better avenue of getting the info needed for the sounds.
wvmarle:
Well, then my original question still stands: what controls the trains? Because that could be a better avenue of getting the info needed for the sounds.
Yes, I asked the same question in post #6, but no answer.
Tom...