IUH.                                                        Lecturer – Le Ngoc Tran, Ph.D.
Course: CSE479 – Internet of Things (IoT)
Lab 3 – Serial Communication and Buzzer Device
Duration: 4 hours
Group ID                                   Write group number here
Students’ name                      Write students’ name in the group here
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: buzzer
   -   Understand serial communication and PWM pin
               Content                                Lab Description
                                       - Dimming LED by using PWM
                                       - Controlling LED via serial port
   Lab 3. PWM & Serial                 - Ringing the buzzer using the PWM
   Communication                       - Ringing the buzzer using the Timer
                                       Equipment: Computer, Arduino Board, LED
                                         module, Buzzer
NOTE: The final report should be written in English and submitted with the
programming source files.
                                       - Good luck - 
                                                                                        1
IUH.                                                       Lecturer – Le Ngoc Tran, Ph.D.
Hardware Requirement
       #   Device                                           Quantity
       1   Arduino Board                                    1
       2   BreadBoard                                       1
       3   LED                                              3
       4   Resistor 220Ω, 1k                                5
       5   Arduino USB connector                            1
       6   Jumper Wires (male, female)                      10
       7   Buzzer (speaker)                                 1
       8
Software Requirement
       #   Software                                         Quantity
       1   Arduino IDE                                      1
       2   Fritzing tool                                    1
       3   Visual Studio 2013                               1
Report Requirement
  1. Submit the Arduino source code
  2. Final report (word): include the circuit diagram (by Fritzing tool) and the photo
     taken when the circuit is running
                                                                                         2
IUH.                                                           Lecturer – Le Ngoc Tran, Ph.D.
Lab Experiment Procedure:
Task 1 – Working with Buzzer (Piezo Speaker)
Hardware requirements
       #   Device                                               Quantity
       1   Arduino Board                                        1
       2   BreadBoard                                           1
       3   Buzzer                                               1
       4   Resistor 220Ω                                        1
       5   USB connector                                        1
       6   Jumper Wires                                         10
                                                 Description
       - A Piezo is an electronic piece that
         converts electricity energy to sound. It is a
         digital output device. You can make white
         noise or even exact musical notes
         (frequencies for musical notes) based on
         the duration that you iterate between
         HIGH and LOW signals.
       - A Piezo is a directional piece, meaning
         that it has a positive and negative pole.
       - The positive pole should be connected to
         the digital output pin that you allocate to
         control the piezo and the negative pole
         should be connected to Ground pin
       Coding sample
                                                                                           3
IUH.   Lecturer – Le Ngoc Tran, Ph.D.
                                   4
IUH.                                                     Lecturer – Le Ngoc Tran, Ph.D.
 // An example of using the buzzer
 int buzzerPin = 12;
 void setup()
 {
   pinMode(buzzerPin, OUTPUT);
   digitalWrite(buzzerPin, HIGH);
 }
 void loop()
 {
   digitalWrite(buzzerPin, HIGH);
   delay(2000);
   digitalWrite(buzzerPin, LOW);
   delay(2000);
 }
Experiment Procedure
       1. Connect the buzzer to Arduino with correct pin (PWM)
       2. Write the code with Arduino IDE with the following requirements:
          - Turn on/off the buzzer in 2s with highest volume
Task 2 – Controlling LED and buzzer via Serial communication
Hardware requirements
       #    Device                                        Quantity
       1    Arduino Board                                 1
       2    BreadBoard                                    1
       3    LED                                           1
       4    Resistor 220Ω                                 2
       5    USB connector                                 1
       6    Jumper Wires                                  10
       7    Buzzer                                        1
Procedure
                                                                                     5
IUH.                                                      Lecturer – Le Ngoc Tran, Ph.D.
       1. Connect one LED, buzzer, resistor and Arduino to Breadboard
       2. Use Fritzing tool to draw the final circuit diagram
       3. Write the code with Arduino IDE with the following requirements:
          - Control the LED and buzzer via serial port (use Serial Monitor):
             + Type “led on” or “led off” turn LED on/off,
             + Type “buzzer on” or “buzzer off” to turn Buzzer on/off
             + Print “Invalid command” message in other cases
Reference:
              http://www.instructables.com/id/Arduino-Function-Serialread-And-
              SerialreadString/
              https://arduinogetstarted.com/reference/serial-readstringuntil
Task 3 – Playing a melody with Buzzer
Hardware requirements
       #     Device                                        Quantity
       1     Arduino Board                                 1
       2     BreadBoard                                    1
       3     LED                                           1
       4     Resistor 220Ω                                 2
       5     USB connector                                 1
       6     Jumper Wires                                  10
       7     Buzzer                                        1
Reference:
       https://www.arduino.cc/en/Tutorial/PlayMelody
       (see the attached file for details)
Procedure
                                                                                      6
IUH.                                                      Lecturer – Le Ngoc Tran, Ph.D.
       1. Connect one LED, buzzer, resistor and Arduino to Breadboard
       2. Use Fritzing tool to draw the final circuit diagram
       3. Write the code with Arduino IDE with the following requirements:
          - Send “ON” in the Serial monitor: Buzzer plays “Happy birthday” song
          - Send “OFF” to turn it off
Task 4 – Building an application (Web, C# program) to control a LED
Procedure
       1. Write a simple application (Web, C# program) to turn ON/OFF a LED via
          serial port (see the example attached in this lab)
       2. Reference:
http://arduino.vn/bai-viet/902-c-sharp-c-mot-cach-dieu-khien-arduino-bang-may-tinh