Project tutorial

Doorbell © LGPL

Using eeprom as sound source

  • 2,484 views
  • 0 comments
  • 9 respects

Components and supplies

About this project

A doorbell project for Arduino Uno with ATMEGA328P device. The EEPROM 24C512 is 512Kbits and it can store up to 3 seconds wave file of 22.050KHz, 8 bits, mono.

The Arduino reads the ROM bytes in a sequential read mode and stream each byte to the PWM generator at a rate of about 22 KHz. The I2C bus works at 200 KHz for the purpose of managing to process 22 Kbits per second. Changing the bus frequency changes the speed of the sound.

The transistors are a push-pull buffer for driving the speaker, any replacement can be used.

The I2C lib doesn't have a function for sequential read, so I added a routine.

To convert sound file to hex do this:

Convert sound file to .wav PCM 22.050KHz, 8 bits, mono

Change the file name extension from wav to bin.

Load the bin file to the EEPROM Programmer.

Schematics

Code

eeprom_bell.inoC/C++
/*
 * eeprom_bell.ino
 *
 * Created: 30/06/2017 23:34:47
 *  Author: moty22.co.uk
 */ 
#include <Wire.h>


const int ampON = 8;          // switch supply to amplifier
const int audio = 6;     //output D6
const int ring = A2;     //ring pushbutton
int ringPB=1;         // ring pushbutton status

void setup() {
  // put your setup code here, to run once:
pinMode(ampON, OUTPUT);
//pinMode(audio, OUTPUT);
pinMode(ring, INPUT_PULLUP);

  //PWM Timer0
OCR0A = 64;
TCCR0A = _BV(COM0A1) | _BV(WGM01) | _BV(WGM00);  //output in phase, fast PWM mode
TCCR0B = _BV(CS00); // 16MHz/256 = 64KHz
pinMode(audio, OUTPUT);


Wire.begin();        // init i2c bus
Wire.setClock(200000);  //200khz

digitalWrite(ampON, LOW); 

}



void loop()
{
    unsigned int i;
    
    ringPB=digitalRead(ring);
    if(ringPB==LOW)   //pushbutton
     {
      digitalWrite(ampON, HIGH);

          //go to address 0
      Wire.beginTransmission(0x50);
      Wire.write((int)(0));   //MSB of eeprom address
      Wire.write((int)(0)); // LSB
      Wire.endTransmission();


       //start sequential read
      TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); //start command
      while (!(TWCR & (1<<TWINT)));   //till interrupt 
        //write address
      TWDR = 0b10100001;    //address+read
      TWCR = (1<<TWINT)|(1<<TWEN);
      while (!(TWCR & (1<<TWINT)));   //till interrupt 
    
          //read all the bytes
      for (i=0; i<0xfff0; i++)
      {
         //send ACK
        TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWEA);
        while (!(TWCR & (1<<TWINT)));
        OCR0A =  TWDR;      //PWM = eeprom data
      }  
    
        //send NACK, no-aknowledgement + stop commands ends reading
      TWCR = (1<<TWINT)|(1<<TWEN);
      while (!(TWCR & (1<<TWINT)));
      OCR0A =  TWDR;  
      
        //stop
      TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN);  

       digitalWrite(ampON, LOW);
     }
     
}

Comments

Similar projects you might like

Guess the Number With Arduino KeyPad

Project tutorial by Giovanni Gentile

  • 80 views
  • 2 comments
  • 3 respects

Control a 7 Segment Display with a keypad!

Project tutorial by Isaac100

  • 109 views
  • 2 comments
  • 2 respects

Launch Pad Count Down Sequence Display

Project in progress by Douglas Frey

  • 88 views
  • 0 comments
  • 2 respects

Know the Temp of Your Home From Anywhere with Arduino Cloud!

Project tutorial by Isaac100

  • 2,011 views
  • 2 comments
  • 11 respects

Safe City: A Device to Keep You Safe

Project tutorial by Patel Darshil

  • 1,297 views
  • 0 comments
  • 9 respects

Water Softener

Project tutorial by moty

  • 661 views
  • 0 comments
  • 7 respects
Add projectSign up / Login