FunkyTunez 1.1 (due Oct 2nd) (FIXED)

For this assignment, I made a musical instrument using flex sensors and switches. It’s an upgrade to my previous instrument and looks way cooler. There are three different buttons, each which represents a range – LOW, MEDIUM or HIGH. Once in one of these ranges, the user can move the flex sensor to control the pitch of the tune within that range and can use another flex sensor to control the time delay between two successive notes. 

Let me say that this took me quite a bit of effort get right and I had many of those moments where I was just pulling my hair from my head. However, the joy of completion was worth all the effort. I will try my best to explain all the various problems I encountered and how I managed to solve them! 

Materials Used: 

  • 2 * Flex Sensors
  • 3 * Push buttons
  • 1 * Breadboard
  • 1 * Speaker
  • 5 * 10kΩ Resistor
  • 1 * RedBoard (Arduino)
  • Glue Gun
  • Soldering Iron
  • Wires, as required

Here’s how the instrument looked – 

Here’s the circuit underneath –

My schematic – 

For the coding part, I used map() to transpose the values from a certain range to another. Here is the code – 

 

Everything was working very well before I made the decision to go off the breadboard and implement a sort of design to my project. My end goal was that I didn’t want the user to see the wires and the mess that was involved with the creation of this instrument. All my problems started there. Here they are, along with what I did to overcome them, in no particular order – 

  1. Not using stranded wire to solder the legs of the switch. Because of this, the legs of switch just broke and rendered the switch obsolete. Solution: Used stranded wire the next time.
  2. Making the switches stay in place – I tried tape, didn’t work. Then tried superglue, also didn’t work + I ruined a switch because of that. Solution: Used a glue gun- wonderful results. I would highly recommend getting used to a glue gun for future projects. 
  3. Bad readings from flex sensors- This was because I used 330 instead of 10k, resulted in very different readings and Professor Shiloh helped me figure this one out. Solution: Used the appropriate resistor. Future tip: Since these silly errors are the most annoying, make sure to double check all components in the circuit. 
  4. The Big ONE – one of the wires was bad. I never ever imagined that I could have an error because a wire is bad. I literally spent 1.5 hours at night rechecking my code and my circuit but found no problem whatsoever. I then assumed that the problem was with the switch. To be sure, I pulled out a multimeter and ran a continuity test. Turns out the problem wasn’t with the switch (Poor switch, I cursed it so much). After a while, Professor Shiloh suggested I try a different wire, as the wire may be bad. And success! The last problem was fixed. 

Overall, this project was quite an experience. I aimed for a very minimalistic design and didn’t want to explicitly tell the user what to do. I wanted that the User experiment, and using the symbols and clues I provided, figure out how the instrument works. 

My sincere apologies to Laine, Atoka and Nathalie who had to struggle to understand how my device works during the class – because half the things weren’t working. Here’s a video of how it actually works.

Message From Mars

For this week’s assignment, I made an instrument using a flex sensor, two buttons and a speaker. Here’s my schematic (I tried my best to color-code according to my circuit; it really helps) : 

My instrument had two modes, a low frequency and a high frequency which was toggled using the two switches. The flex sensor when moved, would change the output frequency according to the input. I used the map() function to achieve this. My code is pasted below :

The serial monitor really helped to understand the range of input values from the flex sensor so I could map it effectively. 

Here’s a video of how it finally worked out! Notice how by pressing the button, the tone changes to a different range. The noise sounded similar to a coded Alien message, hence the title (duh).

Assignment 6 – Buzzer, Servo, Switch

For this week’s assignment, I ran a Pokemon Intro sequence, lit up an LED and controlled a servo on the push of a button. 

Here’s what it looked like: 

Here is my schematic (CirucitLab gave up on me, and I couldn’t figure out how to work Fritzing – I just went old school):

Credit for the music sequence goes to a smart guy who shared his work here. Here’s my code for the project – 

A mistake I made here was that I placed the pokemonIntro() inside partA and partB instead of inside the transition change part of the code. Because of this, the music played endlessly, and I couldn’t use the button. (Silly me)

Assignment 5 – Servo

This week’s assignment was to control a Servo motor using an analog input.  Here is the schematic. I used Circuit Lab to make this – 

