0% found this document useful (0 votes)
3 views

Arduino

The document is a comprehensive guide on advanced Arduino programming and hardware, covering topics such as Arduino and ESP32 boards, key components, programming languages, and common functions. It includes practical examples of using sensors, motors, and interrupts, as well as various project ideas for implementing these concepts. The guide is designed for individuals interested in embedded systems and robotics, providing both theoretical knowledge and hands-on applications.

Uploaded by

Jana Droubi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Arduino

The document is a comprehensive guide on advanced Arduino programming and hardware, covering topics such as Arduino and ESP32 boards, key components, programming languages, and common functions. It includes practical examples of using sensors, motors, and interrupts, as well as various project ideas for implementing these concepts. The guide is designed for individuals interested in embedded systems and robotics, providing both theoretical knowledge and hands-on applications.

Uploaded by

Jana Droubi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 61

Advanced

Arduino
Course

Prepared by: Qossay Abu Rida


IEEE Robotics and Automation Society
Introduction
Embedded systems (Symbolic-Based)
Arduino Hardware
Arduino Boards
• Microcontroller-based boards with various input/output capabilities.
• Examples: Arduino Uno, Arduino Mega, Arduino Nano.

Key Components
• Microcontroller: The brain of the board (e.g., ATmega328 on Arduino Uno).
• Digital Pins: Used for digital input/output (e.g., LEDs, buttons).
• Analog Pins: Used for analog input (e.g., sensors).
• Power Supply: Can be powered via USB or external power source.
• Communication Ports: Serial, I2C, SPI for interfacing with other devices.
ESP32 Hardware
ESP32 Overview
• A low-power Wi-Fi and Bluetooth microcontroller with various input/output capabilities.
• Developed by Espressif Systems, commonly used in IoT applications.

Key Components
• Microcontroller: Dual-core Tensilica Xtensa LX6 processor with up to 240 MHz clock speed.
• Digital Pins: Supports multiple GPIO pins for digital input/output operations.
• Analog Pins: Features ADC (Analog-to-Digital Converter) and DAC (Digital-to-Analog Converter).
• Power Supply: Operates at 3.3V, powered via USB or external Li-ion battery.
• Wireless Connectivity: Built-in Wi-Fi (802.11 b/g/n) and Bluetooth (Classic & BLE) for wireless
communication.
• Communication Ports: Supports UART, I2C, SPI, PWM, and CAN protocols for external device
interfacing.
Arduino Uno board
ESP-32 board
Arduino Software (use for Arduino UNO & ESP32)
Arduino IDE
• Integrated Development Environment for writing, compiling, and uploading code to Arduino
boards.
• Available for Windows, Mac, and Linux.

Key Features
• Code Editor: Write and edit Arduino sketches (programs).
• Compiler: Convert sketches into machine code that the microcontroller can execute.
• Uploader: Transfer the compiled code to the Arduino board via USB.
• Serial Monitor: Communicate with the board and debug sketches using serial communication.

Programming Language
• Based on C/C++ with simplified syntax and functions.
• Uses libraries to add functionality (e.g., controlling motors, reading sensors).
How to Program Arduino & ESP 32

Setup Function:
• Purpose: Initializes settings.
• Runs Once: This code runs once when
the Arduino is powered on or reset.

Loop Function:
• Purpose: Contains the main logic of the
program.
• Runs Repeatedly: This code runs in a
loop after the setup function has
completed.
Arduino IDE simple sketch.
Common Functions Used
in Arduino Programming
pinMode():
• Purpose: Configures a specified pin to
behave either as an input or an output.

digitalWrite():
• Purpose: Sets a specified digital pin to
HIGH or LOW.

digitalRead():
• Purpose: Reads the value from a
specified digital pin, either HIGH or
LOW.
Example:
Common Functions Used
in Arduino Programming
analogRead():
• Purpose: Reads the value from a
specified analog pin.

analogWrite():
• Purpose: Writes an analog value
(PWM wave) to a specified pin.
Example:
Common Functions Used
in Arduino Programming
delay():
• Purpose: Pauses the program
for a specified number of
milliseconds.

millis():
• Purpose: Returns the number of
milliseconds since the Arduino
board began running the current
program.
Common Functions Used
in Arduino Programming
Serial.begin():
• Purpose: Sets the data rate in bits per
second (baud) for serial data
transmission.

Serial.print():
• Purpose: Prints data to the serial port
as human-readable ASCII text.

Serial.println():
• Purpose: Prints data to the serial port
as human-readable ASCII text,
followed by a carriage return character.
Interrupts
Definition
• Interrupts are signals that temporarily halt
the main program execution to
immediately run a special function called
an Interrupt Service Routine (ISR).

Purpose
• To handle time-critical tasks, respond to
external events, or process real-time
signals without delay.

Benefits
• Allows for efficient handling of tasks
without continuously checking for events
within the main loop.
Using Interrupts in Arduino
Attaching an Interrupt:
• Use the attachInterrupt() function to specify which pin and condition will
trigger the interrupt, and which ISR to call.

• Parameters:
• pin: The pin number where the interrupt is attached.
• ISR: The name of the function to call when the interrupt occurs.
• mode: The condition that triggers the interrupt (LOW, CHANGE,
RISING, FALLING).
Example:
Sensors
Ultrasonic Sensor

