Friday, February 6, 2015

Day 1 - Electronics and Arduinos

Date: 1/30/15       Lab Partner: Camille

Getting Started with Arduinos - Session 1

Section 1 - The Simplest Circuit
We began this lab by installing the Arduino software. Then we built "the simplest circuit" consisting of a voltage source from the Arduino chip and a 1kΩ resistor. Using Ohm's Law we know that since the voltage from the Arduino is 3.3V and the resistor is 1kΩ that the current through the circuit must be 3.3mA. Since one cannot tell just by looking if current is flowing in a circuit, we used an ammeter to measure the current and confirmed that it was approximately 3.3mA.

Section 2 - Bright Lights, Big Currents
Another method to detect if current is flowing through a circuit is to use an LED. LED's allow there to be a noticeable physical change that humans can see, when sufficient current is running through a circuit. We added a red LED to our "simplest circuit", being careful to make sure the LED was oriented correctly since LEDs only allow current to flow through them in one direction. It is important that we keep the resistor in the circuit with the LED because without a high resistance the current will be extremely large, as we can see from Ohm's law, and the current will be much too great and will burn out the LED.

While you should always make sure to include a resistor in a circuit with an LED it is important that different resistors change the brightness of the LED. The lower the resistance the brighter the LED appears. However, if you cut the resistance in half the LED doesn't look twice as bright, although this has to do with the logarithmic way in which humans perceive brightness.

Section 3 - In the Blink of an Eye
As we just learned, changing the resistance in the circuit changes the brightness of the LED. However, there are other ways to change the LED's brightness, or at least the perceived brightness. This can be done by changing the percentage of time that the LED is on, called a duty cycle. The technique used to do this is called pulse width modulation or PWM. We explored PWM using the Arduino chip by creating a program that told the chip to perform and x% duty cycle with x being a number y, between 0 (fully off) and 255 (fully on), over 255 (y/255). We confirmed that this was working by monitoring the voltage across the resistor with a digital oscilloscope. The higher the duty cycle the wider the high voltage section was on the oscilloscope, corresponding to a longer percentage of time being on.

To further explore PWM we created an Arduino program to "automagically" :) brighten and dim the LED periodically. We did this by creating a pwmValue variable and incrementing it every time we iterated through the loop and resetting it to 0 every time it went over the maximum value of 255.  You can see this works in the video below as the width of the high voltage section increases over time until it resets to zero once it reaches maximum.


Section 4 - Voltage Divider
Next we explored photocells. Photocells are light-dependent resistors and by using a photocell as one of the two resistors in a voltage divider circuit you can create a circuit that detects changes in light.

Quick side exploration here: the Arduino chip uses 10-bit analog to digital converters to output a voltage between 0 and 5V as a 10-bit binary number which is a number between 0 and 1023 in base 10. If the analog-to-digital (ADC) value is 305 that corresponds to an analog voltage of 1.49V. Going in the other direction, if you have 4.1V this is an ADC value of 840. The smallest voltage step you can get with a 10-bit ADC with input voltages from 0 to 5V is 5/1024 or 0.00488.

Going back to our light-dependent circuit, we used Arduino programs called Serial.begin() and Serial.println() to read the input voltage value as an ADC value. We used this logging of the input voltage to determine if our shadow detector was working. When the sensor pin (the pin taking the voltage inputs and logging them to our computer) is connected to ground we expect and ADC of 0, which we saw. When the sensor pin is connected to directly to the 5V pin we expected to and did in fact see an ADC of 1023. When it is connected to the 3.3V we predicted we'd see 676, and actually saw 679 which is very close. This could be due to the fact that there can be up to a margin of 10% on resistors.

When we connected the sensor pin to our light-dependent circuit, it did work as expected with low ADC values corresponding to bright light, and low-light causing high ADC values. Using this relationship, we programmed an if-then-else control structure that would set an output pin to a high voltage if the ADC was below a threshold value (approximately 600) and would change the voltage to low if the value read by the sensor pin went above this threshold. We then connected this output pin to a second circuit containing an LED. Thus we built a shadow-detecting circuit that would have the LED light up when the circuit detected a shadow. Watch the finished product in the video below!








No comments:

Post a Comment