Lab6 - AutoRolling
Description
There are times when you just can't find the beginning of toilet roll paper, or when your hands are wet so you don't want to touch and scroll it.
AutoRolling detects whether part of the roll paper is visible and obtainable to the user. It uses a photocell sensor to detect the existence of the spare part below the roll, and if it doesn't exist, the motor would try to rotate the roll several times until enough part of paper fall out.
Components Used
1- Arduino Uno
1- Breadboard
1- Photocell sensors
1- DC Motor
1- Diode
1- Transistor
1- 3V Power
1- 1kΩ Resistor
1- 10kΩ Resistor
1- Adhesive tape cleaner handle & some toilet roll paper
Code
/* AutoRolling
*
* Created 9 Mar 2013
* Kate Hsiao
*/
int pcPin = 0;
int motorPin = 9;
int pcVal = 0;
int flag = 0;
int wait = 0;
unsigned long previousMill = 0;
long interval = 2000;
void setup() {
Serial.begin(9600);
}
void loop() {
pcVal = analogRead(pcPin);
if (wait==1) {
unsigned long currentMill = millis();
if (currentMill - previousMill > interval) {
previousMill = currentMill;
wait = 0;
}
}
if (wait==0 && pcVal<390) { // Adjust the value based on light condition
flag = 1;
}
else {
flag = 0;
analogWrite(motorPin, 0);
}
if (flag==1) {
for (int i=0; i<200; i++) {
analogWrite(motorPin, 200);
}
previousMill = millis();
wait = 1;
flag = 0;
}
}
Video
- Login to post comments
Drupal theme by Kiwi Themes.