In this lab I used the Arduino to accept analog input using variable resistors and use this input to change the brightness of an LED using Pulse Width Modulation (PWM), as well as control the tone of a piezoelectric speaker.
Materials: - Arduino
- 10k ohm potentiometers (slide and rotation)
- Photocell resistor
- LEDs
- Breadboard
- Jumper wires
Part 1:
This circuit allows the Arduino to receive a variable voltage by using the potentiometer as a voltage divider between the 5v and ground pins, with the middle pin connected to the Arduino's analog input. The program from the Arduino then takes the value measured from the analog pin and maps it to between 0 and 255 for output to the LED using the analogWrite() function. Below are the circuit diagram and Arduino sketch used for this part.
Here is the final result; the LED fades as the slider on the potentiometer is moved.
Part 2:
This part simply involved two independent potentiometers and LEDs functioning exactly the same as in part one, except one of the potentiometers is a light sensitive photo-resistor, or photocell. I had to change the boundaries in the map() function to accommodate for the fact that the brightness in our room did not reach the full brightness level of the photocell, and the voltage did not go completely to 0 when I covered it with my finger. I used the serial window in the Arduino IDE to receive information from the Arduino, and adjusted the bounds of the map function based on the values it displayed.
As you can see, the analog input from both the potentiometer and photocell can independently control the brightness of the LEDs.
Part 3:
In this part I used the analog input from the photocell to change the tone emitted from a piezoelectric speaker. I actually did not have to change my programing or circuitry very much to accomplish this. I just replaced the LED with the piezoelectric element, and changed the analogWrite() function to tone().
Comments