IOT-Nhóm 4-LAB2
IOT-Nhóm 4-LAB2
Duration: 4 hours
Võ Minh Nhựt-2032230330
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:
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
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.
Hardware requirements
# Device Quantity
1 Arduino Board 1
2 BreadBoard 1
3 Push button 1
4 Resistor 220Ω 5
5 USB connector 1
5
IUH. Lecturer – Le Ngoc Tran, Ph.D.
void loop() {
int buttonStatus = digitalRead(button); //Read button status
Serial.println(buttonStatus); //Print status in serial
delay(200); //wait 200ms
}
Procedure
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.println(solannhan);
delay(200);
solannhan++;
trangthaitruoc=docnutnhan;
Link:https://www.youtube.com/watch?v=T6TJLoWYh9E
Procedure
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)
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.
Hardware requirements
# Device Quantity
1 Arduino Board 1
2 BreadBoard 1
3 LED 1
4 Resistor 220Ω 1
5 USB connector 1
Procedure
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
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.
14
IUH. Lecturer – Le Ngoc Tran, Ph.D.
void loop() {
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
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() {
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() {
analogWrite(led,dosang);
Link :https://youtu.be/pmySO4Ljb0Y?si=KyrUV_nd3mHibud8
5.
19