Go Down

Topic: Fun with Arduino - a Series of Introductory Videos (Read 35967 times) previous topic - next topic

RudyB

Fun with Arduino - Introductory Videos

As a model railway hobbyist I have found the Arduino to be an invaluable tool. It can liven up any layout by making things move, switch lights on and off, and it can even be used as a full fledged DCC decoder.

Not every hobbyist has affinity with electronics or with software however. To some the hill to start can be just too steep, even while there may be an interest to use Arduino 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 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

Have fun.
Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

Willpatel_Kendmirez

I enjoyed both of those, and wonder what you plan for future episodes?

I'm asking because there is no shortage of Arduino material around the webz. In fact it sometimes seems there's too much, some of it subtly different from others, some of it conflicting and some of it factually incorrect.

Apart from some factual faults like suggesting to power servos from the Arduino 5V, the examples on this site are as good a place as any to start. What's going to make your series different from the others?




RudyB

@Willpatel_Kendmirez
Yes, many articles and video's are already available. Yet at our model railway club I found the hurdle still is steep for many to start, even 'beginner' tutorials tend to go too fast. I intend to intermingle a bit more explanation on hardware and software, hoping that non electronic / IT educated might be able to follow along.

Future subjects will probably focus on examples related to model railway lauouts: lighting (LED and relay / FET), servo (railway crossong), optical sensor (automate the railway crossong), DC or stepper motor to introduce some movement ... things like that.

On Rudy's Arduino Projects blog I'll probaby not promote powering the Arduino directly via a 5V pin, whereas on my Rudys Model Railway blog I do. If 5V is the only available power on the railway layout there's no choice. What is the 'factual faiult' you mention?
Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

Willpatel_Kendmirez

What is the 'factual faiult' you mention?
That one shouldn't power servos from the Arduino 5V as a matter of good practice... ok, maybe not factually incorrect as long as it's a small servo but even micro servos can draw 7-800mA. Both the servo sweep and knob examples say to do that... as soon as one moves to more than one and / or a bigger servo there's not enough current.

(I didn't say not to power an Arduino into its 5V pin, I said not to power anything substantial out of it.)

I like your idea of making your material "Arduino in a model railway world": that makes perfect sense for your audience, who do not want to get bogged down in the arcana of electrical engineering, but do want to get their model railways to work safely and reliably without too much fannying about.

Coincidentally, Robin2 had this to say to me yesterday:

I use them [nRF24L01's] for radio control for model trains. I have made some units for my model railway club that take the place of wired controllers so folk aren't tripping over the wires. And I have some installed in my own trains for battery powered radio control.


RudyB


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

Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB



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()




Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB


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


Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB


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


Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB


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


Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB


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()


Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB


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


Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

Robin2

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

RudyB


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



Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB


The User Interface works, it shows us 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



Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

RudyB


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()



Rudysmodelrailway = Youtube channel on Model Railway, Traincontroller, Arduino and more.

Go Up