Controlling A Sequence With A Force Sensor

For this project, I borrowed a force sense from a class mate and sought to use it to control pitch. Once I had the sensor’s values mapped to a variable within the audible range, I decided to test out my circuit by making a sequence of notes played out of a speaker.

For this, I used the tone function with the variable as my frequency and then multiplied that fundamental frequency by multiples of 1.06 to get other note values, as I new that one half step on a keyboard is 6% higher in frequency than the previous note. So (1.06*2) is a second, (1.06*3) is a third, and so on. To get a sequence of notes, one played after the other, I used the delay function in even intervals. So then when I pressed the force sensor, I was able to move the overall pitch of the sequence up together as it cycled through. Here is videos of each step and the final code is for the sequence.

Using a force sensor to control the pitch of a frequency played through a speaker.

Using a Force Sensor on an Arduino to Control a Sequence.

//how to make a force sensor control the pitch of a sequence
// patch the force sensor to A0 and ground, and the speaker D12

void setup() {
  // put your setup code here, to run once:
  pinMode(12, OUTPUT);
Serial.begin(9600);
}

void loop() {
  // read the analog input;
  int sensorReading = analogRead(A0);
// convert from ADC reading to voltage
  float voltage = sensorReading * (5.0 / 1024.0);

   tone(12, voltage*100);
   delay(10);
   tone(12, voltage*100*(2*1.06));
   delay(10);
   tone(12, voltage*100*(3*1.06));
   delay(50);
   tone(12, voltage*100*(4*1.06));
   delay(100);
   tone(12, voltage*100*(2*1.06));

  Serial.print(voltage);
  Serial.print("\t");
  Serial.println(sensorReading);

}