Fun with Arduino - a Series of Introductory Videos

Bereich für alle Themen rund um Modellbahn-Software, sowie der nötigen Hardware (PCs, Bildschirme, etc.).

Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino - a Series of Introductory Videos

#1

Beitrag von RudyB » Di 1. Jan 2019, 18:59

I bet almost everyone here at the forum has heard about the Arduino and how much fun and how useful it can be to model railroaders and to other hobbyists.

The price is no issue at about 3,- £$€. But not every hobbyist has affinity with electronics or with software. To some the initial hurdle can be just too steep, even while there may be an interest to get started with Arduno and to try things out.

That is where the plan arose to do a series of articles and videos titled 'Fun with Arduino', aimed at anyone who is not an electronics or IT specialist (yet :) ).

The first two articles, both with video, are out:

Fun with Arduino 01 Getting Started in 6 Easy Steps.

Fun with Arduino 02 Digital Input and -Output

(Language is English)


Bild
Zuletzt geändert von RudyB am Fr 11. Jan 2019, 22:15, insgesamt 2-mal geändert.

Benutzeravatar

Running.Wolf
InterCity (IC)
Beiträge: 533
Registriert: So 15. Jan 2006, 17:02
Nenngröße: H0
Stromart: AC
Steuerung: CS 2
Gleise: C-Gleis / M-Gleis
Wohnort: Isernhagen
Alter: 72
Kontaktdaten:
Deutschland

Re: Fun with Arduino

#2

Beitrag von Running.Wolf » Mi 2. Jan 2019, 17:43

Nice idea
Go ahead.
Gruss Wolfgang

All that the young can do for the old is to shock them and keep them up to date. George Bernhard Shaw


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 03 Connect an External LED and resistor

#3

Beitrag von RudyB » So 6. Jan 2019, 11:50

The third video is online.

To control the on board LED is fun, but the real fun only starts when we can control external LEDs, like on a switch panel, or on a model railway layout. This video is about how to connect a LED and how to choose the value of the series resister we need to set the LED brightness.

In the next video we are going to control the external LED and we will simulate a night cycle on a model layout.

Link to Fun with Arduino 03 External LED and Resistor

Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 04 Readable & Maintainable Code, #define

#4

Beitrag von RudyB » Fr 11. Jan 2019, 14:35

The goals in this video are:
  • To make our code better readable and easier to maintain.
  • We imagine pin 8 operates 20 street lights on a model railway layout. They switch on when we press the button. To simulate a night cycle we want them to stay on for 3 minutes and then automatically switch off again.

Link to Fun with Arduino 04 Readable & Maintainable Code , #define, delay()


Bild


fbstr
InterCity (IC)
Beiträge: 546
Registriert: So 28. Aug 2016, 21:04
Nenngröße: H0
Stromart: digital
Steuerung: Lenz LZV100, DR5000
Gleise: Peco Code 75, Trix C
Wohnort: Stuttgart
Deutschland

Re: Fun with Arduino

#5

Beitrag von fbstr » Fr 11. Jan 2019, 14:43

Hi Rudy,

I'm thrilled to see the chapter: "Arduino and DCC"

That's the next step for me. Unfortunately not much time for Arduino at the moment but I'm hoping to continue with this topic in spring 2019.
Gruss
Frank
------------------------------------------------------------------------------------------------------------------------
Projekt "Bahnpark Augsburg"
Stummitreff BB: jeden 3. Freitag im Monat in Sindelfingen (außer im August)


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Re: Fun with Arduino

#6

Beitrag von RudyB » Fr 11. Jan 2019, 15:33

Hello Frank,

DCC applications fall somewhat outside the scope of 'beginning with Arduino'. I have done a series of articles, sofware included, on an Arduino based DCC servo decoder, accessory decoder, DCC sniffer and an S88 encoder on my Rudysmodelrailway blog.

Here's a link: https://rudysmodelrailway.wordpress.com ... vo+decoder


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 05 Connect More LEDs with Relay or FET

#7

Beitrag von RudyB » So 13. Jan 2019, 13:38

Arduino outputs can only switch 20mA. If we want to control groups of multuple lights on our model railway layout, we will need some more 'oompf'. A 12V power supply will do great and we can use Relay or FET modules, controlled by the Arduino, to swicth the higher current / voltage. How to do this, how to wire this, is the subject of this video and article.


Link to Fun with Arduino 05 Connect multiple LEDs with a Relay or a FET


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 06 Automatic Day & Night Cycle with on/off Switch and LED

#8

Beitrag von RudyB » Do 17. Jan 2019, 13:42

In this 6th video we are going to create a fully automatic day / night sequence, witch a toggle switch and an indicator LED on our switch panel. The day & night times are going to be configurable in seconds, which means we need some math to go to milliseconds.

Link to Fun with Arduino 06 Automatic Day & Night Cycle with on/off Switch


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 07 Day & Night Cycle, Multiple Light Groups, Random Times

#9

