Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to generate sound using 8051 microcontroller (AT89C51)- (Part 18/45)

By Himanshu Choudhary August 6, 2010

This article explains the concept behind generating sound from the 8051 microcontroller (AT89C51). This concept can be used to generate sound with any MCU. It can be used to generate specific sounds or alarms. This circuit has wide applications like in cars to produce sound while reversing, in electronic piano to generate different tones, or in electronic toys to generate tones.

 

 


 

 

Sound is a function of frequency. This concept has been used to generate sound from the microcontroller. Different types of sounds can be produced by varying the frequency.

Frequencies are generated by using Timer1 of microcontroller. Timer is used to produce exact delays and by toggling the output pin we can generate the desired frequencies. These frequencies are then fed to a particular pin (here Pin 0 of port1) which is connected to speaker. The output can be heard on the speaker. By combining the different frequencies we can generate different tones and alarms.       

 

 

Project Source Code

###

// Program to generate different sounds using micro controller

#include<reg51.h>
sbit out=P1^0;  //output pin 1

void delay(unsigned char p,unsigned char q)
{
TMOD=0x01;  //timer0 mode1(16 bit)
TL0=q;      //load TL0
TH0=p;      //load TH0
TR0=1;   //turn on T0
while(TF0==0); // wait for flag generation
TR0=0;   // turn off T0
TF0=0;    // clear TF0
}

void play(unsigned char j,unsigned char k)
{
int i;
for(i=0;i<1000;i++)  //to play sound
{
  out=1;
  delay(j,k);
  out=0;
  delay(j,k);
}
}

void main()
{
int l;
while(1)
{
  play(0xfc,0x66);  //playing sound of frequency of about 500 hertz with a delay between two frequencies
  for(l=0;l<5;l++)   
  {
   delay(0x00,0x00);  //delay of 71 miliseconds
  }
  play(0xfe,0x33);  //playing sound of frequency of about 1000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xa3);  //playing sound of frequency of about 5000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xd1);  //playing sound of frequency of about 10000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xdc);  //playing sound of frequency of about 13000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xcc);  //playing sound of frequency of about 9300 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
  play(0xff,0xe8);  //playing sound of frequency of about 20000 hertz with a delay between two frequencies
  for(l=0;l<5;l++)
  {
   delay(0x00,0x00);  
  }
} 
}

###


Circuit Diagrams

Circuit-Diagram-Of-Generating-sound-Using-8051-Microcontroller-AT89C51

Project Components

  • AT89C51 Microcontroller
  • Piezo Buzzer
  • Speaker


Filed Under: 8051 Microcontroller
Tagged With: 8051, microcontroller, sound
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: 5G Technology
This Tech Toolbox covers the basics of 5G technology plus a story about how engineers designed and built a prototype DSL router mostly from old cellphone parts. Download this first 5G/wired/wireless communications Tech Toolbox to learn more!

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Single ended measuring ports and balanced antenna
  • Right Half Plane Zero
  • Thermal modelling of repetitive power pulse
  • Testing 5kW Grid Tied inverter over 200-253VAC
  • Resistor Selection for Amplifier Layout

RSS Electro-Tech-Online.com Discussions

  • Fun with AI and swordfish basic
  • Can I make two inputs from one??
  • Simple LED Analog Clock Idea
  • Is AI making embedded software developers more productive?
  • Behlke swich

Featured – LoRa/LoRaWan Series

  • What is the LoRaWAN network and how does it work?
  • Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices

Recent Articles

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe