Ultrasonic Sensor HC-SR04 theremin with control_surface midi library

Total noob here. I managed to build a 12 fader and 4 button arduino midi controller using an Arduino Mega 2560, the Mocolufa USB library and Surface_control library after some tweaking here and there.

  1. Now i'am trying to add the Ultrasonic sensor as a pitch bend device (Theremin like) The idea is that when i push a button the sensor will start transmitting pitch bend information.

I downloaded some theremin projects but i can not make sense how to implement this in my actual code.

  1. Also I would like to have two buttons that would let me change between for example 3 midi channels. So i can assign my controller to different instruments and parameters (those 12 faders with the midi change channel would control another instrument).

I would appreciate any help.

This is the actual code i'am using for mi arduino midi controller

#include <Control_Surface.h> // Include the Control Surface library

// Instantiate a MIDI over USB interface.
USBMIDI_Interface midi;

// Instantiate an array of CCPotentiometer objects
CCPotentiometer potentiometers[] = {
  {A0, 0x46},
  {A1, 0x47},
  {A2, 0x48},
  {A3, 0x49},
  {A4, 0x4A},
  {A5, 0x4B},
  {A6, 0x4C},
  {A7, 0x4D},
  {A8, 0x4E},
  {A9, 0x4F},
  {A10, 0x50},
  {A11, 0x51},

CCButton buttons[] {
  {3, 0x5B}, // pin, note number
  {4, 0x5C},
  {5, 0x5D},
  {6, 0x5E < },
void setup() {
  Control_Surface.begin(); // Initialize Control Surface

void loop() {
  Control_Surface.loop(); // Update the Control Surface
1 Like

To send pitch bend messages, use [

midi.sendPB(CHANNEL_1, value)

](Control Surface: MIDI_Sender< Derived > Class Template Reference). Note that the value is unsigned, the range is [0, 2¹⁴-1] = [0, 16383].
All other theremin-related code should be independent of which library you use for MIDI output.

That would be done using banks. See this FAQ entry and the examples it links to.


Thank you Pieter, will take a look.!

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.