Beitrag von RudyB » So 20. Jan 2019, 12:19

Our day / night module of the previous video works perfect, but it controls just one light group. On our layout we probably have multiple groups ... houses, street lights, a railway station or an industry area. In this video we're going to see how we can control multiple light groups in a day / night cycle, while of course they do not switch all at the same time and also while making it non predictable.

Link to Fun with Arduino 07 Day & Night Cycle, Multiple Light Groups, Random Times


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 08 User Interface Serial.print()

#10

Beitrag von RudyB » Do 24. Jan 2019, 16:36

Our way of modifying the day / night cycle time seemed quite handy, but we do need to modify the code and upload it again every time we like to change the cycle time. Is there maybe an easier way?

Yes there is ... we can change the cycle time 'on the fly' via a User Interface. There are different solutions, with hardware otr with software. We're going to try them both. In this video we'll do the first preparations, writing text and numbers to the PC screen via Serial.print().

Link to Fun with Arduino 08 User Interface Serial.print()


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 09 Variables byte int long unsigned

#11

Beitrag von RudyB » So 27. Jan 2019, 10:50

Before we continue to work on our User Interface, let's first take a moment to have a closer look at variables and data types. We are going to use ever more variables in the coming videos ... and ... we'll have a look at a pitfall concerning data types that prevented our code from previous video 8 to always work as intended.

Fun with Arduino 09 Variables byte int long unsigned


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 10 Show Cycle Status and Time with Serial.print

#12

Beitrag von RudyB » Do 31. Jan 2019, 15:11

Now that we have our code working, by using the correct data type or by typecasting, we can continue the work on our User interface. The goal in this video is to display the status of our day / night cycle on screen ... is it switched on or off, is it day or night, and what is the currently used day / night time. All this will be dynamically updated.

Fun with Arduino 10 Show Cycle Status and Time with Serial.print


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 11 Keyboard Input via Serial Read and ParseInt

#13

Beitrag von RudyB » So 3. Feb 2019, 09:41

The User Interface works, it shows the status if the day / night cycle on screen. We're now going to add the option to change the cycle time via the keyboard. The functions we are going to use are Serial.available(), which tells us that there is new input, and Serial.read() or Serial.parseInt() to read the characters that are typed.

Fun with Arduino 11 Keyboard Input via Serial Read and ParseInt


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 12 Analog Input, analogRead(), Change Range, map()

#14

Beitrag von RudyB » Do 7. Feb 2019, 11:37

Now that we can change the cycle time via the PC keyboard, let's have a look at a hardware oriented solution ... a rotating knob. We connect a potentiometer to an analog input and read the voltage with the analogRead() instruction. With the map() instruction we can convert the range from 0-1023 to the range that we like to use for our cycle time, like say 1-9 minutes with a 1 minute step size, or maybe 10-300 seconds, with a 10 second step size.

Fun with Arduino 12 Analog Input, analogRead(), Change Range, map()


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 13 Timer with millis(), no delay(), Multitasking

#15

Beitrag von RudyB » So 10. Feb 2019, 10:33

The delay() statement that we used so far for our timing stalls the Arduino. This leads to a complete lack of feedback when we change the cycle time while the cycle is running. Luckily there is a solution: we can use the Arduino internal clock, which counts milliseconds from the moment the Arduino is started. We can read the clock using the millis() statement and we can decide if it is time for action.

Fun with Arduino 13 Timer with millis(), no delay(), Multitasking


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 14 Day Night Cycle with millis(), no Delay, Direct Feedback

#16

Beitrag von RudyB » Do 14. Feb 2019, 10:46

