0% found this document useful (0 votes)
110 views19 pages

IOT-Nhóm 4-LAB2

This document outlines Lab 2 for the CSE479 Internet of Things course, focusing on working with electronic components using Arduino. It includes detailed instructions for various tasks involving push buttons, LEDs, and potentiometers, along with required hardware and software. Students must submit a final report with circuit diagrams and programming source files by the deadline for full marks.

Uploaded by

Hải Đăng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views19 pages

IOT-Nhóm 4-LAB2

This document outlines Lab 2 for the CSE479 Internet of Things course, focusing on working with electronic components using Arduino. It includes detailed instructions for various tasks involving push buttons, LEDs, and potentiometers, along with required hardware and software. Students must submit a final report with circuit diagrams and programming source files by the deadline for full marks.

Uploaded by

Hải Đăng
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

IUH. Lecturer – Le Ngoc Tran, Ph.D.

Course: CSE479 – Internet of Things (IoT)

Lab 2 – Working with electronic components

Duration: 4 hours

Group ID Nhóm 4 Thứ 3 Tiết1-3


Students’ Nguyễn Minh Tiến-2032230369
name
Nguyễn Hải Đăng-2032230224

Võ Minh Nhựt-2032230330

Trương Nguyễn Trí Toàn-2032230373


Final Score

Lab Exercise Submission

Students are responsible for submitting the final report by the stated
deadline for full marks. Late submissions will NOT be accepted.

Learning Objective: At the end of this Lab, students will be able to:

- Use Arduino hardware, Arduino IDE, Fritzing


- User electronic components: Button Switch, Potentiometer

Content Lab Description


- Clocks and counters
- Blinking LED by timer
Lab 2. Electronic - Making a digital clock using timer
components  Equipment: Computer, Arduino
UNO, LED module, Push Button,
Potentiometer

1
IUH. Lecturer – Le Ngoc Tran, Ph.D.

NOTE: The final report should be written in English and submitted with
the programming source files (if any).

 - Good luck - 

2
IUH. Lecturer – Le Ngoc Tran, Ph.D.

Hardware Requirement

# Device Quantity

1 Arduino Board 1

2 BreadBoard 1

3 Potentiometer 2

4 Resistor 220Ω, 1k 5

5 Arduino USB connector 1

6 Jumper Wires 10

7 Battery 9V (optional) 1

8 Push button 1

Software Requirement

# Software Quantity

1 Arduino IDE 1

2 Fritzing tool 1

Report Requirement
1. Submit the Arduino source code

3
IUH. Lecturer – Le Ngoc Tran, Ph.D.

2. Final report (word): include the circuit diagram (by Fritzing tool)
and the photo taken when the circuit is running

4
IUH. Lecturer – Le Ngoc Tran, Ph.D.

Lab Experiment Procedure:

Task 1 – Working with push button

Hardware requirements

# Device Quantity

1 Arduino Board 1

2 BreadBoard 1

3 Push button 1

4 Resistor 220Ω 5

5 USB connector 1

6 Jumper Wires many

5
IUH. Lecturer – Le Ngoc Tran, Ph.D.

Figure 1. Push button schematic symbol

Figure 2. Circuit diagram with push button

void loop() {
int buttonStatus = digitalRead(button); //Read button status
Serial.println(buttonStatus); //Print status in serial
delay(200); //wait 200ms
}

Procedure

1. Connect all devices as the cuicuit diagram (figure 2).


2. Write the program to allow the circuit working as follows:
- In Serial monitor, display the number of times when the push
button is pressed

6
IUH. Lecturer – Le Ngoc Tran, Ph.D.

NOTE: Before continuing, review the schematic for this circuit and
check that your components are wired correctly.

Answer:

1.

2.

Code:

int A=2;

int solannhan=0;

int trangthaitruoc=1;

