0% found this document useful (0 votes)
5 views

01 Arduino Program

Uploaded by

穆林
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

01 Arduino Program

Uploaded by

穆林
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Reference Arduino Program

Dr Frazer K. Noble
Department of Mechanical and Electrical Engineering
Massey University
E: [email protected]
O: AV 1.18, Albany Village

1
Introduction
In this presentation, I will present:

A reference Arduino program we will use for later lectures.

2
Getting started
Create a new directory named "arduino_program" in C:\Users\%USER%\Documents .

Note: Replace %USER% with your username.

3
Connect an Arduino to your computer.

Open the Start menu, type "Device Manager", and press Enter . This will display
Windows' Device Manager.

Expand the "Ports" menu to view the Arduino's COM port.

4
Something similar to the following will be displayed:

Figure: Windows' Device Manager. Here, we can see that an Arduino Uno is connected
to the computer. It has enumerated as COM3 .

5
Open the Arduino IDE.

Open the Start menu, type "Arduino", and press Enter . This will display the Arduino
IDE.

Create a new sketch: Select "File > New" or press Ctrl + N .

6
Something similar to the following will be displayed:

Figure: Arduino IDE.


7
Type the following C++ program into the file:

void setup()
{
Serial.begin(9600);

pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}

8
void loop()
{
if (Serial.available() >= 2)
{
char buffer[3] {};
Serial.readBytes(buffer, 3);
int pin {atoi(buffer)};

switch(pin)
{
case 13:
{
digitalWrite(13, !digitalRead(led));
Serial.println(digitalRead(led));
break;
}
}
}
}

9
Save the sketch in C:\Users\%USER%\Documents\arduino_program : either:

1. Select File > Save ; or,


2. Press Ctrl + S , and navigate to C:\Users\%USER%\Documents\arduino_program .

Upload the sketch to the Arduino: either:

1. Select Sketch > Upload ; or,


2. Press the → button.

Afterwards, something similar to the following will be displayed in the terminal:

10
Testing
Open the Serial Monitor: either:

1. Select Tools > Serial Monitor ; or


2. Press Ctrl + Shift + M ; or
3. Press the Serial Monitor button.

11
Something similar to the following will be displayed:

Figure: (Left) Serial Monitor; and (Right) the Arduino plugged into the computer. Here,
we can see that the LED connected to Pin 13 is ON.

12
Ensure that the default port settings (9600, 8, N, 1, False, COM3) are selected.

Type 13 into the Serial Monitor's input and then click the "Send" button.

13
Something similar to the following will be displayed:

Figure: (Left) Serial Monitor; and (Right) the Arduino plugged into the computer. Here,
we can see that the LED connected to Pin 13 is OFF.

The LED has been turned off via a COM port using the Serial Monitor!

14
Conclusion
In this presentation, I have presented:

A reference Arduino program we will use for later lectures.

15

You might also like