Wednesday, September 30, 2009

Lab 2 - Reading Sensors/Microprocessor & PC Interfacing

Team Members:

Deokkyun Yoon
Frank Sandner
Piyush Soni
Takumi Jinmon

Tuesday, September 29, 2009

Our own Theramin!

Theramin is a musical instrument which seems to be controlled by hand movement of the user. It works on the principles of proximity sensors like hall effect sensor and the photoresistor to name a couple. To the uninformed, this device has a mystic charm about it!

All our tasks in this laboratory were built up so that we could finally make our own Theramin! Initial task of checking each sensor proved instrumental in choice of sensors for the musical device. We understood the working of each of the sensors and made a note of their capacity to produce a change in signal. After these inspection, it was decided by common consensus that we use a photoresistor and a force sensing resistance in our device. The former would control the pitch of the device while the latter provides volume control. We chose these over others as they seemed to provide the maximum range of output.

A rough circuit was built to begin with and we got on the task of writing appropriate code to control the sound of the device. Simultaneous experiments on the device provided us with immediate feedback on the code which would then be modified to incorporate stuff/music which we found missing. Final circuit was built neatly when we were satisfied with the quality of output music.

Now it was the time to work on the packaging of the device and also thinking about the human interface. A cardboard box which would be just big enough to hold Arduino board and the bread board was luckily found and we made some subtractions on it to make way for the speakers, switch and the sensors!

The design is such that the user can control the switch and the volume contol (i.e. Force sensing resistor) with one hand while the other one can be used to control the pitch of the instrument (i.e. Photoresistor).

The device was tested in the ambiance of the lab and seemed to work great! The accompanying code on the Arduino is such that it gives the user a feedback as to which note is being played and we could see the various notes by covering the light on the photoresistor. (See attached video)

Lab 2 Arduino Codes and Plots

Here's the Arduino code for our instrument. Basically, the user input from the phtoresistor is read by Arduino and a musical note is assigned. We made eight bins where the input signal can fall into, so it's easier to pick up a note when we play the instrument. However, this can be changed and the musical note (frequency) can be continously varying by simple scaling of the input signal instead of quantizing. We also have a digital input via a mechanical switch, which plays the assigned note only when the switch is closed. As long as the switch is closed, the musical note will be fixed at the frequency when the switch is pressed and the sound will be played continously. Lastly, the sensor read out is transferred back to the computer where a user can see the sensor read out value and the assigned musical note.

Below the code is an example plot for the photoresistor sensor readout.


-----------------------------------------------------------------------------
int speakerPin = 9;
int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)
int switchValue = 0; // switch to turn on or off the sound
const int analogInPin = 1; // Analog input pin that the potentiometer is attached to
const int digitalInPin = 22;// Digital input pin that the switch is connected to


int length = 15; // the number of notes



void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(speakerPin, OUTPUT);
}

void playTone(int tone) {
for (long i = 0; i < 1;) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
if (digitalRead(digitalInPin) == 1){
i=1;
}
}
}

void playNote(char note) {
char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };

// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i]);
}
}
}



void loop() {
for (int i = 0; i < length; i++) {
sensorValue = analogRead(analogInPin);

// map it to the range of the analog out:
char note;
if (sensorValue < 600) {
note = 'C';
}
else if (sensorValue >=600 & sensorValue < 638) {
note = 'C';
}
else if (sensorValue >=638 & sensorValue < 676) {
note = 'b';
}
else if (sensorValue >=676 & sensorValue < 714) {
note = 'a';
}
else if (sensorValue >=714 & sensorValue < 752) {
note = 'g';
}
else if (sensorValue >=752 & sensorValue < 790) {
note = 'f';
}
else if (sensorValue >=790 & sensorValue < 828) {
note = 'e';
}
else if (sensorValue >=828 & sensorValue < 866) {
note = 'd';
}
else if (sensorValue >=866 & sensorValue < 900) {
note = 'c';
}
else if (sensorValue > 900) {
note = 'c';
}
if(digitalRead(digitalInPin) == 0) {
playNote(note);
}


Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.print(note);
Serial.print("\t switch = ");
Serial.println(digitalRead(digitalInPin));
}

}
-----------------------------------------------------------------------------

