rice washer

hi

currently im doing an automatic/smart rice washer that use arduino.. sadly im new to arduino since my friend just introduce arduino to me past week.. i need all your help or guidance for me to complete this project.. for starter, im currently learning about button/debounce.. the problem i have is understanding the debounce function.. im trying to put break function at the end of the debounce so it will stop it.. and how to put array coding in that particular code..

well my general idea about my project is as a starter, i will push a pushbutton to open the water inlet valve(solenoid valve) and after some time, the valve will close..

sorry for my english.. thanks

Hi crytosis and welcome.

Please post your sketch so far. Use code tags. Also post a scematic or picture of the circuit, if you have one.

Paul

Here is a schematic for a hardware debounced switch. Many switches that I have tested with this circuit need no further debouncing in software.

A simple delay(10); after you detect a switch press should be sufficient to debounce it.

thanks for the reply

as for now, i already build the hardware.. since my inexperience doing circuit, im unable to provide the circuit/schematic itself.. the code i been working is not complete as im still learning to insert break,array and debounce function in a sheet.. im new to coding itself too.. so im very grateful that you guys willingly assist me to get this project done.. i will update the coding time to time

crytosis: the code i been working is not complete as im still learning to insert break,array and debounce function in a sheet.. im new to coding itself too.. so im very grateful that you guys willingly assist me to get this project done.. i will update the coding time to time

Don't let your feeling of having poor code to show get in the way. Everyone was a beginner at one time or another, and learning can be accelerated a lot by showing your code to others, especially if the others you show it to are folks like us, who enjoy helping.

thanks for the encouragement… below is my still broken code… for now im trying to create 2 debounce as for the 1st button, only 1 led(led1) will turn on and 2nd button will trigger 2 led(led2 and led3)… led4 is just for show for now… the error i get is at line 100

too many arguments to function ‘int digitalRead(uint8_t)’

// constant
const int buttonPin1 = 2;
const int buttonPin2 = 3;
int led1 = 10;
int led2 = 11;
int led3 = 12;
int led4 = 13;
// variable
int pinCount = 4;
int ledState1 = LOW;
int ledState2 = LOW;
int ledState3 = LOW;
int ledState4 = LOW;
int buttonState1;
int buttonState2;
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
int timer = 1000;
// debounce
long lastDebounceTime = 0;
long debounceDelay = 50;

void setup () {
  pinMode (buttonPin1, INPUT);
  pinMode (buttonPin2, INPUT);
  pinMode (led1, OUTPUT);
  pinMode (led2, OUTPUT);
  pinMode (led3, OUTPUT);
  pinMode (led4, OUTPUT);
  digitalWrite (led1, ledState1);
  digitalWrite (led2, ledState2);
  digitalWrite (led3, ledState3);
  digitalWrite (led4, ledState4);
}

void loop() {
  
  int reading = digitalRead (buttonPin1, buttonPin2);
  
  if (reading != lastButtonState1) {
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay) {
    
    if (reading != buttonState1) {
      buttonState1 = reading;
      
      if (buttonState1 == HIGH) {
        ledState1 = !ledState1;
      }
    }
  }


  
 
  
 else if (reading != lastButtonState2) {
    lastDebounceTime = millis();
  }
  
  if ((millis() - lastDebounceTime) > debounceDelay) {
    
    if (reading != buttonState2) {
      buttonState2 = reading;
      
      if (buttonState2 == HIGH) {
        ledState2 = !ledState2;
        ledState3 = !ledState3;
      }
    }
  }

  
  digitalWrite (led1, ledState1);
  digitalWrite (led2, ledState2);
  digitalWrite (led3, ledState3);
  digitalWrite (led4, ledState4);
  
  lastButtonState1 = reading;
}

instead of :

 int reading = digitalRead (buttonPin1, buttonPin2);

put int reading; up with the other variables. Next, I'm pretty sure you can only read one input per variable.

you should probably go with

int reading1;
int reading2;

and the rest would be someting like

reading1 = digitalRead(buttonPin1);
reading2 = digitalRead(buttonPin2);

that resolve the problem.. thanks :)

next step is getting the led turn off after a few sec.. all i can do is just delay when the led will toggle after pushing the button.. should i use a new function in this.. if yes, what function should i use

crytosis: that resolve the problem.. thanks :)

next step is getting the led turn off after a few sec.. all i can do is just delay when the led will toggle after pushing the button.. should i use a new function in this.. if yes, what function should i use

You need to post up a description (in english) of your project and how you expect/want it to work i.e.

