Homework 10 due October 11, 2017

Decription

The inner dancer in me was always disappointed that my mom never got me the music box with a ballerina in it. For this assignment, I created one for myself, however it stands on a panel and rotates around itself, if the button is pressed.

Materials used

  • Foam (yes, again!)
  • Hot glue
  • Ballerina cutout + wooden stick
  • Wires
  • DC motor
  • Transistor
  • Pushbutton
  • 10 K resistor
  • Redboard
  • Breadboard

Issues

The code was fairly simple and I learnt the on/off button code which I had not used before. Up until the basic hardware, it also worked fine, as the motor was rotating when it was supposed to, etc.

The issues arose, when I had to build the prototype itself – apparently the foam and cutout were too heavy for the motor, so the ballerina kept flying away. At one point, it became extremely frustrating, because there was no way I could explain it as a “feature”, not a “bug”. Fortunately, James from the IM lab helped me out with a different motor than the one of our kits. It was still a bit tilted because it was not entirely stable, but at least it gave a good idea of what it was supposed to do.

Schematic

Code

 

Homework 9 due October 9, 2017

Description

For this homework, I made a game with a snake with 4 teeth. One of them aches, so if the person interacting with the snake presses on the aching tooth, the snake eats the hand by closing it’s mouth. The snake communicates with the person by writing messages on the laptop screen. If the person presses a healthy tooth, it will say “Nope”. If the person presses on the aching tooth, it will say “Om nom nom” as it closes it’s mouth. Once the hand is eaten, it opens its mouth again and a new random tooth aches, so the game starts again.

Materials used

  • Breadboard
  • Redboard
  • Wires
  • 4 pushbuttons
  • 4 x 10K resistors
  • Servo motor
  • Black foam material
  • Blue paper for eyes and tongue

Schematic

Issues

First of all, foam is probably the worst material I could have used, because I could not stick different parts of the snake together, such as the servo motor and the snake’s “mouth”. Super glue and glue gun would melt the foam and taping different parts looked a bit messy from the design perspective and did not really hold the parts together. The best solution would have been to sew them together, but there were no threads in the IM lab. So I decided to staple some parts, which was not the most efficient way, but it did the trick. I also used tape for other parts.

When the snake’s mouth moved, it was not even on both sides, and a solution would have been using a servo motor on each side, so I will keep it in mind for the next project.

I also encountered some software issues. For the code, I used a random() function which I had not used before, so it took me a while to understand how it works. Initially, the code generated a new random value every time any button was pressed, which was not what I wanted. After talking to my friend, Miha, he hinted that I should generate a new random number only if the pressed button is the right one. That way, the random number remained the same, if I pressed the wrong buttons, until I picked the right one. To check if it works, I put the Serial.println(randNumber). In order to not spoil the game, I made the line as a comment in the final code.

Code

Evaluating Alex’s project

Alex’s project was a game with an arrow and a platform with multiple sectors, worth different number of points, for example, 10, 20, 50. The arrow was moving back and forth, unless the button was pressed. Then the angle of the arrow would determine the points the user gets. The goal was to get as many points as possible.

The design was very efficient, as I only saw the push-button, the arrow and panel, and the button had directions next to it. There were no distractions that might confuse the user. It looked like a real prototype of an actual game.

For potential improvements, the different patterns of the lights around the panel made it a bit confusing, because the pattern was random. I initially thought that it changed based on the arrow location or, more specifically, the points gained. It might have been a good use of the lights, apart from the aesthetics of the design.

To make it more meaningful, a screen nearby could have shown the total points gained in a single game.

Homework 8 due October 2, 2017

Description

I made a piano with two octaves depending on the amount of light the LDR receives. If the user puts their finger over the LDR, the notes are an octave higher than without the finger.

Issues encountered

The software seemed to work fine and the way I had imagined – if the LDR prints values lower than 800, the tone of each push button is 2x higher than if the values are higher than 800.

However, sometimes the buzzer would start to buzz seemingly out of nowhere, with different tone each time. At first, I thought it was a faulty button somewhere, however the different tones, even after I switched some buttons up, kept buzzing once in a while. The solution was gently tapping the breadboard to the table, but I do not consider it as a permanent solution.

Another issue or inconvenience was that the code for homework now seems to get pretty long which makes it harder to go through it. Fortunately, in this case the code was not too extensive, but I realized that Ctrl+T option is going to come in-handy very, very soon.

Improvements

I think the LDR should appear separately from the rest of the buttons, but I do not feel comfortable enough with soldering yet. I know the design could have been a little better, particularly the many wires on one side of the breadboard. A solution to these problems is spending some time in the IM lab learning how to cut wires, solder, connect different parts together, etc.

Schematic

Code

 

Assignment #7: Piano keyboard

For this assignment, I made a piano keyboard from C note to the next C note. I started off by making the first 4 notes work and then added another breadboard to have 8 notes.

Issues