Lab 2 Circuit Diagrams

The first step to become familiar with the Arduino Microprocessor was to set up a program in Arduino C-Code and load it to the device. As a first task we produced a digital output, which switched on an LED in a formerly coded rhythm. A video of this example can be seen below.



As a test for higher loads on the output circuit we connected a servomotor and controlled its rotation via Arduino. In order to achieve a higher current we built up a transistor circuit with an additional power supply:



The video below shows the rotation of the servomotor controlled by arduino microprocessor.



The next step was to test our sensor devices such as a photoresistor, a force sensing resistor and a hall effect sensor. First we tried to apply them as digital sensors. Therefore we set up a voltage divider with the sensors as adjustable resistance. With some of the resistors it was quite well possible to achieve a analog signal whos range covered digital 'on' and 'off' strength. In a next step we figured out the range of analog input signal, their accuracy and controllability. The circuit diagrams for those sensors can be seen below.







The analog application of the photoresistor and the force sensing resistor as a sensor can be seen in the video below.




In the next step we faced the challenge to write analog input signal to EEPROM and read it with the scope.



Now that we had become familiar with the arduino i/o ports and the coding in arduino c-code we wanted to access its pins through LabVIEW. We faced some data conversion problems (string vs byte) but finally fixed them and we were able to control the frequency of a square wave function at a digital output port. The program for this function had been loaded to the microprocessor before. We also managed to read analog input signals through LabVIEW. An example of how to control the microprocessor through LabVIEW can bee seen below.



At this point we had all necessary knowledge about our devices to build up a "Thevenin-like" musical instrument. We programmed a connection between analog input and output ports in order to be able to control a speaker by adjusting the above mentioned sensors.
Here you can watch the video of our final Thevinin instrument:


Tuesday, September 22, 2009

Lab 1 - Introduction to Circuits

Lab Objective
The objective of this lab was for us to:
  • Review how to implement simple breadboard circuits
  • Review how to read data specifications for components
  • Design a circuit that turns on an LED under the command of signals by switches and logic chips
  • Learn how to use an oscilloscope and calibrate an oscilloscope probe
  • Create TTL signals with an LM555 timer chip and various logic chips
  • Use transistors to amplify said TTL signals to drive LEDs, motors, and speakers
Parts
PN2222 NPN transistor; 74LS00, 74LS02, 74LS04, 74LS08 logic gates; power supply; LM78L05 voltage regulator; breadboard; LEDs; switches; LM555 timer chip; potentiometer; pager motor; small speaker

Background
We were given the following circuit diagram on which to base the rest of our design:

Process
  • We set up a voltage regulator to supply 5V to logic chips.
  • We selected and set up the NAND logic chip. This was based on the fact that we wanted 2 pressed switches (A = "1" and B = "1") to return Q = "0", which would serve as one input into another NAND chip and allow the out put of that to be Q = "1". This would in turn go to the base, and the transistor would be activated, turning on the LED. See below for truth table verification.
  • We calculated the resistances necessary to light the LED. See below for sample calculations.
  • We built the circuit for the LED based on the circuit diagram above with our specified gate and resistors. See below for layout.
  • We calculated the resistances necessary to drive the pager motor instead of the LED. See below for sample calculations.
  • We built the circuit for the pager motor with our specified resistors. See below for layout.
  • We familiarized ourselves with the LM555 timer chip to create a 1 Hz square wave and then replaced a switch with said timer chip.
  • We calculated the resistances necessary to drive the speaker instead of the pager motor. See below for sample calculations.
  • We built the circuit for the speaker with our specified resistors and a potentiometer to regulate frequency.
Final Circuit
This is our final circuit with calculations.





