Week 3 Lab

From Robert-Depot
Revision as of 09:28, 16 October 2009 by Rtwomey (talk | contribs) (force / pressure sensor)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

from Electronic Technologies for Art

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

Pot in.png

A_IN can be any of the Analog In pins (0-5) on your Freeduino.

Pot photo.JPG

  • 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

Photo resistor.png

Photoresistor.JPG

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: val = analogRead(potPin); Looking at the Arduino help for that function (analogRead()), what do you think the value val 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 map() 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 [1]

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)

FSR.JPG

datasheet purchase

Voltage returned is proportional to force applied to surface:

Flexi-response.gif

Application circuit ([2]):

flexi-circuit-new.jpg

Good for substantial physical interaction (this project: http://roberttwomey.com/hitme/)

more force sensors

FlexiForce Sensors: http://www.tekscan.com/flexiforce/flexiforce.html

IR rangefinders

Sharp GP2D12 INFRA-RED RANGER

IR RANGER.JPG

"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." [3]

datasheet

One of many Sharp Rangers, with different effective ranges 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 analogWrite() function.

NOTE: The function analogWrite() 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"/>

LED FADER.JPG

  • It looks like a MacBook napping...
  • Get this working. Then...
  • Q: Drive this dimming example with the light sensor from before.
    • use analogRead() to get the value from the sensor, like you did before, then use analogWrite() to output the value to the LED. NOTE: analogRead() will return values from 0-1023, and analogWrite() 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 map()
  • 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).

Lamp fader.png

BULB.JPG

Motor

  • Basic motor speed control (for a DC motor).
  • Same circuit as above, swapping the motor for the lamp.

MOTOR SPEED.JPG

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 (analogWrite()) 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:

A Cornucopia of sensors

I gave some examples of sensors in the first part of today's lab.

Actuators, for future reference

SERVO.JPG

Servo

SOLENOID.JPG

Solenoid

Stepper Motor

Cellphone buzzer (I have one here)

Buzzer.JPG

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)