Introduction To ARDUINO
Introduction To ARDUINO
Introduction To ARDUINO
ARDUINO
BAU – FALL 2018
CONTENTS
INTRODUCTORY LEVEL
Section 3 • Delay()
Section 4 • LED blinking (Flasher)
Programming • If, else • LED activation using Push Button
Functions • For loop
Examples • Fading an LED (up Dimming)
Power Pins
Digital Pins : 12
In / Out
Including
Analog Output Pins : 6
Analog Input
Pins : 6
BLOCK A
BLOCK B
BLOCK C
BLOCK D
• To write on a digital pin HIGH or LOW (0v or 5v) it must be one of the Digital
Output pins (ALL of them).
• Example:
digitalWrite (2 , LOW );
digitalWrite (10 , HIGH);
• To write on a digital pin HIGH or LOW (0v or 5v) it must be one of the Digital
Output pins (ALL of them).
• Example:
digitalWrite (2 , LOW ); PIN 2 will output a LOW Value : 0V
digitalWrite (10 , HIGH); PIN 10 will output a HIGH Value : 5V
5v 0v V lamp = 5 – 0 = 5v (ON)
13 SECTION 2 : SOFTWARE 25.11.2018
0v 0v V lamp = 0 – 0 = 0v (OFF)
Pin Configuration
digitalRead()
• To read if a digital pin is HIGH or LOW (0v or 5v) it must be one of the Digital
INPUT pins (ALL of them).
• Example:
digitalRead (2);
digitalRead (10);
• To read if a digital pin is HIGH or LOW (0v or 5v) it must be one of the Digital
INPUT pins (ALL of them).
• Example:
digitalRead (2); PIN 2 will read a HIGH Value : 5V
digitalRead (10); PIN 10 will read a LOW Value : 0V
• To write on an analog pin value between HIGH & LOW (from 0 to 255) it must
be one of the analog Output pins (D3, D5, D6, D9, D10, D11).
• Example:
analogWrite (3 , 125); PIN 3 will output a HIGH Value : 2.5V (50%)
digitalWrite (10 , 255); PIN 10 will output a HIGH Value : 5V
• To read an analog value across a pin between HIGH & LOW (from 0 to 1023) it
must be one of the analog Input pins (A0, A1, A2, A3, A4, A5).
• Example:
analogRead (A0); PIN A0 will read a LOW Value : 0V (0)
analogRead (A3); PIN A3 will read a HIGH Value : 5V (1023)
• To set a condition use if () otherwise if it is not true the else() will executed.
• Example:
int x = 10;
if (x > 8){
digitalWrite(2,HIGH);
}
else{
digitalWrite(2,LOW);
}
• Example 1
void setup () { void setup () { Built-in LED
pinMode (13,OUTPUT); pinMode (2,OUTPUT);
} }
void loop () { void loop () {
External LED
Built-in LED
• Example 3
void setup () {
pinMode (3,OUTPUT);
}
void loop () {
for ( int i = 0 ; i <= 255 ; i ++ ) {
digitalWrite (3, i );
delay (50);
}
}
24 SECTION 4 : Examples 25.11.2018
THANK YOU!
November 25 / “Tue 27,Wed 28”
Phone ext.:
3483
Email:
[email protected]
Office:
B3 – Industrial Automation & Control LAB