Arduino Vademecum
Arduino Vademecum
------------------------------------------------------------------
Arduino Vademecum
https://docs.arduino.cc/tutorials/uno-rev3/board-anatomy
While all Arduino boards differ from each other, there are several
key components that can be found on practically any Arduino. Let's
take a look at the image below:
https://docs.arduino.cc/retired/boards/arduino-uno-rev3-with-long-
pins
2)Language Reference
https://www.arduino.cc/reference/en/
Structure
Sketch
➔ setup()
◆ Description: The setup() function is called when a
sketch starts. Use it to initialize variables, pin
modes, start using libraries, etc. The setup() function
will only run once, after each powerup or reset of the
Arduino board.
➔ loop()
◆ Description: After creating a setup() function, which
initializes and sets the initial values, the loop()
function does precisely what its name suggests, and
loops consecutively, allowing your program to change and
respond. Use it to actively control the Arduino board.
Arithmetic Operators
➔ % (remainder)
➔ * (multiplication)
➔ + (addition)
➔ - (subtraction)
➔ / (division)
➔ = (assignment operator)
Comparison Operators
➔ != (not equal to)
➔ < (less than)
➔ <= (less than or equal to)
➔ == (equal to)
➔ > (greater than)
➔ >= (greater than or equal to)
Boolean Operators
➔ ! (logical not)
➔ && (logical and)
➔ || (logical or)
Variables
Constants
➔ HIGH | LOW
◆ When reading or writing to a digital pin there are only
two possible values a pin can take/be-set-to: HIGH and
LOW.
◆ HIGH digitalRead():
➔ INPUT | OUTPUT | INPUT_PULLUP
➔ LED_BUILTIN
➔ true | false
Conversion
➔ byte()
➔ char()
➔ float()
➔ int()
➔ long()
➔ word()
Functions
Digital I/O
➔ digitalRead()
◆ Description: Reads the value from a specified digital
pin, either HIGH or LOW.
◆ Syntax: digitalRead(pin)
◆ Parameters: pin - the Arduino pin number you want to
read
◆ Returns: HIGH or LOW
➔ digitalWrite()
◆ Description: Write a HIGH or a LOW value to a digital
pin.
◆ Syntax: digitalWrite(pin, value)
◆ Parameters: pin - the Arduino pin number; value - HIGH
or LOW
◆ Returns: Nothing
➔ pinMode()
◆ Description: Configures the specified pin to behave
either as an input or an output.
◆ Syntax: pinMode(pin, mode)
◆ Parameters: pin - the Arduino pin number to set the mode
of; mode: INPUT, OUTPUT, or INPUT_PULLUP.
◆ Returns: Nothing
Analog I/O
➔ analogRead()
◆ Description: Reads the value from the specified analog
pin. Arduino boards contain a multichannel, 10-bit
analog to digital converter. This means that it will map
input voltages between 0 and the operating voltage(5V or
3.3V) into integer values between 0 and 1023. On ATmega
based boards (UNO, Nano, Mini, Mega), it takes about 100
microseconds (0.0001 s) to read an analog input, so the
maximum reading rate is about 10,000 times a second.
◆ Syntax: analogRead(pin)
◆ Parameters: pin - the name of the analog input pin to
read from
◆ Returns: The analog reading on the pin. Although it is
limited to the resolution of the analog to digital
converter (0-1023 for 10 bits or 0-4095 for 12 bits)
◆ Data type: int
➔ analogWrite()
◆ Description: Writes an analog value (PWM wave) to a pin.
Can be used to light a LED at varying brightnesses or
drive a motor at various speeds. After a call to
analogWrite(), the pin will generate a steady
rectangular wave of the specified duty cycle until the
next call to analogWrite() (or a call to digitalRead()
or digitalWrite()) on the same pin.
◆ Syntax: analogWrite(pin, value)
◆ Parameters: pin - the Arduino pin to write to (allowed
data types: int); value - the duty cycle: between 0
(always off) and 255 (always on) (allowed data types:
int)
◆ Returns: Nothing
Time
➔ delay()
➔ delayMicroseconds()
➔ micros()
➔ millis()
Math
➔ abs()
➔ constrain()
➔ map()
➔ max()
➔ min()
➔ pow()
➔ sq()
➔ sqrt()
Random Numbers
➔ random()
➔ randomSeed()
3. The message area, gives feedback while saving and exporting and
also displays errors.
4. The text console displays text output by the Arduino Software
(IDE), including complete error messages and other information.
Selecting a board
Selecting the port
Choosing an example
Code_0:
/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
2. The Sidebar for regularly used tools. It gives you quick access
to board managers, libraries, debugging your board as well as a
search and replacement tool.
Selecting a board
Choosing an example
Once the upload is complete, you should see on your board the
yellow LED with the letter L next to it, start blinking. You can
adjust the speed of blinking by changing the delay number in the
parenthesis to 100, and upload the Blink sketch again. Now the LED
should blink much faster.
To install a new library into your Arduino IDE you can use
the Library Manager. Open the IDE and click to the "Sketch" menu
and then Include Library > Manage Libraries.
Then the Library Manager will open and you will find a list
of libraries that are already installed or ready for installation.
Scroll the list to find it, click on it, then select the version
of the library you want to install. Sometimes only one version of
the library is available. If the version selection menu does not
appear, don't worry: it is normal.