Вы находитесь на странице: 1из 4

Digital Systems

Foundations for Embedded Design

Laboratory 1:

Arduino intro and simple LED control


Objectives:
To get familiar with Arduino IDE, try out LED control by
writing simple C program.

Equipment Required
Arduino board
Wires
330 ohm resistors (5)

Bread board
LEDs (5)

Digital Systems
Lab 1: Getting started with Arduino IDE

Prelab: - Download and install Arduino IDE from Arduino.cc website on your home PC.
Go to website Arduino.cc, in download page, download and install the latest Arduino software. It
includes the IDE and also device drivers.

Inlab:
Step 1:
The lab PC already has the Arduino software installed. Find and launch the Arduino IDE software.
Step 2:
Now plug the Arduino Mega PCB board using a USB cable to an USB port on USB hub, dont connect
directly to PC! You should see a yellow LED is lit on the Mega board.
Open Device Manager of your computer, expand Ports, you should see Arduino Mega (COM3) or
on other COM port, record the COM port of Arduino Mega on your PC.
Mega COM port: _____________________

Step 3:
In Arduino IDE, click on Tools --- > Boards , select Arduino Mega 2560.
Click on Tools --- > Port, select the COM port from last step.

Step 4:
Connect a LED with 330 ohm resistor in seriel, and drive the LED with arduino Megas pin 9. Pay
attendtion to the polarity of LED, and connect the cathode of LED to GND. You can also connect the Vcc
and GND from Arduino board to the breadboard power lines (the red and blue bars on breadboard).

Step 5:
Type the following code to Arduino IDE and save the sketch folder as: Lab1A. It will automatically create
a file called Lab1A.ino inside the folder.
//A blinking led
//turn on the LED for half a second,then off for half a second,reaptedly
/************************************************/
const int ledPin = 9;//the number of the LED pin
/************************************************/
void setup()
{
pinMode(ledPin,OUTPUT);//initialize the digital pin as an output

}
/************************************************/
//the loop routine runs over and over again forever
void loop()
{
digitalWrite(ledPin,HIGH);//turn the LED on
delay(500);
//wait for half a second
digitalWrite(ledPin,LOW); //turn the LED off
delay(500);
//wait for half a second
}
/*************************************************/
Verify and then upload the code into Arduino board. If there are any errors after verifying, you need
to correct them before you can upload the code.
When you see the LED blinking, ask instructor to sign on your lab sheet:

Instructors Signature

Date

Step 6:
Connect 4 more LEDs following the similar way as in step 4 (still keep the previous LED connections),
put all LEDs in parallel on breadboard, and connect their anode to Arduino digital pin 3, 4, 5, 6, and 7
respectively (Now you have 5 LEDs total).
Modify the Lab1A code, to turn on the LED one by one from left to right in a 1 second interval. Save your
code as sketch Lab1B.
Bonus: Further modify the code of Lab1B, to flash the LEDs from left to right, then from right to left, and
running continuously. Save your code as Lab1C.
You can play with the timing to see the effect, and show your work to the instructor.
Congratulations! You have completed your first Arduino project!

_________________________________________________________
Instructors Signature
Date

******* The End********

Вам также может понравиться