Raspberry Pi 3 :: Sonic Volume Adjustment 🔊
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
img
lib
.gitignore
README.md
index.js
package.json

README.md

Raspberry Pi 3 :: Sonic Volume Adjustment 🔊

A little RPi3 project. Having some fun with RPi3, sensors and ES6/Node.js

Breadboard / Wiring / Physics / Math

Fritzing

Basically, these are two components: Dual-Colour LED + Ultrasonic Ranging Sensor wired together. LED colours mix (red & green) and brightness controlled by PWM, Ultrasonic Ranging Module sends sound impulses and gets the echo (low level) so knowing the time difference between sending and receiving signal we could calculate the distance distance = (high level time * velocity of sound) / 2 (*1) (actually the speed of sound depends on the air temperature [and other factors], but for purposes of simplicity I assume that it is a constant - 343.59 m/s, as for 20°C). After calculating the distance we have to convert the number of cm to the dB in range accepted by amixer command (in our case -2400 — 400 for -24dB - 4dB). To do so I'll use Range Mapping implemented in linear-conversion library. And as the result we call a shell command amixer cset numid=1 -- <volume> setting the output volume of the speaker connected through 3.5mm stereo jack. And voilà: you've got yourself a sonic volume adjustment system.

(*1) Constant 2 here means sound does a double path (from and than back to the module, being reflected from the obstacle)

Components closer look: T-Cobbler & Breadboard Ultrasonic Ranging Sensor Dual-Colour LED

Usage

# First: Run mplayer with any station (See: Links)
mplayer -playlist http://s7.nexuscast.com/tunein/247christmasheaven.pls

# Second: run the script. Note the sudo:
sudo node index.js

# Third: adjust the volume with your hand (~ 30cm above the sensor)
# Option 1: wave on desired height
# Option 2: put your hand above the sensor and move it up & down
#
# DONE! :)

Links

Radio Stations

tunein.com

shoutcast.com

radio.net

Semantic Commits