01 Arduino Program
01 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:
2
Getting started
Create a new directory named "arduino_program" in C:\Users\%USER%\Documents .
3
Connect an Arduino to your computer.
Open the Start menu, type "Device Manager", and press Enter . This will display
Windows' Device Manager.
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.
6
Something similar to the following will be displayed:
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:
10
Testing
Open the Serial Monitor: either:
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:
15