Assignment 7: Instrument part 1

Materials:

  • 1 red board
  • 1 bread board
  • 11 wires 
  • 3 10kΩ resistors 
  • 1 buzzer 
  • 3 push buttons 

Schematic drawing: 

Code: 

The weird thing about my coding is for some reason, when I printed the button state as “HIGH” the buzzer would be playing as soon as my program was uploaded and would only stop when I pressed on the button. So I decided to try programming the other way; if I were to change condition from  “HIGH” to “LOW” would the buzzer play the tone when I press on the button? And the answer was YES! 

This is the original song that I wanted to play with my instrument except, I only have 3 buttons in my kit, for some reason, so I couldn’t play the 4th note. 

This is the demonstration: 

Assignment 6: Buzzer, Push Button, and Servo

Materials: 

  • 1 red board
  • 1 bread board
  • 9 wires 
  • 1 servo
  • 1 buzzer
  • 1 Push button 
  • 2 10Ω resistor 

Code: 

I made my circuit so that when I press on the yellow push button, the servo would turn then play “Mary had a little lamb”. 

Schematic Drawing: 

 

Here is the demonstration: 

 

Assignment 5: LDR and Servo

Materials: 

  1. Red Board
  2. Bread Board
  3. 11 wires (3 red, 2 white, 3 yellow, 3 black) 
  4. LDR 
  5. Servor
  6. 10kΩ resistor 

Schemetic drawing: 

My code:

I had difficulties in getting the servo to move different with different brightness. I was very confused because with the servo, the serial monitor would not show me the brightness of the LDR. I thought it was a problem with my hardware so I tried coding the LDR on its own but it worked perfectly fine. Unfortunately I could only get my program to do one action, which was to move with a brightness and return in a neutral setting. 

Links and tutorial that were helpful: 

My Result:

Assignment 4: Fade and Fading, Serial.println (), Blink without delay

  1. Fade v.s Fading 

When the LED is connected and the code is uploaded for the LED to display the commands, the outcome of both Fade and Fading is the same. When the LED was connected to pin 9, both functions caused the light to fade in and out. However, the major difference between these two command depends on the coding itself. In fade, the program runs with only one “if” statement. The LED is lit only depending on a single “if” statement within the 0 to 255 boundary. When fadeAmount is positive, the light increases its brightness and when it hits a certain highest number below 255 (indicated by the command), the fadeAmount turns negative and decreases the brightness of the light until it hits 0. 

Differently from fade, fading uses a nested loop, which means that there is a loop inside a loop. The first loop commands the LED light to increase by 5 starting from 0 until it hits 255. Then when the brightness hits 255, the second loop decreases the brightness from 255 back to 0 by 5 fadeValue. Then when the brightness hits 0, the first loop starts again and vice versa. 

Below is the Fading coding: 

Below is the Fading code: 

2. Serial.println() to show LOW, HIGH, AO and LED_BUILTIN

3. Blink without delay 

In order to identify the difference, I add Serial.print()s and Serial.println()s to wherever the millisecond changed from one variable to the other. 

This is a quick picture of the serial monitor to see how it would be displayed:

Here is a video to show the LED blink without any delay: 

Blink without Delay

 

Assignment 3: AnalogWrite

For this circuit: 

  • Red Board & Bread Board
  • 2 LED Lights (Green and Blue) 
  • 5 wires (2 green, 2 blue, 1 white) 
  • 2 resistors (330Ω) 

I have created a fade circuit so that one LED light (green) would increase and decrease its brightness and the other would follow the same motion afterward, except in repeats. 

Here is a demonstration (Although the computer code that I have used is supposed to make the blue on the loop increase and decrease its brightness, it it not working):

Green and Blue lights

Below is the picture of the schematic drawing: 

Below is the coding: 

int BLUE = 5;// Loop
int GREEN = 3;// Set up

void setup() {
// put your setup code here, to run once:
analogWrite (GREEN, 0);
delay (500);
analogWrite (GREEN, 25);
delay (500);
analogWrite (GREEN, 50);
delay (500);
analogWrite (GREEN, 75);
delay (500);
analogWrite (GREEN, 100);
delay (500);
analogWrite (GREEN, 125);
delay (500);
analogWrite (GREEN, 150);
delay (500);
analogWrite (GREEN, 175);
delay (500);
analogWrite (GREEN, 200);
delay (500);
analogWrite (GREEN, 225);
delay (500);
analogWrite (GREEN, 200);
delay (500);
analogWrite (GREEN, 175);
delay (500);
analogWrite (GREEN, 150);
delay (500);
analogWrite (GREEN, 125);
delay (500);
analogWrite (GREEN, 100);
delay (500);
analogWrite (GREEN, 75);
delay (500);
analogWrite (GREEN, 50);
delay (500);
analogWrite (GREEN, 25);
delay (500);
analogWrite (GREEN, 0);
delay (500);
}

void loop() {
// put your main code here, to run repeatedly:
analogWrite (BLUE, 0);
delay (500);
analogWrite (BLUE, 75);
delay (500);
analogWrite (BLUE, 100);
delay (500);
analogWrite (BLUE, 175);
delay (500);
analogWrite (BLUE, 200);
delay (500);
analogWrite (BLUE, 175);
delay (500);
analogWrite (BLUE, 100);
delay (500);
analogWrite (BLUE, 75);
delay (500);
analogWrite (BLUE, 0);
delay (500);
}

Assignment 2: 3 LED lights and Light Sensor

Below is the schematic drawing of the circuit

 

I have created the circuit so that inside in a dark room, the blue light would turn on, inside a regular NYUAD room light, there would be yellow light and inside a bright room, the red light would turn on. 

Here is the demonstration: 

Video Link

Finally, this is the code for what I have done: 

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode (13, OUTPUT);
pinMode (12, OUTPUT);
pinMode (11, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);

if(sensorValue <50) {
digitalWrite (11, HIGH);
} else {
digitalWrite (12, LOW);

digitalWrite (13, LOW);
}

if(sensorValue < 450 && sensorValue > 51) {
digitalWrite (11, LOW);

digitalWrite (13, HIGH);
digitalWrite (12, LOW);
}
if(sensorValue > 450) {
digitalWrite (12, HIGH);
digitalWrite (11, LOW);
digitalWrite (13, LOW);
}
delay(1);
}

Yellow light = 13, Blue Light = 12, Red Light = 11

Assignment 1: Coca Cola Ad and Window Blind Switch

  1. This is a Coca Cola advertisement that was installed all around the States in order to promote coke zero. Working with the phone app Shazam (an app that helps people to find music), Coca cola created an interactive board, which allows people to shazam the music of the ad, which allows them to either virtually sip on the coke on the interactive ad board or to pour the coke inside a virtual glass displayed on the phone.

 

2. My creative switch is called a Window Blind switch. It is a switch that is useful specifically during daytime. It is designed so that when the blinds go down, the lamp (LED light) would switch on, brighting up the room and when the blinds go up, the light will switch off as you would have the natural sunlight brightening the room.

Here is a quick sketch of what it would look like.