EEP Practical Applications in Electrical Engineering Common - Lecture 02 - Arduino 2.ppt

shafee0011 12 views 23 slides Sep 29, 2024
Slide 1
Slide 1 of 23
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23

About This Presentation

EEP Practical Applications in Electrical Engineering Common - Lecture 02 - Arduino 2


Slide Content

Lecture (02)Lecture (02)
Arduino 2 Arduino 2
By:By:
Dr. Ahmed ElShafeeDr. Ahmed ElShafee
Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical
Applications in Electrical Engineering 2Applications in Electrical Engineering 211

Project 02, press controlled led

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
2


Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
3
#define LED 12
#define BUTTON 7
int Button_status=0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON,INPUT);
}
void loop()
{
Button_status=digitalRead(BUTTON);
if(Button_status==HIGH)
{
digitalWrite(LED,LOW);
}
else
{
digitalWrite(LED,HIGH);
}
}

Project 03, press controlled led
status toggle
Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
4


Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
5
#define LED 12
#define BUTTON 7
int Button_status=0;
int Led_Status=0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON,INPUT);
digitalWrite(LED,Led_Status);
}
void loop()
{
Button_status=digitalRead(BUTTON);
if(Button_status==LOW)
{
Led_Status=!Led_Status;
digitalWrite(LED,Led_Status);
delay(1000);
}
}

Project 04; press controlled led
Flasher

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
6

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
7
#define LED 12
#define BUTTON 7
int Button_status=0;
int Led_Status=0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON,INPUT);
digitalWrite(LED,Led_Status);
}
void loop()
{
Button_status=digitalRead(BUTTON);
if(Button_status==LOW)
{
Led_Status=!Led_Status;
digitalWrite(LED,Led_Status);
delay(250);
}
else
{
Led_Status=0;
digitalWrite(LED,Led_Status);
}
}

Analog Output
•To create an analog signal, the microcontroller uses a
technique called PWM. By varying the duty cycle, we can
mimic an “average” analog voltage.
Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
8
•Pulse Width Modulation (PWM)

Project 05, led dimmer

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
9


Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
10
#define LED 3
int brightness=0;
int fade=5;
void setup()
{
pinMode(LED, OUTPUT);
}
void loop()
{
analogWrite(LED,brightness);
brightness+=fade;
if((brightness==0) || (brightness==255))
fade=-fade;
delay(10);
}

Analog input
•Arduino uses a 10-bit A/D Converter:
•this means that you get input values from 0 to 1023
•0 V  0
•5 V  1023
Ex:
• int sensorValue = analogRead(A0);
Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
11

Project 06, Analog DC dimmer

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
12


Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
13
#define LED 3
int brightness=0;
int control=0;
void setup()
{
pinMode(LED, OUTPUT);
}
void loop()
{
control=analogRead(0);
brightness=control/4;
analogWrite(LED,brightness);
}

Project 07, serial echo

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
14
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available() > 0)
{
char inByte = Serial.read();
Serial.print("you typed : ");
Serial.print(inByte);
Serial.println();
}

}

Project 8, serial controlled leds

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
15


Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
16
#define led1 11
#define led2 12
int led1_status=0;
int led2_status=0;
void setup()
{
Serial.begin(9600);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
digitalWrite(led1,led1_status);
digitalWrite(led2,led2_status);
}
void loop()
{
if (Serial.available() > 0)
{
char inByte = Serial.read();
switch(inByte)
{
case '1':
led1_status=!led1_status;
digitalWrite(led1,led1_status);
Serial.print("led one is now :");
Serial.println(led1_status);
break;
case'2':
led2_status=!led2_status;
digitalWrite(led2,led2_status);
Serial.print("led two is now :");
Serial.println(led2_status);
break;
default:
Serial.println("unknown command");
break;
}
}
}

Project 9, serial controlled leds,
monitor press and pot
Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
17

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
18
#define led1 11
#define led2 12
#define button 7
int led1_status=0;
int led2_status=0;
int potValue=0;
int pressStatus=1;
void setup()
{
Serial.begin(9600);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
digitalWrite(led1,led1_status);
digitalWrite(led2,led2_status);
}
void loop()
{
if(pressStatus!=digitalRead(button))
{
pressStatus=(int)digitalRead(button);
Serial.print("Button value = ");
Serial.println(pressStatus);
}
if (Serial.available() > 0)
{
char inByte = Serial.read();
switch(inByte)
{
case '1':
led1_status=!led1_status;
digitalWrite(led1,led1_status);
Serial.print("led one is now :");
Serial.println(led1_status);
break;
case '2':
led2_status=!led2_status;
digitalWrite(led2,led2_status);
Serial.print("led two is now :");
Serial.println(led2_status);
break;
case 'p':
potValue=analogRead(0);
Serial.print("Pot value = ");
Serial.println((float)potValue*5/1024);
break;

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
19
default:
Serial.println("unknown command");
break;
}
}
}

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
20
#define led1 11
#define led2 12
#define button 7
int led1_status=0;
int led2_status=0;
int potValue=0;
int pressStatus=1;
void setup()
{
Serial.begin(9600);
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
digitalWrite(led1,led1_status);
digitalWrite(led2,led2_status);
}
void loop()
{
if(analogRead(0)!=potValue)
{
potValue=analogRead(0);
Serial.print("Pot value = ");
Serial.println((float)potValue*5/1024); }
if(pressStatus!=digitalRead(button))
{
pressStatus=(int)digitalRead(button);
Serial.print("Button value = ");
Serial.println(pressStatus);
}
if (Serial.available() > 0)
{
char inByte = Serial.read();
switch(inByte)
{
case '1':
led1_status=!led1_status;
digitalWrite(led1,led1_status);
Serial.print("led one is now :");
Serial.println(led1_status);
break;
case '2':
led2_status=!led2_status;
digitalWrite(led2,led2_status);
Serial.print("led two is now :");
Serial.println(led2_status);
break;

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2
21
default:
Serial.println("unknown command");
break;
}
}
}

Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical Applications in Electrical
Engineering 2neering 2App EE II
22

Thanks,..Thanks,..
See you next week (ISA),…See you next week (ISA),…
Dr. Ahmed ElShafee, ACU : Spring 2019 - EEP02 Practical
Applications in Electrical Engineering 2neering 2App EE II
2323
Tags