# Introduction to Arduino part 1 - What can a microcontroller do for you



## Shdwdrgn (Dec 23, 2014)

Microprocessors have become so cheap and easy to use that you can throw them into virtually any project. In this series I want to explore the possibilities of using miniature computers to control even mundane components of a train layout, and hopefully give you the tools to apply this knowledge to your own projects.

To begin, let's discuss some of the capabilities of microprocessors. This is not your desktop PC where you point and click to make things happen. Here, you will be dealing directly with inputs: switches, sensors, even reading the voltage from the track; and you will be controlling the outputs: LEDs, motors, communications over WIFI. Anything which requires a set of actions, timers, or more precision is a viable candidate for computer control. As an example, one of the projects in this series will control the gates and flashing lights for a crossing. We will have the lights start flashing for a moment before bringing the crossing gates down slowly, then when the train has passed the gates will rise back up and finally turn off the flashing lights. Microprocessors excel in situations where you want a series of events to take place.

You will want to consider your own skills. Are you familiar with voltages? Can you do precise soldering? Can you read a schematic? I will try to help walk you through an understanding of how each component is connected, and why. When we get up to writing programs, once again each part will be explained. Skills are built up one small piece at a time, but the combined knowledge will allow to do amazing things. The discussions will include examples of using a breadboard to temporarily test your designs, where you simply plug wires and components into available sockets, but we will also talk about soldering components together for more permanent creations.

One last thing to keep in mind is static electricity, like when you walk across the carpet in Winter and get a shock off of a metal surface. While that shock may sting you, imaging what it does to fragile electronic components. You should keep this in mind when working with any electronics. When you sit down to work on these circuits, try to have a way to discharge any static build-up in your body. For instance, most desktop computers require a grounded outlet, and touching the outside case will ground you.

Getting back to the computer, the arduino is a popular series of microprocessors because of the low costs and wide range of availability. Not only can you buy these online, but they are also available in local stores. Many of the boards available are based on open-source projects, which means not only can you get access to all the information about the board, but you will find clones built exactly the same way. At the heart of any computer project is the software which tells the components what to do. The easiest way to load that program is through a standard USB port from your desktop computer, and because even the smallest computers have versions available with the USB port already installed, programming your arduino will be a simple task.

The most popular arduino boards are built around a series of computer chips sold by ATmega, and when looking for supplies you will probably see this name a lot. However there are other systems available which can be programmed from the same desktop software by installing the support packages for them. For our smaller projects, we will be using a chip called the ATtiny. In particular, the ATtiny85 is a small 8-pin chip which gives you 5 lines to read and control devices and can be purchased for around $2 each. The board that I use, including the USB port, is only 3/4" x 1" and could be easily hidden inside a building or even buried underneath an HO scale track. There are a number of different microcontrollers available that can be sized to your project, whether you need more power or less power. Nearly all of them cost less than $20, with the majority being even less than $10. The best part is you will be able to use nearly the same code to program each (with adjustments made for your I/O pins), so you can use one of the larger microcontrollers to follow along on all of the projects presented here.

If you wish to begin purchasing some components, consider these items:

Starter kit (includes an impressive assortment of components): https://www.adafruit.com/products/170

*Prototype breadboard plus male-male jumper wires ($3.59 each): http://www.ebay.com/itm/New-Prototy...-Breadboard-Tie-Line-Wire-Cable-/331701798786

female-female jumper wires (40 pcs for $0.68): http://www.ebay.com/itm/40pcs-10cm-...mper-Cable-1P-1P-For-Arduino-SC-/221949738581

male-female jumper wires (40 pcs for $0.68): http://www.ebay.com/itm/NEW-40pcs-D...Ribbon-Cable-Arduino-Unique-CB2-/331637900982

*red LEDs (20 pcs with wires for $2.41): http://www.ebay.com/itm/20-X-5MM-Red-LED-Light-Bulb-Lamp-Pre-Wired-12V-DIY-Hot-/271719309603

