Fun with Arduino - a Series of Introductory Videos


RudyB

Active Member
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 other hobbyists.

Price is no issue, an Arduino can be had 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 IT specialist (yet :)).

The first video is on how to get up and running: Getting Started in 6 Easy Steps.


34759779nz.jpg
 
You've convinced me. I'd been considering using these to operate portions of my layout anyways, but for the cost of a basic kit, I might as well start learning, so that I know what it can and can't do before I do any planning.
 
Fun with Arduino 03 Connect an External LED and resistor

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 third 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

34766252wx.jpg
 
Fun with Arduino 05 Connect More LEDs with Relay or FET

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


34829491px.jpg
 
Fun with Arduino 07 Day & Night Cycle, Multiple Light Groups, Random Times

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


34878792si.jpg
 
I started working with these a long time ago but it’s been a few years now since I’ve had a chance to make anything with these yet. I will keep up with this and contribute as I can.
Dave
 
Fun with Arduino 08 User Interface Serial.print()

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


34911023ti.jpg
 
Fun with Arduino 09 Variables byte int long unsigned

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


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

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


34964832sg.jpg
 
Fun with Arduino 11 Keyboard Input via Serial Read and ParseInt

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


34986161sw.jpg
 
Fun with Arduino 12 Analog Input, analogRead(), Change Range, map()

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


35016651zo.jpg
 
Fun with Arduino 13 Timer with millis(), no delay(), Multitasking

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


35036320hc.jpg
 
Fun with Arduino 14 Day Night Cycle with millis(), no Delay, Direct Feedback

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


35064128sm.jpg
 
Fun with Arduino 15 LED Dimmer, analogWrite(), Pulse Width Modulation

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


35088670bd.jpg
 
Fun with Arduino 16 LED Dimming with Fade, analogWrite(), millis()

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


35120672uf.jpg
 
Fun with Arduino 17 Railway Crossing, State Transition Diagram, switch()

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


35150263is.jpg
 



Back
Top