I hope this is the right section to post this. It does have to do with sensors - particularly a 'piezo element'...but I don't think the sensor is the problem...I think the problem is something else.
Here's the deal - I'm working on a washer/dryer notification project. I want it to email/text me when my washer / dryer is done. I've got the piezo element taped to the side of my dryer, and the piezo element is connected to my Arduino Duemilanove board. While I've been writing the code for this, I naturally have a USB cable connecting my laptop to the Arduino Duelimanove and running serial monitor to watch what's going on.
I thought I had the main part of my code done (haven't really started the notifying via email/text yet), but I discovered that when I have the Arduino run independently from my laptop (not powered/connected via USB cable) on a separate power supply (have tried a 5V and a 9V with same results), it doesn't seem like it's working. What I mean by that is that I let my dryer run through a load of clothes, and the Arduino never notifies me when it's done (lights up 'dryerLedPin' on pin 13 - the little built-in orange LED on the Arduino Duemilanove board). It has worked perfectly (turns on 'dryerLedPin' on pin 13 when dryer is 'done') several times when my laptop is connected to the Arduino via USB cable and serial monitor running.
It's the same exact sketch - I don't modify it when I have the Arduino run standalone.
Here is the exact sketch on the Arduino unmodified (except that I removed all the comments just for this post):
const int dryerLedPin = 13;
const int dryerKnockSensor = A0;
const int dryerThreshold = 9;
const unsigned long dryerXSeconds = 300;
const unsigned long dryerIsRunningXSeconds = 600;
const boolean notifyWasherDoneMultipleTimes = 1;
const boolean notifyDryerDoneMultipleTimes = 1;
const int notifyWasherDoneEveryXMinutes = 30;
const int notifyDryerDoneEveryXMinutes = 30;
int dryerSensorReading = 0;
int dryerSensorDetectorCounter = 0;
int dryerSensorDetectorCounterDryerRunning = 0;
unsigned long dryerXSecondsCounter = 0;
unsigned long dryerIsRunningXSecondsCounter = 0;
boolean dryerIsRunning = 0;
boolean dryerIsDone = 0;
#define dryerResetButton 2
int dryerButtonVal = 0;
void setup() {
pinMode(dryerLedPin, OUTPUT);
digitalWrite(dryerLedPin, LOW);
pinMode(dryerResetButton, INPUT);
Serial.begin(9600);
}
void loop() {
dryerSensorReading = analogRead(dryerKnockSensor);
dryerButtonVal = digitalRead(dryerResetButton);
if (dryerButtonVal == HIGH) {
digitalWrite(dryerLedPin, LOW);
dryerSensorDetectorCounterDryerRunning = 0;
dryerIsRunningXSecondsCounter = 0;
dryerIsDone = 0;
dryerIsRunning = 0;
}
Serial.println(dryerSensorReading);
Serial.println(dryerXSecondsCounter);
Serial.println(dryerSensorDetectorCounter);
Serial.println(millis());
if (millis() >= dryerXSecondsCounter + (dryerXSeconds * 1000)) {
dryerSensorDetectorCounter = 0;
dryerXSecondsCounter = 0;
}
if (dryerIsRunning == 0 && dryerIsDone == 0) {
if (dryerSensorReading >= dryerThreshold) {
Serial.println("Dryer Detect!");
if (dryerSensorDetectorCounter == 0) {
dryerSensorDetectorCounter = dryerSensorDetectorCounter + 1;
dryerXSecondsCounter = millis();
} else {
if (millis() <= dryerXSecondsCounter + (dryerXSeconds * 1000)) {
dryerSensorDetectorCounter = dryerSensorDetectorCounter + 1;
} else {
dryerSensorDetectorCounter = 1;
dryerXSecondsCounter = millis();
}
}
if (dryerSensorDetectorCounter == 3) {
dryerIsRunning = 1;
dryerSensorDetectorCounter = 0;
dryerXSecondsCounter = 0;
Serial.println("**************************DRYER IS RUNNING*************************");
}
}
}
if (dryerIsRunning == 1 && dryerIsDone == 0) {
if (dryerSensorReading >= dryerThreshold) {
Serial.println("Dryer is still running!");
if (dryerSensorDetectorCounterDryerRunning == 0) {
dryerSensorDetectorCounterDryerRunning = dryerSensorDetectorCounterDryerRunning + 1;
dryerIsRunningXSecondsCounter = millis();
} else {
if (millis() <= dryerIsRunningXSecondsCounter + (dryerIsRunningXSeconds * 1000)) {
dryerIsRunningXSecondsCounter = millis();
}
}
} else if (millis() >= dryerIsRunningXSecondsCounter + (dryerIsRunningXSeconds * 1000)) {
dryerSensorDetectorCounterDryerRunning = 0;
dryerIsRunningXSecondsCounter = 0;
dryerIsDone = 1;
dryerIsRunning = 0;
digitalWrite(dryerLedPin, HIGH);
}
}
if (dryerIsDone == 1) {
Serial.println("************DRYER IS DONE**********");
}
delay(250);
}
I have tried removing all the 'serial-related stuff' from the sketch and uploading to the Arduino for when I run the Arduino 'standalone' but that didn't seem to help.
As far as the hardware/circuit goes, I have it hooked up basically how it shows on this page:
But here's a photo of it sitting on my dryer (being powered by a separate DC power supply - not connected to a laptop/computer):
(The red and black wires going off the picture to the left are to the piezo sensor)
I have no idea what's going on here and was thinking someone here have maybe had a similar problem before...any other info needed from me, just ask.