void setup() {

pinMode(A,INPUT_PULLUP);

7
IUH. Lecturer – Le Ngoc Tran, Ph.D.

Serial.begin(9600);

void loop() {

int docnutnhan=digitalRead(A);

if (docnutnhan==0&&trangthaitruoc==1)

Serial.print("So lan nhan la:");

Serial.println(solannhan);

delay(200);

solannhan++;

trangthaitruoc=docnutnhan;

Link:https://www.youtube.com/watch?v=T6TJLoWYh9E

Task 2 – Working with push button and LED

Procedure

1.Reuse Lab 2.1


2.Connect one LED and resistor 220 Ω to an I/O port
3.Draw the circuit diagram using Frizting tool
4.Write the program to allow the circuit working as follows:
- When the button is pressed, LED is turn on and print “Button
on” in Serial monitor
- When the button is pressed again, LED is turn OFF and print
“Button off” in Serial monitor

Answer:

2.

8
IUH. Lecturer – Le Ngoc Tran, Ph.D.

3.

4.

9
IUH. Lecturer – Le Ngoc Tran, Ph.D.

Code:

int A=2;

int led=4;

int solannhan=0;

int trangthaitruoc=1;

void setup() {

pinMode(A,INPUT_PULLUP);

Serial.begin(9600);

pinMode(led,OUTPUT);

void loop() {

int docnutnhan=digitalRead(A);

if (docnutnhan==0&&trangthaitruoc==1)

if (solannhan%2==0) Serial.println("Button off");

else if (solannhan%2==1) Serial.println("Button on");

delay(200);

solannhan++;

trangthaitruoc=docnutnhan;

if(solannhan%2==0) digitalWrite(led,1);

else digitalWrite(led,0);

Link:https://www.youtube.com/watch?v=M84MJR9Nmvo
10
IUH. Lecturer – Le Ngoc Tran, Ph.D.

Task 3 – LED Dimming

Hardware requirements

# Device Quantity

1 Arduino Board 1

2 BreadBoard 1

3 LED 1

4 Resistor 220Ω 1

5 USB connector 1

6 Jumper Wires many

Procedure

1. Connect one LED and resistor 330 Ω to an PWM I/O port on


your Arduino
2. Write the code to allow the circuit working as follows:
- The light level of LED will be changed from min to max level
(100% brightness)
- Then it changes from max to min level (LED off)

Answer:

1.

11
IUH. Lecturer – Le Ngoc Tran, Ph.D.

2.

Code:

int led=3;

int i;

void setup() {

pinMode(led,OUTPUT);

12
IUH. Lecturer – Le Ngoc Tran, Ph.D.

void loop() {

for(i=0;i<256;i++){

analogWrite(led,i);

delay(20);

for(i=255;i>=0;i--){

analogWrite(led,i);

delay(20);

}Link:https://www.youtube.com/watch?v=L0ptFTZNCtY

Task 4 – Working with the Variable resistor (Potentiometer)

Hardware requirements

# Device Quantity

1 Arduino Board 1

2 BreadBoard 1

3 LED 1

4 Resistor 220Ω 7

5 USB connector 1

6 Jumper Wires 10

7 Variable resistor 1

13
IUH. Lecturer – Le Ngoc Tran, Ph.D.

Figure 3. Various types of the variable resistor

Figure 4. A circuit diagram for connecting potentiometer to


Arduino board

14
IUH. Lecturer – Le Ngoc Tran, Ph.D.

// An example of reading the value of potentiometer and print to serial


void setup() {
Serial.begin(9600);
}

void loop() {

int value = analogRead(A5); //read value from A5 pin in range(0-1023)


Serial.println(value);

int voltage;
voltage = map(value,0,1023,0,5000);
//change from scale (0 -1023) to (0 – 5000) mV
Serial.println(voltage);

Serial.println();
delay(200);
}

Procedure

1. Connect all devices according to the circuit diagram.


2. Write the code to read the value from pin A5 and print it to
serial monitor
3. Connect one LED and resistor 220 to pin 10 of Arduino
4. Modify the given code to perform the following task:
- When we change the value of potentiometer, the bright level of
LED is changed accordingly
5. Use Fritzing tool to draw the final circuit diagram.

Answer:

1.

15
IUH. Lecturer – Le Ngoc Tran, Ph.D.

2.

Code:

int analog=A5;

void setup() {

Serial.begin(9600);

16
IUH. Lecturer – Le Ngoc Tran, Ph.D.

void loop() {

int value = analogRead(A5);

Serial.println(value);

int voltage;

voltage = map(value,0,1023,0,5000);

Serial.println(voltage);

Serial.println();

delay(2000);

3.

17
IUH. Lecturer – Le Ngoc Tran, Ph.D.

4.

Code:

int led=10;

int analog=A5;

void setup() {

Serial.begin(9600);

pinMode(led,OUTPUT);

18
IUH. Lecturer – Le Ngoc Tran, Ph.D.

void loop() {

int value = analogRead(A5);

int dosang = map(value,0,1023,0,255);

analogWrite(led,dosang);

Link :https://youtu.be/pmySO4Ljb0Y?si=KyrUV_nd3mHibud8

5.

19

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