EasyManuals Logo

Arduino uno User Guide

Arduino uno
27 pages
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #27 background imageLoading...
Page #27 background image
27
Arduino Programming Basics
Command
Description
pinMode(n,INPUT)
Set pin n to act as an input. One-time command at top of program.
pinMode(n,OUTPUT)
Set pin n to act as an output
digitalWrite(n,HIGH)
Set pin n to 5V
digitalWrite(n,LOW)
Set pin n to 0V
delay(x)
Pause program for x millisec, x = 0 to 65,535
tone(n,f,d)
Play tone of frequency f Hz for d millisec on speaker attached to pin n
for()
Loop. Example: for (i=0;i<3;i++){} Do the instructions enclosed by {} three times
if (expr) {}
Conditional branch. If expr true, do instructions enclosed by {}
while (expr) {}
While expr is true, repeat instructions in {} indefinitely
For more commands see the ME2011 “Arduino Microcontroller Guide” and the Language Reference
section of the arduino web site.
Instructions in the setup() function are executed once. Those in the loop() function are executed
indefinitely.
Examples
1. Turn on LED connected to Pin 2 for 1 s.
void setup() {
pinMode(2,OUTPUT);
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
}
void loop()
{}
2. Flash LED connected to Pin 2 at 1 Hz forever.
void setup() {
pinMode(2,OUTPUT);
}
void loop() {
digitalWrite(2,HIGH);
delay(500);
digitalWrite(2,LOW);
delay(500);
}
3. Turn on motor connected to Pin 4 for 1 s.
void setup() {
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
delay(1000);
digitalWrite(4,LOW);
}
void loop()
{}
4. Play 440 hz tone for one second on speaker
connected to pin 5. Delay is needed because
the program does not wait for the tone()
command to finish but rather immediately goes
to the command following tone().
void setup() {
pinMode(5,OUTPUT);
tone(5,440,1000);
delay(1100);
}
void loop()
{}
5. LED is on Pin 2 and switch is on Pin 6. Turns
on the LED for one sec when switch is pressed.
void setup() {
pinMode(2,OUTPUT);
pinMode(6,INPUT);
while (digitalRead(6) == HIGH)
;
digitalWrite(2,HIGH);
delay(1000);
digitalWrite(2,LOW);
}
void loop()
{}

Other manuals for Arduino uno

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Arduino uno and is the answer not in the manual?

Arduino uno Specifications

General IconGeneral
Form factorArduino
CertificationRoHS, FC, CE
Processor model-
Processor frequency- MHz
Microcontroller modelATmega328
Microcontroller frequency16 MHz
DC input voltage7-12 V
Operating voltage5 V
DC current per I/O pin40 mA
Flash memory0.032 MB
Maximum internal memory- GB
SRAM (Static Random Access Memory)2 KB
EEPROM (Electrically Erasable Programmable Read-Only Memory)1 KB
Wi-FiNo
Number of analog I/O pins6
Number of digital I/O pins14
Weight and Dimensions IconWeight and Dimensions
Board dimensions53.4 x 68.6 mm

Related product manuals