1) Push button 1 - solenoid and Led turn on for 10 secs and water flows - then turns off after 10 sec 2) Push Button 2 - etc etc etc

Craig

before i started using arduino, i would guess that i could make a single pushbutton that operate like cloth washing maching.. but after started learning arduino, it looks like very hard to make it so i just make simpler version of it.. there is 3 push button

1st push button = water inlet solenoid valve.. it will close after 1 minute 2nd push button = water outlet solenoid valve.. same like 1st push button 3rd push button = a dc motor (for the wash).. im using a stepper motor with L293D

im trying to input array/loop iteration in the code as im trying to create only 1 push button but hey, im a newbie, so lets start simple 1st..

I wouldnt't recommend using the delay function for something so long as 10 seconds. the delay function puts a hold on everything in the program and waits until the delay is done before moving on.

Take a look at the Blink without Delay example sketch and try to incorporate that into your sketch. http://arduino.cc/en/Tutorial/BlinkWithoutDelay

ok… i’ll try and i will upload the code later

crytosis: before i started using arduino, i would guess that i could make a single pushbutton that operate like cloth washing maching.. but after started learning arduino, it looks like very hard to make it so i just make simpler version of it.. there is 3 push button

1st push button = water inlet solenoid valve.. it will close after 1 minute 2nd push button = water outlet solenoid valve.. same like 1st push button 3rd push button = a dc motor (for the wash).. im using a stepper motor with L293D

im trying to input array/loop iteration in the code as im trying to create only 1 push button but hey, im a newbie, so lets start simple 1st..

This is quite easy if you map it out

1) Push Button 2) Timer starts for 60 seconds 3) Turn on Solenoid 4) Check Timer once 60 seconds gone then 5) Turn off Solenoid 6) Start next timer for how long you want motor to run 6) Turn on Motor 7) Check timer until elapsed time = desired time 8) Turn off motor 9) start 3rd timer 10) Open Drain Solenoid 11) Check Timer until elapsed time =desired time 12) Turn off solenoid 13) Sound Buzzer to say cycle completed

You should be able to post your code up and break the actions down into simple steps in a single linear flow with a couple of loops as i have setout above

Craig

sorry for the late update

that idea looks compromising… for now i already done with the valve part… just a simple edit from the debounce example… assume the led is valve for now… since my valve use higher voltage (12V) than arduino can supply (5V), which pin should i put the external power supply… for the timer part, i still dont know how to put it inside the code

// constant and variable (SOV = solenoid valve)
const int inletButton = 2;    // SOV switch input
const int outletButton = 3;   // SOV switch input
const int motorButton = 4;    // motor switch input
const int motorPin1 = 5;      // pin 2 on L293D
const int motorPin2 = 6;      // pin 7 on l293D
const int inlet = 11;         // SOV
const int outlet = 12;        // SOV

int inValve = HIGH;
int outValve = HIGH;
int inletState;
int outletState;
int inletButtonState = LOW;
int outletButtonState = LOW;
int enablePin = 9;            // pin 1 on L293D

// debounce
long lastDebounceTime = 0;
long debounceDelay = 50;

void setup() {
  
  // set switch as input
  pinMode(inletButton, INPUT);
  pinMode(outletButton, INPUT);
  pinMode(motorButton, INPUT);
  
  // set other as output
  pinMode(inlet, OUTPUT);
  pinMode(outlet, OUTPUT);
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(enablePin, OUTPUT);
  
  // enable pin
  digitalWrite(inlet, inValve);
  digitalWrite(outlet, outValve);
  digitalWrite(enablePin, HIGH);

}

void loop() {

  int reading1 = digitalRead(inletButton);
  int reading2 = digitalRead(outletButton);
  
  // start the motor
  if (digitalRead(motorButton) == HIGH) {
    
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);

  }
  
  // stop the motor
  else {
    
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);

  }
    
  // debounce
  if (reading1 != inletButtonState) {
    lastDebounceTime = millis();

  } 

  if (reading2 != outletButtonState) {
    lastDebounceTime = millis();

  }  

  if ((millis() - lastDebounceTime) > debounceDelay) {

    if (reading1 != inletState) {

      inletState = reading1;
      if (inletState == HIGH) {

        inValve = !inValve;

      }

    }

    if (reading2 != outletState) {

      outletState = reading2;
      if (outletState == HIGH) {

        outValve = !outValve;

      }

    }

  }

  digitalWrite(inlet, inValve);
  digitalWrite(outlet, outValve);
  inletButtonState = reading1;
  outletButtonState = reading2;
  
}

