The Alpha Geek – Geeking Out

Project #22: Synthesizer – Theremin – Mk02

——

#DonLucElectronics #DonLuc #Synthesizer #Theremin #Arduino #ArduinoProMini #Project #Fritzing #Programming #Electronics #Microcontrollers #Consultant

——

Theremin

——

Theremin

——

Theremin

——

Theremin

The theremin was invented in 1920 by a Russian physicist named Lev Termen. Today, this marvelous instrument is once again in the musical spotlight. Besides looking like no other instrument, the theremin is unique in that it is played without being touched.

Two antennas protrude from the theremin, one controlling pitch, and the other controlling volume. As a hand approaches the vertical antenna, the pitch gets higher. Approaching the horizontal antenna makes the volume softer. Because there is no physical contact with the instrument, playing the theremin in a precise melodic way requires practiced skill and keen attention to pitch. The electric signals from the theremin are amplified and sent to a loudspeaker.

In the late 1920’s, RCA produced approximately 500 theremins, manufactured by General Electric and Westinghouse. Today, it is estimated that only half of these still exist. The spooky sound of the theremin was used in several movie soundtracks during the 1950’s and 1960’s. Electronic music pioneer Robert Moog built theremins long before he built synthesizers. In the 1960’s, he produced such models as the wedge-shaped Vanguard theremin and the shoebox shaped Moog Melodia theremin. It provided background mood music for such sci-fi classics. During the 60’s and 70’s, bands such as Lothar and the Hand People, the Bonzo Doo Dah Dog Band, and Led Zeppelin brought the theremin into the public eye for a short time.

Theremin + Arduino Pro Mini + Ultrasonic Sensor + Mozzi

Arduino Pro Mini does not come with connectors populated so that you can solder in any connector or wire with any orientation you need. This is the ultrasonic distance sensor. This economical sensor provides 2cm to 400cm of non-contact measurement functionality. The ultrasonic range detectors replace the antenna of the traditional Theremin. Control the frequency (pitch) of the output. Operation of the sensor is straightforward. The Arduino sends a digital pulse to the TRIG pin of the sensor causing it to emit a burst of high frequency audio. If an echo is detected the sensor toggles the ECHO pin which is monitored by the Arduino. By measuring the time delay between the outgoing pulse and returning echo we can calculate the distance. As sound takes 29 microseconds to travel one cm, and must travel out and back, we can divide the time to the echo by 5.8 to get the distance in mm. The project uses the Mozzi audio library to generate a sine table for oscillator which is sent to the output.

DL2203Mk01

1 x Arduino Pro Mini 328 – 5V/16MHz
1 x SparkFun FTDI Basic Breakout – 5V
1 x HC-SR04 Ultrasonic Sensor
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable

Arduino Pro Mini 328 – 5V/16MHz – Receiver

Ech – Digital 13
Tri – Digital 12
SPK – Digital 9
VIN – +5V
GND – GND

DL2203Mk01p.ino

/* ***** Don Luc Electronics © *****
Software Version Information
Project #22: Synthesizer - Theremin - Mk02
22-02
DL2203Mk01p.ino
1 x Arduino Pro Mini 328 - 5V/16MHz
1 x SparkFun FTDI Basic Breakout - 5V
1 x HC-SR04 Ultrasonic Sensor
1 x Audio Jack 3.5mm
1 x SparkFun Audio Jack Breakout
1 x Hamburger Mini Speaker
1 x Full-Size Breadboard
1 x SparkFun Cerberus USB Cable
*/

// Include the Library Code
// Mozzi
#include <MozziGuts.h>
// Oscillator template
#include <Oscil.h>
// Sine table for oscillator
#include <tables/sin2048_int8.h>
// Rolling Average
#include <RollingAverage.h>
// Control Delay
#include <ControlDelay.h>

// Control Rate
#define CONTROL_RATE 64
// Echo Cells
unsigned int echo_cells_1 = 32;
unsigned int echo_cells_2 = 60;
unsigned int echo_cells_3 = 127;
// Contro lDelay = 2 seconds
ControlDelay <128, int> kDelay; 
// Oscils to compare bumpy to averaged control input
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin0(SIN2048_DATA);
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin1(SIN2048_DATA);
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin2(SIN2048_DATA);
Oscil <SIN2048_NUM_CELLS, AUDIO_RATE> aSin3(SIN2048_DATA);
// RollingAverage <number_type, how_many_to_average> myThing
// How many to average has to be power of 2
RollingAverage <int, 32> kAverage;
int averaged;

