Sign In
Upload
Download
Table of Contents
Contents
Add to my manuals
Delete from my manuals
Share
URL of this page:
HTML Link:
Bookmark this page
Add
Manual will be automatically added to "My Manuals"
Print this page
×
Bookmark added
×
Added to my manuals
Manuals
Brands
Arduino Manuals
Computer Hardware
uno
User manual
Arduino uno User Manual page 22
Hide thumbs
Also See for uno
:
Quick start manual
(311 pages)
,
Manual
(11 pages)
,
Application note
(6 pages)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Table Of Contents
28
page
of
28
Go
/
28
Contents
Table of Contents
Troubleshooting
Bookmarks
Table of Contents
Advertisement
{
Serial.begin(9600);
}
void loop()
{
if (digitalRead(3) == LOW) {
Serial.println("Somebody closed the switch!");
}
}
The if line reads the state of pin 3. If it is high, which it will be for this circuit when the switch is
open, the code jumps over the Serial.println command and will repeat the loop. When you close
the switch, 0V is applied to pin 3 and its state is now LOW. This means the if condition is true so
this time around the code between the braces is executed and the message is printed
The syntax for the if statement is
if (condition) {
//commands
}
If the condition is true, the program will execute the commands between the braces. If the
condition is not true, the program will skip to the statement following the braces.
The condition compares one thing to another. In the example above, the state of pin 1 was
compared to LOW with ==, the equality condition. Other conditional operators are != (not equal
to), > (greater than), < (less than), >= (greater than or equal to), and <= (less than or equal to).
You can have the program branch depending on the value of a variable. For example, this
program will print the value of i only when it is less than 30.
int i;
void setup()
{
Serial.begin(9600);
i=0;
}
void loop()
{
i=i+1;
if (i<30) {
Serial.println(i);
}
}
for
22
Table of
Contents
Previous
Page
Next
Page
1
...
19
20
21
22
23
24
25
26
Show Quick Links
Quick Links:
What You Need for a Working...
Arduino Hardware
Arduino Programming Language
Arduino Programming Basics
Hide quick links:
Permanently
Temporary
Cancel
Advertisement
Table of Contents
Need help?
Do you have a question about the uno and is the answer not in the manual?
Ask a question
Questions and answers
Related Manuals for Arduino uno
Motherboard Arduino Arduino Uno Quick Start Manual
(311 pages)
Computer Hardware Arduino Uno Manual
Motor driver shield (11 pages)
Motherboard Arduino UNO Manual
(9 pages)
Microcontrollers Arduino UNO Application Note
Arduino uart interface to telaire t6613 co2 sensor (6 pages)
Arduino UNO R3 A000066 - Computer Hardware Manual
(article)
Computer Hardware Arduino UNO R4 WiFi Product Reference Manual
(23 pages)
Computer Hardware Arduino XY-J02 User Manual
1 way digital display timer relay module (3 pages)
Computer Hardware Arduino Portenta C33 Product Reference Manual
(15 pages)
Computer Hardware Arduino ASX00049 Product Reference Manual
Portenta hat carrier (34 pages)
Arduino Nano RP2040 Connect Manual
(article)
Arduino Due Manual
(article)
Computer Hardware Arduino MKR Vidor 4000 Product Reference Manual
(15 pages)
Computer Hardware Arduino MKR IoT Carrier Rev2 Product Reference Manual
(18 pages)
Computer Hardware Arduino Due Product Reference Manual
(27 pages)
Computer Hardware Arduino PRO Portenta X8 Product Reference Manual
(20 pages)
Computer Hardware Arduino Mega ADK User Manual
(5 pages)
Related Products for Arduino uno
Arduino UNO R4 WiFi
Arduino UNO R3
Arduino UNO R4 Minima
Arduino A000062
Arduino ABX00022
Arduino ABX00050
Arduino ABX00061
Arduino ABX00073
Arduino ABX00074
Arduino ABX00087
Arduino AKX00034
Arduino ASX00026
Arduino ASX00049
Arduino ASX00055
Arduino Due
Arduino Edge Control
Table of Contents
Save PDF
Print
Rename the bookmark
Delete bookmark?
Delete from my manuals?
Login
Sign In
OR
Sign in with Facebook
Sign in with Google
Upload manual
Upload from disk
Upload from URL
Need help?
Do you have a question about the uno and is the answer not in the manual?
Questions and answers