Projects / Adjustable tone generator

Adjustable tone generator

Beginner1.5 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. UNO

    Wire the pot

    Outer legs to 5V and GND, middle to A0.

  2. UNO

    Wire the display

    SDA to A4, SCL to A5, VCC to 5V, GND to GND.

  3. UNO

    Wire the buzzer

    Plus to D8, minus to GND.

  4. UNO

    Upload the sketch

    The display shows the title and a frequency.

  5. UNO

    Turn the pot slowly

    The pitch rises and the number follows.

  6. UNO

    Turn to each end

    Near 100 Hz and near 5000 Hz.

  7. UNOHelloPCF8574

    Adjust the screen contrast

    Use the small screw on the backpack if text is faint.

  8. UNO

    Try changing the range

    Edit 100 and 50 in the formula.

In short

How do you build an adjustable tone generator?

A potentiometer sets a tone from 100 Hz to 5 kHz, with the frequency shown on a character display. You need Arduino Uno R3, Potentiometer 10 kΩ, 16x2 LCD with I2C backpack (PCF8574), Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 90 minutes.

Level
Beginner
Time
About 90 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Pot outer legsUno 5V and GNDVoltage divider
Pot middle legUno A0Frequency control
LCD backpack SDAUno A4I2C data
LCD backpack SCLUno A5I2C clock
LCD backpack VCC and GNDUno 5V and GNDPower
Passive buzzer plusUno D8Tone output
Passive buzzer minusUno GNDGround

Code

The tone() function makes a square wave at the frequency you give it on the chosen pin, so a passive buzzer or small speaker sounds that note. Human hearing judges pitch on a logarithmic scale: going from 100 to 200 Hz sounds like the same step as 1000 to 2000 Hz. A straight linear map from pot to frequency would squash all the low notes into a tiny part of the turn. The sketch uses an exponential formula, 100 x 50 to the power of the pot position, so the pitch feels even across the dial and ends at 5000 Hz. The display only updates when the value changes by more than 5 Hz to avoid flicker. You need a passive buzzer here, because an active buzzer has its own oscillator and makes a single fixed tone whatever you send. Keep the volume modest, as high tones can be tiring. Add a button to step through musical notes, such as A at 440 Hz, as an extension.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);       // try 0x3F if the screen stays blank
const int POT = A0;
const int BUZZER = 8;

int lastShown = -1;

void setup() {
  lcd.init();
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Tone generator");
}

void loop() {
  int raw = analogRead(POT);
  // Exponential mapping sounds even: each turn step is a similar musical step
  float freq = 100.0 * pow(50.0, raw / 1023.0);   // 100 Hz to 5000 Hz
  int f = (int)freq;

  tone(BUZZER, f);

  if (abs(f - lastShown) > 5) {                   // update only on real change
    lcd.setCursor(0, 1);
    lcd.print("                ");
    lcd.setCursor(0, 1);
    lcd.print(f);
    lcd.print(" Hz");
    lastShown = f;
  }
  delay(30);
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Pot at minimumAbout 100 Hz
Pot at middleAbout 700 Hz
Pot at maximumAbout 5000 Hz
Turn slowlySmooth pitch change
Screen blankChange the address to 0x3F

If it does not work

Screen blank

Try address 0x3F and adjust the contrast screw.

No sound

Check the buzzer is passive and on D8.

Pitch jumps

Add a 100 nanofarad capacitor from A0 to GND.

Display flickers

Increase the 5 Hz change threshold.

Library not found

Install LiquidCrystal I2C from the Library Manager.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the adjustable tone generator?

Arduino Uno R3, Potentiometer 10 kΩ, 16x2 LCD with I2C backpack (PCF8574), Passive buzzer, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the adjustable tone generator take to build?

About 90 minutes for a beginner maker, in 8 steps.

How do I know the adjustable tone generator works?

Pot at minimum: About 100 Hz. Pot at middle: About 700 Hz. Pot at maximum: About 5000 Hz.

Screen blank: what should I check?

Try address 0x3F and adjust the contrast screw.

No sound: what should I check?

Check the buzzer is passive and on D8.

Pitch jumps: what should I check?

Add a 100 nanofarad capacitor from A0 to GND.

Display flickers: what should I check?

Increase the 5 Hz change threshold.