0% found this document useful (0 votes)
41 views10 pages

EE 391 Lab1 Done by Anas Bamaqa

The lab report details various experiments with an Arduino, focusing on controlling LEDs using a push button. Each part includes circuit diagrams, code snippets, and explanations of functionality, demonstrating how the state of the LEDs changes based on button presses. Challenges faced included issues with button activation and LED functionality due to resistor values, leading to a conclusion on the learning experience with Arduino programming and simulation.

Uploaded by

oyws222
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)
41 views10 pages

EE 391 Lab1 Done by Anas Bamaqa

The lab report details various experiments with an Arduino, focusing on controlling LEDs using a push button. Each part includes circuit diagrams, code snippets, and explanations of functionality, demonstrating how the state of the LEDs changes based on button presses. Challenges faced included issues with button activation and LED functionality due to resistor values, leading to a conclusion on the learning experience with Arduino programming and simulation.

Uploaded by

oyws222
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/ 10

EE 391

Lab Report 1

Anas Mohammed Bamaqa


20930910

Dr. Ziyad Al-Swaidan


Lab Work:
Part I: Draw the circuit (by hand or software) and comment on
its functionality.

Comment:
It is function, is to use the push button to turn off and on the LED. When
we press the button, it will turn on and when we stop pressing it will
turn off.
Part II: Draw the circuit and attach the code, explain the
functionality of the code on the circuit.

int switchState = 0;
void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop(){
switchState = digitalRead(2);
if(switchState == LOW) {
digitalWrite(3,HIGH);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
}
else{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(250);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(250);
}
}

Explanation:
To enhance clarity in our explanation, I've assigned numbers to the LED
colors and designated pin2 as the button input. When the button isn't
pressed, the initial state illuminates the first two LEDs: green and red.
Yet, when the button is pressed, the first and second LEDs will turn off.
Subsequently, the third LED will light up for a 250-millisecond duration.
After this interval, the third LED will switch off, and the second LED will
illuminate for another 250 milliseconds. This sequence will repeat in a
continuous loop as long as the button remains pressed.
Part III: Draw the circuit and attach the code, explain the
functionality of the code on the circuit.

int switchState = 0;
void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop(){
switchState = digitalRead(2);
if(switchState == LOW) {
digitalWrite(3,HIGH);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
delay(200);
digitalWrite(3,LOW);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(200);
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,HIGH);
delay(200);
}
else{
digitalWrite(3,LOW);
digitalWrite(4,LOW);
digitalWrite(5,LOW);
}
}

Explanation:
To enhance clarity in our explanation, I've assigned numbers to the LED
colors and designated pin2 as the button input. In the absence of a
button press, the system operates as follows: the first LED lights up
exclusively for 200 milliseconds with all other LEDs turned off, followed
by the second LED with all other LEDs turned off for the same duration.
Subsequently, the third LED illuminates while all others remain off for
another 200 milliseconds. This cycle repeats continuously as long as the
button remains unpressed. However, pressing the button will instantly
turn off all the lights.
Part IV: Comment on how defining the variable “switchst” can
be useful.
We can easily change the state of the LEDs and button by modifying
only one variable instead of changing each LED status one by one. And
for that we could achieve a code that is more readable and will help us
to quickly change the behavior of the LEDs status and button.

Part V: Draw the circuit and attach the code, explain the
functionality of the code on the circuit.

int switchState = 0;
int switchst = LOW;
void setup(){
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop(){
switchState = digitalRead(2);
if(switchState == switchst) {
digitalWrite(3,~switchst);
digitalWrite(4,switchst);
digitalWrite(5,switchst);
delay(200);
digitalWrite(3,switchst);
digitalWrite(4,~switchst);
digitalWrite(5,switchst);
delay(200);
digitalWrite(3,switchst);
digitalWrite(4,switchst);
digitalWrite(5,~switchst);
delay(200);
}
else{
digitalWrite(3,switchst);
digitalWrite(4,switchst);
digitalWrite(5,~switchst);
delay(200);
digitalWrite(3,switchst);
digitalWrite(4,~switchst);
digitalWrite(5,switchst);
delay(200);
digitalWrite(3,~switchst);
digitalWrite(4,switchst);
digitalWrite(5,switchst);
delay(200);
}
}

Explanation:
To enhance clarity in our explanation, I've assigned numbers to the LED
colors and designated pin2 as the button input. In the absence of a
button press, the system operates as follows: the first LED lights up
exclusively for 200 milliseconds with all other LEDs turned off, followed
by the second LED with all other LEDs turned off for the same duration.
Subsequently, the third LED illuminates while all others remain off for
another 200 milliseconds. This cycle repeats continuously as long as the
button remains unpressed. However, pressing the button it will flip how
the LEDs turn on. Which will be the third LED lights up exclusively for
200 milliseconds with all other LEDs turned off, followed by the second
LED with all other LEDs turned off for the same duration. Subsequently,
the first LED illuminates while all others remain off for another 200
milliseconds. This cycle repeats continuously as long as the button
remains pressed.
Challenges: Write down any challenges that you have
encountered during the experiment.
I encountered a couple of difficulties during the project. Firstly, I had
trouble activating the button because its pins were quite small, making
it challenging to establish a proper electrical connection. Secondly, I
faced issues with the LEDs not turning on, even though I was confident
that they were correctly connected to the breadboard. It turned out
that the problem was related to the resistor's value, as it was drawing
too much current, leaving insufficient current to power up the LEDs.

Conclusion:
We learned how to use Arduino and how to program it using the C
language. We also learned how to program using C language. We used
the Arduino to write some simple programs. We also learned how to
simulate the Arduino using tinkercad website and we use it to write
some simple programs.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy