Shahariar
Published © CC BY

Washing Machine Timer

Replacement for broken mechanical timer of a washing machine with electronic timer.

IntermediateFull instructions provided5 hours3,252
Washing Machine Timer

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
1306 OLED Display
×1
Gravity:Digital Push Button (Yellow)
DFRobot Gravity:Digital Push Button (Yellow)
×2
Grove - 2-Channel SPDT Relay
Seeed Grove - 2-Channel SPDT Relay
×1
5V 2.5A Switching Power Supply
Digilent 5V 2.5A Switching Power Supply
×1
SparkFun USB UART Serial Breakout - CY7C65213
SparkFun USB UART Serial Breakout - CY7C65213
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)
Tape, Double Sided
Tape, Double Sided
Tape, Green
Tape, Green

Story

Read more

Schematics

Washing machine internal schematic

electronic timer schematic

Code

Untitled file

C/C++
#include "U8glib.h"
//SSD1306 oled waveshare(clk,din,cs,d/c,res);
U8GLIB_SSD1306_128X64 u8g(A4,A5,12,11,10);

volatile int rbc = 0;
volatile int bbc = 0;
 int sec =0;
 int mi = 0;
 int motor_rotation = 0;

void setup()
{
  u8g.setRot180();
  analogReference(INTERNAL);
  pinMode(2,INPUT_PULLUP);
  pinMode(3,INPUT_PULLUP);
  attachInterrupt(0, ISR_SW_RED,FALLING);
  attachInterrupt(1, ISR_SW_BLACK,FALLING);
  pinMode(5,OUTPUT);
  digitalWrite(5,LOW);
  pinMode(4,OUTPUT);
  digitalWrite(4,LOW);
}


void loop(void) 
{
  
 while(!rbc)
 {
   // show timer set menu
    u8g.firstPage();  
    do {
      draw_menu();
       } while( u8g.nextPage() );
   
   // show user proper operation message
     if (rbc>0 && bbc==0)
       {
         u8g.firstPage();  
        do {
            draw_message();
           } while( u8g.nextPage() );
    delay(2000);
    rbc=0; //u8g.clear();
        }
 }

 // start timer
 if(rbc>0)
 {
       sec =59;
       mi = bbc-1;
 
    while(mi>=0)
    {
     // show countdown timer message
        unsigned long temp = millis()+1000;
        while(temp>=millis())
        {
         u8g.firstPage();  
         do {
             draw_timer();
             } while( u8g.nextPage() );
         }
         
         sec=sec-1;
         if(sec%5==0)
         {
         control_motor(); // call every 5 sec
         }
         if (sec <= 0)
            {
             sec = 59;
             mi = mi - 1;
            }      
      }
    rbc = 0; bbc = 0;
    mi = 0 ; sec = 0;
    digitalWrite(5,LOW);digitalWrite(6,LOW);
  }
 
}// end of loop

void draw_menu(void)
{
 u8g.setFont(u8g_font_timB24);
 if (bbc<10)
 {
 u8g.drawStr( 22,30,"0");
 u8g.setPrintPos(38,30);u8g.print(bbc);
 }
 else
 {
   u8g.setPrintPos(22,30);u8g.print(bbc);
 }
 u8g.drawStr( 54,30,":00");
 u8g.setFont(u8g_font_8x13);
 u8g.drawStr( 0,62," 'WASHING TIMER'");
 
 u8g.setFont(u8g_font_5x8);
 u8g.drawStr( 0,47,"Red:START  Black:SET TIME");
 
 
}

void draw_message(void)
{
   u8g.setFont(u8g_font_8x13);
   u8g.drawStr( 0,10," SET WASH TIMER");
   u8g.drawStr( 0,23,"FIRST BY PUSHING");
   u8g.drawStr( 0,36,"THE BLACK BUTTON");
 //  u8g.setFont(u8g_font_8x13);
 u8g.drawStr( 0,62," 'WASHING TIMER'");
 
 u8g.setFont(u8g_font_5x8);
 u8g.drawStr( 0,47,"Red:START  Black:SET TIME");
   
}

void draw_timer(void)
{

      u8g.setFont(u8g_font_timB24);
      if (mi<10)
      {
       u8g.drawStr( 22,30,"0");
       u8g.setPrintPos(38,30);u8g.print(mi);
      }
       else
      {
      u8g.setPrintPos(22,30);u8g.print(mi);
      }
      
      u8g.drawStr( 54,30,":");
      
            if (sec<10)
      {
       u8g.drawStr( 70,30,"0");
       u8g.setPrintPos(86,30);u8g.print(sec);
      }
       else
      {
       u8g.setPrintPos(70,30);u8g.print(sec);
      }
      
      
       if(motor_rotation==0)
       {
        u8g.setFont(u8g_font_5x8);
        u8g.drawStr( 0,47,"  WASHING MOTOR CW Spin");
        digitalWrite(5,HIGH);
       }
 
       if(motor_rotation==1)
       {
        u8g.setFont(u8g_font_5x8);
        u8g.drawStr( 0,47,"  WASHING MOTOR STOPPED ");
        digitalWrite(5,LOW);digitalWrite(4,LOW);    
       }

       if(motor_rotation==2)
       {
        u8g.setFont(u8g_font_5x8);
        u8g.drawStr( 0,47,"  WASHING MOTOR CCW Spin");
        digitalWrite(4,HIGH);
        
       }
       if(motor_rotation==3)
       {
       u8g.setFont(u8g_font_5x8);
       u8g.drawStr( 0,47,"  WASHING MOTOR STOPPED ");
       digitalWrite(5,LOW);digitalWrite(4,LOW);

       }

        u8g.setFont(u8g_font_8x13);
       u8g.drawStr( 0,62," 'WASHING TIMER'");
      
}

void ISR_SW_RED()
{
  sei();
  rbc++;
  cli();
}

void ISR_SW_BLACK()
{
  sei();
  bbc++;
  cli();
}

void control_motor()
{
 motor_rotation++;
 if(motor_rotation>3)
 {
 motor_rotation = 0;
 }
}

Credits

Shahariar

Shahariar

47 projects • 153 followers
"What Kills a 'Great life' is a 'Good Life', which is Living a Life Inside While Loop"

Comments

Add projectSign up / Login