Monday, February 29, 2016

Transistor Labs

Force sensitive resistor and LED

1. A. Force sensitive resistors at doorways, so that lights turn on if the resistors activate in a certain direction (have multiple resistors), and off in the opposite.
B. Force sensitive resistors to determine which side of the elevator you are on. Eg for staircases with the machines that act as elevators, whichever side has an activated resistor is the side that the person is coming from.

Temperature sensor and LED

1. You technically are still using a voltage divider circuit. For the others, the other resistors had the ability to have a voltage drop of 0 (meaning resistor not activated). Here, in real-time terms, we're never going to reach temperatures close to absolute zero, so there is always some resistance in the temperature. The 3 pin nature of the temperature resistor alludes to a voltage divider circuit still being used, just internally.
2. Whatever interactions rely on this sensor need to be based on a scales of large amounts of time. Eg using a temperature sensor to detect if someone walked into a room or not wouldn't work. However, it'd work decently knowing whether to turn on the heater or not.
3. A. Turning on the heater or A/C in a room.
B. Tuning shower water temperature to a comfortable one (user has a specified preferable temperature, shower automatically attempts to keep water around that temperature).

Transistor as switch

1. The circuit involving the switch has a 10k ohm resistor. The circuit involving the transistor has a 560 ohm resistor. By applying Ohm's law where the voltage is 5 V, the current in the transistor circuit must be higher than the current in the switch circuit, which explains the brightness difference (more current implies brighter LED).
2. According to http://electronics.stackexchange.com/questions/83685/need-help-calculating-resistance-for-transistor-base, the transistor has a resistance of about 1k ohms. However, given the question asks to ignore the effect the transistor might have, we can say it has a resistance of 0 ohms. Then the circuit containing the transistor has 5/560 A, or about 9 mA, and the circuit containing the switch has 5/10000 A, or about 0.5 mA.

Transistor as amplifier

1. When the potentiometer is at minimum resistance, the LED is very sensitive to changes in the photoresistor. When the potentiometer is at maximum resistance, the LED is not very sensitive to changes in the photoresistor. Maybe I have that backwards because when looking at the circuit, I didn't know which end of the potentiometer implied minimum (or maximum) resistance.

Transistor controlled by Arduino

switch

amplifier

(no questions)

Sunday, February 21, 2016

Musical Instrument

Three Note Piano

pictures:

above is the entire circuit (on the white cardboard) and user input area (hanging off the cardboard at the bottom)

closeup of the user input area

closeup of the circuit

This plays the notes C, D, and E. Songs like "Mary Had a Little Lamb" and "Hot Cross Buns" are possible.

Here I play "Mary Had a Little Lamb:"