For tone() function I initially had written tone(5, frequency, time), but had switched buzzer to a different pin, so it did not work. With the help of James, we first went through the code with serial.Print() to see if all the buttons work, then checked the hardware (if the wires for buttons are the right ones and if there’s not a short circuit) and then realized the mistake that the code was still related to the previous pin.

Schematic

Code

 

Assignment 6: Stand By Me

Description

For this homework, I decided to learn and understand the tone sample of Arduino and play a song once when the button is pressed. When the button is pressed, servo moves to 150 degrees, the buzzer plays the bass track of “Stand by Me” by Ben E King. Once the song finishes playing, the servo goes back to 10 degrees.

Issues

Initially, the servo was supposed to be positioned at 0 and 180 degrees, but it caused twitches, so I changed the positions to 10 and 150 degrees, which solved the problem.

It took me a while to translate the notes from piano sheet to Arduino code, but this song was very easy in terms of note durations, the issue arose with putting the right notes.

I realized that it is important to understand every line of code and each word of the line, especially if I intend to use the code for another project, so I made sure that each line had a comment next to it.

I still have not figured out how to add the video to this post such that the video media appears, instead of a link to it.

Additionally, I need to spend some time to learn how to draw schematics online, but I like drawing them by hand because it allows me to make sure I fully understand my circuit.

Video

 

Schematic

Code

I used toneMelody tutorial by Arduino as the basis for the buzzer part of the circuit and used my previously made code for pushbutton.

 

Homework 5: night and day

I decided to create a circuit that indicates whether it is time to go to sleep or stay awake. When it is light, the arrow points at sun and green LED is lit. When it is dark, the arrow points at moon and if it gets too dark to see the chart, the blue LED is lit.

For this circuit, I used:

  1. 15 wires
  2. 2x 330 Ω resistors
  3. 10K Ω resistor
  4. 2 LEDs (1 green and 1 blue)
  5. LDR
  6. Micro Servo with an arrow attached to it
  7. RedBoard
  8. Breadboard
  9. Day/night chart

Some difficulties I encountered:

  1. The servo was not rotating 180° degrees, the approximate amplitude was around 160° degrees. After discussing it with professor, it turned out they tend to be fairly imprecise.
  2. Initially I tried to adjust the code, given in the example. After trying to play with for() loop, I realized that it would be simpler to use if() statement instead, because it was more intuitive for me and the project did what I had imagined.

  3. However, in the new if() code, there was initially no command for either LEDs to turn off (the if statements had only HIGH command) so after checking if it works for, both light and dark condition, both LEDs were lit up, which was not useful for my project. So I changed the code to indicate, which LED has HIGH and which – LOW in each condition.

The final schematic and code is available below.

 

 

Homework 4: fading, blinking without delay, Serial.Println()

1. Different codes for fading – same result?

I tried both samples for LED fade and it seemed to give the same effect on the LED light. So I had to look into the code to figure out the differences. I couldn’t figure out how to make both LEDs to blink at the same time with the for() code, and the if() command only allowed both LEDs to blink simultaneously. I also noticed that for for() loop, the first light lit up and only then the other LED started lighting up. This made me understand that for() loop runs within loop as long as the fadeValue is lower (or higher) than 255, but if() statement happens once within each loop. At the same time, there were two loops, because one loop increased fadeValue, the other decreased fadeValue.

2. Values of LOW, HIGH, A0 and LED_BUILTIN

 

3. No delay in blinking – how?

To understand this exercise, I had to go through each line of the code, because the way the hardware worked did not give a lot of information, as it looked very similar to previous blinking exercises.

The LED blinks every second by checking when was the last time it blinked. Variable previousmillis defines the last time the LED was updated (based on sample code), and currentmillis shows the number of milliseconds since the Arduino board started running the current program (Arduino reference). So the program checks, whether this difference is equal to previously defined interval (in this case, 1000 milliseconds). If this statement is true, the previousmillis is set to be equal to currentmillis. Furthermore, if the LED is at LOW, the LED gains value of HIGH for 1000 milliseconds. Otherwise, the LED is at LOW, until another 1000 milliseconds are gone.

For Serial.println(), I defined a variable blinkTimes to see how many times the LED blinks (or is turned on). To avoid double-counting, the number of blinks only changes when the LED is turned on (i.e., within the second if statement).

Homework 3: fading LEDs in setup and loop

 

For this circuit, I used:

  • Redboard
  • Breadboard
  • 2 LEDs – red and green
  • 3 wires
  • 2 resistors

For the code, I initially used the circuit provided in Arduino examples, but I noticed that the red LED light did not light up. After looking through the code, I realised that since the brightness initially was 0 and the first step would have increased it by 5 within 30 miliseconds, my eye did not catch the difference. So I changed the code to 9 analogWrite() steps, varying the brightness.

In this case, the red LED light up and faded first and then a loop started with green LED fading in and out. This is because red LED was part of the setup and once the program runs each line of the setup, it proceeds to the loop with green LED.

 

