Create Your Own FM Radio with Arduino: A Step-by-Step Guide

Great! This article is a step-by-step guide to constructing an FM radio tuner using Arduino, in which two buttons cycle through the channels of an FM radio and a 7-segment display that shows the current frequency.


Materials Required:

  • Arduino Uno
  • TEA5767 FM Radio Module
  • 7-Segment Display (Common Anode or Common Cathode)
  • Two push buttons
  • Resistors: 220Ω for the display; 10kΩ for the buttons
  • Jumper wires
  • Breadboard

Step 1: Wiring the Components

1. Wire the TEA5767 FM Radio Module:

  • SDA data to A4 on Arduino – I2C data line
  • SCL clock to A5 on Arduino – I2C clock line
  • VCC to 5V on Arduino
  • GND to GND on Arduino

2. Now, Connect 7-Segment Display:

In case you have a Common Anode display, connect the anode to 5V with a current-limiting resistor in between.

In case you have a Common Cathode display, connect the cathode to GND with a current-limiting resistor in between.

Now, connect the display segments (a, b, c, d, e, f, g) with Arduino digital pins, say 2-8 for segments a-g. The decimal point, if needed, is connected to another digital pin. 3. Connect the Buttons: Connect one side of every button to GND. Connect the other side of the first button to pin 9 on Arduino. Connect the other side of the second button to pin 10 of Arduino.

Use a 10kΩ pull-up resistor between every button pin and 5V to ensure we get stable readings at the input.

Step 2: Implementing the Code

We'll be using the TimerOne library so that our display is updated non-blocking and the main loop stays free to read the buttons, and the Wire library for I²C communication with the TEA5767 module.


copy code.

 #include <Wire.h>

#include <TimerOne.h>

#include <TM1637Display.h>  // Library for 7-Segment Display


#define CLK 2   // 7-Segment clock pin

#define DIO 3   // 7-Segment data pin

#define BTN_UP 9

#define BTN_DOWN 10


TM1637Display display(CLK, DIO);


int frequency = 1011;  // Start frequency (e.g., 101.1 MHz)


void setup() {

  Wire.begin();

  pinMode(BTN_UP, INPUT_PULLUP);

  pinMode(BTN_DOWN, INPUT_PULLUP);


  display.setBrightness(0x0f);  // Set brightness

  Timer1.initialize(1000000);   // Timer for updating the display

  Timer1.attachInterrupt(updateDisplay);


  setFrequency(frequency);  // Set initial frequency

}


void loop() {

  if (digitalRead(BTN_UP) == LOW) {

    frequency += 1;  // Increment frequency by 0.1 MHz

    if (frequency > 1080) frequency = 1080;  // Max FM frequency

    setFrequency(frequency);

    delay(200);  // Debounce delay

  }


  if (digitalRead(BTN_DOWN) == LOW) {

    frequency -= 1;  // Decrement frequency by 0.1 MHz

    if (frequency < 880) frequency = 880;  // Min FM frequency

    setFrequency(frequency);

    delay(200);  // Debounce delay

  }

}


void setFrequency(int freq) {

  byte frequencyH = (freq * 1000000 + 225000) / 32768 >> 8;

  byte frequencyL = (freq * 1000000 + 225000) / 32768 & 0xFF;

  

  Wire.beginTransmission(0x60);

  Wire.write(frequencyH);

  Wire.write(frequencyL);

  Wire.write(0xB0);

  Wire.write(0x10);

  Wire.write(0x00);

  Wire.endTransmission();

}


void updateDisplay() {

  int displayFreq = frequency / 10;

  display.showNumberDec(displayFreq, true);

}

Step 3: Explanation of the Code

Libraries:

Wire.h: This library is used to interface I2C communication with the TEA5767 FM module.
TimerOne.h: This manages non-blocking timed events; it is used to update the display regularly while checking the state of the buttons.
TM1637Display.h: This controls the 7-segment display.

Setting up the Frequency:

The frequency will be stored as an integer; for example, 1011 would be 101.1 MHz.
The setFrequency(int freq) function works out what high and low bytes are needed by the TEA5767 to receive the correct frequency

Button Handling:

It checks whether either button has been pressed. In the event of the 'up' button being pressed, it increases the frequency by 0.1 MHz, and in the event of the 'down' button, it decreases the frequency by 0.1 MHz.
It is constrained within the FM radio range: from 88.0 to 108.0 MHz.

Display Update:

The updateDisplay() function gets called from the TimerOne interrupt. This function updates the current frequency on the 7-segment display.
This is division by 10 to cancel out the decimal for display. The display library controls display of the digits coming up on the 7-segment.


Step 4: Uploading and Testing


  • Upload the Code to the Arduino using the Arduino IDE.
  • Test the Buttons: Press the up and down buttons, this will cause a change in the FM radio frequency.
  • Observe the Display: The display in 7-segment shall be indicative of the current frequency and will change as one presses the buttons.

Conclusion


You have just created an FM radio tuner using Arduino; it changes the frequency using two buttons and displays the current channel using a 7-segment display. This project shall enable you to practice many of the Arduino capabilities: I2C communications, timed interrupts, digital input/outputs.

This tutorial is more than functional; it acts as an example of how you can use hardware components with Arduino in the creation of practical and interactive electronics projects.

Post a Comment

Previous Post Next Post