I made use of the map() function to transpose the values from a range of 0 – 1023 (analog input) to a range of 0 – 180 (angle of the servo motor). Here’s my code: 

The most interesting part of the code was the map() function. It took a certain value and a range that that value was in, and then returned a value within a specified new range.

The result was fun! Like using the force I was I felt. Here’s a video of how it worked:

Asignment #4

The assignment consisted of 3 parts. 

Part 1

The first assignment was to run the fade() tutorial and compare it with our previous assignment. The fade tutorial was an optimized version of our assignment last week. It used a for loop to increase/decrease the value from 0 to 255. It also made the use of an if-statement to switch from increasing to decreasing or vice versa when the value approached the higher/lower end. However, both codes accomplished the same result. 

Part 2

The second assignment was to use Serial.println() to print the values of LOW, HIGH, A0, and LED_BUILTIN. Here’s the code. It is placed in setup as the assignment asks for it to be printed only once.

Here was the result on the Serial Monitor: 

LOW: 0

HIGH: 1

LED: 13

A0: 14

Part 3

The third assignment was to run the BlinkWithoutDelay program and understand its workings by inserting Serial.println() at different points to get a good idea. In the code below, I have used 3 Serial.println() statements to understand how the code works.

An important function that is used here is the millis() function. It returns the value of the number of milliseconds since the program ran in an unsigned long. Using this, we can effectively calculate the change in time between two iterations of loop(). The output that I got gave me 2 bits of information which helped me understand the program – 

  1. The value of the variable previousMillis after it had been changed in accordance with the difference between it and currentMillis and the interval
  2. The led state – it showed 0 for off and 1 for on.

 

Assignment 3: Fading

The assignment seemed really confusing when I first read it, but Professor Shiloh cleared out a few things and when I just took a bit of time to read it, it was pretty straightforward.

Now the assignment asks us for two things – a fade program in the setup() function, and one in the loop() function. Of course I started off with the one in the loop() function. After reading the fade tutorial, I had my own go at coding it from scratch. This is how it looked; it’s pretty straightforward in my opinion:

int pinBlue=9;
int bright=0;
int fadeAmt=5;

void setup() {
    pinMode(pinBlue, OUTPUT);
}

void loop() {
   analogWrite(pinBlue, bright);
   bright += fadeAmt;
      if(bright>254)
     {
         fadeAmt=-fadeAmt;
     }
     if(bright<1)
     {
         fadeAmt=-fadeAmt;
     }
  delay(50); //to get a neat transition, or else it would just blink?
}

Here’s how the connections looked like (note that the other LED is also connected here in the diagram, but not in the video that will soon follow) :

Circuit diagram

Everything worked perfectly! Here’s the video (please excuse the laugh, aliens to this subject find our work amusing) :

Then I had my crack at trying to make the LED fade by having the code in the setup() function. 

TL;DR – I failed.

Here’s how I tried – I first thought about what the assignment asked for (I hope I have understood it correctly). I reasoned out that the assignment pretty much asked that we accomplish the same thing as what we did in the loop() function. I struggled with how to approach the problem. It seemed to me as though we were being asked to make the light fade in and out but with using an iterative statement (i.e, a loop). I figured that since I am not allowed to loop it, I would try using a jump statement to go back to a point in the code and repeat doing so until a certain condition is met. In theory, that is a LOOP, but without using a loop statement (Seems a bit odd, yeah?). I have some programming experience in Java, so I had look up how exactly the syntax worked in C++. Here’s the code I tried to use : 

int pinRed=10;
int bright=0;
int fadeAmt=5;

void setup() {
   pinMode(pinRed, OUTPUT);

start:
   int i=1;
   i++;
bright += fadeAmt;
   if(bright>254)
   {
      fadeAmt=-fadeAmt;
   }
if(bright<2)
  {
      fadeAmt=-fadeAmt;
  }
   delay(50);
if (i<50)
{
   goto start;

}}

I agree, that this fundamentally is a loop, but I couldn’t figure out any other way. Also, this never worked and the LED didn’t light up at all. I reasoned out that this is because the setup() function has to complete execution before the circuit actually begins to work the way we intend to. Or it could simply be that my code has some errors. Or it could be something else, I am not really sure. 

I hope to have another go at this sometime and see if I can figure out what the answer is.