Changes

Jump to: navigation, search

Classes/2010/VIS147A/Labs

8,716 bytes added, 18:01, 12 January 2010
Lab 8 - Analog Input/Output, PWM
= Lab 8 - Analog Input/Output, PWM =
== Analog Input ==
* File->Sketchbook->Analog->AnalogInput
 
The value of the input signal changes the timing of the light: the lower the signal the lower the on-off frequency, the higher the signal, the higher the frequency. We can return to this at the end of the lab.
 
First we will use a potentiometer as our input.
=== Potentiometer ===
[[Image:Pot_in.png]]
 
A_IN can be any of the Analog In pins (0-5) on your Freeduino.
 
[[Image:Pot_photo.JPG|400px]]
 
*Q1.1: What will the voltage at A_IN be? What are the upper and lower values? (HINT: it is a voltage divider. How do you calculate the voltage in a voltage divider?)
 
=== photoresistor ===
[[Image:Photo_resistor.png]]
 
[[Image:Photoresistor.JPG|400px]]
 
Take the photoresistor from your 147A kit, which has a resistance between 140k - 800 depending on your lighting conditions.
 
*Q2.1: With the same R2 resistor (10k) from above, replacing R1 with the photoresistor, what range of voltages (and corresponding data values) would you expect to see at your A_IN pin?
 
*Q2.2: The important part of this sketch is the line where the microprocessor reads the analog input:<code> val = analogRead(potPin);</code> Looking at the Arduino help for that function (<code>analogRead()</code>), what do you think the value <code>val</code> will be for those highest and lowest voltages at your A_IN pin?
 
*Q2.3: How can you verify your guess for the previous question? Come up with a plausible method, and try it out. Anything goes! (even using functions next weeks material, like Sketchbook->Communication->Graph) If you have a good idea, share it with the class....
 
* Q2.4: How could you make this more sensitive? There are least three ways to try... think in terms of the physical enclosure around the sensor, the hardware setup (a voltage divider), and the software (look at File->Sketchbook->Analog->Calibration..., specifically the <code>map()</code> function)
* Q2.5: Does changing the code make this more sensitive?
 
=== FYI other sensors ===
I have some of them here if you want to try them.
 
