This electronic cricket is a fun project. A real crickets chirp at night and faster in warmer temperatures. A cricket chirp is composed of a group of three sinus waves of a single frequence of about 5kHz. occurring in rapid succession.

Introduction

This electronic cricket is a fun project. A real crickets chirp at night and faster in warmer temperatures. A cricket chirp is composed of a group of three sinus waves of a single frequence of about 5kHz. occurring in rapid succession. Each group of three is one chirp. The rate of the chirp depends on the temperature. 

 

 

Circuit

For this project the ATMega328P is used. It can produce square waves that almost sound as the sinus waves a real cricket make. The circuit itself is very simple, a small loudspeaker of 8ohm/0,5W is connected to portb.1 and ground of the ATMega328P microcontroller.You can build the circuit on a breadboard or use the ATMega328P board. You can buy the ATMega328P board at www.bizztronix.eu.

 

Software

The major difficulty is to program the microcontroller to produce a cricket sound realistic enough. The core of the program is routine that produces a square wave of 5kHz of about 0,6 seconds. This is then repeated 3 times after each other with an interval of 0,4 seconds, and then the three waves are repeated again with an delay of 1 second. You can tweak the sound by adjusting the delays and the repeats in the for loops. 

 

// program: electronic cricket
// last update: 15.09.2017
// author: www.avrprojects.net
// target device: atmega328
// harware: ATMEGA328 board PWM mode, LED
// software: WinAVR-20100110 compiler

#include <avr/io.h>
#include <util/delay.h> 

int main(void)
{
int i; // 
int t; //
int s; //
DDRB |= (1<<DDB0);// set port B0 for output 

while(1)

{for (s=1;s<4;s=s+1)
    {for (t=1;t<5;t=t+1) 
        {for (i=1;i<25;i=i+1)
            {    
            PINB |= (1<<PINB0); //  toggle PORTB0
            _delay_us(200);
            }
        _delay_us(300);
        }
    _delay_ms(500);
    }
_delay_ms(600);
}
return 1;
}