Circuit 1 Code:
Default Code for 1 Blinking LED with Potentiometer Control
int sensorPin = 0; // The potentiometer is connected to
// analog pin 0
int ledPin = 13; // The LED is connected to digital pin 13
void setup() // this function runs once when the sketch starts up
{
pinMode(ledPin, OUTPUT);
}
void loop() // this function runs repeatedly after setup() finishes
{
int sensorValue;
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(sensorValue); // Pause for sensorValue
digitalWrite(ledPin, LOW); // Turn the LED off
delay(sensorValue); // Pause for sensorValue
}
Circuit 1 Video:
My apologies for the lack of voice editing. The hoarseness of my voice after being overly enthusiastic at a sporting event this week would not have worked very well for narration. Please see the text comments for my videos.
In this video, I demonstrate the blinking LED that is controlled by the potentiometer in the circuit. The blinking ranged from very slow to so fast that my eyes (and the camera from my phone) could not pick up the blinks. in the video, I turned the potentiometer back from the max so the camera could pick up the blinking.
Circuit 2 Code:
Code for 2 Blinking LEDs with Potentiometer Control
int sensorPin = 0; // The potentiometer is connected to
// analog pin 0
int ledPin = 13; // The LED is connected to digital pin 13
void setup() // this function runs once when the sketch starts up
{
pinMode(ledPin, OUTPUT);
}
void loop() // this function runs repeatedly after setup() finishes
{
int sensorValue;
sensorValue = analogRead(sensorPin);
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(sensorValue); // Pause for sensorValue
digitalWrite(ledPin, LOW); // Turn the LED off
delay(sensorValue); // Pause for sensorValue
}
Circuit 2 Schematic:
Circuit 2 Photo:
Circuit 2 Video:
For the second circuit, I was able to add an LED to have them both blink in tandem. I added the second LED in series with the first LED so I did not need to add another resistor to the circuit. I also added a third LED in the same fashion but was not able to upload the video.
Circuit 3 Code:
Code for 2 Blinking LEDs with Digital Potentiometer Control
int sensorPin = 7; // The potentiometer is connected to
// digital pin 7
int ledPin = 13; // The LED is connected to digital pin 13
void setup() // this function runs once when the sketch starts up
{
pinMode(ledPin, OUTPUT);
}
void loop() // this function runs repeatedly after setup() finishes
{
int sensorValue;
sensorValue = digitalRead(sensorPin);
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(sensorValue); // Pause for sensorValue
digitalWrite(ledPin, LOW); // Turn the LED off
delay(sensorValue); // Pause for sensorValue
}
Circuit 3 Schematic
Circuit 3 Video
I was not successful in getting the potentiometer to control the blinking in this circuit. I am not sure if it was a code problem or if it was a problem in the way that I wired the circuit. I checked the Arduino reference site online and it appears that my implementation of digitalRead() is proper. I will keep experimenting with this circuit
Reflection
Although I was not able to make everything work this week, I felt like I was able to learn more than I knew previously about circuits. I had built circuits in the past (in physics classes) that involved potentiometers but had never seen what went on behind the scenes in the software. I can think of many uses for a potentiometer (including those mentioned in eCollege) but one of the most common uses I can think of is in a car windshield wiper (one that has the intermittent setting.) The timing of the wiper is adjusted by the potentiometer which translates to the timing interval between wipes being varied.




No comments:
Post a Comment