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

Arduino_Introduction_YA_Spring 25

The document provides an introduction to Arduino, covering its hardware, software, and the Arduino IDE. It includes objectives such as turning an LED ON/OFF, working with variables, and controlling LED brightness. Additionally, it explains the structure of Arduino programs and various functions like pinMode(), digitalWrite(), and analogRead().

Uploaded by

Yasmeen Al-Saleh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Arduino_Introduction_YA_Spring 25

The document provides an introduction to Arduino, covering its hardware, software, and the Arduino IDE. It includes objectives such as turning an LED ON/OFF, working with variables, and controlling LED brightness. Additionally, it explains the structure of Arduino programs and various functions like pinMode(), digitalWrite(), and analogRead().

Uploaded by

Yasmeen Al-Saleh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Introduction of Arduino

ENG 102 Lab


Instructor: Yasmeen AlSaleh
Objectives
• What is Arduino?
• Arduino Hardware
• Arduino software
• Familiarizing Yourself With The Arduino IDE
• Variables (setup, loop)
• Control Structures
• Arduino Libraries
• Turn an LED ON/OFF
• Work with variables in Arduino Code
• Control the number of times the LED is turned ON/OFF
• Adding Text Output
Part 1: What is Arduino?

Inputs Outputs

PIR SensorUltrasonic SensorGas Sensor Servo Motor LCD

LEDs

Potentiometer TemperaturePushbutton
Photoresistor 7
Buzzer
Sensor Segmen
Part 1: What is Arduino?

Inputs Microcontroller Outputs


Part 2: Arduino Hardware

Classic Family Nano Family MKR Family


Part 2: Arduino Hardware
Classic Family: UNO Rev 3

Reset button:
Resets the ATmega microcontroller.

Microcontroller:
ATmega328P

https://store-usa.arduino.cc/products/arduino-uno-rev3?sele
Part 2: Arduino Hardware
USB port:
Used for powering your Arduino
Classic Family: UNO Rev 3 UNO, uploading your sketches to
your Arduino, and for
communicating with your
Arduino sketch (via Serial.
println() etc.).
Power connector:
This is how you power your
Arduino when it's not plugged
into a USB port for power. Can
accept voltages between 7-12V.

Power LED:
Indicates that your Arduino is
receiving power. Useful for
debugging.
Part 2: Arduino Hardware
General Purpose Input/Output Pins
Classic Family: UNO Rev 3 GPIO
Operate at 5V, and can provide/receive
20mA
20 pins

14 Digital Pins: 6 Analog Pins:


- ON/OFF (Push - Operate within range of
button) values (Temp sensor)
- Input/Output - Inputs labeled as A0 up
>> pinMode() to A5
>> digitalWrite() - 10 bits of resolution
>> digitalRead() >> analogRead()
>> analogReference()
Part 2: Arduino Hardware
Classic Family: UNO Rev 3 Pin 13 LED
The only actuator built-in to your
board. Besides being a handy
target for your first blink sketch,
this LED is very useful for
debugging.

Digital Input/Output Pins:


13 pins
6 of them can be used as PWM outputs
(~)

Note:
Use these pins with digitalRead(),
digitalWrite(), and analogWrite().
- analogWrite() works only on the pins with
the PWM symbol.
Part 2: Arduino Hardware
Classic Family: UNO Rev 3

Power:
GND, 3.3 V, and 5V pins Use
these pins to provide +3.3 V,
+5V power, and ground to your
circuits.

Analog In:
6 input pins:
Note: Use these pins with analogRead().
Part 3: Arduino software

Arduino IDE 1.8.19Write your code Upload your code