Introduction:
• Definition: Ultrasonic sensors use sound
waves to measure the distance between the
sensor and an object.
• Common Model: HC-SR04.
Working Principle:
• Sound Waves: Sends out an ultrasonic
wave and measures the time it takes for the
echo to return.
• Distance Calculation: Uses the speed of
sound to calculate distance based on the
time it took for the echo to return.
Pin Configuration

VCC: +5V Power Supply


GND: Ground
Trig: Trigger Pin
Echo: Echo Pin
Example:
IR Sensor

Introduction:
• Definition: Infrared (IR) sensors use infrared
light to detect objects or measure the distance
between the sensor and an object.
• Common Model: TCRT5000.

Working Principle:
• Infrared Light: Emits an infrared light beam
and detects the reflection from an object.
• Distance Calculation: Measures the intensity
of the reflected light to determine the
presence or distance of an object.
Pin Configuration

VCC: +5V Power Supply


GND: Ground
OUT: Output pin
Other models for the IR sensor
Example:
LIDAR Sensor
Introduction:
• Definition: The VL6180X is a laser range finder (micro
LIDAR) that uses time-of-flight (ToF) technology to
measure the distance between the sensor and an object
with high precision.
• Common Model: VL6180X.
Working Principle:
• Laser Emission: Emits a laser pulse toward the target
object.
• Time-of-Flight Measurement: Measures the time it takes
for the laser pulse to reflect off the object and return to the
sensor.
• Distance Calculation: Uses the speed of light to calculate
the distance based on the time-of-flight of the laser pulse.
Pin Configuration

VCC: +5V Power Supply


GND: Ground
I2C PIN: Communication with the sensor
Example:
Motor
Wheels
Motor with Encoder:
Has a sensor to provide position, speed, and direction feedback for precise control.

Motor without Encoder:


Lacks feedback, offering simpler, cost-effective control but less accuracy.
How encoder works:
Optical encoder. It uses an LED and a rotating disk. and light-
receiving elements generate electrical signals. These signals
represent the position, speed, and direction of the motor.
H-Bridge (Motor Driver L298N)

L298N H-Bridge is a motor driver module that allows control of two DC motors. It supports
forward/reverse rotation, speed control via PWM.
How to connect:

Method 1:

Direction Control:
Two input pins (IN1, IN2) for each motor determine the motor's direction.
IN1= High , IN2 = Low → Motor rotates forward.
IN1= Low , IN2 = High → Motor rotates backward.
Speed Control:
Speed is adjusted using Pulse Width Modulation (PWM) applied to the Enable pin (EN).
Higher duty cycle → Faster speed.
Lower duty cycle → Slower speed

Method 2:

Direction and Speed Control:


Connect EN to 5 volt use jumper then
IN1 = PWM, IN2 = LOW → Forward speed controlled by IN1's PWM.
IN1 = LOW, IN2 = PWM → Reverse speed controlled by IN2's PWM.
How H-Bridge works:
How H-Bridge works:
Examples
Example 1 => Blinking LED
Blinking LED using Delay function:
Example 2 => Blinking LED
Blinking LED using millis function:
Example 3 => Toggle LED
Toggle LED without interrupts:
Example 4 => Toggle LED
Toggle LED with interrupts:
Example 5 => Toggle LED
Toggle LED with interrupts and avoid bouncing effect:
Example 6 => Controlling LED

Creating an interactive system using an Arduino that involves the following


components:
• Potentiometer
• Button
• LED
Requirements:
• The potentiometer should control the brightness of the LED.
• Button should toggle the LED on and off.
• Use interrupts to handle the button presses efficiently.
Example 6 => Controlling LED
Example 6 => Controlling LED
Example 7 => Controlling Array of LEDs
Unsolved example

You need to create an Arduino system that controls four LEDs based on the value of a
potentiometer.
Requirements:Use a potentiometer to determine how many LEDs should be turned on.
The system should work as follows:
• If the potentiometer value is between 0 and 255, turn on 1 LED.
• If the potentiometer value is between 256 and 511, turn on 2 LEDs.
• If the potentiometer value is between 512 and 767, turn on 3 LEDs.
• If the potentiometer value is between 768 and 1023, turn on all 4 LEDs.
Example 8 => LED Reaction Game
Unsolved example

Design an Arduino-based reaction game that uses LEDs, a potentiometer, and a button.
The goal of the game is to test the player's reaction time.
Requirements:
• Use a potentiometer to set the difficulty level of the game.
• An LED should light up randomly after a delay.
• The player must press a button as quickly as possible when the LED lights up.
• The system should display the player's reaction time using LEDs.
• The game should reset automatically after displaying the reaction time.
Example 9 => Print Your Name
Example 9 => Print Your Name
Example 10 => Distance Measurement
Example 10 => Distance Measurement

The speed of sound in air is


approximately 343 meters per
second or 0.0343 centimeters
per microsecond.
Example 11 => Motion detection
Example 11 => Motion detection
Example 12 => Servo Motors
Example 12 => Servo Motors
Example 13 => DC Motors
Example 13 => DC Motors
Example 14 => H-Bridge
Example 14 => H-Bridge
Contact us

You might also like