//Calibration - Arduino Smart Paint/Towel/Cloth Dryer //Written by: Ali Kazemian (January 31, 2016) //Part of code is used from instructable project : "Arduino Basics: RCtime" //This is related to one of the projects of my course ISE511 @ USC // ATTENTION! after uploading this sketch open the serial monitor, so you can see the readings and compare it to how dry is the paper or towel int sensorPin = 2; long result = 0; long temp = 0; int motorPin = 9; void setup() { Serial.begin(9600); Serial.println("start"); pinMode(motorPin, OUTPUT); } void loop() { temp = RCtime(sensorPin); Serial.println(temp); if (temp < 1400) { //The goal of calibration is finding this threshold value. You will have to change 1400. Serial.println("FAN"); analogWrite(motorPin, 255); //The fan start working as soon as the reading is lower than threshold value (1400). } else { analogWrite(motorPin, 0); // The fan stop working only when the reading is higher than the threshold value (paper or towel is dry!) } delay(1000); } long RCtime(int sensPin) { long result = 0; pinMode(sensPin, OUTPUT); // make pin OUTPUT digitalWrite(sensPin, HIGH); // make pin HIGH to discharge capacitor - study the schematic delay(1); // wait a ms to make sure cap is discharged pinMode(sensPin, INPUT); // turn pin into an input and time till pin goes low digitalWrite(sensPin, LOW); // turn pullups off - or it won't work while (digitalRead(sensPin)) { // wait for pin to go low result++; } return result; // report results }