Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Arduino Introduction 2022

This document provides an overview of the Arduino MEGA 2560 board and describes some common Arduino functions for input/output, analog input/output, timing, and serial communication. The Arduino MEGA 2560 has analog inputs, digital I/O pins, PWM outputs, a USB connection, and a reset button. Functions like digitalRead(), digitalWrite(), analogRead(), analogWrite(), Serial.print(), and delay() are explained.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Arduino Introduction 2022

This document provides an overview of the Arduino MEGA 2560 board and describes some common Arduino functions for input/output, analog input/output, timing, and serial communication. The Arduino MEGA 2560 has analog inputs, digital I/O pins, PWM outputs, a USB connection, and a reset button. Functions like digitalRead(), digitalWrite(), analogRead(), analogWrite(), Serial.print(), and delay() are explained.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Arduino Basics

ESIB – USJ

Rayan Mina

Arduino Introduction 1
Arduino MEGA 2560 Board
PWM Signal outputs
Plug your USB cable to
upload your Sketch to
the Arduino board

Digital Inputs / Outputs (I/O)


USB
Connector

MEGA
Processor

Reset Button
5V regulator

Power Pins Analog Inputs


To power your Arduino MEGA board:
1. Connect a battery of 7V – 12V to “Vin” pin
2. Connect your USB cable to power the board with 5V

4/1/2022 Rayan MINA Arduino Introduction 2


Arduino Reference Functions (1)
➢ digitalRead (pin)
❑ Reads the value from a specified digital pin, either HIGH or LOW
❑ pin: the number of the digital pin you want to read from
❑ Returns HIGH or LOW

➢ digitalWrite (pin, value)


❑ Write a HIGH or a LOW value to a digital pin
❑ pin: the number of the digital pin you want to write to
❑ value: the value, HIGH or LOW, you want to write on that pin
❑ Returns Nothing
❑ The pin must be configured as an OUTPUT using pinMode(), before applying the digitalWrite() function

➢ pinMode (pin, mode)


❑ Configures the specified digital pin to behave as an input or output
❑ pin: the number of the digital pin you want to set its mode
❑ mode: the mode, INPUT or OUTPUT, you want to set on that pin
❑ Returns Nothing

4/1/2022 Rayan MINA Arduino Introduction 3


Arduino Reference Functions (2)
➢ analogRead (pin)
❑ Reads the value from the specified analog pin with a 10-bit ADC. Input voltage between 0 and 5V is
mapped into integer values between 0 and 1023 (~5 mV step), with a maximum sampling rate of 10kHz
❑ pin: the number of the analog pin you want to read from
❑ Returns an integer value between 0 and 1023

➢ analogWrite (pin, value)


❑ Generates a PWM wave on a PWM pin → a square wave with a specified duty cycle. The frequency of
the PWM signal is 488Hz on pins from 2 to 13, except on pins 4 & 13 it is 976Hz.
❑ This function works on pins 3, 5, 6, 9, 10, 11 on UNO boards and on pins 2 - 13 and 44 – 46 on MEGA
❑ pin: the number of the PWM pin you want to write to
❑ value: the value is integer and corresponds to the duty cycle: 0 (always off) – 255 (always on)
❑ Returns Nothing
❑ The analogWrite() function has nothing to do with the analog pins or the analogRead() function
❑ You do not need to call pinMode() to set the pin as an output before calling analogWrite()

4/1/2022 Rayan MINA Arduino Introduction 4


Arduino Reference Functions (3)
➢ delay (value)
❑ Pauses the program for the amount of time (in milliseconds) specified as parameter
❑ value: the number of ms to pause, unsigned long
❑ Returns Nothing

➢ delayMicroseconds (value)
❑ Pauses the program for the amount of time (in microseconds) specified as parameter, maximum 16383
❑ value: the number of 𝜇𝑠 to pause, unsigned int
❑ Returns Nothing

➢ micros ()
❑ Calculates and returns the duration in 𝜇𝑠 since the Arduino began running the current program. This
number goes back to 0, after 70 minutes. On 16 MHz boards (Mega), the function’s resolution of 4𝜇𝑠

➢ millis ()
❑ Calculates and returns the duration in 𝑚𝑠 since the Arduino began running the current program. This
number will go back to zero, after 50 days, unsigned long

4/1/2022 Rayan MINA Arduino Introduction 5


Arduino Reference Functions (4)
➢ Serial Port communication on Arduino boards

❑ Used for communication between the Arduino board and a computer or other devices

❑ All Arduino boards have at least one serial port called Serial
✓ It can communicate on digital pins 0 (RX) and 1 (TX)
✓ Or with the computer via USB

❑ To use the Arduino IDE built-in serial monitor → Click the serial monitor button in the tools menu

➢ Serial.begin (value)

❑ Sets the data rate in bps for serial data transmission. For communicating with the computer, use one of
these rates: 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200

➢ Serial.end ()

❑ Disables serial communication

4/1/2022 Rayan MINA Arduino Introduction 6


Arduino Reference Functions (5)
➢ Serial.print (value, format)
❑ Prints data to the serial port as ASCII text:
✓ Serial.print(78) gives 78 as text !
✓ Serial.print(1.23456) gives 1.23
✓ Serial.print('N') gives N
✓ `Serial.print("Hello world.") gives Hello world

❑ An optional 2nd parameter specifies the format to use: BIN (binary), DEC (decimal), HEX (hexadecimal)
✓ Serial.print(78, BIN) gives 1001110
✓ Serial.print(78, DEC) gives 78
✓ Serial.print(78, HEX) gives 4E

❑ For floating point numbers, this parameter specifies the number of decimal places to use
✓ Serial.println(1.23456, 0) gives 1
✓ Serial.println(1.23456, 4) gives 1.2346

❑ Serial.println → same as Serial.print with additional carriage return (return to line)

4/1/2022 Rayan MINA Arduino Introduction 7


Additional Help
➢ https://www.arduino.cc/reference/en/

4/1/2022 Rayan MINA Familles Logiques 8

You might also like