Download presentation
Presentation is loading. Please wait.
Published byShawn Parrish Modified over 8 years ago
1
Trying Arduinos or Arduinos Trying Our Patience
2
Clinic Rules and Housekeeping 1. NO SMOKING 2. Restrooms are out in the hallway. Take a break when you need. 3. No food or drinks in the room, other than water. 4. Stop me and ask questions. I might even know the answer. Or we'll find it together. 5. The only wrong way to do something won't work. Be fearless, or at least willing to try.
3
Thomas Edison said: I have not failed. I've just found 10,000 ways that won't work. Many of life's failures are people who did not realize how close they were to success when they gave up. Our greatest weakness lies in giving up. The most certain way to succeed is always to try just one more time.
4
What is Arduino Arduino: an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards read inputs and turns them into outputs. Its actions and reactions are all written in code. Source: www.arduino.cc
5
What is Arduino (in layman's terms) An Arduino (or its clone) is a small microprocessor controlled board. It can be programmed to read inputs, operate a program responding to the inputs, and making some change to the outside world through any number of outputs. An Arduino will run the loop portion of the program over and over and over. It will spend more process time waiting for the conditions to change in the outside world then it will take to make changes through the outputs.
6
Inputs Pushbuttons Sensors Current sensors Light sensors Rotary switches Feedback from output devices such as a Tortoise switch machine
7
Outputs Lights LEDs Anything with a logic voltage trigger Servos Tortoise switch machines Relays
8
Arduinos in Model RR If you can apply repetitive logic to the situation, an Arduino can take over and run it for you. Simple Control Point (end of passing siding) An Automated Interlocked Crossing A Seven Track Staging Yard Ladder with embedded crossings Simulating an industry gate with a guard Lots of other projects you can think of
9
Before we get crazy, let's set up the playing field 1. You brought your laptop 2. Downloaded and installed the Arduino IDE (Integrated Development Environment)? (www.arduino.cc)www.arduino.cc 3. Brought your Arduino Uno board and connector cable 4. Plug in the Uno board to the USB port on your computer. 5. See the LED blinking? (We will run the “Blink” sketch later) 6. You have a selection of goodies in front of you
10
Arduino Sizes and Number of I/Os The Uno was the original (duh!). It has 14 digital I/O pins and 6 analog input pints. It's also the one we're working with today. The Mega is just that: it has 54 digital I/O pins of which 15 can be pulse width modulated, 16 analog pins, and 4 hardware serial ports The Nano is small; has 14 digital I/O pins (6 can be PWM) and 8 analog input pins. Several other sizes are available as well.
11
List of Goodies Prototyping Breadboard Breadboard power module Jumper wires LEDs (lots of LEDs) Photoresistors Pushbuttons A couple of servos
12
Blank Breadboard The upper two and lower two lines are connected horizontally The inner areas (of 5 lines) are connected vertically
13
Breadboard and Goodies The upper area has 6 photoresistors in place The lower area has LEDs and resistors
14
Arduino Commands If you've programmed in C or Basic, some of these commands and functions will be familiar If not, you'll catch on Remember, “copy and paste” is our friend. If a code block works once, it will work again with a little tweak. Also, check your code with the “verify/compile” button under “Sketch” in the IDE. This will catch your syntax errors and unfinished commands. It WON'T catch any logic errors.
15
Arduino Commands setup() loop() pinMode() digitalWrite() digitalRead() analogRead() analogWrite() delay() if if...else for do...while while ; (semincolon) // (comment, very important)
16
Help while programming When I'm writing the code for any sketch, I have at least three windows open. 1. The sketch I'm working on. 2. The reference code library on the Arduino website. 3. Any sketch from which I'm going to copy code snippets. 4. Any example sketch from the Arduino library.
17
Blink Blink is the first and simplest sketch A variation of it is already on your board Open your IDE and from the examples select the Blink program and open it Let's walk through the code
18
Blink This example shows the simplest thing you can do with an Arduino or Genuino to see physical output: it blinks an LED. Hardware Required Arduino or Genuino Board LED 220 ohm resistor Circuit To build the circuit, connect one end of the resistor to Arduino pin 13. Connect the long leg of the LED (the positive leg, called the anode) to the other end of the resistor. Connect the short leg of the LED (the negative leg, called the cathode) to the Arduino GND, as shown in the diagram and the schematic on the next slide. Most Arduino boards already have an LED attached to pin 13 on the board itself. If you run this example with no hardware attached, you should see that LED blink. The value of the resistor in series with the LED may be of a different value than 220 ohm; the LED will light up also with values up to 1K ohm.
19
Set up for Blink
20
// the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } Code for Blink
21
Blink Code on your board // the setup function runs once when you press reset or power the board void setup() { // initialize digital pin 13 as an output. pinMode(13, OUTPUT); } // the loop function runs over and over again forever void loop() { digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(5000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }
22
Blink with 2 LEDs on a board Grab your breadboard, 2 LEDs (any two colors), 2 resistors, and some jumper wires Put the LEDs and resistors on the board with the jumpers as the diagram shows on the next screen Now add code to your blink code which turns on and off Pin 12 in opposition to the Pin 13
24
// Pin 13 has an LED connected on most Arduino boards. // give it a name: int led1 = 12 ; int led2 = 13; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); } // the loop routine runs over and over again forever: void loop() { digitalWrite(led1, HIGH); digitalWrite(led2, LOW); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led1, LOW); digitalWrite(led2, HIGH); // turn the LED off by making the voltage LOW delay(5000); // wait for a second digitalWrite(led1, LOW); digitalWrite(led2, LOW); delay(5000); digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); delay(5000); }
25
Arduino is small power An Arduino can control many things, but can only drive low voltage (5 volts or less) devices. Since some of the devices we want the Arduino to control are 12 volt devices, we have to use something to control the 12 volt. In the next example, we let an Arduino control, but not operate, a Tortoise switch machine. With a 12 volt power supply going through a DPDT relay with a 5 volt control circuit, the Arduino can throw a switch that reverses the power to a Tortoise.
26
The Tortoise and The Arduino (not the Tortoise and The Hare) A very basic system A Tortoise connected to the DC terminals of a power pack (any 12 volt power supply) An Arduino controlling a DPDT relay to reverse the power to the Tortoise
27
Wiring a DPDT relay The input to the relay is simple The output you have to double wire to provide reversing control of the Tortoise
28
Arduino Connections The ground on the relays goes to the ground on the Ardunio The power comes from the 5V on the Arduino The relay is controlled by the digital pin (in this case pin 12)
29
Tortoise Example As you saw, I had the Tortoise powered through a DPDT relay. The relay is triggered by the Arduino. If you need to know the position of the switch before you throw it, the Arduino can use one set of the Tortoise's internal contacts to determine the current position of the Tortoise. I use this feedback from a Tortoise at Jack Keene's to control the South End Staging Loops.
30
Input for Occupancy Detection For model railroading applications, the Arduino is going to need to know if there is a train that is about to trigger an event. How to let the Arduino know can be accomplished several ways: photoresister, Hall Effect Current detector, Ataras BD8, Optimzied Detector, and other devices
31
Track Signal Project Grab 9 LEDs (3 green, 3 yellow, 3 red) and resistors 3 Photoresistors Place the LEDs in traffic light settings with photoresistors below With the sketch “Track_signal” loaded, place your hand over each photoresistor in turn See how all 3 sets of signal LEDs respond
32
Track Signal Breadboard
33
void setup() { // put your setup code here, to run once: pinMode(13, OUTPUT); pinMode(12, OUTPUT); pinMode(11, OUTPUT); pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT); pinMode(5, OUTPUT); int analogpin1; int analogpin2; int analogpin3; } void loop() { // put your main code here, to run repeatedly: int analogpin1 = analogRead(1); int analogpin2 = analogRead(2); int analogpin3 = analogRead(3); // analogpin4 = analogRead(4); if (analogpin1 == HIGH) { digitalWrite(11, HIGH); digitalWrite(8, HIGH); digitalWrite(5, HIGH); } if (analogpin2 == HIGH) { digitalWrite(13, HIGH); digitalWrite(11, LOW); } if (analogpin3 == HIGH) { digitalWrite(13, LOW); digitalWrite(12, HIGH); digitalWrite(10, HIGH); digitalWrite(5, HIGH); digitalWrite(8, LOW); } delay(10000); digitalWrite(13, LOW); digitalWrite(12, LOW); digitalWrite(11, LOW); digitalWrite(10, LOW); digitalWrite(9, LOW); digitalWrite(8, LOW); digitalWrite(7, LOW); digitalWrite(6, LOW); digitalWrite(5, LOW); }
34
Changes to Track_signal Sketch If we added a second set of photoresistors, we could sequence the LEDs as though they were on a bidirectional stretch of single track similar to Absolute-Permissive Block signalling
35
Automated Junction On the display board, I have an automated junction based on photoresistor detection. The two single track mainlines cross but do not interchange (simplistic example here). The first train to be detected gets the slow approach signal while the second train receives a stop indication. The Arduino holds the crossing until the second photoresistor on the same track is cleared before Arduino resets the crossing.
36
Automated Junction Process How would you program the Arduino? What steps Open discussion of process Let's write the code or attempt to write it
37
New Wrinkles to use Random time Random selection By using a pseudo random number generator we can add an element of chance/life/reality to the operation While no one is actually at the crossing, the Arduino will randomly clear one route and then reset. This is good for a “dummy” crossing on your layout (example of Tom's WM/PRR crossing)
38
Control Point (CP) with Servo Earlier I showed you how to use an Arduino, 5 volt DPDT relay and a Tortoise to operate together. This requires a separate 12 volt power supply for the Tortoise. On this example, I'm using the same photoresistor detection but using a RC model servo to operate the switch.
39
Control Point (CP) with Servo Sequence of Operation Pushbutton to select which route (normal left to right, normal right to left, take siding, leave siding) Arduino sets the switch to appropriate route Sets the appropriate signals Waits until both photoresistors are uncovered Resets signals to All Stop and switch to Normal
40
Servo note If you are only using one or two servos, they can be controlled and powered from the Arduino If you're using more than two, the Arduino will not be able to power them. Power the servos from a separate 5 volt supply but tie the ground together with the ground from the Arduino.
41
Attaching a single servo
42
Your Ideas What do you see using an Arduino for? Signalling a single track with Absolute- Permissive Block System? Controlling a flood loader for coal using IR detectors for hopper car positioning? Protecting gauntlet trackage and signals? Taking care of some other task?
43
Arduinos and the Achievement Program Electrical Certificate Any successful Arduino project fulfills one part of your AP Electrical certificate If not in a defined way, Arduinos will fit in the “Other undefined project” category Add a relay to shut off the power at the CP end and you have met one requirement, a junction with power (Req. C, parts 2, 5, 8, 11, 12, 22, and the ever popular 23 “Other”)
44
Resources www.arduino.cc Yahoo group Arduinos and MR Youtube, just search Arduino Your kid, neighbor's kid/grandkid, etc. (some of them already have a grasp of programming) Fritzing software for documentation Even me by email, kurtrain@verizon.net
45
A reminder about the Arduino It doesn't get mad It doesn't get sad It doesn't laugh at my jokes (too bad for me) It doesn't get bored It just runs programs Liberally lifted from the 1980s movie “Short Circuit”
46
In Conclusion Well, not conclusion, more the beginning Now I've shown you some stuff and opened the door An Arduino is willing to do any task you can code for it. It won't get bored between operations From here, the ideas and sketches are yours There are several resources available as listed before NEXT?!!!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.