Arduino – An Introduction
Hardware and Programming
Presented by Madu Suthanan, P. Eng., FEC. Volunteer, Former Chair (2013-14) PEO Scarborough Chapter
Arduino for Mechatronics 2017 This note is for those contesting in - - PowerPoint PPT Presentation
Arduino An Introduction Hardware and Programming Presented by Madu Suthanan, P. Eng., FEC. Volunteer, Former Chair (2013-14) PEO Scarborough Chapter 2 27 October, 2017 Arduino for Mechatronics 2017 This note is for those contesting
Hardware and Programming
Presented by Madu Suthanan, P. Eng., FEC. Volunteer, Former Chair (2013-14) PEO Scarborough Chapter
PEOSC
components, and basic programming techniques for this
Raspberry Pi, Beaglebone Black etc.
Arduino for use in Mechatronics 2017, and other applications.
27 October, 2017
2
▫ This will introduce you to the various important parts of Arduino.
transistors, LEDs, motors and safety considerations
▫ Voltage, and current requirements and limiting values
▫ How to download the program from the Arduino.cc web-site
▫ How to think in pseudo-code and write comments ▫ Include Programming Codes (Sketches) ▫ Run the sketches
▫ Face the judges ▫ Race the cars – May the best win☺.
27 October, 2017
3
Hardware are the physical parts that you can see, touch or kick
27 October, 2017
4
At the end of this Section you will know
▫ About Limiting Voltages and Currents, to be covered in Section 2
27 October, 2017
5
▫ There are many models ▫ Many equivalent compatible models are also available
▫ It is built around Atmel’s ATmega328P microcontroller (μC) ▫ It comes in 2 flavours:
Uses removable 28 DIL 328μC Uses 328μC surface mounted Device (SMD)
▫ For all your purposes they work the same way
27 October, 2017
6
28 pin DIL removable μC 328 μC Surface Mounted Device (SMD) μC 328 μC
27 October, 2017
7
The important parts of ARDUINO UNO R3
The 2 rows of strips of Pins (actually sockets) are designed to accept sensors and actuators, and to piggyback accessory boards called Shields. 5 Power Pins: Only Vin and Gnd is used to supply power to the board. You can use 6 to 20 V. Recommended is 7 to 12 V. You can also supply same value power through the Jack, but not Both. 6 Analog IN pins (A0 to A5). To connect Analog sensors. These can measure 1024 levels of small voltages. 14 digital IN/OUT pins (0 to 13). When set as INPUT, they can accept sensors. When set as OUTPUT, they can supply 5 (HIGH) or 0 (LOW) Volts to control Actuators. INPUT, OUTPUT, HIGH, LOW are specified in the Sketches. 6 Analog OUT pins (3,5,6,9,10,11). These are actually Digital pins which can output PWM Pulse Width Modulated signals, which imitates analog output. They can be used to dim LEDs and change speeds of motors.
328μC USB B Power Jack Voltage Regulator: 5V out
S1
27 October, 2017
8
▫ exceed 5 volts through the USB (normally USB voltages are regulated) ▫ Be within 6 to 20 Volts (recommended 7 to 12 volts), through the jack or Vin pin.
A built-in Voltage regulator keeps the voltages supplied to the board at 5 volts.
Pins are NOT overload or short-circuit protected. Easy to damage
27 October, 2017
9
▫ Used mainly to try out circuits easily as component can be plugged in wires connected and retried easily. ▫ Once finalised, final circuit boards are made and the components are soldered in.
▫ a1 to e1 (5 holes) – Row 1 Left bank (L): are internally connected. ▫ The internal connection for Row 3 L is shown. ▫ similarly all rows 1L to 30L, and rows 1R to 30R. ▫ The + holes are all internally connected (as shown) ▫ Similarly the – holes on Left, and + and – holes on right.
trying your circuits for proper working, and measure voltages, currents, resistances etc.
27 October, 2017
10
Printed Circuit Board, if highly reliable circuits are desired.
▫ Useful if you are manufacturing many similar circuits.
be soldered the way you wish.
▫ It is a Universal Printed Circuit Board.
27 October, 2017
11
27 October, 2017
12
Arduino uses Input sensors and output Actuators. Sensors: Switches, Light, Sound, Pressure, Temperature, Shock, Proximity, Position and others Actuators: LED, Motors, Speakers, Lasers and others Other components required: resistors, diodes, transistors, capacitors, inductors etc.
27 October, 2017
13
At the end of this Section you will know
▫ Understanding their values, ratings, and intended uses.
Arduino
▫ About Limiting Voltages and Currents, Wattages Well selected components with make the project work reliably as intended and lasts very long – years for most cases.
27 October, 2017
14
Read about above components in Part 1 of the Guidelines. Read about other components supplied and their uses for designing more advanced projects (after the contest) We have supplied LDR, diodes, transistors, capacitors etc. for your learning and use at your
27 October, 2017
15
▫ Name & Value.
Learn to recognise a component and read its value and the rated maximum voltage, current and power (Watt). Use on-line Datasheets to get full details of components Values are sometimes colour codes (resistances) Wattage is sometimes by size of component Sometimes resistors and inductors look same (we have not supplied inductors)
these.
27 October, 2017
16
OUTPUT pin and ground?
Arduino may get damaged.
▫ LEDs drop about 1.7 volts to 2.4 volts depending on the colour and size. ▫ Output pins of Arduino supply 5 Volts. ▫ So if an LED is connected directly, it will
resistance has to drop 5 – 2 = 3 volts.
the Arduino or 20 mA for the LED. Try to keep it to say 10 mA. = .01 Amp.
R=V/I = 3/.01 =300 ohms. We can use the nearest available resistor. If necessary you can connect resistors in series
resistor? = I2R = .012x300 = 0.03 W. So use ¼ W.
27 October, 2017
17
Ground and pin 10
connected to positive side.
program you can make them blink in various
Mechatronics 2017)
27 October, 2017
18
Arduino?
stalled (shaft stopped) it may draw more than 1 Amp. (Check these by using a meter carefully set to Amp).
Read about Darlington Transistor (TIP120) and how to connect them and use of a resistor in our Guidelines and Notes Part 1.
Next slide I give a possible circuit. Use your own ingenuity and creativity to improve on it.
27 October, 2017
19
I have given a possible sample circuit for the car project for Mechatronics 2017. The software to make the car run is given in next Sections. How the car is to be started or stopped etc. is in our web-site
I have not shown any switch or
battery wire when not in use. A resistor is used in the base circuit to limit the current through the base.
27 October, 2017
20
The freely downloadable Arduino IDE is used to program the Arduino. Arduino programs are called Sketches in Arduino parlance. You can use the sketches on line or download and .exe executable program or a Zip file to be
27 October, 2017
21
At the end of this Section you will be able to
▫ You can also use the program on-line and save your files on the Cloud
Note: Some of the schools and offices may have protected the computers from downloading programs
▫ If so, you have to inform the IT Department and get this site downloadable and accessible.
27 October, 2017
22
http://Arduino.cc/en/Main/Software
at: http://Arduino.cc/en/Guide/HomePage
computer using the supplied USB A/B cable or a USB printer cable.
connect to the Arduino and select UNO model.
27 October, 2017
23
(programs) under: File>Examples.
Arduinos. File>Examples>01. Basics>Blink.
blink slower or faster.
make it Blink at various speeds, or blink solidly.
uploading, make sure that the correct COM port is selected, and there are no errors in the
cursor stops against the line where the error
misleading and not clear enough.
programming in more detail.
27 October, 2017
24
Arduino uses C Programming language modified especially for use with Arduino. It is called Arduino IDE and is freely downloadable from Arduino.cc or you can work on line in their site. There are many examples and projects at this site for you to learn from.
27 October, 2017
25
At the end of this Section you will learn
▫ the format of the sketches
▫ Use comments to make your sketches easier to understand
▫ to write a working sketch ▫ To Verify/Compile Sketch ▫ To Upload to Arduino and run the sketch
27 October, 2017
26
very precise and does not lend to double meanings.
written in its proper syntax.
▫ This is called pseudo-coding
27 October, 2017
27
called:
▫ void setup () { } ▫ void loop () { } ▫ If a function runs into many lines, each line has to end with a ; (semi colon) ▫ You can also add comments to make the sketch understandable to a reader. ▫ The functions will use commands with arguments which has to follow some simple
Comments are text entered starting with /* and ending with */ This can be multiline. Or comments can be single line starting anywhere on a line with //. Comments are useful for you to read and understand the sketches. They are not read by the compiler of the IDE. Commands are single words in the format: pinMode, digitalWrite, etc. They are case sensitive: Pinmode or PinMode pin Mode will no be accepted.
27 October, 2017
28
constants in Arduino
is connected to an LED.
between -32,768 to +32,767.
rules.
27 October, 2017
29
/* This is an example sketch to blink an LED. We can modify this to blink more LEDs and to run motors etc.*/ // Blink by Madu – 27 Oct 2017 int ledPin = 8; // LED is connected to pin 8 void setup() { pinMode (ledPin, OUTPUT); // Pin 8 is set for output } void loop() { digital Write (ledPin, HIGH); // set LED on delay (1000); //wait 1 sec. 1000 is 1000 msec. digitalWrite (ledPin, LOW); //make LED off delay (2000); // wait 2 seconds }
codes are clearly understood by a reader.
end of the sketch it run through the loop again and again.
more advanced commands, not covered here.
blink at different rates. Also you can connect LEDs to different pins.
signals, hazard signals in a car or as traffic light and more!
27 October, 2017
30
blinking?
proper transistor to allow the high current?
motor?
motor run at different speeds?
▫ This is where you use PWM. Pulse Width
pulse Width Modulation. It is not necessary for the motor as you want to run the car as fast as possible. ▫ Seniors can try to dim their LEDs if they so
commands here. Students can do their own reading/research.
/* This is an example sketch to run a motor. We can modify this to include blinking of many LEDs etc.*/ // Run motor by Madu – 27 Oct 2017 int motorPin = 9; // Motor is connected to pin 9 void setup() { pinMode (motorPin, OUTPUT); // Pin 9 is set for
digitalWrite (motorPin, HIGH); set PIN 9 as high } void loop() { }
27 October, 2017
31
Read the specifications carefully. Follow the Notes, Questions and Answers and the exercises
27 October, 2017
32
At the end of this Section you will be able to
▫ Program it to work as designed
▫ Get good confidence and self-esteem about facing interviews
▫ Winning is no objection☺. May all be winners.
27 October, 2017
33
Questions and Answers given in our website.
not be the main objective.
important.
prepared notes, and diagrams do not carry extra marks.
27 October, 2017
34
27 October, 2017
35