Tuesday, October 2, 2012

Lab: Analog Output

Overview:

The purpose of this lab was to familiarize myself with performing analog output with motor, servos, and piezo elements.


Pulse-Width Modulation:

Pulse-Width Modulation is a technique I used in order to get analog results (a range of results i.e. 0-255) with digital means (on or off). In order to make the digital output reflect an analog output, I can change the amount of time the light is in an off and on state. For example, If the light switches on for 1.5 milliseconds and off for .5 milliseconds then back to on repeatedly, the light would shine about 75% of its brightness. If the light is on for less and off for more of the time, the light will be more dim. 

I connected a motor to the breadboard controlled by a potentiometer from the analog input side of the Arduino. When I turned the potentiometer one direction the motor would increase speed, and when I turned it the other way the speed would decrease. I also used Serial.print in my code in order to see the speed increase/decrease on the monitor.


A Single Servos:

While the motor from the last circuit helped demonstrate analog control, the motor is weak and can be stopped easily. Servos can also be used to control but because they include a small gearbox inside they give a more powerful movement and can also make it easier to control. The servo has 3 wires: signal, power, and ground.

I connected the Arduino to the white wire (signal) of the servo, the red wire (power) to the voltage, and the black wire (ground) to the ground. The code was a continuous loop making the servo "sweep" from side to side from 0 degrees to 180 degrees.


Music:

A piezo element allows for an output of sound. It works by creating a "click" for every pulse of current it is given. To make a song, I have to give it current at the right frequency. If you want the note A, the frequency will have to be 440 times a second. The frequency is so fast that the output of sound will run together and give you notes!

I connected my Arduino to my piezo element and gave it code that sends the correct frequencies to the piezo to create a the right tone.


Problems:

I ran into a problem while adding the potentiometer to my PWM circuit. The wiring was not correct so I checked myself by looking back at a previous lab to connect my circuit correctly. If you run into a problem with an addition to your circuit, try getting to addition to work by itself (in my case the potentiometer and an led) and then connect it to your current circuit the correct way.


Links:

For more information on analog outputs:

No comments:

Post a Comment