Download presentation
Presentation is loading. Please wait.
1
Getting Started: Building & Programming
Arduino Circuits Getting Started: Building & Programming
2
What we’ll cover What is Arduino Why we want to use it
Arduino Board Anatomy What is an Arduino Sketch? How to Use Arduino IDE software Arduino Foundations - more learning resources
3
What is Arduino Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the microcontroller on the board. To do so you use the Arduino programming language (based on Wiring), and the Arduino Software (IDE), based on Processing. Arduino Introduction:
4
Why we want to Arduino The Arduino software is easy-to-use for beginners, yet flexible enough for advanced users. It runs on Mac, Windows, and Linux. Teachers and students use it to build low cost scientific instruments, to prove chemistry and physics principles, or to get started with programming and robotics. Designers and architects build interactive prototypes. Musicians and artists use it for installations and to experiment with new musical instruments Makers, of course, use it to build many of the projects exhibited at the Maker Faire. Arduino is a key tool to learn new things.
5
Arduino Board Anatomy Arduino/Genuino boards senses the environment by receiving inputs from many sensors, and affects their surroundings by controlling lights, motors, and other actuators. Arduino/Genuino boards are the microcontroller development platform that will be at the heart of your projects. When making something you will be building the circuits and interfaces for interaction, and telling the microcontroller how to interface with other components. Here the anatomy of Arduino/Genuino Uno. 1. Digital pins Use these pins with digitalRead(), digitalWrite(), and analogWrite(). analogWrite() works only on the pins with the PWM symbol. 2. Pin 13 LED The only actuator built-in to your board. Besides being a handy target for your first blink sketch, this LED is very useful for debugging. 3. Power LED Indicates that your Genuino is receiving power. Useful for debugging. 4. ATmega microcontroller The heart of your board. 5. Analog in Use these pins with analogRead(). 6. GND and 5V pins Use these pins to provide +5V power and ground to your circuits. 7. Power connector This is how you power your Genuino when it’s not plugged into a USB port for power. Can accept voltages between 7-12V. 8. TX and RX LEDs These LEDs indicate communication between your Genuino and your computer. Expect them to flicker rapidly during sketch upload as well as during serial communication. Useful for debugging. 9. USB port Used for powering your Genuino Uno, uploading your sketches to your Genuino, and for communicating with your Genuino sketch (via Serial. println() etc.). 10. Reset button Resets the ATmega microcontroller.
6
What is an Arduino Sketch?
A sketch is the name that Arduino uses for a program. It's the unit of code that is uploaded to and run on an Arduino board.
7
Parts of a Sketch: Comments
Comments are King - without them others can’t help you debug your code. You won’t even know what’s going on with your code. They keep you organized. Everything between the /* and */ is ignored by the Arduino when it runs the sketch (the * at the start of each line is only there to make the comment look pretty, and isn't required). It's there for people reading the code: to explain what the program does, how it works, or why it's written the way it is. It's a good practice to comment your sketches, and to keep the comments up-to- date when you modify the code. This helps other people to learn from or modify your code. There's another style for short, single-line comments. These start with // and continue to the end of the line. For example, the message "LED connected to digital pin 13" is a comment.
8
Parts of a Sketch: Variables
A variable is a place for storing a piece of data. It has a name, a type, and a value. The advantage of using a variable is that it's easier to modify the code: you only need to edit the one line that assigns the initial value to the variable. Often, however, the value of a variable will change while the sketch runs. For example, you could store the value read from an input into a variable. Further information on variables can be found here: “Global” variables are variables that are declared before the function setup(). For example, the line from the Blink sketch on the previous slide (int ledPin = 13;) declares a variable with the name ledPin, the type int, and an initial value of 13. It's being used to indicate which Arduino pin the LED is connected to. Every time the name ledPin appears in the code, its value will be retrieved. In this case, the person writing the program could have chosen not to bother creating the ledPin variable and instead have simply written 13 everywhere they needed to specify a pin number.
9
Parts of a Sketch: Functions
A function (otherwise known as a procedure or sub-routine) is a named piece of code that can be used from elsewhere in a sketch. For example, here's the definition of the setup() function from the Blink example. The first line provides information about the function, like its name, "setup". The text before and after the name specify its return type and parameters: these will be explained later. The code between the { and } is called the body of the function: what the function does. You can call a function that's already been defined (either in your sketch or as part of the Arduino language). For example, the line pinMode(ledPin, OUTPUT); calls the pinMode() function, passing it two parameters: ledPinand OUTPUT. These parameters are used by the pinMode() function to decide which pin and mode to set. The pinMode() function configures a pin as either an input or an output. To use it, you pass it the number of the pin to configure and the constant INPUT or OUTPUT. When configured as an input, a pin can detect the state of a sensor like a pushbutton; this is discussed in a later tutorial. As an output, it can drive an actuator like an LED. The digitalWrite() functions outputs a value on a pin. For example, the line digitalWrite(ledPin, HIGH); set the ledPin (pin 13) to HIGH, or 5 volts. Writing a LOW to pin connects it to ground, or 0 volts. The delay() causes the Arduino to wait for the specified number of milliseconds before continuing on to the next line. There are 1000 milliseconds in a second, so the line, delay(1000); creates a delay of one second.
10
Parts of a Sketch: Functions (cont)
There are two special functions that are a part of every Arduino sketch: setup() and loop(). The setup() is called once, when the sketch starts. It's a good place to do setup tasks like setting pin modes or initializing libraries. The loop() function is called over and over and is heart of most sketches. You need to include both functions in your sketch, even if you don't need them for anything.
11
Using Arduino IDE The Arduino Integrated Development Environment - aka Arduino Software (IDE) contains: a text editor for writing code a message area a text console a toolbar with buttons for common functions a series of menus It connects to the Arduino and Genuino hardware to upload programs and communicate with them.
12
Using Arduino IDE: Writing Sketches
Programs written using Arduino Software (IDE) are called sketches. These sketches are written in the text editor and are saved with the file extension .ino. The editor has features for cutting/pasting and for searching/replacing text. The message area gives feedback while saving and exporting and also displays errors. The console displays text output by the Arduino Software (IDE), including complete error messages and other information. The bottom righthand corner of the window displays the configured board and serial port. The toolbar buttons allow you to verify and upload programs, create, open, and save sketches, and open the serial monitor.
13
Using Arduino IDE: Sketchbook
The Arduino Software (IDE) uses the concept of a sketchbook: a standard place to store your programs (or sketches). T he sketches in your sketchbook can be opened from the File > Sketchbook menu or from the Open button on the toolbar. The first time you run the Arduino software, it will automatically create a directory for your sketchbook. You can view or change the location of the sketchbook location from with the Preferences dialog. Basically, this is where you’ll save your file on your computer….being organized is crucial to being an all-star coder!
14
Using Arduino IDE: Uploading
When you upload a sketch, you're using the Arduino bootloader, a small program that has been loaded onto the microcontroller on your board. It allows you to upload code without using any additional hardware. The bootloader is active for a few seconds when the board resets; then it starts whichever sketch was most recently uploaded to the microcontroller. The bootloader will blink the on-board (pin 13) LED when it starts (i.e. when the board resets). Before uploading your sketch, you need to select the correct items from the Tools > Board and Tools > Port menus. Once you've selected the correct serial port and board, press the upload button in the toolbar or select the Upload item from the Sketch menu. Even more information about using the IDE software can be found here:
15
Arduino Foundations: Learning Resources
Getting Started with Arduino Foundations: All you need & more Arduino Language Reference Arduino Playground Arduino Create: Connect, Collaborate, Create Helpful links to learn more, get inspired or unstuck, do more with Arduino. Instructors may want to share this with students to learn on their own.
16
Let’s Review What is Arduino?
Give one example of why someone would use arduino Briefly, how does the arduino board work? What is a sketch? Why should you use comments? Why might it be helpful to use “global” variables? What are the two functions all Arduino programs must have? Where are your arduino programs saved? What must you do before uploading your sketch to arduino? Answers A micro controller, an open source electronics platform Musician making interactive instruments You write a program/sketch, upload that code to the arduino, Arduino senses the environment by receiving inputs from many sensors, and affects their surroundings by controlling lights, motors, and other actuators. Another name of an arduino program, the code you write Comments help keep you organized. Comments are king Easier to modify code, ex. Blink : edit one line instead of multiple lines setup() & loop() In a sketchbook (aka folder on your computer) Select your board & port
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.