==== flex sensor ====
spectra symbol flex sensor [https://www.jameco.com/webapp/wcs/stores/servlet/ProductDisplay?langId=-1&krypto=6pWdQhy2AZPZ2sD8W5xEl6aJV6WqDHEGqOKNa%2FdOSS9%2BxO5uYYYPAp%2FlelrGLAWKNyXGozz0WUJ%2B%0D%0APBDIeyVBNlu11KbfyDwz&ddkey=CookieLogon]
 
==== home made strain gauge ====
A poor man's flex sensor. See page 32 in Forest Mims "Electronic Sensor Circuits & Projects" to make your own.
 
==== force / pressure sensor ====
Force Sensing Resistor (FSR)
 
[[Image:FSR.JPG|300px]]
 
[http://www.trossenrobotics.com/images/productdownloads/FSR%20data.pdf datasheet]
[http://www.trossenrobotics.com/store/p/3221-1-5-Inch-Force-Sensing-Resistor-FSR-.aspx purchase]
 
Voltage returned is proportional to force applied to surface:
 
http://www.tekscan.com/images/Flexi-response.gif
 
Application circuit ([http://www.tekscan.com/flexiforce/flexiforce.html]):
 
http://www.tekscan.com/images/flexi-circuit-new.jpg
 
Good for substantial physical interaction (this project: http://roberttwomey.com/hitme/)
 
[http://www.trossenrobotics.com/store/c/2670-Force-Sensors-Pressure-Touch-Sensors.aspx more force sensors ]
 
FlexiForce Sensors:
http://www.tekscan.com/flexiforce/flexiforce.html
 
==== IR rangefinders ====
Sharp GP2D12 INFRA-RED RANGER
 
[[Image:IR_RANGER.JPG|300px]]
 
"This sensor takes a continuous distance reading and returns a corresponding analog voltage with a range of 10cm (4") to 80cm (30"). The sensor package includes a JST 3-pin connector, three pre-crimped wires, and a booklet with detailed information and examples." [http://www.acroname.com/robotics/parts/R48-IR12.html]
 
[http://www.acroname.com/robotics/parts/SharpGP2D12-15.pdf datasheet]
 
One of many Sharp Rangers, with different effective ranges [http://www.acroname.com/robotics/parts/sharp_guide.pdf comparison guide]
 
==== Ultrasonic rangefinders ====
http://www.acroname.com/robotics/parts/R271-SRF05.html
range of four meters
 
==== And more... ====
See the Homework section.
 
=== can we sample sound? ===
 
* That is a good question.
* We can do definitely do threshold detection: is a sound louder than a certain point.
* Can we make WAV files? I Don't Know...
 
== Analog Output ==
Continually varying signals, rather than discrete "steps". How does a digital microprocessor create an analog output?
 
PWM, duty cycle, and effective voltage.
 
=== LED Dimming ===
*File->Sketchbook->Examples->Analog->Fading
The crux of this sketch is the <code>analogWrite() </code> function.
 
NOTE: The function <code>analogWrite()</code> only works on some digital output pins. Look up the help for the function, it will tell you which pins work: Digital pins 3,5,6,9,10, and 11.
<youtube v="62gWVWCyw_w" loop="true"/>
 
[[Image:LED_FADER.JPG|400px]]
 
* It looks like a MacBook napping...
* Get this working. Then...
* Q: Drive this dimming example with the light sensor from before.
** use <code>analogRead()</code> to get the value from the sensor, like you did before, then use <code>analogWrite()</code> to output the value to the LED. NOTE: <code>analogRead()</code> will return values from 0-1023, and <code>analogWrite()</code> writes values from 0 to 255, so you will need to divide your read value by 4 to get the output value. Or you could use <code>map()</code>
* Q3.1: Does yours turn on when it is light, or does it turn off? Switch this to give it the opposite behavior, in either hardware or software. You could do either!
 
=== Lightbulb ===
Same as the LED, but with a higher current load: your microprocessor can not source enough current to power the bulb. (Or maybe it can, but you probably don't want to test it!) We need to use a power transistor: TIP120. This allows you to control a larger current (the bulb) with a smaller current (digital out from the chip).
 
[[Image:Lamp_fader.png]]
 
[[Image:BULB.JPG|400px]]
 
=== Motor ===
* Basic motor speed control (for a DC motor).
* Same circuit as above, swapping the motor for the lamp.
 
[[Image:MOTOR_SPEED.JPG|400px]]
 
Q: Drive it with the input from the potentiometer.
 
=== Sound/Tone Generation! For Sound People (optional) ===
An analog output, different from the light dimmer. To make a varying sound, you would want to change the frequency of the output signal, not the amplitude.
* This is more like the light blinking from part one, where changing the input voltage will change the rate of the light. But now you will do it with a Piezo, adjusting the time delay in microseconds.
* If you like sound, try this: http://www.arduino.cc/en/Tutorial/PlayMelody, I have a piezo you can use. (Or you can get one at RadioShack).
* This example adjusts the frequency of the output (tone) not the magnitude.
* the light fading above (<code>analogWrite()</code>) adjusts the brightness of the light (magnitude) with PWM.
 
== Homework ==
NEW ASSIGNMENT:
Acquire a sensor of some sort... not one of the ones from your kit. Could be a pressure, temperature, VOC, range-finder, accelerometer (!!) ... there are lots of options. Start with some of the links below. If you need more ideas, look through the web. Be sure to have your new sensor by next week!! We are going to use them in class, for Serial Communications.
 
Don't worry if you don't know how to make it work: if you are concerned whether your choice is viable, send me an e-mail with a link to your sensor of interest before you get it.
 
MORE SENSORS:
* http://www.sparkfun.com/commerce/categories.php?c=23
 
===A Cornucopia of sensors===
I gave some examples of sensors in the first part of today's lab.
* http://www.acroname.com/robotics/parts/c_Sensors.html
* Very good for interactive artworks!
* What else looks interesting?
** temperature
** pressure
** VOCs (Volatile Organic Compounds) [http://www.synkera.com/pdf/Synkera%20VOC%20Data%20Sheet.pdf] (see Natalie Jeremijenko's Feral Robotic Dogs: http://www.nyu.edu/projects/xdesign/feralrobots/)
** Hall Effect sensor
 
===Actuators, for future reference===
 
[[Image:SERVO.JPG|400px]]
 
Servo
 
[[Image:SOLENOID.JPG|400px]]
 
Solenoid
 
Stepper Motor
 
Cellphone buzzer (I have one here)
 
[[Image:Buzzer.JPG|400px]]
 
AC appliances with a relay (!!!!CAUTION CAUTION CAUTION!!! get input from me before you try anything VERY DANGEROUS!!!!) (think dancing pixar light)
 
Anything that moves, blinks, has activity, and runs off electricity... ?
 
== BONUS ==
Cadsoft EaglePCB - the program I have been using to make these schematics. http://www.cadsoft.de/download.htm
 
If you want to get a headstart on the future, download this software. It is free. You can use it to design circuits, from schematic to layout to fabrication. (FYI It is also installed on the lab computers)
 
= Lab 9 - Interfacing with the computer, higher level sensors =
= Lab 10 - Summary, discussion, wind-down / Final Project Work =

Navigation menu