Here is the source code of my program (note that I got the file pitches.h from this website: https://www.arduino.cc/en/Tutorial/toneMelody):
#include "pitches.h"
#define THRESHOLD 500

// left, center, right pins

int l_pin = 5;
int c_pin = 1;
int r_pin = 3;
int speaker_pin = 5;

void play(int note)

{
  tone(speaker_pin, note, 500);
}

void play_note(bool left, bool center, bool right)

{
  if (left)
    play(NOTE_C5);
  if (center)
    play(NOTE_D5);
  if (right)
    play(NOTE_E5);
}

void setup()

{
  Serial.begin(9600);
  pinMode(speaker_pin, OUTPUT);
}

void loop()
{
  int l_reading = analogRead(l_pin);
  int c_reading = analogRead(c_pin);
  int r_reading = analogRead(r_pin);
  
  bool l_on = l_reading > THRESHOLD;
  bool c_on = c_reading > THRESHOLD;
  bool r_on = r_reading > THRESHOLD;
  
  Serial.println((String)l_reading + " " + (String)c_reading + " " + (String)r_reading);

  play_note(l_on, c_on, r_on);
  
  delay(500);
}

Crawford's model of interaction:
input: user presses a force-sensitive sensor, computer receives input as an analog value from 0 to 1023
process: user decides what note to play next and determines which sensor to press next, computer translate the input value (from 0 to 1023) and which sensor was pressed to play the corresponding note (see source code for exact formula)
output: user listens, computer plays note via speaker

Improvements:
Originally I decided to make a trumpet, however after looking up how the key-presses are processed, there was an additional component of how air is blown into the trumpet that changes which note is played. Emulating this with the Arduino would require an additional piece (probably a potentiometer), but it'd be hard for the user to play the instrument easily. Instead I changed the design to be a three note piano.
I could add more notes (that requires more force-sensitive resistors and those don't come cheap, $7 at NYU computer store)
I could allow multiple notes to be played at once (like a real piano), this would require more speakers (and I would have to order these online probably, no idea on cost)
In terms of interactiveness, I could also use switches to act as input rather than force-sensitive resistors, this way playing the instrument would seem more "natural" to the user.

Wednesday, February 10, 2016

Arduino Labs

Blinking LED circuit with Arduino

Switch and LED circuit with Arduino

1 Move the wire that connects to pin 3 before the switch (in parallel, not in series). This way, when the switch is not pressed, pin 3 receives 1 as its digital input (the large analog input translates to a digital input of 1), and when the switch is pressed, pin 3 receives 0 as its digital input (a smaller analog input than before translates to a digital input of 0). The key with this scenario is to know the cutoff point between analog to digital translation of analog values.

Potentiometer and LED circuit with Arduino

1 0 V
2 5 V.
3 5000 ohms
4 Arduino gives us an output range from 0-1023. But the input we must give it must range from 0-255. So there's a simple mapping from output (x) to input (y) that is y = x >> 2 (or x * 0.25).

Potentiometer and speaker circuit with Arduino

1 Only if the speaker has a low resistance. But if it has a non-low resistance (which it does), then it's fine. Not only that, we're not doing a direct write to the speaker, but instead using the tone() function. My guess is that this drastically lowers the voltage given to the circuit (rather than on a scale of 0-5V, probably something like 0-0.1V).
2 Put some more speakers. Don't increase the voltage (too much) on the circuit containing the speakers otherwise you'll blow them (I did this with my headphones, and they started crackling after a few days).
3 I wish I had a more organized system of keeping wires/resistors/etc.

Photoresistor and speaker circuit with Arduino

1 Put the wire that leads to pin A0 after the photoresistor (in parallel, not in series).

Sunday, February 7, 2016

Electricity Labs

Setting up a breadboard

nothing to say here, literally plug it in

Simple LED circuit


1 The resistor is used to regulate how much current flows through the circuit. The LED itself has negligible resistance, so Ohm's law dictates that an insanely high current will run through the circuit. The resistor then causes the entire circuit to have a non-negligible resistance, so the current through the circuit isn't insanely high.
2 V is 5V, R is 560 ohms, so I is 5/560A, or 8.93 mA.
3 V is 5V, I is 15 mA, or 15/1000A, then R must be 333 ohms.
4 2.8V. The entire circuit drops 5V, and if the LED drops 2.2V, then the resistor must drop 2.8V.

Simple LED circuit with switch

(for this exercise, I had plugged in the switch in the wrong orientation, so it didn't function. I ended up recording my partner's circuit)

1 Nothing would change
2 Nothing would change
The reason nothing changes is because if the switch is on, then the entire circuit is connected and functional. if the switch is off, then the circuit is disconnected. You need the circuit to be a complete loop from and back to the power source.

Simple LED circuit with potentiometer


1 Same reason as the simple LED circuit. You might think that the potentiometer would be enough, but if the potentiometer is set to nearly 0 resistance (which it can easily be set to), then the same problem as the simple LED circuit would arise.
2 Use Ohm's law. V = 5V, R = 560+10k ohms, then I is 0.473 mA.
3 Photoresistors, thermoresistors, digital resistors, and rheostat.

Dueling LEDs circuit with potentiometer

1 The potentiometer has 2 sides, a top and bottom. Turning its dial changes on which side the majority of the resistance lies (and how much). As in, top and bottom must always add up to 10k ohms. So if the top is set to 1k resistance, then the bottom must be 9k resistance. So we can control which side is "dimmer" or "brighter" (or "equally as dim/bright"). Whichever side has the higher resistance has less current flowing through it, so the light on that side is dimmer.

Capacitor charging circuit

1 It will take longer to charge the capacitor. Adding the 2.2k ohm resistor implies that less current flows through the entire circuit (via Ohm's law), so the capacitor will take more time to build up charge (as current is charge per unit time).

Capacitor discharging circuit with LED decay

1 When the switch is off, there is a circuit within a circuit (the circuit made by the capacitor, 560 ohm resistor, and the LED). The capacitor here acts as a temporary power source (battery), and can light up the LED for a short amount of time (as in, discharges via the LED).