i include an attachment of my circuit (still dont know if it good or bad)… by the way, do you have any idea regarding how to connect external power supply to the solenoid(valve)

crytosis: sorry for the late update

that idea looks compromising.. for now i already done with the valve part.. just a simple edit from the debounce example.. assume the led is valve for now.. since my valve use higher voltage (12V) than arduino can supply (5V), which pin should i put the external power supply.. for the timer part, i still dont know how to put it inside the code

// constant and variable (SOV = solenoid valve)
const int inletButton = 2;    // SOV switch input
const int outletButton = 3;   // SOV switch input
const int motorButton = 4;    // motor switch input
const int motorPin1 = 5;      // pin 2 on L293D
const int motorPin2 = 6;      // pin 7 on l293D
const int inlet = 11;         // SOV
const int outlet = 12;        // SOV

int inValve = HIGH; int outValve = HIGH; int inletState; int outletState; int inletButtonState = LOW; int outletButtonState = LOW; int enablePin = 9;            // pin 1 on L293D

// debounce long lastDebounceTime = 0; long debounceDelay = 50;

void setup() {    // set switch as input  pinMode(inletButton, INPUT);  pinMode(outletButton, INPUT);  pinMode(motorButton, INPUT);    // set other as output  pinMode(inlet, OUTPUT);  pinMode(outlet, OUTPUT);  pinMode(motorPin1, OUTPUT);  pinMode(motorPin2, OUTPUT);  pinMode(enablePin, OUTPUT);    // enable pin  digitalWrite(inlet, inValve);  digitalWrite(outlet, outValve);  digitalWrite(enablePin, HIGH);

}

void loop() {

 int reading1 = digitalRead(inletButton);  int reading2 = digitalRead(outletButton);    // start the motor  if (digitalRead(motorButton) == HIGH) {        digitalWrite(motorPin1, LOW);    digitalWrite(motorPin2, HIGH);

 }    // stop the motor  else {        digitalWrite(motorPin1, LOW);    digitalWrite(motorPin2, LOW);

 }      // debounce  if (reading1 != inletButtonState) {    lastDebounceTime = millis();

 }

 if (reading2 != outletButtonState) {    lastDebounceTime = millis();

 }  

 if ((millis() - lastDebounceTime) > debounceDelay) {

   if (reading1 != inletState) {

     inletState = reading1;      if (inletState == HIGH) {

       inValve = !inValve;

     }

   }

   if (reading2 != outletState) {

     outletState = reading2;      if (outletState == HIGH) {

       outValve = !outValve;

     }

   }

 }

 digitalWrite(inlet, inValve);  digitalWrite(outlet, outValve);  inletButtonState = reading1;  outletButtonState = reading2;   }




i include an attachment of my circuit (still dont know if it good or bad).. by the way, do you have any idea regarding how to connect external power supply to the solenoid(valve)

OK you will need a relay or some form of transistor to switch the higher voltages - personally i would just go with a 4 port optoisolated relay board - less than $10 and your Arduino is protected from nasty stuff

http://yourduino.com/sunshop2/index.php?l=product_detail&p=201

Your code seems to jump all over the place - can i suggest you put it in the format that i stepped out above and see how far that gets you ?

Craig

Your code seems to jump all over the place - can i suggest you put it in the format that i stepped out above and see how far that gets you ?

yes please

im having problem with the L293D for overheating.. maybe i try to replace with L298 people suggest.. about the relay, i will try to buy it in near future.. for now i will go to what i have..

crytosis:

Your code seems to jump all over the place - can i suggest you put it in the format that i stepped out above and see how far that gets you ?

yes please

im having problem with the L293D for overheating.. maybe i try to replace with L298 people suggest.. about the relay, i will try to buy it in near future.. for now i will go to what i have..

The relay board was to operate the two solenoids - depending on the size of them you will not be able to operate them with L293 - i assumed you were using that for the motor(s) not the solenoids ? What are the motors doing anyway ? Spinning the rice or somesuch ?

Craig

yes… its for the motor…the motor is to spin the rice… as for the solenoid, can i use normal relay…if yes, where should i put it…

edit:
i put 2 relay for the solenoid… looks work on the paper

crytosis: yes.. its for the motor..the motor is to spin the rice.. as for the solenoid, can i use normal relay..if yes, where should i put it..

edit: i put 2 relay for the solenoid.. looks work on the paper

I am not seeing where you arduino is getting power in this circuit. Yes you can use normal relays of the correct rating for the solenoids - if you get Opto isolated relays then you do not have to worry about the reverse emf protection etc from the solenoids

Craig