0% found this document useful (0 votes)
3 views44 pages

Sensors Sec1

The document provides an introduction to Arduino, detailing its significance in electronics and IoT, along with a focus on the Arduino Uno microcontroller board and its components. It outlines steps for writing Arduino code, basic electronics concepts, and various programming structures and data types in Arduino C. Additionally, it includes examples of using control structures and constants in Arduino programming.

Uploaded by

mazenkeke2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views44 pages

Sensors Sec1

The document provides an introduction to Arduino, detailing its significance in electronics and IoT, along with a focus on the Arduino Uno microcontroller board and its components. It outlines steps for writing Arduino code, basic electronics concepts, and various programming structures and data types in Arduino C. Additionally, it includes examples of using control structures and constants in Arduino programming.

Uploaded by

mazenkeke2005
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

Introduction to Arduino

SENSORS - SECTION1
What is Arduino?
• It is a series of open-source
microcontroller board based
on a diverse range of
microcontrollers (MCU)
• Importance: Widely used in
electronics, automation, and
IoT projects.
• Different Boards: Arduino
Uno, Mega, Nano.
INTRO. TO ARDUINO

• It’s a micro-computer/
microcontroller .
• As any computer it has internal
CPU, RAM, IOs interfaces.
• It’s used for control purposes.
• Arduino uno is reprogrammable,
codes can be ported into it for
specific application.
What is Arduino Uno?
• A microcontroller board based on ATmega328P
Key Components:
• Microcontroller unit
• Digital & Analog Pins
• Power Supply & Voltage Regulators
• USB Interface for programming
Arduino Uno
Board
Layout
Board Components
•Reset Button : This will restart any code that is loaded to the Arduino board

•Ground Pin : There are a few ground pins on the Arduino and they all work the same

•Analog Pins (A0 - A5): These pins read the signal from an analog sensor and convert it to digital

•Digital Input/Output : Pins 0-13 can be used for digital input or output

•PWM ((~3, ~5, ~6, ~9, ~10, ~11): The pins marked with the (~) symbol can simulate analog

output

•USB Connection : Used for powering up your Arduino and uploading sketches
Board Components
• TX/RX : Transmit and receive data indication LEDs
• ATmega Microcontroller : Popular microcontroller chip,
• Power LED Indicator : This LED lights up anytime the board is plugged
in a power source
• DC Power Barrel Jack : This is used for powering your Arduino with a
power supply
• 3.3V Pin : This pin supplies 3.3 volts of power
• 5V Pin : This pin supplies 5 volts of power
steps to write Arduino code

1.download and install the Arduino IDE


(integrated development environment).
2.Connect the Arduino to your computer's USB port
‫‪Arduino IDE‬‬
‫شريط القوائم‬
‫شريط األوامر السريعة‬

‫كتابة الكود هنا‬

‫عرض األخطاء والرسائل‬


steps to write Arduino code

3. Settings { choose Arduino board and port number }

Tools --> Boards Tools --> Serial port


Basic electronics

1- BREADBOARD

• It’s an important board in


electronics to do prototyping
Basic electronics

1- BREADBOARD …
Basic electronics

2- LED
• Light Emitting Diode.
Avo meter

It is a device used to measure voltage, current,


and resistance
Basic electronics

3- RESISTORS

• Resistors provide a specific


amount of resistance to a path
in a circuit or wire.
Basic electronics

3- BATTERY

• A battery is a source of electric


power.
• 9v , 12v,…
Basic electronics

6-BATTERY CLIPS

Basic electronics
3- JUMPER WIRES MALE
MALE
• To connect two points to each
other without soldering.
Basic electronics

6-REGULATOR
• takes an input voltage of up to
38 V and efficiently reduces it
to 5 V.
Basic electronics

CIRCUITS EXAMPLE
• To turn on a led
Basic electronics

CIRCUITS EXAMPLE
• To turn on a led
Code Structure

1.void setup( ){ } 2. void loop( ) { }


setting up your Arduino for the rest of contains the statements that
the program. will run
code here run once The loop() function is next to
the setup() function is called first. It’s the setup() function and it is
executed only once and must be used iterated infinitely
to set pinModes, make settings for
hardware components.
useful functions
1.pinMode( pinNumber, direction ); set a pin as input/output

2.digitalWrite( pinNumber , state ); set a digital pin high/low

3. Delay( time ); wait an amount of time in milliseconds


Arduino C Syntax
comments

// This is a single-line comment

/* This
is
a
multi-line
comment */
variables
In Arduino C, identifiers should contain only alphanumeric
characters, dash (-), or underscore(_).
An identifier can only start from an underscore or a letter.

dataType variable_name ;

int x ;

or..

int x = 3;
Variables datatypes
Data type Size range
boolean (8 bit) true/false
byte (8 bit) 0-255
char (8 bit) (A-Z) or -128 to 127
word (16 bit) 0-65535
unsigned int (16 bit) 0-65535
int (16 bit) -32768 to 32767
unsigned long (32 bit) 0-4,294,967,295
long (32 bit) -2,147,483,648 to 2,147,483,647
float (32 bit) -3.4028235E38 to 3.4028235E38
Examples
Arithmetic operators
Comparison
Operators
Boolean Operators
Compound Operators
Operator name Operator simple Description Example

increment ++ Increment operator, increases integer value by one A++ will give 11

decrement -- Decrement operator, decreases integer value by one A-- will give 9

Add AND assignment operator. It adds right operand to


compound addition += B += A is equivalent to B = B+ A
the left operand and assign the result to left operand

Subtract AND assignment operator. It subtracts right


compound subtraction -= operand from the left operand and assign the result to B -= A is equivalent to B = B - A
left operand

Multiply AND assignment operator. It multiplies right


compound
*= operand with the left operand and assign the result to B*= A is equivalent to B = B* A
multiplication
left operand

Divide AND assignment operator. It divides left operand


compound division /= with the right operand and assign the result to left B /= A is equivalent to B = B / A
operand

Modulus AND assignment operator. It takes modulus


compound modulo %= B %= A is equivalent to B = B % A
using two operands and assign the result to left operand
What is Variable Scope?

Variables
Scope

Global
local variables Parameters
variables

Declared inside Declared defined inside


a function or a outside of all function
block functions parentheses
Constants
• Constants are fixed values that do not change during program
execution.
• Constants help improve code :
• readability
• maintainability
• prevent accidental changes.
Types of Constants in Arduino
1. #define Preprocessor Constant
2. const Keyword (Recommended)
3. Built-in Constants (HIGH, LOW, INPUT, OUTPUT, etc.)
Preprocessor Constant
• Uses #define to create a macro constant (no data type).
• replaces values before compilation.
• No memory usage (just replaces text).
• No type checking
const Keyword
• Uses const to create a typed constant variable.
• Uses memory (stored in RAM)
Built-in Constants

Constant Value Description


HIGH 1 Sets pin to HIGH (5V)
LOW 0 Sets pin to LOW (0V)
INPUT 0 Sets pin as input
OUTPUT 1 Sets pin as output
Arduino c Syntax

Control Structures

Arduino C supports these control structures:

•if
•if …else…
•for
•switch case
•while
•do… while…
Blinking led Example
Blinking led Example
Blinking led Example

You might also like