Part 4: Familiarizing Yourself With The
Arduino IDE
Part 4: Familiarizing Yourself With The
Arduino IDE
1.Open the IDE: Double-click the shortcut 6.Verify a sketch: Let’s check your
on your desktop or in your app folder. sketch for any errors by hitting the
2.Find your sketch and library checkmark at the top left of your sketch.
locations: Open up your documents folder You’ll see the status of your sketch
and look for a sub-folder called Arduino. This outlined in the black notification box at
is where your sketches and libraries will be the bottom of your screen.
stored (more on libraries later). 7.Upload a sketch: Now hit the little
3.Open a sketch: To open a sketch, just go right-pointing arrow to upload. If you look
to File>Examples>01.Basics>Blink. closely at the Arduino board during this
4.Connect your board: While we’re here, step, you’ll see the TX and RX lights
let’s look at this Blink sketch in action! Grab blinking.
your Arduino board and plug it into your 8.Play with the sketch: Once the Blink
computer with your USB cable. sketch is uploaded, the built-in LED on
5.Test your board is connected: Click on your board will start blinking.
Tools>Board. Now you can select your board
by name. Now hit Tools>Port. Simply select
the port that shows the name of your board.
Language References:
How To Use Variables
A variable has four ingredients:
• Type: The kind of information that you’re actually going to store in
the variable
• Name: Variable names can contain letters, numbers, and underscores, but
they can’t start with a number.
• Assignment operator: When you initialize a variable, you’ll see an equals
sign to signal that the type and name apply to whatever information the
sketch includes next.
• Value: finally, there’s the value you assign to the variable.
How To Use Control Structures
control structures allow you to adjust the flow of code,
and that paves the way for your Arduino to produce more
sophisticated and complex outcomes.
if else switch...case
Syntax Syntax Syntax
if (condition) { if (condition1) {
switch (var) {
//statement(s) // do Thing A
} }
case label1:
else if (condition2) { // statements
// do Thing B break;
} case label2:
else { // statements
// do Thing C break;
}
default:
// statements
break; }
Arduino Functions (PinMode())
• The pinMode() function in Arduino is used to configure a specific
pin as either an input, output. It determines how the pin behaves
•in
pin:
a The pin. number you want to configure.
circuit
•mode: Can be one of the following:
• INPUT – Configures the pin to read signals (e.g., from a sensor or
button).
• OUTPUT – Configures the pin to send signals (e.g., to an LED or
motor).
Arduino Functions (DigitalWrite())
• The digitalWrite() function in Arduino is used to set a digital
pin to HIGH (1) or LOW (0) when it is configured as an OUTPUT.

• pin: The pin number you


want to control.
• value:
• HIGH (1)
• LOW (0)
Example: Blink an LED
Arduino Functions (DigitalRead())

• The digitalRead() function in Arduino is used to read the state


(HIGH or LOW) of a digital input pin.

•Pin: The pin number to read from.


•Returns:
• HIGH (1) – If the pin is receiving voltage (e.g., button
pressed).
• LOW (0) – If the pin is at ground (e.g., button not
pressed).
Example: Reading a Button Press
(Digital Read ())
Arduino Functions (AnalogRead())
• The analogRead() function in Arduino is used to read the
analog voltage from an analog input pin (A0 to A5 on most
boards) and convert it into a digital value. It is commonly used
for reading sensors like temperature sensors, potentiometers,
and light sensors.

•pin: The analog pin (A0, A1, A2, etc.) from which to read the
value.
•Returns: An integer between 0 and 1023 (for 10-bit ADC on
most Arduino boards).
•0 → 0V
•1023 → 5V (or 3.3V on some boards)
Basic Code to Read
Temperature
void setup() {
Serial.begin(9600); // Start serial monitor
}

void loop() {
int sensorValue = analogRead(A0); // Read analog value from LM35
float temperatureC = sensorValue * 0.488; // Convert to °C (simplified formula)

Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");

delay(1000); // Wait 1 second


}
Arduino Functions (AnalogWrite())
• The analogWrite() function is used to output a PWM (Pulse
Width Modulation) signal on PWM-capable pins (marked with ~
on most Arduino boards).

n: The PWM pin (3, 5, 6, 9, 10, or 11 on most Arduinos).


alue: A number from 0 to 255, where:
•0 → Always OFF (0% duty cycle)
•255 → Always ON (100% duty cycle)
•127 → 50% brightness (for an LED)
Example: Adjust LED Brightness
Experiment 2: Turn ON/OFF an LED using
Arduino
Task 1: Circuit 1: Turn ON/OFF an LED using
Arduino
NOTE: positive anode + (bent wire) should be
on the resistor side and the negative cathode
- (straight wire) should be leading towards the
– on the board.
Arduino Program Structure
void setup()
- Called once
- Used to initialize the pin
modes and start the serial
communication
Note: it has to be included
even if there are no
statements
void loop()
- Execute the set of
statements enclosed in
the curly brackets
repeatedly.
- Used to read inputs,
trigger outputs, check
conditions
Task 1: Turn ON/OFF an LED using
Arduino

Note: time is measured in millisecond


Task 2: Variables in Arduino Code

4 places where variables can


be declared:
• Before void setup():
• In the void setup():
• Above void loop():
• In the void loop():

• int = integer numbers (positive and negative)


• double or float = decimal numbers (positive and
negative)
• char = character (one letter / symbol / digit)

Task 3: Control the Number of Times
the LED is turned ON/OFF
Task 3: Control the Number of Times
the LED is turned ON/OFF
Task 4: Adding Text Output
Task 5: LED Brightness Control
Objective:
• You will build upon the work you completed in Task 1.
• LED2 (Brightness Control): Connect a second LED to a different pin on the
Arduino board. Use analogWrite() to control the brightness of LED2.

Results:
•LED1 should blink continuously.
•LED2's brightness should gradually increase and decrease, creating a fading
effect.
•Make sure to comment your code explaining the logic behind each section.

You might also like