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. For this project the attiny2313 is used. It can produce square waves that almost sound as the sinus waves a real cricket make.

Circuit

The circuit itself is very simple, a small loudspeaker of 8ohm/0,5W is connected to portb.1 and ground of the Attiny2313 microcontroller.You can build the circuit on a breadboard or use the ATTiny2313 board. You can buy the ATTiny2313 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
// target device: attiny2312
// date: 01-11-2012

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

int main(void)
{
int i; int t; int s;
DDRB=0xFF;// set port B 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)
{PORTB =1;
_delay_us(200);
PORTB =0;
_delay_us(200);}
_delay_us(300);}
_delay_ms(500);}
_delay_ms(600);}
return 1;
}

 

 Video