Difference between revisions of "Week 3 Lab"

From Robert-Depot
Jump to: navigation, search
(Motor Speed Control)
(Sound, Tone Generation)
Line 47: Line 47:
  
 
=== Sound, Tone Generation ===
 
=== Sound, Tone Generation ===
 +
A kind of analog output. (but different from the light dimming)
 
* With Piezo, adjusting time delay.
 
* With Piezo, adjusting time delay.
** i.e. frequency, not duty cycle.
 
 
* http://www.arduino.cc/en/Tutorial/PlayMelody
 
* http://www.arduino.cc/en/Tutorial/PlayMelody
** the light fading above (<code>analogWrite()</code>)was an adjustment of magnitude, not frequency.  
+
* this adjusts the frequency of the output (tone) not the magnitude.
* With Speaker?  
+
* the light fading above (<code>analogWrite()</code>) adjusted the brightness of the light (magnitude) with PWM.  
 +
* Can you drive a speaker?  
 
[[Image:Pwm_tones.png]]
 
[[Image:Pwm_tones.png]]
  

Revision as of 23:27, 12 April 2009

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 pins (0-5) on your Freeduino.

  • Q: What will the voltage at A_IN be? What are the upper and lower values?

The important part of this sketch is the line where the microprocessor reads the analog input:

val = analogRead(potPin); // read the value from the sensor

  • Q: 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?
  • Q: How can you verify your guess? Try and verify your values, in some plausible manner. Anything goes!!

other loads

photoresistor

  • taking the photoresistor from your 147A kit, it has a resistance of ~160k - ~10k (depending on your lighting conditions)
  • Q: 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?
  • Q: Using methods you invented above, verify your data readings.

strain gauge

flex sensor

ultrasonic rangefinder

Analog Output

Continually varying signals, rather than discrete "steps". Your processor approximates Analog signals with PWM.

LED Dimming

  • File->Sketchbook->Examples->Analog->Fading

   analogWrite(ledpin, value);           // sets the value (range from 0 to 255) 

PWM (pulse width modulation)

  • lights, fading

<youtube v="62gWVWCyw_w" loop="true"/>

Motor Speed Control

  • Basic motor control (DC motor) see week 5

Q: Drive it with the input from the potentiometer.

Sound, Tone Generation

A kind of analog output. (but different from the light dimming)

  • With Piezo, adjusting time delay.
  • http://www.arduino.cc/en/Tutorial/PlayMelody
  • this adjusts the frequency of the output (tone) not the magnitude.
  • the light fading above (analogWrite()) adjusted the brightness of the light (magnitude) with PWM.
  • Can you drive a speaker?

Pwm tones.png

BONUS

Cadsoft EaglePCB - the program I have been using to make these schematics.

If you want to get a headstart on the future, download this software: http://www.cadsoft.de/download.htm. It is free. And then you can design complete circuits, from schematic to layout to fabrication. (It is also installed on the lab computers)