Project tutorial

Frequency Counter for Android

Frequency Counter and voltage meter for Android phone or tablet.

  • 1,246 views
  • 3 comments
  • 5 respects

Components and supplies

Apps and online services

About this project

The Android app is made using MIT App Inventor which is an easy way to make Android apps. http://appinventor.mit.edu/explore/ . The app has buttons to connect and disconnect the Bluetooth to the phone and 2 displays of voltage and frequency. The .apk file is the file that installs manually the app to your phone. The .aia file can be imported after you install the MIT App Inventor. The software (1.5 MB) can be downloaded from my website: http://www.moty22.co.uk/sw/android.zip

The Arduino generates an accurate 1 second time base for the counter by cascading timer0 and timer2. The link between digital inputs 3 and 4 connects the output of timer2, 250 Hz, to input of timer0. The software waits for the output of timer0 to go positive to start the count of frequency input to timer1. Timer1 is a 16 bits timer, it overflows at the count of 32768, that in turn advances overFlow register. At the end of the 1 second the 16 bit register is recorded. The Arduino then sends to the Bluetooth 5 bytes of data in serial RS232 protocol.

The Bluetooth module HC-05 can be paired with the phone using the code 1234.

The frequency input is TTL signal levels, for low signal a video amp has to be added. The specs recommend input up to 6 MHz, I tested it at 2 MHz. The voltage input is 0-5VDC.

Schematics

bt_meter
Android counter emo6uus64v

Code

frequency_counterC/C++
/*
 * Blurtooth Frequency Counter
 * Created: 12/08/2017 23:34:47
 *  Author: moty22.co.uk
*/


  unsigned char overF=0;
  unsigned int freq=0;

// the setup function runs once when you press reset or power the board
void setup() {
        // initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
    
          //1 Hz timer
    OCR0A = 249;
    TCCR0A = _BV(WGM00) | _BV(WGM01) | _BV(COM0A0); //   
    TCCR0B = _BV(WGM02) | _BV(CS02) | _BV(CS01);  //  PWM mode, input T0 pin D4
    pinMode(6, OUTPUT);
    
      //250 Hz - timer2
    OCR2A =249;
    OCR2B = 125;  
    TCCR2A = _BV(COM2B1) | _BV(COM2B0) | _BV(WGM21) | _BV(WGM20);  //output B in phase, fast PWM mode
    TCCR2B = _BV(WGM22) | _BV(CS22) | _BV(CS21); // set prescaler to 256 and start the timer
    pinMode(3, OUTPUT);
    
        //  counter input T1 pin D5
    OCR1A = 32767;   //32768 counts
    TCCR1A = _BV(WGM10) | _BV(WGM11) | _BV(COM1A0); //   
    TCCR1B =_BV(WGM12) | _BV(WGM13) | _BV(CS12) | _BV(CS11); //input pin D5
    pinMode(9, OUTPUT);
    
}

  
  // the loop function runs over and over again forever
void loop() {

    while(digitalRead(6)){} //wait for port low 
    while(!digitalRead(6)){} //wait for port high
 
    TIFR1 = _BV(OCF1A);    //reset int
    OCR1A = 65535;  //32767
    TCNT1=0;
    overF=0;
    while(digitalRead(6)){
    if(TIFR1 & (1<<OCF1A)) {++overF; TIFR1 = _BV(OCF1A);}   //overflow 
    }
    freq = TCNT1 ; 

    Serial.write(highByte(analogRead(A1)));  //send low byte of 10 bits analogue read
    Serial.write(lowByte(analogRead(A1))); //send high byte of 10 bits analogue read
    //counter bytes
    Serial.write(overF);
    Serial.write(highByte(freq));
    Serial.write(lowByte(freq));

}

Comments

Similar projects you might like

Version 2.0 Advanced Attendance System (Without Ethernet)

Project tutorial by GadgetProgrammers

  • 2,724 views
  • 5 comments
  • 43 respects

Get The Arduino Dice

by Ingo Lohs

  • 272 views
  • 0 comments
  • 4 respects

Control LED Using Your Voice Command

by IoTBoys

  • 788 views
  • 0 comments
  • 7 respects

Critter: Crawling Arduino Robot

Project showcase by Slant Concepts

  • 5,027 views
  • 10 comments
  • 31 respects

Musical Fairy Lights

Project tutorial by Ian Cumming

  • 556 views
  • 0 comments
  • 4 respects

Cloud Costume

Project tutorial by Monica Houston

  • 1,061 views
  • 3 comments
  • 10 respects
Add projectSign up / Login