FruitPiano

Introduction

FruitPiano is an interactive project that turns 8 fruits into piano keys — each one triggering a specific musical note. When a fruit is touched, the system plays the corresponding sound and displays the note on an LCD screen. An additional feature is a recording mode, allowing users to save and replay up to five custom melodies.

The project aims to create an unconventional, educational, and engaging musical instrument by applying key concepts learned in microcontroller laboratories. It combines capacitive touch detection with real-time audio, visual, and textual feedback to deliver a rich user experience.

FruitPiano stands out by blending play and learning — making it ideal for tech demos, creative presentations, or hands-on STEM education.

General Description

Hardware Modules

Arduino Uno - Main control unit. It receives input from all sensors (capacitive touch, push button) and drives all outputs (buzzer, LEDs, LCD display).

Fruits (Capacitive Sensors) - Each fruit acts as an individual capacitive touch sensor. Touching a fruit changes the capacitance, which is detected via dedicated sensing pins.

Buzzer - A passive buzzer is used to produce musical tones. Each fruit corresponds to a unique frequency played using PWM.

16×2 LCD Display (I2C) – Provides textual feedback by displaying the current note or system state (e.g., recording, playback). It uses the I²C interface to save digital pins.

Record Button – Toggles recording mode on/off. When active, all notes and pauses are stored sequentially into memory.

Playback Button – Allows the user to sequentially replay previously recorded melodies (up to five), navigating through them one by one.

Record Indicator LED – Lights up to show when the system is in recording mode. Turns off when exiting record mode or after automatic save.

Interaction Flow

1. The user touches a fruit

 → Capacitive sensor detects input  
 → Arduino identifies which fruit was touched  
 → Plays corresponding tone on buzzer  
 → Displays note name on the LCD

2. If recording mode is active (LED ON):

 → Each touched note is stored with its duration  
 → Any pause (time between touches) is also measured and saved  
 → Recording stops when the user presses the record button again  
    OR when the maximum number of notes is reached (auto-save)

3. When the playback button is pressed (and recording is OFF):

 → The system plays the most recent saved melody  
 → Notes and pauses are reproduced with original timing  
 → Each press plays the previous melody (up to 5 stored)  
 → If more than 5 recordings are made, the oldest is overwritten

4. The LED indicator:

 → ON when recording is active  
 → OFF when not recording

Block Diagram

Diagramă Arduino UNO - Fruit Piano

Hardware Design

Components Scheme

All pin mappings were chosen to minimize interference, keep I²C free for the display, and allow PWM output for the buzzer. The capacitive sensing uses a shared send pin (D2) and 6 receive pins (D3–D10), each connected via a 1MΩ resistor to the respective fruit. Digital pins A0 and A1 are used for control buttons with internal pull-up configuration. A digital output pin (D12) is used to control an LED as a visual indicator during the recording state.

Components Diagram - Fruit Piano

Pin Configuration

Component Arduino Uno Pin(s) Type Description
Capacitive Input (Fruits) D3 – D10 Digital Input One input pin per fruit (8 total) for detecting touch events
Capacitive Send Pin D2 Digital Output Common send pin used by all capacitive sensors
Buzzer D11 PWM Output Plays audio tones
LCD Display (I2C) A4 (SDA), A5 (SCL) I2C Interface Displays note names and system status
Record Button A1 Digital Input Toggles recording mode on/off (using INPUT_PULLUP)
Playback Button A0 Digital Input Cycles through saved melodies and triggers playback
Recording LED D12 Digital Output Turns on during active recording session

Additional Notes

- Pins A4 and A5 are reserved for the I²C bus and used exclusively by the LCD display.

- D11 was chosen for the buzzer since it supports PWM, but any other PWM-capable digital pin could be used.

- D2 is used as the common send pin for all capacitive sensors; it must remain stable during sensing.

- Buttons are wired using INPUT_PULLUP mode, eliminating the need for external pull-down resistors.

- The system supports up to 5 saved melodies in memory; a recording LED provides visual status.

Bill of Materials (BOM)

Component Description Quantity
Arduino Uno Microcontroller board 1
Passive Buzzer Used for sound output (PWM controlled) 1
LCD 16x2 with I2C Display module with I2C backpack 1
Fruits Capacitive touch input elements 8
Resistors 1MΩ (sensors), 10kΩ (buttons), 220Ω (LED) 10+
Breadboard Solderless prototyping board 1
Jumper Wires Male-male / Male-female as needed ~30
LED Indicates recording mode 1
Push Button (x2) Toggle record / playback 2

Software Design

External Libraries Used

  • CapacitiveSensor.h – used for interfacing with capacitive touch inputs (fruits)
  • LiquidCrystal_I2C.h – used for controlling the I2C LCD display

Code Components

The code is divided into three major components:

  • Capacitive Sensor Handling:
    • Uses 8 capacitive touch channels wired via a 1 MΩ resistor to a common send pin
    • Each sensor is sampled and filtered to detect a valid touch above a dynamic threshold
    • Touch input maps to musical notes from C to C2 (1 octave)
  • LCD Menu & Feedback:
    • Displays start screen, note names during interaction, and messages during recording/playback
    • Guides the user through interactions and displays visual feedback
  • Recorder and Playback System:
    • Allows toggling a record mode using a button
    • Records sequences of notes and durations including pauses
    • Enables playback of stored melodies using another button
    • Stores up to 5 recordings (each with 50 notes max)

Game Flow / Usage Flow

  • On startup: displays “Fruit Piano” and awaits interaction
  • Press 'Record Button (A1)':
    • LED lights up and “Recording…” message is shown
    • Notes touched are stored with their durations and pause intervals
    • Press Record Button again to finish recording
  • Press Play Button (A0):
    • Plays the latest saved recording with screen feedback
    • Pressing repeatedly cycles through older recordings (circular buffer)

Implementation Details

  • Notes are played using tone() on a buzzer while LCD displays the current note
  • Touch detection uses dynamic thresholds per channel (zeroLevel[]) with a decay filter
  • Pauses are recorded using timing gaps between notes
  • Playback logic is non-blocking (except tone delay)
  • tone() is called only when note changes to ensure smooth sound
  • System works with fruit or any capacitive-conductive object

Optimizations

  • tone() only called on note change (avoids glitches)
  • Dynamic zeroLevel[] recalibration prevents drift
  • Filtering avoids false positives and noise
  • LCD updated only on state changes to reduce flicker

Used Labs / Theoretical Foundations

  • Lab 0: GPIO – for buttons and LED control
  • Lab 1: USART – for debugging with Serial Monitor
  • Lab 3: PWM – for generating tones on the buzzer
  • Lab 5: I2C – for LCD screen communication

Results

Conclusion

I’m proud to say I’ve met every requirement—from demonstrating concepts in at least three labs (GPIO, USART, PWM, I²C) to delivering a fully functional Fruit Piano with recording and playback. The project works smoothly, and the process has been a delightful learning experience in sensor calibration. As a bonus, my “hardware” happens to be the most changeable of them all—bananas are wonderfully perishable, so this is about as far from rigid hardware as you can get!

Bibliography

pm/prj2025/iivasciuc/oana.titoc.txt · Last modified: 2025/05/21 20:28 by oana.titoc
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0