/*Laine Una Melkerte
* September 12, 2017
*/
int green = 11, red = 10; //green pin will be connected to pin11, and red to pin 10
void setup() {
// five values of brightness to cause fade effect: 0, 50, 100, 150, 200, 255
analogWrite(red, 0); //set the brightness to 0
delay(100); //delay
analogWrite(red,50); //set the brightness to 50, etc.
delay(100);
analogWrite(red,100);
delay(100);
analogWrite(red,150);
delay(100);
analogWrite(red,200);
delay(100);
analogWrite(red,255);
delay(100);
analogWrite(red,200);
delay(100);
analogWrite(red,150);
delay(100);
analogWrite(red,100);
delay(100);
analogWrite(red,50);
delay(100);
}

void loop() {
//make a loop for a fading green LED using the same values as for red LED: 0, 50, 100, 150, 200, 255
analogWrite(green, 0);
delay(100);
analogWrite(green,50);
delay(100);
analogWrite(green,100);
delay(100);
analogWrite(green,150);
delay(100);
analogWrite(green,200);
delay(100);
analogWrite(green,255);
delay(100);
analogWrite(green,200);
delay(100);
analogWrite(green,150);
delay(100);
analogWrite(green,100);
delay(100);
analogWrite(green,50);
delay(100);
}

Homework 2

I decided to make a circuit that involved 3 LEDs (green, yellow, red), 3×330 ohm resistors, 1x10K ohm resistor and LDR. I developed a loop with 2 if statements:

  • if the light sensor read an integer >800, the green LED was blinking,
  • if the integer lied between 600 and 800, the yellow LED blinked,
  • otherwise, the red LED blinked.

The respective LED, based on darkness, blinked every half a second. This circuit might be helpful for someone like me, who rarely notices that the room has become too dark for reading, writing or working. I used the classic green-yellow-red scheme, because people are the most familiar with the implications of these colors in case of warnings. 

Issues:

It took me a while to remember that I had to use 3 wires for properly connecting the LDR, because the serial port monitor gave out 0s, or the numbers seemed random, when LDR was connected to A0 pin and ground only. I found exploring basic LDR circuits on internet very helpful. Once I got it to work and connected LEDs, the serial port monitor displayed the output every half a second – same interval as the blinking lights. As I played with the LED blinking intervals, the output delay monitored the change in blinking. I could not come up with a solution to it, even after switching the “delay” line before or after  the if statements. I also struggled with implementing multiple if statements, where the internet came to help as I explored Arduino language, and “else if” statements. The developed circuit worked otherwise the way that I had intended.

Code:

int greenLight = 11, yellowLight = 12, redLight = 13; //define variables based on which light is connected to which pin
void setup() {
pinMode(redLight, OUTPUT); //red
pinMode(yellowLight, OUTPUT); //yellow
pinMode(greenLight, OUTPUT); //green
Serial.begin(9600);
}

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

//if the value is greater than 800, LED 13 blinks every second
if (sensorValue > 800) {
digitalWrite(greenLight, HIGH);
delay(500);
digitalWrite(greenLight, LOW);
delay(500);
}

//if the value is less than 800 but higher than or equal to 600, LED 12 blinks every second
else if (sensorValue < 800 && sensorValue > 600) {
digitalWrite(yellowLight, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for half a second
digitalWrite(yellowLight, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for half a second
}
//otherwise, LED connected to pin 13 blinks every second
//the other two pins receive LOW
else {
digitalWrite(redLight, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for half a second
digitalWrite(redLight, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for half a second
}

delay(1); // delay in between reads for stability
}

 

Homework 1: Rijksmix and ballet switch

Example:

Rijksmix project

Rijksmix creates a juxtaposition between artists and their artworks, displayed at Rijksmuseum in the Netherlands whose collections database is available on their website, and Soundcloud, a large music distribution platform. As the author of the project claims: “Visiting a classical art museum normally amounts to silent appraisal of exhibited art pieces. Silence indeed eliminates environmental distraction and allows the visitor to contemplate art, yet I would sometimes wish a classical art exhibition would not only stimulate my vision (and thought), but other senses as well.”

On the Rijksmix website, the user can type the name of their favourite artist. If the artist’s work is displayed in Rijksmuseum, a picture of an artwork will appear. Additionally, a search query is submitted to Soundcloud’s API, which sends back a list of tracks corresponding to the search query. One of these tracks is played, as the user sees the artist’s painting.

Switch:

Dance, especially ballet is based on multiple basic elements. One of the first things a ballet dancer learns is the different positions of feet, from 1st to 6th. I decided to create a switch that would allow to see, whether a person’s 1st position is entirely straight, meaning that their heels would touch each other. If the heels are touching, then the LED light turns on, if they are not – LED light is off. This is a simple circuit, using Arduino board, breadboard, 3 wires, resistor, LED light, ballet shoes and blue tape. Ideally, the back of the heel part would be covered by conductive material.