Тёмный

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

DIY and Digital Railroad
Подписаться 62 тыс.
Просмотров 18 тыс.
50% 1

Welcome back everybody! Be sure to subscribe! In a previous tutorial, I used a premade model railroad current sensor combined with an arduino to detect current. Today I am building a DIY model railroad current sensor from scratch that can detect current using a combination of hardware and code to achieve this. This is a far more cost effective way to do current sensing!
CHECK OUT THE MODEL RAILROAD SOLDERING KIT FROM SRA SOLDER!
sra-solder.com...
Check out their youtube channel
/ @srasolderlab
Github
github.com/DIY...
Arduino Sketch UPDATED FROM VIEWER COMMENTS!
drive.google.c...
Text file of the Arduino Sketch
drive.google.c...
BD20 Current Sensing Tutorial
• Easy Arduino Current S...
PARTS
Arduino UNO
amzn.to/3q2NQqj
Breadboard
amzn.to/3pWjxBq
Current Transformer
amzn.to/3pVv97O
Diode
amzn.to/3kufFXj
Resistors
amzn.to/3b17FKb
LEDs
amzn.to/3aXuUop
Check out my Facebook page
/ diyanddigitalrr
Support the channel on Patreon
/ diyanddigitalrailroad
Check out my Instagram
/ diydigitalrailroad
Check out my Etsy Store
www.etsy.com/s...
N Scale Train Set
amzn.to/33TzsbS
HO Scale Train Set
amzn.to/311N17g
O Scale Train Set
amzn.to/3lAZCGu
G Scale Train Set
amzn.to/312Cn09
I do a lot of 3D Printing. Here are some great printers
Anycubic Photon
amzn.to/2SAnJZn
Creality Ender 3
amzn.to/3lkMogX
Camera I use
amzn.to/2SyuPh5
Support the channel with some Merchandise!
teespring.com/...
Connect with me at ddrrcommunity@gmail.com
I do a lot of 3D Printing. Here are some great printers
Anycubic Photon
amzn.to/2SAnJZn
Creality Ender 3
amzn.to/3lkMogX
Original Prusa Mini
shop.prusa3d.c...
Elegoo Mars
amzn.to/386NZSa
Anycubic Mega Zero
amzn.to/3mHfdpi
Qiditech Shadow S 5.5
amzn.to/3cZl059
Samaritan’s Purse
www.samaritans...
Camera Used
amzn.to/2X87yWR
“The godly may trip seven times, but they will get up again.
But one disaster is enough to overthrow the wicked.
Don’t rejoice when your enemies fall;
don’t be happy when they stumble.
For the Lord will be displeased with you
and will turn his anger away from them.
Don’t fret because of evildoers;
don’t envy the wicked.”
Proverbs 24: 16-19 NLT

Опубликовано:

 

12 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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!!
@geesharp6637
@geesharp6637 3 года назад
Nice to see this sample code in github. Hope to see more of your examples end up here.
@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
@bighfanboy5130
@bighfanboy5130 Год назад
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.
@terrybailey2769
@terrybailey2769 8 месяцев назад
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
@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.
@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.
@sturnie1
@sturnie1 3 года назад
You put it together nicely I am sure this took you a while to figure out first.
@derailroad
@derailroad Год назад
great video Jimmy, thank you for awesome information brother
@billiestewart5220
@billiestewart5220 3 года назад
Great host and Topics I have learned a lot from this program keep it coming .
@jolliemark6294
@jolliemark6294 3 года назад
Jimmy like the idea of this simple detector, but I'm not sure about the using adrinos yet...👍
@donaldkormos5529
@donaldkormos5529 3 года назад
OK ... I'll try the text file ... thanks for all your efforts!!!
@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.
@redwoodcityintheuknscalera7179
@redwoodcityintheuknscalera7179 3 года назад
Brilliant Jimmy kudos to you Paul in England
@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 🇦🇺
@caprailroad
@caprailroad 3 года назад
as always amazing work. another project ill be trying
@bobsinclair9886
@bobsinclair9886 2 года назад
STILL LEARNING THANKS
@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....? :(
@wilvdwee5711
@wilvdwee5711 6 месяцев назад
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
@shamiester
@shamiester Год назад
How can so add a tortoise switch with this solution and replace the current sensor with an ir sensor
@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?
@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.
@henrybest4057
@henrybest4057 3 года назад
Are you using a special 5V LED that doesn't need a resistor?
@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.
@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
@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?
@jerrydowell5962
@jerrydowell5962 3 года назад
Will try that thanks
@Steelerfan820
@Steelerfan820 3 года назад
Great may try my first arduino
@Fer-mu3yq
@Fer-mu3yq 28 дней назад
Hi, can I use this current sensor for JMRI? If I need to use 18 blocks how can I connect in Arduino?
@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.
@krishsoundar3857
@krishsoundar3857 Год назад
how is the DCC packet sent to command station ?
@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.
@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?
@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?
@dthead
@dthead 2 года назад
How many blocks can the same arduino do concurrently ??
@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.
@MP25Productions
@MP25Productions 3 года назад
So, the million dollar question... how can this be implemented into JMRI/CMRI?
@strobelightaudio
@strobelightaudio 3 года назад
there's no >= in arduino? (instead of comparing to clearsample-1)
@anfieldroadlayoutintheloft5204
@anfieldroadlayoutintheloft5204 3 года назад
good vid jimmy
@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.
@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.
@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 года назад
Current transformers not available todate
@DIYDigitalRailroad
@DIYDigitalRailroad 3 года назад
They go in and out of stock.
@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
@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
@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.
@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 😂
Далее
УДОЧКА ЗА 1$ VS 10$ VS 100$!
22:41
Просмотров 364 тыс.
iPhone 16 для НИЩЕБРОДОВ!
00:51
Просмотров 2,1 млн
НЕВОЗМОЖНЫЙ ЭКСПЕРИМЕНТ
00:39
Просмотров 74 тыс.
Hi Resolution Block Detector (Video #33)
16:48
Просмотров 19 тыс.
Easy Arduino Current Sensing for Occupancy Detection
14:08
DIY Arduino Model Railroad Reversing Loop
25:24
Просмотров 29 тыс.
I Made an Automated Model Train With An Arduino!
25:20
G scale track discussion (LGB, Bachmann, Peco, Piko)
6:08
Can Jewel Bearings Be Pressed In The Home Shop?
17:37
Просмотров 159 тыс.
DCC for less than $45!!!  Building a DCC++ Base Station
13:29
УДОЧКА ЗА 1$ VS 10$ VS 100$!
22:41
Просмотров 364 тыс.