As an expressive musical instrument, our circuit (while very rewarding on the educational side of things) was at the very best a noisemaker. It had a limited range of notes because of the fact that it would saturate when current was high.

Human-circuit interface was less than ideal, as we had no ability to vary volume and notes simultaneously (as most instruments minus percussion do). Also, while the system is analogous to a trombone in that there are not any stops marked so that one knows where to adjust to for the next note, it is different from it in that it is very small, therefore requiring more accuracy and precision to get to that next note than a trombone.


Monday, September 14, 2009

Lab 0 - Rapid Prototyping Principles Lab

Objective
The objective of this lab was to gut a toy to understand its use of a motor and sensors. These electronics were to guide our creation of a mechanism that launches 10 ping pong balls into buckets placed around the X50 lab.

Specifications and Limitations
The specifications and limitations given to us were as follows:
  • The ping pong ball must be the activation of at least one electrical part of the system
  • The competition involves aiming only once, dropping 10 ping pong balls into the system and targeting for a desired bucket all within 40 seconds
  • The footprint of the mechanism must be able to fit on one of the tables along the outside wall in the lab
Approach
We divided this lab into 5 steps:
  • Brainstorming
  • Determining best option via Pugh chart
  • Design
  • Manufacturing and assembly
  • Testing
We took the candy machine toy apart and found the switches for the translation motion to stop at the ends. There was also a photo gate that could detect when the toy or candy dropped into the shoot to turn sound on for celebration. The other electronics were wires and manual triggers for controlling the crane, which were not useful in our design. We ended up using one of the limit switches from our toy for our control circuit. The motor we needed was found in the lab in our provided "extras" box.

Brainstorming worked well for our team. We spent a half hour to brainstorm individually during our first meeting. After this we explained our sketches and grouped similar ideas so that we could make Pugh charts to decide on the overall best design. Some of the ideas that seemed silly actually were ranked higher than others that seemed rather basic. A couple ideas were lumped together to finalize the project starting point. Please see the figures and explanations below.

1. Spring Catapult– For this idea, a bucket would be mounted at the end of a long lever. The other end of the lever would be connected to the base by a hinge. A compression spring would be mounted between the base and a point between the two ends of the lever. By pulling back and down on the bucket, the spring would be compressed. Releasing the bucket would allow the spring to relax, transforming the potential energy stored in the spring into kinetic energy of the ping-pong ball. By adjusting how much the spring was compressed, the range of the ball could be adjusted.

2. Motorized Catapult– For this concept, a catapult arm would have a motor connected as the hinge between arm and base. The motor would be used to drive the arm forward or backward. A movable stop bar would be mounted to the
base, allowing the release angle to be controlled. Contact switches would be mounted so that the system would know when the arm was in the home position or contacting the stop bar. A photo-gate sensor could be used to determine whether or not a ball was in the bucket. When a ball was placed in the bucket, the system would drive the motor forward, throwing the ball. Upon contacting the stop arm, the lever would be driven in reverse, resetting the system.

3. Compression-Spring Launcher– Main components of this concept include a barrel, piston, and spring. The piston would be drawn back against the spring, storing energy. When released, the piston would accelerate a ping-pong ball along the barrel. Angle of the barrel could be adjusted to control range. A mechanism would be
required to draw back the piston.

4. Spinning Wheel Launcher– Another concept involved a mechanism to accelerate the ball similar to that used for hot-wheels tracks. Spinning rollers or belts would be placed along the sides of a c-shaped chute. As a ping-pong ball passed between the rollers, they would grip it, pull it along, and throw it along the chute. Range could be adjusted by changing the angle of the chute or adjusting the speed of the rollers. A photo-gate sensor could be used to determine when a ball was at the mouth of the chute and cause an actuator push it into the rollers.

5. Track-Lever Launcher– This concept involved a cart with an arm mounted on top by a hinge. The cart would be accelerated along a track and brought to an abrupt stop at the end, causing the lever to throw the ball it was carrying. After throwing the ball, the cart would need to be brought back to the beginning of the track.

