Description:
The goal of this lab was to learn to control the speed of a DC motor using input from a transducer. In the first part of the lab, I built the circuit and successfully used a potentiometer to control the speed of the DC motor.
For the homework assignment, I chose to use a photocell to control the speed of the DC motor. The scenario that I've created is that when the photocell is surrounded by light the flower is open (the motor is spinning and petals are held open) and when it is dark and no light reaches the photocell the flower closes (the motor stops and the petals close).
Finding the right material for the construction of the flower was a slight challenge. I first tried using a napkin, then paper but neither moved into a closed position when the motor stopped spinning. I then realized that I needed something similar to cloth. I was able to find some duct tape and was pleased to discover that the petals do have a structure to them but also move into a more folded position when resting.
Components Used:
1 - Arduino Uno
1 - Breadboard
1 - 1K Resistor
1 - 10K Resistor
1 - DC motor
1 - Transistor
1 - Diode
1 - Photocell
1 - Battery pack
wires
For the flowers:
duct tape
yellow wire (the center of the flower)
Code:
int photocellPin = 0; // select the input pin for the photocell
int motorPin = 9; // select the pin for the Motor
int valPhotocell = 0; // variable to store the value coming from the photocell
void setup() {
Serial.begin(9600);
}
void loop() {
valPhotocell = analogRead(photocellPin); // read the value from the photocell
Serial.println(valPhotocell);
if (valPhotocell <= 300){ //trouble shooting was conducted to estimate this value
analogWrite(motorPin, 0);
}
else {
analogWrite(motorPin, valPhotocell/4);
valPhotocell = valPhotocell*2; // process the value a little
}
}
- Login to post comments