Go Down

Topic: Project not working without USB cable being plugged in (Read 425 times) previous topic - next topic

domiflichi

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):

Code: [Select]


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:
https://www.arduino.cc/en/Tutorial/Knock
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.

domiflichi

I guess this is sort of a bump/update.

I tried using a different Arduino board (still Duemilanove), but it did not change anything. Still same problem. :(

knut_ny

The value for "dryerThreshold" may change, as powersupply is below 5V when running from USB.

Try 3.3V as external reference and update dryerThreshold
Ny

domiflichi

Ok, thanks...but do you mind elaborating on that? I'm not sure how to do that (use 3.3V as external reference)

domiflichi

I'm also having other problems with these sensors. I've gone through at least 3 of them during all my testing. Eventually it seems that they stop functioning properly. They start acting like they're detecting all kinds of vibrations even though there are no vibrations. So I throw it away and start with a brand new one. This last one just keeps constantly outputting the reading of 1023.

Check out the serial monitor screenshot:



I wish I wasn't such a newb.

Should I be using an accelerometer/gyro instead of these piezos? (I was hoping to avoid further complicating this project/circuit - I'm still working on the Arduino/ESP8266 side separately for the actual notification (send email), and not having much success with that either)

knut_ny

Ny

domiflichi

Wow, it must not have been connected very well. I brought everything in from my garage (where my washer/dryer is), and I just looked at the connections and the resistor came completely out of the Arduino's ground pin. I reconnected it, and tried the serial monitor, and it seems to be working correctly again. I'll have to bring it back to the dryer in the garage later on in the week when I'm able.

Thank you knut_ny!

I'll report back here after I do more tests.

But I still do wonder if the piezo is the best way to go...

Go Up