10. Output Devices
Group assignments
- Group assignment:
- Measure the power consumption of an output device.
- Document your work on the group work page and reflect on your individual page what you learned.
- Individual assignment:
- Add an output device to a microcontroller board you’ve designed and program it to do something.
Link to a Group page of Output Devices
Summary
This week of output divice I explored diffferent output modules. These include servo motors, Passive Buzzer Module and Liquid Crystal Display. I focused on Passive Buzzer Module to sound an alarm when a object is detected. I also used LCD screen to display distace where an object is located. I used ultrasonic sensor to detect this object.
KY-006 Passive Buzzer Module
This is an electronic component used to generate sound. It requires a signal (usually a PWM or square wave) to produce sound. It is commonly used in alarms, sound effects in projects, notifications in embedded systems and more.

I paired this module with HC-SR501 PIR module Sensor. The aim was to produce sound (sound an alarm) when motion is detected.

Arduino code
// Define the pin connected to the PIR sensor OUT pin
const int pirPin = D2;
void setup() {
// Start the serial communication
Serial.begin(115200);
// Setting the PIR pin as an input
pinMode(pirPin, INPUT);
}
void loop() {
// Reading the value from the PIR sensor (HIGH or LOW)
int motionDetected = digitalRead(pirPin);
if (motionDetected == HIGH) {
// Motion detected
Serial.println("Motion Detected!");
} else {
// if no motion
Serial.println("No motion detected.");
}
// Add a small delay to avoid flooding the Serial Monitor
delay(1000);
}

Result
As shown in this video, when motion is detected the buzzer will send an alarm.
Liquid Crystal Display (LCD)
It is a flat-panel display divice commonly used in electronic projects to visually display text, numbers, and symbols. It works by manipulating liquid crystals with electric signals to block or allow light.
I used this screen to display distance at which an object is located detected by an ultrasonic sensor.

Code
I first installed Wire.h and LiquidCrystal_I2C.h libraries.
- Wire.h is the built-in Arduino library used to enable I2C communication, which allows the Arduino and other microcontrollers such as RP2040 to talk to devices such like the LCD two wires (SDA and SCL).
- LiquidCrystal_I2C.h is an external library that provides an easy-to-use interface for controlling LCD displays via I2C. It simplifies writing text to the screen, positioning the cursor, and turning on/off the backlight.
#include
#include
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Defining pin connections
#define TRIG D2
#define ECHO D1
#define BLUE_LED D0
// Setting pins mode
void setup() {
Serial.begin(9600);
pinMode(TRIG, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(BLUE_LED, OUTPUT);
//Display setup
lcd.init();
lcd.backlight();
lcd.clear();
lcd.print("Ready...");
}
void loop() {
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
int duration, distance;
duration = pulseIn(ECHO, HIGH);
distance = duration * 0.0343 / 2;
Serial.print("distance is ");
Serial.print(distance);
Serial.println(" cm");
// Printing to screen
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Dist= ");
lcd.print(distance);
lcd.print(" cm");
// Calling blink function
// blink_led(distance);
if (distance < 10){
digitalWrite(BLUE_LED, HIGH);
delay(300);
digitalWrite(BLUE_LED, LOW);
delay(300);
Serial.println("Too close");
}
else{
digitalWrite(BLUE_LED, LOW);
}
delay(800);
}

Result
As shown here, serial monitor as well LCD screen display the distance where an object is located. The LCD screen is used doen't not display many characters. Therefore I reduced the number of characters for only LCD display unlike serial monitor which is basically a pc screen.
Download files
Here are source code files for Ultrasonic and PIR Sensors
PIR sensor and buzzer Ultrasonic and LCD display