Hi, How Are You - Not Totally Functional (But It's Okay)

Recently, I have been going through my record collection and came across the album “Hi, How Are You” by Daniel Johnston. On the cover there is an interesting little frog creature; I wanted to make this weeks assignment based around this frog. I decided to try my hand at using the laser cutter to make the frog since I haven’t used it before. The process of creating the file and using the actual laser cutter was much easier than I had previously thought and quite enjoyable. The finished cut is shown below.

20181003_103525.jpg

I wanted to make it interactive so I decided to use a noise detection sensor as the input and have the frog react by making its eyes light a few different colors and having it pivot when a person spoke to it. these actions required:

1 - FC-04 Sound Sensor

1 - Servo

2 - RGB LEDs

6 330 ohm resistors

The schematic is shown below:

 Figure 1. Responsive album schematic

Figure 1. Responsive album schematic

(Fritzing did not have the exact noise sensor schematic piece so I substituted and left the NC of the chosen piece open)

20181004_114237.jpg

After creating the circuit I began to try and fine tune the noise sensor. Documentation I read online said that it’s internal potentiometer was very sensitive and if the voltage tigger point (VTP) was not in the exact right spot then the sensor’s voltage would get stuck at either HIGH or LOW and trigger the output immediately without any smooth transition. I was able to see this problem immediately when I began running and debugging my code.

It turned out that the sound sensor would continually cause me problems no matter what I had sent the potentiometer to. Retrospectively, I should have had a backup sensor that I knew would work but given that I didn’t give myself the time necessary to pivot and work the project in another direction. It is possible that there were other self-driven errors which caused the sensor to not function properly as well. Given the nature of the issue and the fact that I wasn’t able to fix it, I didn’t take the project as far as I wanted to in terms of functionality and casing but am going to keep playing with the sensor and seeking outside help to see if the error is an oversight on my part.

CODE:

#include <Servo.h>
int soundSensor = A0;
Servo servoMotor;
int servoPin = 3;
int LED1_red = 4;
int LED1_green = 5;
int LED1_blue = 6;
int LED2_red = 7;
int LED2_green = 8;
int LED2_blue = 9;
int sensorVal = 0;
void setup() {
  //set sound sensor to input
  pinMode(soundSensor, INPUT);
  //set rgb led pins to outputs
  pinMode(LED1_red, OUTPUT);
  pinMode(LED1_green, OUTPUT);
  pinMode(LED1_blue, OUTPUT);
  pinMode(LED2_red, OUTPUT);
  pinMode(LED2_green, OUTPUT);
  pinMode(LED2_blue, OUTPUT);
  servoMotor.attach(servoPin);
  Serial.begin(9600);
}
void loop() {
  // read the noise sensor and set it equal to sensorVal
  sensorVal = analogRead(soundSensor);
  Serial.println(sensorVal);
  //map sensor value to a smaller range
  int sensorRead = map(sensorVal, 0, 1023, 0, 179);
  //Serial.println(sensorRead);
  digitalWrite(LED1_green, HIGH);
  // digitalWrite(LED2_red, HIGH);
   //read the servopin
  int analogValue = analogRead(servoPin);
  //map the servo to an angle
  int servoAngle = map(analogValue, 0, 1023, 0, 179);
  if ( sensorRead > 500 ) {
    servoAngle ++;
  }
  else if (sensorVal < 500) {
    //    servoMotor.write(servoAngle -= 1);
    servoAngle --;
  }
  servoMotor.write(servoAngle);
  //write green LED high if the servo's angle is > 90
  if (servoAngle > 90) {
    delay(50);
    digitalWrite(LED1_green, HIGH);
    delay(50);
    digitalWrite(LED2_green, HIGH);
  }
  //set all leds low otherwise
  else {
    digitalWrite(LED1_green, LOW);
    digitalWrite(LED1_blue, LOW);
    digitalWrite(LED1_red, LOW);
    digitalWrite(LED2_green, LOW);
    digitalWrite(LED2_blue, LOW);
    digitalWrite(LED2_red, LOW);
  }
}