6. Crossbow– A cross-bow could be used to throw the ball. By adjusting how far back the string was pulled, the initial velocity could be controlled. Angle of the launch-track could also be adjusted to control range. An actuator would be needed to pull back and release the string.


7. Blower– A hair-dryer, leaf-blower, or other fan could be used to push a ping-pong ball through a tube. The launch tube would be mounted on a pivot so that the exit angle could be adjusted. Something would be needed to insert the ball into the tube without the ball being simply pushed back out the entrance hole. One idea was to place a flexible membrane with a slit in it over a hole in the launch tube. A sensor would determine when a ball was just outside the launch tube. An actuator would then be used to force the ball into the tube through the membrane. If output velocity needs to be adjusted, a mechanism would need to be added which would allow the output from the blower to be partially or fully blocked.

8. CO2-Canister Launcher– This design would be similar to the previous concept, but would use a CO2 canister to supply pressure to propel the ball. A solenoid valve or other electronically-actuated valve would be required for this system.

9. Expendable Track– Several types of expendable tracks were proposed, including ones which used telescoping segments, fold-out segments supported by suspension-bridge-like cables, or inflatable segments. Each would cause a track to extend out over or into the bucket. Once the track was in place (determined using some sort of sensor), balls would be released and allowed to roll down the track into the bucket. Range would be limited by the number/length/stiffness of segments.


Determining the best option



We eventually selected the hair-dryer blower design. Our mechanism consisted of four main components: a hair-dryer, a barrel, a loading mechanism, and an aiming/support structure. The barrel was simply a length of PVC pipe, fitted to the hair-dryer with a flexible coupling. The loading mechanism was built using a motor with a bottle cap attached to the end of the shaft. Hot-glue was used to add a grip to the bottle cap. The bottle cap was mounted so that it protruded into a hole cut in a T-fitting added between the barrel and the hair-dryer. When turned on, it forces balls to enter the barrel against the airflow leaking out from the barrel at the entry point. This motor is turned on when a ball is bumped against a touch-switch near the top of a Plinko board mounted at the top of the loading mechanism. A relay-circuit was constructed to force the motor to remain on once the switch was bumped (See the circuit below). A foam-board tower was constructed to support the front end of the barrel, allowing it to be angled up or down by moving the tower backward or forward. A pivoting platform was attached to the top of the tower so that the barrel could remain tangent to its support, regardless of aiming angle. The back end of the barrel (with the hair dryer) was supported with a block of Styrofoam with a hole cut in it.


Design Considerations
The most robust structural part of the project is the connection between the hair dryer and the barrel. This was a purchased part, but necessary to decrease the diameter from the hair dryer to the barrel and efficient in minimizing pressure loss at this connection.

The least robust part of the design is the tubing after it is cut. The PVC deforms when drilled through or slotted. We need to drill or slot the tube so that a light ping pong ball does not get blown in the wrong direction due to the hair dryer. However, in letting the excess air to flow out the drilled holes and slots, the deformed PVC becomes too small to allow the ball to fall through.

The most entertaining part of our project was the Plinko board. We used the toy walls for this and cut up a clothes hanger for the pegs. This was a design idea that came from our brainstorming session.

Conclusion

It was immediately apparent that there was a disparity of mechatronics knowledge among the team members. Two team members are experienced with robotics through internships and extracurricular activities. The other two members have only had structural and manufacturing experience to aid in the project. The team functioned well this way, however, since the work and time was still possible to split up evenly.

It was fun taking the toy apart and learning how the coin slot worked and how the traveling crane knew when to stop at its limits. The most enjoyment was found during testing because flinging ping pong balls in a school building is a rather unique experience. We enjoyed the brainstorming process because we tried to stick with the rules of the game. There were no bad ideas and its fun to let the mind wander. The process seemed to work well since one of the more random ideas became our final project.