Arduino Basics: Using sensors on your Model Railroad!
ฝัง
- เผยแพร่เมื่อ 25 เม.ย. 2024
- Welcome back everybody! Be sure to subscribe! In this video we take a look at arduino sensors and how to properly use them. Sensors are incredibly useful for modeling realistic automated processes on a model railroad like block signals and crossing gates.
Arduino UNO
amzn.to/2SX0Vlk
Infrared Sensor
amzn.to/2JMirVr
Photoresistor
amzn.to/2qzxUiL
LED
amzn.to/2PNo62V
Breadboard
amzn.to/2RHu6HH
Resistors
amzn.to/2DsaJQ6
Wires
amzn.to/2Dc84sX
DC Power supply
amzn.to/2D8gYaB - แนวปฏิบัติและการใช้ชีวิต
Good stuff!
Two code style comments (I teach C/C++ programming, sorry) -
Use spaces for better legibility -
int valA1 = analogRead( sensor );
pinMode( LED, OUTPUT );
You don't need the "if" after the "else" or the second test if it is the last option in the if block since there are only two possible states in this case:
if ( valA1 < 500 ) {
digitalWrite( LED, HIGH );
} else {
digitalWrite( LED, LOW );
}
Based on 30+ years of this, these make the code a lot easier to follow - especially in the case of new coders.
Timpraetor Thank you!
@@DIYDigitalRailroad My pleasure - your simplified "chunks" make all of this easier for everyone to follow.
Great tutorial Jimmy...This is going to really help when I get around to setting up my signaling system...Thank You Tom
tom carr Thank you!
One day I will get busy and use this valuable info. Thank you and take care... Paul.
Another great tutorial. Thanks, Jimmy.
Playing With Trains Thank you!
My... you're pretty awesome with electronics. I'm surprised you don't have faller car system running around your layout or your own built. I bet you can do it. Thanks for the tutorial, Jimmy. Happy railroading.
Drew
This was a good one, thanks for sharing. It was easy but very useful
Joe G Thank you!
Hi Jimmy, thank you for this video. I'm interested in your experiences with both the IR sensor and the photorestor under low light conditions. Do they still trip properly if it's darker in the train room? Overall, do you prefer using the IR sensor or the photoresistor?
Nice one Jimmy, the clarity of your presentations is much appreciated, you just need to practice your tiepin!. Would it be easy to add extra LED sensors? Would that mean just adding the same commands to the sketch with different pin Nos. etc.?
another awesome video Jimmy.. thx for sharing.. vinny
Thanks Vinny!
Thank you :)
WHAT A TEACHER
Can the infrared be replaced with hall effect sensors, as people reaching over the track can activate the infrared sometimes?
Cheers 🍻 Bob
Hi Jimmy,
Great video, where can I download the sketch?
Regards Chris
great show Jimmy ,aww pity next week end of Arduino lessons, look forward to watching though ,thanks regards John
Thank you! It isn't the last overall. I will have more segments for beginner arduino tutorials later!
@@DIYDigitalRailroad Great Jimmy thank you very much, theres so much more an arduino can to on railway , a DCC controller, i look forward to seeing if you will do one on working stepper motor for turntable ,theres a project buddy.
Can u do a tutorial on 12v dc motor(or just servo motor) with a sensor??? I really enjoy your channel :)
I will add that to my episode idea list!
@@DIYDigitalRailroad thank you & take care !!!!
I need to buy a few more UNO's
Any chance of getting a copy of your sketch, i have typed it in from the screen but it trips up on the IF statement. Syntax in everything so a copy of yout text would be a big help thanks
I'll go and grab you a copy.
Thanks I intend to use them to trigger signals if you like you could send a txt file to my email address or you may have a better idea.
I think I need to adjust the trigger threshold.
The IR sensor is digital out...Either a high or a low.
The following is open source. Advantage: faster code, better structure, less nonsense.
// completely parametrize code....
const int SENSOR = A0;
const int LED = 13;
const int SENSOR_THRESHOLD = 500;
const int DEBUG_MODE = false;
void setup() {
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
// read
int sensorValue = analogRead(SENSOR);
// write
int ledValue = (SENSOR_THRESHOLD > sensorValue) ? HIGH : LOW;
digitalWrite(LED, ledValue);
if (DEBUG_MODE) {
Serial.print(sensorValue);
Serial.print(ledValue);
}
// wait
delay(100);
}
Great stuff! Thanks for the code!
@@DIYDigitalRailroad It's give and take, isn't it? Thanks, mate.
It would really help if this guy put the schematics for these circuits. You cannot really tell the hookups by looking at the video, as they are not 3D. So you have to guess at how the circuit is connected. This made this video extremely frustrating.
I can certainly make some and add it to them. This video is from a long time ago and I didn’t know how to make schematics like I do now.
@@DIYDigitalRailroad Wow, didn't expect a response because the video was a few years old. Yes, well I am trying to get sensors on my layout, hence the Mega, which I have yet to make sense of. Thanks for your quick response, and I will look forward to the schematics. There are plenty of Arduino type deals on the internet, plus I am trying to make use of the Micro-Cap also. Thanks again! (P.S.) and for Arduino MEGA, because automation and control is dependent on on sensors, and you need a lot of them. Thanks again.