Micro Controller Washing Machine Timer
Micro Controller Washing Machine Timer
Contents:
Introduction 3
Objectives
Design Consideration
Block Diagram
13
Explanation &Innovation
14
Flow Chart
17
C Codes
18
24
Discussion
31
Conclusion
33
References
34
Appendix
35
Introduction:
Washing machines are the devices which are used for cleaning of the clothes without a person rubbing, scrubbing or beating the clothes by oneself and getting dirty. Washing machines have an important place in the modern society, without it one cant imagine how difficult and tiresome life would be (present days). Washing machines are used to reduce human labor and save time. Now days we can see various kinds of washing machines, especially the fully automatic ones as they are the front runners in sale, customers want to have fully automatic machines instead of semi-automatics.
We build a simple washing machine spin timer using microcontroller (PIC 16f877a). Microcontrollers and microprocessors are used to control various electronic devices such as cellular phones, laptops, monitoring systems, controlling systems etc. Microcontrollers and microprocessors are used to perform repetitive operations exactly the same way time after time. They are cheap to produce and all their components are in the same package. They very rarely fail in operation.
For the system created developer is using 1 PIC 16f877a, 1 DC Motor, 1 DIP Switch (8 ways), few resistors, 3 LEDs, 2 SPDT Switches, 2 7-Segment Displays, 1 Training Kit and 1 SK40c.
The functioning of the system is fairly simple, the speed of motor is controlled according to the time, the time is set according to the DIP switch input, the time is shown on the 7-segments displays, the switches provided are used to control the circuit in various manners and at last there are LEDs which act as indicators or alarms as per need in the system.
Developer used C language for coding the system using the MPLAB software, has shown the simulation using Proteus software and has finally made a very simple prototype for presentation purpose.
Objectives:
The Objects for this system can be the design consideration specified by specified by the lecturer, which are:
3.
The spin process should begin when the start button is pressed and then START the Motor (LED ON) The display value on the seven segments should start counting down
5.
Other modifications have been done or added in the system by the developer which is discussed below.
Design Consideration:
For the simple washing machine spin timer system developed by the developer. He has used a PIC 16f877a as the CPU or the brains of the system, which works on the C codes provided to it using MPLAB software via an USB burner.
DIP 8-ways switch is used as input, whose maximum value can be 0-255, it is used to control the countdown timer, we have coded the PIC in such a way that count is maximum at 99, does not go pass it
System starts as the Power switch is turned on and stops as its off
System pauses as soon as Start\Pause switch is turned off and starts as its on
When value of DIP switch is above 99, the 7-segment displays still show value of 99
When the value of DIP switch is below 99, the 7-segment displays show whatever value is at DIP switch
When value on 7- segment displays is above 45 the DC Motor runs at its full speed
When value on 7-segment displays is below 45 and above 0 DC Motor runs at half speed
When value on 7-segment displays goes to 00 from higher values after countdown there is an indicator LED which indicated the spin is over and motor has stopped
Various variations of the switches states are used to control the system in various manner (SW1 and SW2) (00,01,10,11) (conditions)
Microcontroller is the brain of the system; all the decisions are taken by it autonomously. We are using this particular series of PIC microcontroller because:
Below are some of the features present in the PIC 16F877A, its pin and block diagram:
Pin Count Program Memory Max Crystal Speed RAM bytes EEPROM bytes Timers Digital Communication Capture/ Compare/ PWM ADC Comparators
40 pin - PDIP 14KB or 8K 14-bit Flash 20MHz 368 256 2 x 8 bit, 1 x 16-bit 1xA/E/USART, 1 x MSSP(SPI/I2C) 2 x CCP 8ch, 10-bit 2
10
DC Geared Motor (Developer would use LED while presentation as does not have DC Motor):
Developer would be using four SPG50-10K dc geared motors to provide the power to the fan or the mixer inside Tank B.
For controlling the DC Geared motor we are using the motor driver MD10B. It is designed to drive high current brush motor or application. It is designed for wide range of robotics and automotive applications. The board incorporates most of the components of the typical applications. With minimum interface, the board is ready to be plugged and play. Simply add in power, this driver is ready to drive high current motor. It has been designed with capabilities and features of:
11 Industrial grade PCB with heavy copper material for high current applications Each component is soldered properly and tested Support up to 10A maximum 5V logic level compatible inputs 12V as Vcc PWM speed control up to 10KHz Bi-directional control for 1 motor Very low standby power consumption System ground is isolated from motors power source with opto-isolator 4 Schottky diode as clamping diode Dimension: 6cm x 4.5cm
12
13
Block Diagram:
14
Similarly, considering the above situation if DIP switch is 55 and SW2 is START the countdown begins which can be seen on the 7- segments. Now suddenly SW1 is OFF the POWERLED
15 would be OFF, DC Motor would stop rotating, 7-segments will display 00 and ALARMLED would come on indicating spinning is over, whatever condition might be.
Now, if again as first the DIP switch is 55 and SW2 is START the countdown begins which can be again seen on the 7-segments, suddenly SW2 is PAUSE, the countdown pauses then it there, consider the value on 7-segment was 48 when SW2 was toggled to PAUSE the 7-segment would show 48, while DC Motor would stop rotating, countdown down pauses and POWERLED still remains ON. Again SW2 is toggled from PAUSE to START the system starts counting down from where it left that is 48, the DC Motor starts rotating again at full speed as value on 7sements above 45, countdown starts and POWERLED still remains on.
This was the working of the simple washing machine timer system. For the simulation developer has used DC Motor and 7-segments displays (Binary to HEX decoder) but in real life the developer has used just LEDs instead as, could not get DC Motor and 7-segments displays (Binary to HEX decoder). The developer tried to use the code of conversion of HEX to BCD and HEX to decimal but due to less time to debug he did not use the code as code wasnt working properly (needed more time for trial and error).
The innovations which developer has put into the system are: (All of which have been explained above as a whole system)
Using ON/OFF switch separately instead of SK40c Using START/PAUSE switch POWERLED ALARMLED
ON/OFF switch can be used by a user to turn on or off the washing machine, START/PAUSE can be used by user in case he wants to add more clothes to wash or wants to add more washing powder in between of wash, POWERLED is to indicate the system is ON and the ALARMLED helps the user to know the wash is over.
16 The innovation which developer wished to add was changing the direction of motor for a particular interval of time repeatedly (for 1-2 wash), wished to add servo motor which could be used to control opening of water into the system and finally use a LCD for display instead of 7segments in Proteus or LEDs in prototype, but as time was less these all remained just wishes (Developer did do the task which he wished above in Mechatronics Design).
17
Flow Chart:
18
Codes (C Language):
#include <pic.h> #include <htc.h> #ifndef _XTAL_FREQ #define _XTAL_FREQ 20000000 #endif //===============configuration============================== __CONFIG (0x3F32); //===============define IO port============================= #define #define #define #define #define #define #define ALARM POWERLED SW1 SW2 DIP DISPLAY DCMOTOR RA0 RA1 RB0 RB1 PORTC PORTD RE0 //When i==0 or goes to it then LED ON //When SW1==1 LED ON if SW1==0 then LED OFF //ON & OFF switch //START & PAUSE switch //Input for the timer or counter //7 Segments, LCD or LED //Spinner //Defining crystal frequency //Header files
//====================MAIN================================ void main() { TRISA=0b00000000; TRISB=0b11111111; TRISC=0b11111111; TRISD=0b00000000; TRISE=0b00000000; //All outputs //All inputs //All inputs //All outputs //All outputs
19
int i; i=PORTC; if(SW1==0 && SW2==0) { POWERLED=0; DISPLAY=0b00000000; DCMOTOR=0; ALARM=0; } if(SW1==0 && SW2==1) { POWERLED=0; DISPLAY=0b00000000; DCMOTOR=0; ALARM=0; } if(SW1==1 && SW2==0) { POWERLED=1; DCMOTOR=0; if(i>99) { DISPLAY=0b01100011; } if(i<=99) { DISPLAY=i; } } if(SW1==1 && SW2==1)
//If OFF and PAUSE //POWERLED OFF //7 Segments shows 00 //DC Motor doesn't rotate //ALARMLED OFF
//If OFF and START //POWERLED OFF //7 Segments shows 00 //DC Motor doesn't rotate //ALARMLED OFF
//POWERLED ON // DC Motor doesn't rotate //Value on DIP switch is more than 99 //Display 99 on 7 segments //Value on DIP switch is less than or equal to 99 //Display the value of which is at DIP switch
// If ON and START
20
{ POWERLED=1; if(i>99) { i=99; while(i>45) { i=i--; DISPLAY=i; delay(50000); DCMOTOR=1; while(SW2==0) { DISPLAY=i; DCMOTOR=0; POWERLED=1; if(SW1==0) { break; } } if(SW1==0) { PORTD=0x00; DCMOTOR=0; i=0; } } while(i<=45 && i>0) { i=i--; DISPLAY=i; delay(50000); DCMOTOR=1; //i=i-1 (decrementing) //Display value of i after decrement //Delay between change of values //DC Motor runs at full speed //While value of i is less or equal to 45 and above 0 //7 Segments shows 00 //DC Motor doesn't rotate //Value of i assigned to be 00 //If OFF //Come out of loop immediately //Display the value of last i on 7-segments //DC Motor doesn't rotate //POWERLED ON //If OFF //i=i-1 (decrementing) //Display value of i after decrement //Delay between change of values //DC Motor rotates at full speed //While Pause //Display 99 on 7 segments //While value of i is more than 45 //POWERLED ON //Value on DIP switch is more than 99
21
delay(8000); DCMOTOR=0; delay(4000); while(SW2==0) { DISPLAY=i; DCMOTOR=0; POWERLED=1; if(SW1==0) { break; } } if(SW1==0) { PORTD=0x00; DCMOTOR=0; i=0; } } while(i==0) { DISPLAY=0x00; DCMOTOR=0; ALARM=1; } } //7 Segments shows 00 //DC Motor doesn't rotate //ALARMLED ON //While i==0 or becomes equal to 0 //7 Segments shows 00 //DC Motor doesn't rotate //Value of i assigned to be 00 //If OFF //Come out of loop immediately //Display the value of last i on 7-segments //DC Motor doesn't rotate //POWERLED ON //If OFF //For this much interval //DC Motor doesn't rotate //For this much interval //While Pause
//Value on DIP switch is more than 99 //Value of i is same as that on DIP switch //While value of i is more than 45
22
{ i=i--; DISPLAY=i; delay(50000); DCMOTOR=1; while(SW2==0) { DISPLAY=i; DCMOTOR=0; POWERLED=1; if(SW1==0) { break; } } if(SW1==0) { PORTD=0x00; DCMOTOR=0; i=0; } } while(i<=45 && i>0) //While value of i is less or equal to 45 and above 0 { i=i--; DISPLAY=i; delay(50000); DCMOTOR=1; delay(8000); DCMOTOR=0; delay(4000); while(SW2==0) { DISPLAY=i; DCMOTOR=0; POWERLED=1; //Display the value of last i on 7-segments //DC Motor doesn't rotate // POWERLED ON //i=i-1 (decrementing) //Display value of i after decrement //Delay between change of values //DC Motor rotates at full speed //For this much interval //DC Motor doesn't rotate //For this much interval //While Pause //7 Segments shows 00 //DC Motor doesn't rotate //Value of i assigned to be 00 //If OFF //Come out of loop immediately //Display the value of last i on 7-segments //DC Motor doesn't rotate //POWERLED ON //If OFF //i=i-1 (decrementing) // Display value of i after decrement //Delay between change of values //DC Motor rotates at full speed //While Pause
23
if(SW1==0) { break; } } if(SW1==0) { PORTD=0x00; DCMOTOR=0; i=0; } } while(i==0) { DISPLAY=0x00; //7 Segments shows 00 DCMOTOR=0; ALARM=1; } } } } //=================delay============================== void delay(unsigned short n) { for(;n>0;n--); } //For any given number, when n is still greater than 0, n=n-1 //Assigning for Delay //DC Motor doesn't rotate //ALARMLED ON //While i==0 or becomes equal to 0 //7 Segments shows 00 //DC Motor doesn't rotate //Value of i assigned to be 00 //If OFF //Come out of loop immediately // If OFF
24
25
(When at DIP switch all 1s, SW1=1 and SW2=1, DCMOTOR=1, POWERLED=1)
26
(When at DIP switch 5 - 1s, SW1=1 and SW2=1, DCMOTOR=0, POWERLED=0, ALARM=1) (Countdown to 00)
27
(When at DIP switch all 1s, SW1=0 and SW2=1, DCMOTOR=0, POWERLED=0, ALARM=1) (Suddenly SW1=0)
(When at DIP switch all 1s, SW1=0 and SW2=1, DCMOTOR=0, POWERLED=0, ALARM=0) (When at starting SW1=0)
28
29
30
31
Discussion:
In the simple washing machine spin timer system developed, the DIP switches are working perfectly in sync with the 7- Segments Display and the PIC. Whenever there is change in the DIP switches manually the output changes. Plus the SW1 which is used to ON/OFF the circuit is doing work same as if sk40c power switch was on and off, also the SW2 which is used for PAUSE/START is doing the work exactly thought of by the developer and the DC Motor is perfectly being controlled by the switches using the PIC.
There is still room for lot of improvement in the design, mainly more controlling options such as more speeds, various alarms at various intervals, changing of direction of motor, control of water supply, display etc. Developer already has the logic for conversion of HEX TO BCD and BINARY TO DECIMAL but due to time restrained couldnt successfully apply to the system, as the system was getting unstable while the logic for conversion was applied, so needed more time to try out the code. Here below are some of the codes which could be applied: For BINARY from DIP switches to DECIMAL to display
i=0; if(RC0==1) i=i+1; if(RC1==1) i=i+2; if(RC2==1) i=i+4; if(RC3==1) i=i+8; if(RC4==1) i=i+16; if(RC5==1) i=i+32; if(RC6==1) i=i+64; if(RC7==1) i=i+128; return i;
unsigned char convert (unsigned char i) { unsigned char y; unsigned char x; unsigned char z; y = (i / 10) << 4; x=i % 10; z=x+y; return (z); }
Development of this system has taken a lot of time and was very tough, mainly because of the coding of the PIC 16f877a. The hardware or components selection and connection wasnt that tough but, user had to try 100s of combination to finally come up with the code with works fine still not perfect. It is even tougher as developer cant see what is happening inside and has to rely on his logic and experience. And there isnt any one way of solving a problem using codes, there are so many different methods so, it gets even tougher to find one which suits ones design.
33
Conclusion:
The system created by the developer using the DIP switch, PIC 16f877a, SPDT switches, 7 Segment displays, DC Motor, LEDs and resistors works absolutely fine. But it took many hardships to reach to this position of even making the system work (as developer has very low knowledge of C). The developer is happy because in the end his outputs were perfectly being controlled by the inputs but still there are some clashes in the outputs due to some logic error in coding which was hard to find.
First developer had tried to compile code many times using MPLAB but failed due to some or other error, then when MBPLAB code was compiled when it was put in Proteus to simulate it did not work due to some error which developer could not understand, he had to change his logic and try again and again, finally when it worked in Proteus, developer loaded it into actual PIC. Then again same thing, the prototype did not work, developer had to check and recheck the codes and the circuit for the slightest mistake.
After doing this assignment developer came to know one thing for sure nothing is easy in life, and without pain there is no gain. This assignment taught the developer to be patient and keep on trying without giving up because without experience one cant learn, one has to fail to learn.
This assignment has taught the developer more about how does the internals of the microcontroller and microprocessor work, how does the functions happen inside them, plus learnt more about the C language and ASM coding, which would be really helpful to get ready for the FYP.
So, to conclude all the developer has made the block diagram of the circuit, has made the flow chart, has written the codes for the PIC, has done simulation in Proteus and finally did the prototype of the system he developed.
34
References:
35
Appendix:
36
37
38
39
40