1n4001 diodes (50 pcs for $0.99): http://www.ebay.com/itm/Hot-Sale-50...-Rectifier-Diodes-Free-Shipping-/262157246627

*miniature stepper motors ($0.68 each): http://www.ebay.com/itm/252246110151

L293D motor driver (10 pcs for $3.98): http://www.ebay.com/itm/10x-L293D-L293-Push-Pull-Four-Channel-Motor-Driver-IC-HPT-/201485786131
* Similar items are included in the starter kit.

If you have the ability to solder small components, you might also consider these items...

USB-A to USB-micro cable (used for almost all arduinos that you solder to)($0.68 each): http://www.ebay.com/itm/Black-Micro...-for-android-Samsung-Galaxy-HTC-/311384834523

Arduino pro micro 3.3v (requires soldering)($5.99 each): http://www.ebay.com/itm/New-Pro-Mic...-ATmega328-Arduino-Pro-Mini-M94-/351493857244

ATtiny85 kickstarter ($1.69 each): http://www.ebay.com/itm/Digispark-K...evelopment-Board-for-arduino-GM-/262136733848

(Yes I buy a lot of Chinese components from Ebay, but at these prices I can usually buy bulk-packs so I have lots of extras on hand.)

One final comment here... You can follow along on a shoestring budget IF you can solder components properly (keep it neat and clean, use the minimum heat required). Get the arduino pro-micro and solder the included header pins to the board. Add a USB micro cable for your computer, the breadboard and male-female jumper wires, and some LEDs for a total of $13.35 if you use the links above, and you will have enough to follow along when we start writing programs.

Coming up next: We will discuss setting up the arduino software that allows you to program various microcontrollers.


----------



## 2869ral (Dec 15, 2015)

Very nice! Thanks for doing this.


----------



## DonR (Oct 18, 2012)

I'm going to try to keep up with you. Fascinating.

Don


----------



## Shdwdrgn (Dec 23, 2014)

Please do ask questions, I'm a lot better at answering specifics. The abstract nature of trying to write an article such as this is difficult for me.


----------



## gregc (Apr 25, 2015)

i think it worth mentioning:

while early microprocessors required external clock, I/O, Timer, crystal and memory chips, that today's microcontrollers are complete standalone systems that also integrate higher-level functions such as UARTS, analog-to-digital converters (ADC and DAC), pulse width modulators (PWM), ...

the advantage of microcontrollers over hardware is that a single processor can replace many integrated circuits.

a single microcontroller circuit with multiple inputs and outputs can be programmed for many different purposes. Arduino circuit boards are one example.

that a single microcontroller can perform like different hardware circuits at different times.

unlike early microprocessor circuits where memory was programmed in devices external to the circuit, today's micro-controllers can be programmed in-circuit (e.g USB)

and today's integrated development environments (IDE) with direct in-circuit connections to the processor allow developers to single step thru the program to examine the inputs, see the outputs and debug the program.


----------



## Shdwdrgn (Dec 23, 2014)

Sorry, I haven't had any time this weekend to work on the next article. I'll try to get to it soon...


----------



## IslandTrains (Feb 14, 2016)

I am interested in getting an Arduino and notice a lot of "starter packs" on Amazon. Are they worth buying? Here is one that I thought might be a good way to start:
https://www.amazon.ca/Kuman-Project-Starter-Mega2560-included/dp/B0188TO4VU/ref=sr_1_16?ie=UTF8&qid=1459430909&sr=8-16&keywords=arduino


----------



## TomW2034 (Jun 2, 2015)

I bought a starter pack on Amazon and both my son & I have thoroughly it. I thought it was a good purchase because we could start immediately instead of having to figure out what else we needed to accomplish simple projects.

Tom


----------



## PaulPerger (Feb 4, 2014)

Following


----------

