stevie135s
Published © LGPL

Android controlled bluetooth radio

RDA5807 radio module with bluetooth phone app control

BeginnerWork in progress250
Android controlled bluetooth radio

Things used in this project

Hardware components

Arduino esp32 WROOM32
×1
RDA5807M
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

FMRadio app V2

Schematics

ESP32FMRadio

The circuit diagram..

Code

FMRadioV2

Arduino
Flash the esp using the Arduino IDE
#include <BluetoothSerial.h>
#include <Arduino.h>
#include <Wire.h>
#include <RDA5807M.h>


#define FIX_BAND RADIO_BAND_FM   
#define BT_DISCOVER_TIME  10000

BluetoothSerial SerialBT;
RDA5807M radio;

int stations[12] = {9110,9370,9580,9670,9740,9890,9890,10110,10280,10480,10540,10760};
int action = -1;
static bool btScanAsync = true;
static bool btScanSync = true;
int Volume = 8;
//int convert1 = 0;
float convert = 0;
void setup() {
//String myString = "";  
  Serial.begin(115200);
  SerialBT.begin("ESP32FMRadio"); //Bluetooth device name
  Serial.println("The device started, now you can pair it with bluetooth!");


  if (btScanAsync) {
    Serial.print("Starting discoverAsync...");
    if (SerialBT.discoverAsync(btAdvertisedDeviceFound)) {
      Serial.println("Findings will be reported in \"btAdvertisedDeviceFound\"");
      delay(10000);
      Serial.print("Stopping discoverAsync... ");
      SerialBT.discoverAsyncStop();
      Serial.println("stopped");
    } else {
      Serial.println("Error on discoverAsync f.e. not workin after a \"connect\"");
    }
  }
  
  if (btScanSync) {
    Serial.println("Starting discover...");
    BTScanResults *pResults = SerialBT.discover(BT_DISCOVER_TIME);
    if (pResults)
      pResults->dump(&Serial);
    else
      Serial.println("Error on BT Scan, no result!");
  }


  radio.init();
  radio.setBandFrequency(FIX_BAND, 9110);
  radio.setVolume(Volume);
  radio.setMono(false);
  radio.setMute(false);
}

void loop() {
  action = SerialBT.read();
  if (action > 0) {
    if (action < 11) {
      convert = stations[action];
      convert = convert / 100;

      String myString = String (convert,1);
      if (myString.length() == 4) {
        myString = (myString + " ");
      }
  
      Serial.println(myString );
      SerialBT.print(myString);
      radio.setBandFrequency(FIX_BAND, stations[action]);
 }
else {
  switch (action){
  case 11:
    if (Volume >0) {
    Volume --;
  radio.setVolume(Volume);
  }
  break;

  case 12:
    if (Volume < 15) {
    Volume ++;
    radio.setVolume(Volume);
      }
   break;
   
  case 13:
  radio.seekDown();
  break;

  case 14:
  radio.seekUp();
  break;

  case 15:
  convert = radio.getFrequency();
  convert = convert / 100;
  String myString = String (convert,1);
      if (myString.length() == 4) {
        myString = (myString + " ");
      }
  Serial.println(myString);
  SerialBT.print(myString);
  break;
  }
}

  }
}


void btAdvertisedDeviceFound(BTAdvertisedDevice* pDevice) {
  Serial.printf("Found a device asynchronously: %s\n", pDevice->toString().c_str());
}

Credits

stevie135s

stevie135s

13 projects • 1 follower

Comments