Motors and Tone Labs

The lab involving the servo motor was not that different from what we did in class, though I was confused by the addition of a 2nd variable resistor. The lab explains its purpose to an extent, but I wasn’t able to parse what it meant. The lab was easy to get working, however.

Servo Motor Lab from Ian Gibson on Vimeo.

It’s interesting to think about the ways in which the 180 degree motion of the servo can be built upon to create all sorts of interesting movements. I did not have a chance to experiment with the servo to any great degree this week, but will be returning to it when I find the time.

The tone lab probably would have been as easy if I had stuck to the script, but I did not for the last part. That said, the first two parts were fairly simple, and I ran into no major issues.

FSR and Tone from Ian Gibson on Vimeo.

Melody from Ian Gibson on Vimeo.

During the last part, I veered from the suggested three button keyboard a bit. I used that concept as an avenue to explore how different types of variable resistors might be used to create a musical instrument. Instead of three FSRs, I used one FSR, one photoresistor, and one potentiometer. The first issue I ran into is that the code given in the lab would not work with the values of these resistors, and the lab didn’t really explain what the code was doing very clearly (which was actually one of the main sources of frustration for me). After using the analogRead() and print() functions to determine the range of the photoresistor (which was the one giving me the most trouble), I had a better idea of what would be needed. The value of the photoresistor would need to be under a certain threshold, not above it, in order to work properly in this context.

Additionally, it became apparent to me that the code was specific to FSRs, where the resistance will naturally fall below 10 when released. With the potentiometer, this isn’t true unless the knob is physically moved back to 0. This meant that the FSR would not completely change the note unless the potentiometer was reset before pushing it. If it wasn’t, the note would immediately change back to the one mapped to the potentiometer.

Despite experimenting quite a bit, I was not able to get the photoresistor to work at all. I’m going to continue trying, and hope to have a fully-functional 3 component instrument to show tomorrow, but we’ll see what I am able to do. This exercise helped me think about the unique coded needed to produce sound with each component, and to consider how the interaction would change with each in the context of a musical instrument.

Attempt at Musical Instrument from Ian Gibson on Vimeo.

Code for the instrument:

#include "pitches.h"

const int threshold = 10;
const int photoThreshold = 500;
const int speakerPin = 3; 
const int noteDuration = 20; 

int notes[] = {
 NOTE_A4, NOTE_B4,NOTE_C3 };

void setup() {
}

void loop() {
 for (int thisSensor = 0; thisSensor < 3; thisSensor++) {
   int sensorReading = analogRead(thisSensor);
     if (thisSensor = 0){
      if (sensorReading > threshold) {
       tone(speakerPin, notes[thisSensor], 20);
 } 
 } else if (thisSensor = 1) {
     if (sensorReading < photoThreshold) {
      tone(speakerPin, notes[thisSensor], 20);
 } else if (thisSensor = 2) {
     if (sensorReading > threshold) {
      tone(speakerPin, notes[thisSensor], 20);
 }
 }
 }
 }
 }

Leave a Reply

Your email address will not be published.