How To Use PIC Microcontroller For Voice Input And Output

Microcontrollers are purely digital devices which work on logic0 and logic1 voltages; still they are widely used for analog signal processing. There are specialized signal processors chips available which are custom made for particular applications; however a general purpose microcontroller is more than enough for small kind of signal processing applications like audio signal input and output. The microcontroller can read the analog input voltage by sampling it and converting it to their digital values. The Analog to Digital Converter (ADC) available in almost all the microcontrollers help in this task.  A timer can be used to generate the sampling time period. The sampled values can then read and modify by the microcontroller. The modified signal is then output by the microcontroller in the form of Pulse Width Modulated (PWM) waves. Most of the microcontrollers have the PWM module which helps them in generating analog voltage output at an external device.

The PIC18F4550 has a built-in 10bit ADC, which is provided with a13 input channels. It has a PWM module with four output channels. In this particular project the ADC, PWM modules are used along with the timer0 modules and the method of using those modules are already discussed in previous projects. This project is actually an application which makes use of the above mentioned modules. Both the coding and the external circuitry have equal importance in this project.How To Use PIC Microcontroller For Voice Input And Output


The voice input block has a microphone which captures the voice signals from the surroundings. The voice signals are then amplified to a certain level using a small amplifier circuit. The amplified signal may have both positive and negative cycles. Since the ADC of the microcontroller can read only the positive voltages, the signal output from the amplifier should be clamped above the zero voltage level so that the ADC can read the complete cycle.

Hence the VOICE INPUT block is designed to capture the voice signals and modify them in such a way that the ADC of the microcontroller can read them. The following figure shows the different sub blocks inside the AUDIO INPUT block which helps to capture and modify the audio signals.


The microphone used in this project is the commonly available condenser microphone. The microphone is pulled up using a resistor. The voice in the environment causes the capacitor plates of the condenser microphone to vibrate and hence the variation of capacitance occurs. This causes current to flow in an out of the condenser microphone according to the voice signal. The current flow produces voltage drop across the resistor which can then couple out using another capacitor.

The following image is the signal captured using CRO at the output of MICROPHONE CIRCUIT. The Volts/Division of the CRO has been set to 0.05V


The voltage signal coming from the MICROPHONE CIRCUIT is very small and hence these cannot be read by the microcontroller. Before fed this signal to the microcontroller it should be amplified. In this project a NPN transistor is used to amplify the voice signals to a particular level so that the ADC will be able to read it. Another advantage of using the amplifier is that it somewhat reduces the noise which forms along with the voice signal at the MICROPHONE CIRCUIT.


The positive clamper is very important in this project since the ADC can read only the positive voltages and the amplified voice signals from the AMPLIFIER will be having both positive and negative cycles. The entire signal should be clamped to the positive voltage level without any distortion so that the ADC can read both the cycles. A germanium diode clamper is used in this project which can clamp the signal above a positive voltage which is equivalent to its forward bias voltage.

The following image is the signal captured using CRO at the output of POSITIVE CLAMPER. The Volts/Division of the CRO has been set to 1V


The amplified signal could be sometimes larger than which the ADC can convert completely. For all the signal voltages above the ADC reference voltage the ADC will produce its maximum value only. The values which are read by the ADC are directly used to modify the pulse width of the PWM wave.  Since the maximum pulse width in a PWM cycle is also limited the voltage level that is produced by the AMPLIFIER should be kept in a suitable range. The voltage divider block which consists of a variable resistor connected across the POSITIVE CLAMPER will help to keep the voltage level in a range which the ADC can read and also the pulse width of a PWM wave can represent.


The timer module is used to generate period interrupts at a very high frequency which is well above the frequency of the audio signals. Each time the interrupt fires the value captured by the ADC is read   which can be called as the sampled value of the signal at that particular instant. Thus the timer act as the sampling period generating block which samples the audio signal captured by the microphone.

The input signals should be sampled at least double the input frequency, and then only it will be possible to reconstruct the same signal. As the sampling frequency increases the number of samples increases and the reconstructed signal resembles more to the original signal. The audio signals normally fall in a frequency range from 500Hz to 5 KHz and hence the sampling frequency should be well above that frequency.

How To Use PIC Microcontroller For Voice Input And Output Schematic

Using the timer0 module to generate sampling time is explained in a previous project on Sine wave generation using PWM module of the PIC.

#include <p18f4550.h>
#include <timers.h>
//======================= chip config ===================//
#pragma config PLLDIV = 1
#pragma config CPUDIV = OSC1_PLL2
#pragma config FOSC = HSPLL_HS
#pragma config USBDIV = 1
#pragma config IESO = OFF
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config VREGEN = OFF
#pragma config WDT = OFF
#pragma config WDTPS = 32768
#pragma config CCP2MX = ON
#pragma config PBADEN = OFF
#pragma config LPT1OSC = OFF
#pragma config MCLRE = ON
#pragma config STVREN = ON
#pragma config LVP = OFF
#pragma config ICPRT = OFF
#pragma config XINST = OFF
#pragma config DEBUG = OFF
#pragma config WRTD = OFF
//======================= chip config ===================//
//LCD Control pins
#define rs PORTBbits.RB4
#define rw PORTBbits.RB3
#define en PORTBbits.RB2
//LCD Data pins
#define lcdport PORTD
#define lcd_port_dir TRISD
void lcd_clear ( void );
void lcd_2nd_line ( void );
void lcd_1st_line ( void );
void lcd_ini ( void );
void dis_cmd ( unsigned char cmd_value );
void dis_data ( unsigned char data_value );
void lcdcmd ( unsigned char cmdout );
void lcddata ( unsigned char dataout );
void delay_ms ( int delay );
//============================ TIMER 0 ISR =================================//
#pragma interrupt tmr0_interrupt
void tmr0_interrupt(void)
{   unsigned int v = 0;
    ADCON0 |= 0x02;                 // Start A/D conversion
   while ( ADCON0 & 0x02 );        // Wait until conversion gets over


For more detail: How To Use PIC Microcontroller For Voice Input And Output

Current Project / Post can also be found using:

  • pic controller for voice input and output
  • which microcontroller is use for voice input

Leave a Comment

= 5 + 4

Read previous post:
Alarm Clock Retrofit using PIC16F877

I had some beef with my (very) old alarm clock.  It had a radio which was nice to wake up...

Scroll to top