Now that we know how to get rid of the delay(0 and use millis() in stead (video 13) we can finalize our Automatic Day Night Light Cycle unit to have direct on screen feedback of cycle time adjustment by the user and to have the cycle stop, and the lights turn off, immediately when the switch is set to ‘off’.

Our unit has quite nice specifications:
- Configurable timing, via keyboard or via analog input with on screen display
- An option to randomize the times to give it some ‘livelyness’
- On screen display of the on/off, day/night state and the cycles times


Fun with Arduino 14 Day Night Cycle with millis(), no Delay, Direct Feedback


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 15 LED Dimmer, analogWrite(), Pulse Width Modulation

#17

Beitrag von RudyB » So 17. Feb 2019, 10:53

We used analogRead() to read the voltage on our potentiometer. The Arduino also has the opposite instruction: analogWrite(). This name is somewhat misleading. Unlike with an analog input, where a 10 bit A/D converter is used, the Arduino does not have a D/A converter on board.

The analogWrite() function uses a technique called Pulse Width Modulation. A digital output switches between HIGH and LOW in a fast pace, whereby the HIGH percentage is proportional to the analog value we wish to send out. If a device that receives the signal is too slow to follow the switching frequency, the result is it 'sees' the average of the on/off times. This also holds for light ... even though LEDs are fast enough to follow the switch frequency, our human eyes + brain are not and we see an average brightness.


Fun with Arduino 15 LED Dimmer, analogWrite(), Pulse Width Modulation


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 16 LED Dimming with Fade, analogWrite(), millis()

#18

Beitrag von RudyB » Do 21. Feb 2019, 12:07

Now that we know how to dim LEDs with analoWrite(), we can go a step further and change the dimming over time to create a gradual fade in or out. This is a nice effect for instance for LED strips mounted under kitchen cabinets, or for LED strip overhead lighting on a model railway layout to simulate a gradual change from night to day. And also for the red/green transition of railway signals along the track a fade gives just that little extra eye candy.

Fun with Arduino 16 LED Dimming with Fade, analogWrite(), millis()


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 17 Railway Crossing, State Transition Diagram, switch()

#19

Beitrag von RudyB » Mo 25. Feb 2019, 10:39

We're at the start of a new Arduino project: an automatic railway crossing.

The system comprises several parts: train detection (optical), blinking lights ('blink' with a twist), a moving beam (servo motor).

We'll look into a way of specifying these kinds of systems as well as a way to translate the specifications into code, with a stepwise approach that does not put too much strain on our grey cells.


Fun with Arduino 17 Railway Crossing, State Transition Diagram, switch()


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 18 Railway Crossing, Servo Motor to Operate the Gate

#20

Beitrag von RudyB » Do 28. Feb 2019, 10:51

In part 2 of the railway crossing project we are going to connect the servo motor that operates the gate and control it with the Arduino. With the example in the video, the gate beam is mounted directly on the servo. On a layout, the servo motor will probably be mounted under the board, and a metal rod pulls / pushes the beam up and down, through a hole. No matter how it is mounted ... we need to find the correct servo angles. We will write some code with which we can fine tune the servo to find the angles to be used in the code later on.


Fun with Arduino 18 Railway Crossing, Servo Motor to Operate the Gate


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 19 Railway Crossing Train Detection with Optical Sensor

#21

Beitrag von RudyB » Do 7. Mär 2019, 11:32

There are several ways to do train detection, like sensing rail current, or a magnet under the train that triggers reed switches along the track, or with an optical sensor. The latter is used in this video, only because I had some TRCT5000's lying around and they were easy to setup for a demo. As soon as we have them working, we have some fun with them by making a train speed measurement device.


Fun with Arduino 19 Railway Crossing Train Detection with Optical Sensor


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 20 Railway Crossing Putting it all Together

#22

Beitrag von RudyB » So 10. Mär 2019, 12:14

We have seen the separate ingredients for a level crossing in the previous three videos: blinking LEDs, servo to operate the gate, sensors to detect the train ... it is time to put it all together now into one piece of software. We'll use the State Transition Diagram as our starting point and build up the software in 5 easy to follow steps.


Fun with Arduino 20 Railway Crossing Putting it all Together

Railway Crossing UK version


Bild


Max666
InterRegio (IR)
Beiträge: 116
Registriert: Do 28. Dez 2017, 16:04
Nenngröße: H0
Stromart: digital
Steuerung: Piko Smartcontrol
Kontaktdaten:
Vereinigte Staaten von Amerika

Re: Fun with Arduino - a Series of Introductory Videos

#23

Beitrag von Max666 » Do 14. Mär 2019, 09:56

Hello Rudy,

Video Tutorials are great and help a lot of people. I use Arduino in lot of my Projects too in similar way. I must study all that on my own so it's great that someone shares the knowledges!

Have a great fun by modeling!

LG,
Max Supercars


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 22 Step Sequencer for LEDs with array[] and for() loop

#24

Beitrag von RudyB » Do 14. Mär 2019, 15:21

A police car, fire fighter car or an ambulance with flashing lights can liven up any model railway laout. The challenge that we set ourselves is not to have to write different code any time we want another flashing pattern. We want to hav one and the same code and we only want to configure the number of stepd, number of LEDs and the flashing step sequence. Can we manage that? Yes of course we can ...


Fun with Arduino 22 Step Sequencer for LEDs


Bild


Threadersteller
RudyB
InterRegio (IR)
Beiträge: 185
Registriert: Sa 20. Sep 2014, 10:18

Fun with Arduino 23 Neopixel Addressable LED, WS2812, struct{...}

#25

Beitrag von RudyB » Do 21. Mär 2019, 15:10

Neopixels, or addressable LEDs, are color LEDs with a built in chip that takes care of the one wire data communication and of the Pulse Width Modulation for the built in RGB(+W) LEDs. The LEDs are connected via just 3 wires, GND, 5V, Data. The Data line is connected to an Arduino output and we can control the color and brightness of multiple LEDs, via just one output. Wonderful to use in say a village with multiple houses on our model railway layout. The wiring is super simple and the lights in every house switch independently and can each have their own color an brightnes ... just like real.


Link to Fun with Arduino 23 Neopixel Addressable LED, WS2812, struct{...}


Bild

Antworten

Zurück zu „Software und Hardware“