// Trigger pin 12 to pitch distance sensor
const int iTrigPitch = 12;
// Echo Receive pin 13 to pitch distance sensor
const int iEchoPitch = 13;
// Stores the distance measured by the distance sensor
float distance = 0;

// Mini Speaker
int SPK = 9;

// Set the input for the volume
// Volume level from updateControl() to updateAudio()
byte vol;

// Software Version Information
String sver = "22-02";

void loop() {

  // Audio Hook
  audioHook();
  
}

getHC-SR04.ino

// HC-SR04 Ultrasonic Sensor
// Setup HC-SR04
void setupHCSR04() {

  // The trigger iTrig will output pulses of electricity
  pinMode(iTrigPitch, OUTPUT);
  // The echo iEcho will measure the duration of pulses coming back from the distance sensor
  pinMode(iEchoPitch, INPUT);
  
}
// Distance
float isDistance() {
  
  // Variable to store the time it takes for a ping to bounce off an object
  float echoTime;
  // Variable to store the distance calculated from the echo time
  float calculatedDistance;

  // Send out an ultrasonic pulse that's 10ms long
  digitalWrite(iTrigPitch, HIGH);
  delayMicroseconds(10);
  digitalWrite(iTrigPitch, LOW);

  // Use the pulseIn command to see how long it takes for the
  // pulse to bounce back to the sensor
  echoTime = pulseIn(iEchoPitch, HIGH);

  // Calculate the distance of the object that reflected the pulse
  // (half the bounce time multiplied by the speed of sound)
  // cm = 58.0
  calculatedDistance = echoTime / 58.0;

  // Send back the distance that was calculated
  return calculatedDistance;
  
}

getMozzi.ino

// Mozzi
// Update Control
void updateControl(){

  // Volume
  vol = 255;
  // Variable to store the distance measured by the sensor
  distance = isDistance();
  int bumpy_input = distance;
  // Averaged
  averaged = kAverage.next(bumpy_input);
  aSin0.setFreq(averaged);
  aSin1.setFreq(kDelay.next(averaged));
  aSin2.setFreq(kDelay.read(echo_cells_2));
  aSin3.setFreq(kDelay.read(echo_cells_3));

}
// Update Audio
int updateAudio()
{

  // Update Audio
  return 3*((int)aSin0.next()+aSin1.next()+(aSin2.next()>>1)
    +(aSin3.next()>>2)) >>3;

}

setup.ino

// Setup
void setup() {

  // Setup HC-SR04
  setupHCSR04();

  // Echo Cells 1
  kDelay.set(echo_cells_1);

  // Mozzi Start
  startMozzi();

}

——

People can contact us: https://www.donluc.com/?page_id=1927

Technology Experience

  • Single-Board Microcontrollers (PIC, Arduino, Raspberry Pi,Espressif, etc…)
  • IoT
  • Robotics
  • Camera and Video Capture Receiver Stationary, Wheel/Tank and Underwater Vehicle
  • Unmanned Vehicles Terrestrial and Marine
  • Research & Development (R & D)
  • Desktop Applications (Windows, OSX, Linux, Multi-OS, Multi-Tier, etc…)
  • Mobile Applications (Android, iOS, Blackberry, Windows Mobile, Windows CE, etc…)
  • Web Applications (LAMP, Scripting, Java, ASP, ASP.NET, RoR, Wakanda, etc…)
  • Social Media Programming & Integration (Facebook, Twitter, YouTube, Pinterest, etc…)
  • Content Management Systems (WordPress, Drupal, Joomla, Moodle, etc…)
  • Bulletin Boards (phpBB, SMF, Vanilla, jobberBase, etc…)
  • eCommerce (WooCommerce, OSCommerce, ZenCart, PayPal Shopping Cart, etc…)

Instructor and E-Mentor

  • IoT
  • PIC Microcontrollers
  • Arduino
  • Raspberry Pi
  • Espressif
  • Robotics
  • DOS, Windows, OSX, Linux, iOS, Android, Multi-OS
  • Linux-Apache-PHP-MySQL

Follow Us

J. Luc Paquin – Curriculum Vitae – 2022 English & Español
https://www.jlpconsultants.com/luc/

Web: https://www.donluc.com/
Web: https://www.jlpconsultants.com/
Facebook: https://www.facebook.com/neosteam.labs.9/
YouTube: https://www.youtube.com/channel/UC5eRjrGn1CqkkGfZy0jxEdA
Twitter: https://twitter.com/labs_steam
Pinterest: https://www.pinterest.com/NeoSteamLabs/
Instagram: https://www.instagram.com/neosteamlabs/

Don Luc

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories
Archives