Sunday, February 7, 2016

Lab 2: Analogs and Signals


The purpose of this lab is to work with analog inputs and outputs, or more generally, to use micro controllers to generate and measure signals.


Some overall lessons learned for this portion of the lab:

1. Floating numbers are different from integers.
2. Different sounds are a result of different frequencies.
3. Brightness and dimness can` be interpreted as how much a light source is blinking (very rapidly).
4. What an LED looks like in circuit diagram notation.


Part 1


In this part of the lab, we were to display the ramp signal using the StampPlot software. The data was plotted only with respect to time. The ramp signal that we generated went to 10 and then jumped back down to 0, its initial state. We repeated this for a sine curve and the two images that were obtained from the StampPlot software. The graphs are shown below. The code for the first ramp signal is attached here, while the code for the second sine ramp signal is attached here.







Some important points we learned here have to do with computing mathematical operations. For example, we learned to use float instead of int, otherwise the sine function would not appropriately be graphed on the StampPlot program. The Arduino division leads to 3/2 =1 and 1/2 = 0. So we used float i=0 and assigned i as a floating number rather than an integer.



We also used the oscilloscope to display the sound that our Arduino was playing by attaching the oscilloscope probes to the buzzer. The video below for the Mario theme song "displays" the tones. What we see here is that sounds are essentially displayed as ramp signals. The frequencies and durations we program into the Arduino creates ramp functions. These ramp functions are essentially sound waves, and thus the Arduino is able to produce sounds. The video for the oscilloscope can be found as you read along to Part 2 (below).


Part 2



In the next part of the lab, we connected a speaker to the Arduino to create some type of noise. We were able to include a "fun tune" as well as think about a noise associated with medical application. For example, if an incorrect button were pushed on a device, it would make a "try again!" noise whereas if there were a concerning signal with a patient's vital, the device can have an "emergency" sound. In order to create these noises, we played around with different frequencies to determine the pitch and then also played with the tone() and noTone() functions to determine the length of the sounds. The videos attached are relevant to sounds that a medical device can potentially make. There is also one video for a portion of t he Mario theme tune which was our "fun tune." The code for the Mario theme song is attached here. The code for the emergency tune and warning tune is attached here.


The video for the "emergency" tune is below.


The video for the Mario theme song is attached here. If we had more time in the lab, we definitely would have finished the whole tune!



Part 3


This portion of the lab focused on controlling LED brightness. We learned that when an LED is at 50% intensity, it is essentially on half the time and off half the time. The same applies for different intensities. So, we created a brightness function by assigning an integer "maximum brightness" at a level of 30. Then, through an analog function called analogWrite(), we were able to adjust the brightness by using a loop and changing the delay so that it was half the brightness at 50% and so forth. The code for the brute force method can be found here, for both 50% intensity and 25% intensity.


The image of the LED at maximum brightness is below.

IMG_20160129_160103951_HDR.jpg

The image of the LED at 25% intensity is below.

IMG_20160129_160034715_HDR.jpg

Now we varied the brightness of the LED using the Arduino's built in analog capacity. We also fluctuated the LED's brightness the way an alert button would appear on a medical device. The LED's brightness went back and forth from bright to dim and repeated. The video is attached below and the code is attached here.


Note that you need to connect your LED to pins 3,5,6,9, 10, or 11. The other pins do not work with analogWrite().



Part 4.1 - Make a Light Sensor

Now we will work with variable resistance sensors whose resistance changes when influenced by light. First, we will want to monitor resistance changes by converting the resistance changes into voltage changes through a voltage divider. (A voltage divider is two resistors connected end to end). We will need the Arduino to read the voltage, which can be done through analogRead().

We made a light sensor using a photoresistor and a resistor - this is the voltage divider approach.

Here, we connected a photoresistor to a resistor. Then, we used the multimeter to measure the resistance of the photoresistor and measured that it read 6k Ohm in the normal indoor light so we used the 5.1k Ohm resistor because it was closest to the photoresistor's resistance. The code is attached here.






Part 4.2 - RCtime Approach



Then we used another method to determine resistance - the RC time approach. By using a circuit with a capacitor and photoresistor or using a circuit with a capacitor and an LED, we were able to charge and discharge a capacitor: 

a) When using the photoresistor, we essentially provide it with one constant light intensity. Therefore, the resistance of the circuit is fixed. As a result, voltage through the capacitor drops at an exponential rate. (0.1 uF capacitor) 

b) When using the LED, we provide the it again with a constant light intensity. THerefore the current that flows in reverse (which is a very small current) will be constant. Because current is constant, voltage will drop at a constant (linear) rate, unlike with the photoresistor. The LED's orientation must be reversed in this case. (22 pF capacitor) 

**We were not able to determine the capacitance needed so Dr. Bogen helped us and told us which ones to use. We know the output of the RC circuit is going to be some Result = x. This means that the program will be looped x times before the capacitor is discharged. While we do not know how long each loop takes, we cannot specify the time it takes to discharge either. We only know that it takes x loops to discharge, so this will serve as our measurement of time. The code is attached here

This code was provided in the lab by Dr. Bogen. 

RC Time circuit



Part 4.3 - Galvanic Skin Resistance


This part of the lab was particularly interesting because we essentially created a device used in lie detection! We essentially used our body as a resistor and monitored the resistance between two fingers. One finger held on to one electrode (wire) while the other finger to another electrode (wire). The code is attached here.


GSR Circuit






Part 5 - How Fast Can You Tap Your Finger


Here we constructed a system that measures how fast you can press down on a button, which for us were the galvanic sensor-type wires. We could do this two ways: counting the presses over a set period, or time how long it takes to press the "
button" a set number of times. We created the test for how fast one can press the wires exactly ten times.

This was especially difficult for us to create because the Serial Monitor took many recordings when the pushbutton was pressed for more than approximately one sec. Therefore, we decided to work with the wires rather than the pushbutton. For this part of the lab, the code is attached here. In the video below, the task is demonstrated.








Finally, the Fritzing circuit image is attached below.



No comments:

Post a Comment

Disqus Shortname

Ads Inside Post

Comments system