Engineers Garage

  • Electronics Projects and 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

Clap counter using 8051 microcontroller (AT89C51)

By Himanshu Choudhary August 4, 2010

This article explains the concept behind interfacing a sound sensor with the 8051 microcontroller (AT89C51). This project increases the count by one every time a sound is produced. It works well with the sound of a clap. The number of claps is displayed on an LCD module. The circuit consists of four modules, namely, a sound sensor, an amplifying circuit, a control circuit and a display module. The code for interfacing the sound sensor with the MCU is written in C language.


 

The connections of different modules are shown in the circuit diagram. The data pins of the LCD are connected to port P2, while the control pins (RS, R/W & EN) are connected to pins 1-3 of port P1of AT89C51, respectively. The microcontroller receives sound pulses through the first pin of port P0.

A condenser microphone is used to sense the sound produced by the clap. This mic is connected to a two stage transistor amplifier. The mic output is thus amplified to a suitable level so that it can be detected at the TTL logic. A switching circuit made from a single transistor is also employed after the amplifier. The purpose of this circuit is to convert the analog signals into discrete digital signals, which are used as input for the MCU.

The output of the amplifier is coupled with a transistor switch. Whenever a high voltage output is received from the amplifier, it generates a pulse. The transistor switching circuit also ensures that a high TTL logic is not received at the microcontroller due to noise signals.
The pulse, from the switching circuit, is fed to the microcontroller, which is programmed to detect the pulses. Every time a pulse in detected, the count value is increased by one. The output is displayed on a 16×2 LCD screen.
The sensitivity of the sound sensor can be increased by improving the circuit of the amplifying unit. An op-amp can be used to increase the sensitivity.

 

 

Project Source Code

###

// Program to count the number of clap
#include<reg51.h>
#define port P1
#define dataport P2  //Data Port for LCD
#define sec 1000
sbit rs = port^0;
sbit rw = port^1;
sbit e = port^2;
sbit sensor_input=P0^0;
unsigned char str3[10]={' ',' ',' ',' ',' ',' ',' ',' ',' ',' '};


void delay(unsigned int msec) // Time delay function
{
int i,j ;
for(i=0;i<msec;i++)
  for(j=0;j<1275;j++);
}

void lcd_cmd(unsigned char item) // Function to send command
{
dataport = item;
rs= 0;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data(unsigned char item) // Function to send data
{
dataport = item;
rs= 1;
rw=0;
e=1;
delay(1);
e=0;
return;
}

void lcd_data_string(unsigned char *str) // Function to send string
{
int i=0;
while(str[i]!='')
{
  i++;
}
while(i>=0)
{
  lcd_data(str[i]);
  i--;
  delay(10);
}
return;
}

void convert(int num)  // Function to extract digits and send to LCD
{
int i=0;
while(num>0)
{
  str3[i]=(num%10)+48;
  num=num/10;
  i++;
}
str3[i]='';
}
  
void main()
{
int count=0;
sensor_input=1;
sensor_input=0;
lcd_cmd(0x38);
lcd_cmd(0x0e);
lcd_cmd(0x01);
while(1)
{
  sensor_input=0;
  while(sensor_input==0);
  if(sensor_input==1)
  {
   lcd_cmd(0x01);
   count++;
   convert(count);
   lcd_cmd(0x82);
   lcd_data_string(str3);
  }
}
}

###

 


Circuit Diagrams

Circuit-Diagram-of-Clap-counter-using-8051-microcontroller-AT89C51

Project Components

  • AT89C51 Microcontroller
  • Condenser Microphone
  • LCD
  • Preset
  • Transistor BC547
  • Transistor BC548


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

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: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

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

  • How to best test Electrolytic capacitors for premature failure reduced life?
  • Amperage changes in DC-DC conversion
  • Colpitts oscillator
  • What are the advantages and disadvantages of a differential structure compared to a single-ended structure?
  • Audio Switching

RSS Electro-Tech-Online.com Discussions

  • LED circuit for 1/6 scale diorama
  • stud mount Schottky diodes
  • using a RTC in SF basic
  • Hi Guys
  • Can I use this charger in every country?

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • Fischer connector system adds ratchet locking system designed for 300g shock resistance
  • Littelfuse introduces tactile switch with enhanced bracket peg design for mounting strength
  • Infineon releases GaN switch with monolithic bidirectional design
  • Sienna Semiconductor data converters feature sample rates from 20 to 250 Msps
  • Delta’s 5,500 W power supplies achieve 97.5% energy efficiency for AI servers

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

  • Electronics Projects and 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