Building a Cheap DIY Current sensor for DCC with an Arduino!

  Рет қаралды 18,025

DIY and Digital Railroad

DIY and Digital Railroad

Күн бұрын

Пікірлер: 83
@TheSwitchList
@TheSwitchList 3 жыл бұрын
Hey Jimmy - cool video but I think there are a couple of things that are not correct (based on what I believe you are trying to do). In your loop() routine - you are not reading the sensor inside the for loop so you read the sensor once at the start of the routine and then go into your for loop and do not read the sensor in the loop so you are processing the same sensor value 10 times. The logic for calculating the average of the 'numSamples' sensor readings also does not seem correct. Your logic should be summing the valA1 values and then dividing by the current value of 'i' to get the average of the readings in the for loop. You are adding valA1/numSamples (or 1/10th of valA1 in this case) to your result variable. A simple example if you have two readings of 552 and 560 then your logic results in: Iteration 1: result = 552/10 =55 Iteration 2: result = 55 + (560/10) = 55 + 56 = 111
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Hey Rick! No you are not being a pain and I am going to pin this comment. I plugged in the changes and re ran the test and it works great! Since I am no coder, I will make these adjustments on the next video. Thank you again!
@TheSwitchList
@TheSwitchList 3 жыл бұрын
@@DIYDigitalRailroad Thanks Jimmy - only wanted to help and I really appreciate you understanding that. Looking forward to more videos from the DIY & Digital RR!
@jimb5021
@jimb5021 3 жыл бұрын
@@DIYDigitalRailroad another code thought if the delay(10) is really supposed to add a 10 millisecond delay between each reading it should be in the for loop as well. Also no need to print and average the value until all 10 reads are completed since you do not do anything with the result until all 10 reads are completed. So as an alternative you could do this: for (int i=1; i
@michaelsommers2356
@michaelsommers2356 2 жыл бұрын
_"The logic for calculating the average of the 'numSamples' sensor readings also does not seem correct."_ The logic in the original loop is correct, though not optimal. The division by 10 in each iteration of the loop should be division by numSamples for clarity, although when, as here, numSamples is 10, the results are correct. The problem with your example is that you did only two iterations, but still divided by 10. If you had divided by 2 instead, you would have gotten the correct result. Dividing each time by i will never give the average; the last time through the loop i == 9, not 10. Also, the first time through the loop it divides by 0, which ordinarily causes a program to crash and burn. I don't know how Arduino deals with divide by 0 errors. I would have written the loop this way: --- snip --- for (int i=0; i < numSamples; ++i){ result += analogRead(A0); } value = result / numSamples; Serial.println(value); --- snip --- There is no need to do more than one division, especially since all but the last are thrown away, and you don't need to store the reading in a temporary variable. Also, the long result in the first line if the program is never used; the int result in loop() masks it. Since you originally made result long, you might want to do the same in loop(), If you keep numSamples below 30, however, that should not be necessary.
@LeonhardtD
@LeonhardtD 2 жыл бұрын
Hey Jimmy, I took your code and loaded it onto an ATTiny85, mounted it on the board and connected it directly to the sensor. Now I have a current sensor with a digital outputs that I drive an LED and send signal to JMRI sensor shield. Thanks, It works great!
@timnagy2411
@timnagy2411 Жыл бұрын
Great idea! The ATTiny85 are amazing little bit of kit.
@davidgorman2665
@davidgorman2665 3 жыл бұрын
Not sure how you knew I was researching this and not finding what I liked. This is SUPER and I really plan to put this in practice. Thanks, again, Keep them coming.
@johnnyrobertson5971
@johnnyrobertson5971 3 жыл бұрын
Thanks Jimmy great video and love these type of videos and you do such a wonderful job teaching us. Be safe up there!!
@davelees3922
@davelees3922 Жыл бұрын
I'm confused.... I've built the circuit and set the Arduino up as per the video, and when I power it on, the LED is on all the time...!!! - what have I done wrong....? :(
@geesharp6637
@geesharp6637 3 жыл бұрын
Nice to see this sample code in github. Hope to see more of your examples end up here.
@terrybailey2769
@terrybailey2769 10 ай бұрын
I did something very similar but I used a cheap high gain NPN transistor to amplifier in common emitter mode to pull down a digital pin which was defined as INPUT_PULLUP. The input pin on the arduino has a .47uF capacitor across it. The pullup charges the capacitor when the track is not occupied, however when the track is occupied the pulses from the transformer turn on the transistor, discharging the cap. The time constant on the capacitor/resistor in the pullup does not allow the pin to get to a high state before the next pulse from the transformer.
@hdwood76fxe
@hdwood76fxe Жыл бұрын
Nice project. I really need a class on Arduino programming. Thank you
@bighfanboy5130
@bighfanboy5130 2 жыл бұрын
Hi I think 34100 was a rebuilt westcountry. Not sure but I think the 34 denotes westcountry could be wrong but I have 3 and they all start 34 great progress on the layout and I’m proper jealous of the size of yours keep up the good work it’s great to see it go from no name to now.
@WatchesTrainsAndRockets
@WatchesTrainsAndRockets 3 жыл бұрын
Question: Did you look at a solid state Hall effect sensor like the ACS712ELCTR-05B? I am researching that for my own sensing system at the moment. Comment: when deploying this, you can implement two blocks with two of your sensor of choice and 1 ATTiny85 for your micro controller. Hook the sensors to two of the analog pins and use two of the other pins for the output. That leaves 1 pin fo something else unless you re-purpose the RST pin. The code should be the same as the UNO code, just the pins need to be changed.
@CM-ARM
@CM-ARM 3 жыл бұрын
Hey Jimmy I missed your final cost of building it your self. I'm not even close yet for block detection but money and time really matter. Thanks again, Chris
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Hey Chris. This detector can be built with an arduino for under $7
@CM-ARM
@CM-ARM 3 жыл бұрын
WOW thanks for sharing
@wilvdwee5711
@wilvdwee5711 7 ай бұрын
Great video. This question has been asked several times how to send the DCC signal to The command station? Is it possible or not? Thanks in advance
@chriszalenski9443
@chriszalenski9443 Жыл бұрын
Question because I couldn't see either in your video or your SHOW MORE section. The other end of the black wire going through your current transformer where dose it go? I see the one end is connected to the orange wire that goes to the middle of the insulated rail but where dose the other end connect to? Also the 2 orange wires the one before and the one after the insulator connectors on the rail where do these wires hook up to? Dose not show that in your video or SHOW MORE sections. At least I COULD NOT pull up any type of schematics. Do these wires hook up to track power some how? If they hook up to track power dose it mater if its on the positive side or the negative side? Do you need to isolate the current flow in these wires so it only flows one way using diodes?
@derailroad
@derailroad Жыл бұрын
great video Jimmy, thank you for awesome information brother
@henrybest4057
@henrybest4057 3 жыл бұрын
Are you using a special 5V LED that doesn't need a resistor?
@sturnie1
@sturnie1 3 жыл бұрын
You put it together nicely I am sure this took you a while to figure out first.
@Racerbill27
@Racerbill27 Жыл бұрын
I'm a novice! I noticed, in you demonstration, the the current sensor took about 5 seconds to release and the LED to turn off.. Is it possible to shorten that time?
@phoolb7326
@phoolb7326 3 жыл бұрын
Hi Jimmy, I have been building a layout after being out of the hobby for quite some time and am using Arduino based controls for turnout, frog, panel control etc. (OK everything) Love that you are providing this input to the hobby. As you pointed out, much of the commercial products are expensive and there are alternative methods that in. my opinion only add one more aspect of the hobby to enjoy. I would love to share some of my ideas with you re electronics as well as 3D printing, but I could not find any contact info other than FB.
@shamiester
@shamiester Жыл бұрын
How can so add a tortoise switch with this solution and replace the current sensor with an ir sensor
@Fer-mu3yq
@Fer-mu3yq 2 ай бұрын
Hi, can I use this current sensor for JMRI? If I need to use 18 blocks how can I connect in Arduino?
@billiestewart5220
@billiestewart5220 3 жыл бұрын
Great host and Topics I have learned a lot from this program keep it coming .
@donaldkormos5529
@donaldkormos5529 3 жыл бұрын
OK ... I'll try the text file ... thanks for all your efforts!!!
@jolliemark6294
@jolliemark6294 3 жыл бұрын
Jimmy like the idea of this simple detector, but I'm not sure about the using adrinos yet...👍
@bobsinclair9886
@bobsinclair9886 2 жыл бұрын
STILL LEARNING THANKS
@Lancelot_Jago
@Lancelot_Jago Жыл бұрын
Hi, I realise this is two years old, however how many detectors can be run on one UNO? If only one, then it may not be cost effective when you can get 16 in a BDL168 for $8.75 each. And yes, I do need 16 😉 Cheers 🇦🇺
@redwoodcityintheuknscalera7179
@redwoodcityintheuknscalera7179 3 жыл бұрын
Brilliant Jimmy kudos to you Paul in England
@TheMusicalox
@TheMusicalox 3 жыл бұрын
Thanks Jimmy, excellent video. So basically it is a transformer inline with one of the feeder wires from the buss and you are reading the change in the induced current I'm assuming. I seem to remember in one of your previous videos that the signal was too weak, especially in N scale. was this overcome by wrapping the coil 4 times on the primary, and is the sensing nearly 100% now? Thanks, greatly enjoy your channel.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Hey Michael, yes you are correct. The raw data comes out jumpy but jumps to more extreme ups and downs when current is being drawn. So the code averages those and give a number. That number lowers when current is being drawn.
@Jasenkrueger
@Jasenkrueger 3 жыл бұрын
@@DIYDigitalRailroad Hi, I was a bit concerned that a short on the track would spike the current very quickly to the Max current available until current protection kicks in and turns off the track power. I was thinking detecting current that was 5 amp or so would over voltage the Arduino analog input with 4 wraps. But from what you are saying, if I read this correctly, is that the more current through the track feeder wire the lower the voltage going into the Arduino analog channel is. So signal close to ground is occupied and signal close to 5vdc is clear? I wanted to confirm there is built in circuit protection from over current through the coil. How does the 2 megaohm and Diode actually work with the coil? I'm having a hard time wrapping my head around the voltage to the Arduino goes down when current goes up. Is the current changing the effective resistance in the coil? Is there diode reverse bias being detected? Any extra info or a small explanation diagram would be helpful for my understanding. Anyways, Thanks for the sketch. I plan on using Arduino Pro Mini that had 8 Analog channels and and enough Digital outs to my JMRI system. I have another home built system right now but it is not reliable. I'm hoping this will do the trick. Thank you for sharing this video and sketch!
@donaldkormos5529
@donaldkormos5529 3 жыл бұрын
That's once again Jimmy for a good Arduino project ... one problem ... could not download a working Arduino sketch.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Try it now.
@allanandsherralynne
@allanandsherralynne 3 жыл бұрын
Hi, building a HO module in NZ and have just bought my first Arduino's to try out. Noticed a NZ number plate on the wall ?(Carjam: Toyota Corsa). Also love the Be Kind T-Shirt. Will have to get one.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
I actually spent a few months in NZ! I lived in Christchurch before the quake. I also visited Queenstown and Wellington. I love New Zealand!
@doncummings697
@doncummings697 3 жыл бұрын
Great video. I've been looking for a cheaper way to do this. Just wondering how hard it would be to code multiple sensors on a single Arduino. I am no coder. Layout has nearly 60 blocks. Really don't want to use a nano or micro for each block, how many could you put on an AT mega? Feasible?
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
So an Arduino Mega can support 15 sensors like this with its 15 analog inputs. The issue you are going to run into is a lot of code. So if would take you atleast 4 megas to handle 60 blocks with 3 aspect signaling. The issue you are going to run into is code. Your code will be massive to control each. This is why I like daisy chaining my arduino block signals to where they talk to eachother. I would also take a look at the pro mini. You can get the cost down to under $7 per block when you are using one of these.
@jamescoleman7318
@jamescoleman7318 3 жыл бұрын
how far apart from each other do the sensors need to be I have 3 mounted about an inch apart and wiring goes around these at close quarters I am having random triggers with them mounted like this do they and the wiring for them need more separation?
@caprailroad
@caprailroad 3 жыл бұрын
as always amazing work. another project ill be trying
@dthead
@dthead 3 жыл бұрын
How many blocks can the same arduino do concurrently ??
@JohntheTrainman
@JohntheTrainman 3 жыл бұрын
Excellent video! (warts and all! LOL) As a novice to Arduino, I'm wondering if you can detect occupancy in multiple blocks with one Arduino. Also, can this be ported into JMRI? Thanks for a great video series!
@JohntheTrainman
@JohntheTrainman 3 жыл бұрын
OK, I just rediscovered your series on multiple block detection. I still wonder how to put that info through JMRI.
@krishsoundar3857
@krishsoundar3857 Жыл бұрын
how is the DCC packet sent to command station ?
@marcusc3463
@marcusc3463 3 жыл бұрын
Hey Jimmy have you ever thought about using the Allegro ACS712 with your Arduino. I think there was a video of another guy using one for block detection but I can't seem to find that video anymore
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Hey Marcus! I actually tried one of those before. The problem is that it only registers when power is applied. So stationary trains don’t register.
@patrickcawood279
@patrickcawood279 3 жыл бұрын
Hi Jimmy excellent video, and I love your passion and knowledge. But just an observation, you state the BD-20 are expensive if you need several. However you demonstrated one transformer and one Arduino.. does that mean I need another transformer /Arduino pair for the next block?... that sounds more expensive than the BD-20 option
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
That’s a good question. So you can build this with cheap arduino clones. If you use something like an arduino pro mini clone, you can get the cost down to less than $7 per detector. The BD20 still requires an arduino to work in this capacity. So you’re looking at $20-$25 for the BD-20 + the cost of the arduino.
@mmsailingaway
@mmsailingaway 3 жыл бұрын
@@DIYDigitalRailroad And the BD-20 is still only for a single block
@Steelerfan820
@Steelerfan820 3 жыл бұрын
Great may try my first arduino
@MP25Productions
@MP25Productions 3 жыл бұрын
So, the million dollar question... how can this be implemented into JMRI/CMRI?
@johnfi1602
@johnfi1602 3 жыл бұрын
Hi Jimmy, Just wondering how the code with change for multiple sensors on one Uno. I was thinking about one Nano per block vs. adding more loops, etc.
@stephenwadsworth6972
@stephenwadsworth6972 3 жыл бұрын
You should be able to run 8 sensors from one Nano - reading each sensor (A0 to A7) in turn in the loop, and having more states and variables etc. - but I think you will either need to ditch the delays or just have one delay for all the sensors to make it fast enough - what is actually coming being sampled from the transformer is a miniature DCC waveform so all you need is to sample it enough times to cover a cycle of the waveform to know whether it is there or not.
@jerrydowell5962
@jerrydowell5962 3 жыл бұрын
Will try that thanks
@davidorf3921
@davidorf3921 3 жыл бұрын
good video, but there seems to be 2-3 seconds between the train leaving the section and the LED going off, it turned on as soon as the section was occupied, was wondering why this was happening
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
So that is actually written in the code. You can decrease the amount of time by lower the number of clearsamples in the code. I typically have a few seconds before the block shows clear so that false signals are eliminated.
@davidgorman2665
@davidgorman2665 3 жыл бұрын
Jimmy, great videos. Are you interfacing these with JMRI or DCC++? If so are you going to do a video covering that hookup?
@strobelightaudio
@strobelightaudio 3 жыл бұрын
there's no >= in arduino? (instead of comparing to clearsample-1)
@tomgeorge3726
@tomgeorge3726 3 жыл бұрын
Hi, can you explain how having the diode wired as you have it, thus putting a negative voltage on the analog input it works. The DCC current, basically AC to the current coil, is being rectified by the diode. A current transformer is not meant to be used like that, you should have a burden resistor and measure the volt drop across that resistor. Not using a burden resistor will allow the transformer to produce high voltage spikes, and damage your UNO. With the 2 x 1M resistors you are actually using the current transformer as an antenna, not a transformer. I do not deny that it works, BUT how about how it works and its durability is questionable.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
I think that the simple answer to your question is that a regulated DC power source that is connected to the base station does a lot to mitigate the threat of voltage spikes before the signal is even sent to the track. This is not a problem unique to this setup. DC power sources are overwhelmingly used in DCC setups because AC power sources are mostly unregulated and cause voltage spikes that can damage decoders. This way we only need the diode to rectify what is coming from the sensor, then let the arduino do some math functions to let it make sense. I did do some more research before answering your question. I could not find any of the myriad of DIY DCC current sensors that use a burden resistor. Most of them, if they had components for transient voltage, used a capacitor. One guy, Dave Bodnar, who's blog and information I really trust, actually removed burden resistors from a variant of his DCC current sensor in order to make it work. I have linked his article here. trainelectronics.com/DCC_Arduino/Current_Sense/index.htm I do appreciate your question as it did spur me to do some more research and learn more.
@h2osmokey
@h2osmokey 3 жыл бұрын
What is the unit cost savings?
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
If you go with the lowest cost per part. You can make these for between $6-$8 each versus $20+ buying them.
@rgetty
@rgetty 3 жыл бұрын
Is there really only one connection to the coil of black wire wrapped around the transformer? The other end of the black wire is under the test track and not visible.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Hey Robert. Both ends of the black wire are connected as an insert of sorts in the feeder to the isolated rail.
@jerrydowell5962
@jerrydowell5962 3 жыл бұрын
Current transformers not available todate
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
They go in and out of stock.
@donaldkormos5529
@donaldkormos5529 3 жыл бұрын
Using 1.8.13 also. After getting box to download, file appears on desktop. When clicked, Arduino asks to create sketch folder ... after clicking OK I get message saying sketch could not be created.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Ok I am going to work on this. In the meantime. I have created a text file of the arduino sketch. You can download it here and copy it over drive.google.com/file/d/1A9la42Mua2r6FDue5KzmDQbj89hunKgn/view?usp=sharing
@donaldkormos5529
@donaldkormos5529 3 жыл бұрын
Jimmy ... still can't download ... get an Arduino IDE error: can't create sketch.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
hmmm. What version of the IDE are you running? This was built on 1.8.13
@jerrydowell5962
@jerrydowell5962 3 жыл бұрын
How do I download the sketch? When I select the sketch link It takes to a download screen but when I try to view the download file it show nothing I noted this is a google function
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
Is your computer actually downloading the file? If not, it may be an issue with your browser. Try it in a different browser.
@anfieldroadlayoutintheloft5204
@anfieldroadlayoutintheloft5204 3 жыл бұрын
good vid jimmy
@sonysnapper
@sonysnapper 3 жыл бұрын
How many of these can 1 Arduino support? I have lots of blocks, if you add in the cost of 1 Arduino per block, the wiring, the space needed I think the BD20 is a cheaper way to go.
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
It depends on which arduino. The UNO has 5 analog inputs so it can support 5. The Mega has 15 analong inputs so it can support 15
@yngsjo
@yngsjo 3 жыл бұрын
You need to modify the code to do multiply sections, there maybe some smaller code to do it multiply.
@Jasenkrueger
@Jasenkrueger 3 жыл бұрын
@@DIYDigitalRailroad Hi all, The mega can actually do 16 analog channels. Analog A0-A15. Pro Mini can do 8 channels. A0-A7. These are what I have and I have 32 blocks so I intend on needing 4 Arduino Pro Minis. Some boards have A6 and A7 at the bottom and some squeeze A6 and A7 on the inside like A4 and A5 and some don’t have A4-A7. I avoid those.
@josephdobesh9007
@josephdobesh9007 3 жыл бұрын
or.... (clearcount >= clearsample)
@DIYDigitalRailroad
@DIYDigitalRailroad 3 жыл бұрын
My hero 😂
DCC++EX: A Cheap DIY DCC System?!?! This is a Model Railroad Game Changer
17:54
DIY and Digital Railroad
Рет қаралды 86 М.
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 11 МЛН
Миллионер | 2 - серия
16:04
Million Show
Рет қаралды 1,6 МЛН
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 10 МЛН
Hi Resolution Block Detector (Video #33)
16:48
IoTT
Рет қаралды 19 М.
Installing the DIY Arduino Current Sensor on a Model Railroad Crossing!
8:51
DIY and Digital Railroad
Рет қаралды 9 М.
Arduino DCC SoundShield
11:25
Luca Dentella
Рет қаралды 1,3 М.
Hacking a weird TV censoring device
20:59
Ben Eater
Рет қаралды 3,1 МЛН
Short Circuit Protection for Your Model Railroad DCC System
12:51
Ron's Trains N Things
Рет қаралды 38 М.
Arduino Block Signal: Upgrading the Multiblock Signal System to use Current Sensing!
44:54
I Made The Ultimate Cheating Device
9:39
ChromaLock
Рет қаралды 1,2 МЛН
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 11 МЛН