For this lab, I learned the importance of Pulse-Width Modulation (PWM) and the role it plays in analog output. PWM allows for analog output by simply turning power to the load (or, device) on and off very quickly. The average value of voltage and current fed to the load is controlled by turning the switch between supply and load on and off at a fast pace. The longer the switch is on compared to the off periods, the higher the power supplied to the load is.
The duty cycle of PWM describes the proportion of ‘on’ time to the regular interval or ‘period’ of time. Therefore, a low duty cycle corresponds to low power because the power supplied to the load is off for most of the time. Duty cycle is expressed in percent, 100% being fully on.
I completed a circuit to control a motor with a potentiometer, a circuit to control a servo motor, and a circuit that plays songs through a piezo element.
For this part of the lab, I constructed the following circuit:
The schemeatic for a motor. This motor was controlled by PWM.
I wrote a simple program that turned the motor on and off rapidly within a period of time (in msec). I was able to control the duty cycle by using it as a variable defined as a percentage of that period.
I experimented with these five duty cycles.
Then, I added a potentiometer to the circuit. I modified my program so that the duty cycle (the percentage of time that the motor is on during the given period) is controlled by the potentiometer input. I used the map function to map the analog input value read from the potentiometer to a value between 0 and 50 (50 was a time I chose to use as my period.) This controls how much of each 50 msec period the motor stays on.
I also added an LED to the circuit. The LED was used to show that as less power was given to the motor, more was given to the LED, making it brighter.
As the potentiometer is turned one way, the motor receives less power and the LED grows brighter. When I turn the potentiometer back the other way, the motor speeds up and the LED dims.
For this part of the lab, I created a circuit to control a servo.
The schematic for a circuit with a servo.
I used code provided by the Arduino development software to move my servo in a sweeping fashion:
The servo reaches 180 degrees then rotates the other way.
I then added a potentiometer to my circuit. This allowed for me to control my servo’s movement by turning the potentiometer. I used code provided to me to program the Arduino.
For the final portion of this lab, I created a circuit with a piezo element. A piezo element makes a clicking sound each time it is pulsed with current. If it is pulsed at the right frequency for a musical note, strings of notes can be played in sequence to make music.
The schematic for a circuit with a piezo element.
The code given to me programmed the Arduino to play Twinkle Twinkle Little Star.
I have some musical knowledge (very limited) so I had some fun programming the Arduino to play Mary Had a Little Lamb:
The possibilities are endless!
Overall, this lab was a great way for me to learn the basics of analog output using an Arduino. I also now have an understanding of PWM. I had so much fun playing with servos and creating simple songs like Mary Had a Little Lamb! I am now prepared to move on to bigger and better things!