Sound Sensor Interfacing with PIC16F877A

This article is a continuation of the series of tutorials on the PIC16F877A Microcontroller. The aim of this series is to provide easy and practical examples that anyone can understand. In the previous tutorial, we have interfaced the LDR sensor with PIC16F877A. This tutorial is all about Sound Sensor Interfacing with PIC16F877A.

Prerequisites

Before starting this tutorial we should know the below topics. If you know already, please go further.

Components Required

  • PIC16F877A Development Board
  • Sound  Sensor
  • LCD Module (To print the Sensor output)

Introduction

The sound detection sensor module detects whether the sound has exceeded a threshold value. Sound is detected via microphone and fed into an LM393 op-amp. The PCB of this electronic circuit has a potentiometer. The sound level setpoint is adjusted via an onboard potentiometer. When the sound level exceeds the setpoint, an LED on the module is illuminated and the output is sent low.

Product Description

  • Main chip: LM393, electret microphone
  • Working voltage: DC 4 ~ 6V
  • Has the signal output instructions
  • Single signal output.
  • Effective signal output for low level.
  • Output low level and the signal light will on when there has a voice.
  • Can be used for the sonic lamp, with photosensitive sensors act as sound and light alarm, also can be used in the occasion of voice control and sound detection.
  • Circuit boards output switch value.

Note: This sensor only recognizes the availability of sound can not identify the size of the sound or the specific frequencies of sound.

Sound Sensor Interfacing with PIC16F877A

Connection

Sound Sensor

  • Vcc – 5v
  • GND – Ground
  • Out – RD0 (PORTD.0)

LCD

  • RS – RC0
  • RW – RC1
  • EN –RC2
  • Data Lines – PORTB

Sound Sensor Interfacing with PIC16F877A

Source Code

If this sensor detects any sound, LCD will display “Sound Detected”. You can also vary the threshold level by adjusting the Potentiometer in that sensor module.

#include<htc.h>
 
__CONFIG( FOSC_HS & WDTE_OFF & PWRTE_OFF & CP_OFF & BOREN_ON & LVP_OFF & CPD_OFF & WRT_OFF & DEBUG_OFF);
 
#define SOUND RD0             //Sound Sensor Output is connected at PORTD.0
 
#define rs RC0
#define rw RC1
#define en RC2
#define delay for(i=0;i<1000;i++)
 
int i;
 
void lcd_init();
void cmd(unsigned char a);
void dat(unsigned char b);
void show(unsigned char *s);
 
 
void main()
{
    TRISB=TRISC0=TRISC1=TRISC2=0;
    TRISD=0xff;                         //Port D act as Input
    lcd_init();
    cmd(0x80);
    show("   EmbeTronicX  ");
    while(1) {
        if(SOUND == 0) {
            cmd(0xc0);
            show("Sound Detected");
            delay;delay;
        } else {
            cmd(0xc0);
            show("                ");
        }
    }
}
 
void lcd_init()
{
    cmd(0x38);
    cmd(0x0c);
    cmd(0x06);
    cmd(0x80);
}
 
void cmd(unsigned char a)
{
    PORTB=a;
    rs=0;
    rw=0;
    en=1;
    delay;
    en=0;
}
 
void dat(unsigned char b)
{
    PORTB=b;
    rs=1;
    rw=0;
    en=1;
    delay;
    en=0;
}
 
void show(unsigned char *s)
{
    while(*s)
    {
        dat(*s++);
    }
}

Applications

SECURITY SYSTEM FOR HOME/OFFICE

The system can be used for home /office security purposes. When a thief or robber tries to enter the home or office, some sort of sound will be generated. It may be voice or any other sort of sound. The microphone takes the sound and sends message instantly.

CLAPPING SWITCH

The system can be used as a clapping switch. If we add the LED with a relay or BJT, the system acts as a switch. When we clapped, the microphone takes the sound, and the comparator output goes high. As a result, BJT or relay turns on. If we connect this BJT or relay with light, fan, or any electrical/electronic instruments, the system can be operated as a clapping switch.

In our next tutorial, we will see how to interface the Touch sensor with PIC16F877A.

You can also read the below tutorials.

Linux Device Driver TutorialsC Programming Tutorials
FreeRTOS TutorialsNuttX RTOS Tutorials
RTX RTOS TutorialsInterrupts Basics
I2C Protocol – Part 1 (Basics)I2C Protocol – Part 2 (Advanced Topics)
STM32 TutorialsLPC2148 (ARM7) Tutorials
PIC16F877A Tutorials8051 Tutorials
Unit Testing in C TutorialsESP32-IDF Tutorials
Raspberry Pi TutorialsEmbedded Interview Topics
Reset Sequence in ARM Cortex-M4BLE Basics
VIC and NVIC in ARMSPI – Serial Peripheral Interface Protocol
Bootloader TutorialsRaspberry PI Pico Tutorials
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x