Download presentation
Presentation is loading. Please wait.
1
Roller Coaster Design Project
Lab 4 Prelab: Arduino Introduction
2
Learning Objectives Become familiar with:
The Arduino brand microcontroller programming the Arduino for basic functionality Arduino C-code uploading, testing and troubleshooting programs 2
3
Hardware The basic Arduino Uno board: Digital Ports Reset Switch
USB Port Arduino ATMega328 Power Socket Analog Ports
4
Arduino Software You will use the Arduino extensively as part of your add-on Development Tools are available for free at arduino.cc for Windows, Linux, and Mac Development is done in a variant of the C language. See the 'Crash Course in C' document for more information, if need be All programs stored in the “Sketchbook” folder in your documents directory (depends on platform) LOTS of existing libraries for various functions Not expected to be an expert. If you need help with a topic, ask!
5
Setting Up Your Device Open the Arduino IDE
Go to the Tools → Board menu Locate and select your device. Select the appropriate COM port Restart the Arduino IDE
6
Parts of an Arduino Program
Arduino programs always contain three things: The header space – libraries included here, constants declared, etc. The setup() function The loop() function Both setup() and loop() will be discussed next You can have more than this, if needed. In particular, user functions can be included after the loop() function
7
The setup() and loop() functions
Function runs once when the Arduino starts running Used for initialization of global variables, setup of various hardware, and so on After first run, never runs again loop() Runs continuously for as long as the Arduino has power When loop exits, it is automatically called again Used for main program functionality, monitoring sensors, control of other inputs and outputs.
8
Your First Program Enter the following into a new sketch: void setup()
{ Serial.begin(9600); delay(1); // stalls for 1s Serial.write(“Hello World!”); } void loop() {}
9
Programming the Device
Connect your Arduino to your computer via USB Make sure the correct device and port are selected Press the “Play” button Use the built-in serial monitor to watch your code run (Ctrl+Shift+M on Windows and Linux). Make sure the speed is set to 9600.
10
Questions?
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.