Hardware part: -
Complete circuit is quite big so it is divided in two sections. One section includes opto-couplers
(datasheet), ULN2003A (datasheet) chip and relays. Second section includes multivibrator, and stepper motor driver. Figure given below shows first section of circuit.

Connections: - As shown in figure five opto-couplers are used to drive relays through ULN chip using LPT port of PC. The anodes and collectors of every opto-couplers are tied with Vcc. The cathode of each opto-coupler is connected with data pins D0(2) - D4(6). Emitters of each opto-coupler are connected to inputs of ULN chip through current limiting resistors. Outputs of ULN drive relay coils.

Second section of circuit is as shown in above figure. It includes IC555(datasheet) as astable multivibrator, decade counter chip 4017(datasheet), and ULN2003A. Output frequency of IC555 can be changed by changing the resistor R2 to R6. This output is given as clock input to counter IC. Its four outputs are given as input to ULN chip. Q0 and Q2 outputs are given directly while Q2 & Q4 outputs are given through 2 C/O relay as shown. Outputs of ULN chip is connected with stepper motor coil.
Operation: -
-
Sending low logic on any data pin of LPT will turn on that opto-coupler.
-
It will send high op to input of ULN chip. That will switch on the relay.
-
When relay is switched on one of the resistor from R2 - R6 get connected to IC555 and it will start generating pulses.
-
Depending upon the resistor connected the op pulse frequency will be
-
|
Sr. No. |
Transistor |
Resistor |
Frequency |
RPM |
|
1 |
Q1 |
R2 = 6.8 K |
100 Hz |
30 |
|
2 |
Q2 |
R3 = 9.1 K |
75 Hz |
25 |
|
3 |
Q3 |
R4 = 10 K |
70 Hz |
20 |
|
4 |
Q4 |
R5 = 15 K |
50 Hz |
15 |
|
5 |
Q5 |
R6 = 20 K |
35 Hz |
10 |
-
Above table also shows the RPM of motor when one particular resistor is connected.
-
When 4017 receives this pulse input it will produce the output on Q0 - Q3 (1, 2, 3, 4) in this manner
-
|
Outputs |
|
1 |
2 |
3 |
4 |
|
1 |
0 |
0 |
0 |
|
0 |
1 |
0 |
0 |
|
0 |
0 |
1 |
0 |
|
0 |
0 |
0 |
1 |
Software Section:-
The figure given below shows application design.

There are total 6 buttons, 2 radio buttons, 3 group boxes, 3 static texts and 1 edit box. To set their properties please refer the table.
|
Sr. No. |
Item |
Property |
Setting |
|
1 |
Button |
ID
Caption |
IDC_STRT
Start Rotating |
|
2 |
Button |
ID
Caption |
IDC_STP
Start Rotating |
|
3 |
Button |
ID
Caption |
IDC_INC
Increase |
|
4 |
Button |
ID
Caption |
IDC_DEC
Decrease |
|
5 |
Button |
ID
Caption |
IDC_STR
Start |
|
6 |
Button |
ID
Caption |
IDC_STOP
Stop |
|
7 |
Radio Button |
ID
Caption |
IDC_CLK
Clockwise |
|
8 |
Radio Button |
ID
Caption |
IDC_ACLK
Anticlockwise |
|
8 |
Group Box |
caption |
Direction |
|
9 |
Group Box |
caption |
Speed |
|
10 |
Group Box |
caption |
Automatic reversible mode |
|
11 |
Static Text |
caption |
RPM |
|
12 |
Static Text |
caption |
Enter time in sec. :- |
|
13 |
static Text |
ID
caption |
IDC_CNT
0 |
|
14 |
Edit Box |
ID |
IDC_TIME |
After completing the design now we have to attach two variables with IDC_CNT and IDC_TIME. So open class wizard and open member variables. Click on particular ID and attach variables m_scnt of type CSring with IDC_CNT and m_itime of type int with IDC_TIME. Attach one more variable to dialog class of int type with name m_c.
Now for timer event we need to add one more ID to handle timer functions. For this open resource view and right click on resources and select resources symbols from popup menu. Click new and give IDC_CLK_TMR as name and 1 as value.
Now we have to attach function with each button as well as radio button. For this just double click on each button and leave the name of the function as it is just click OK. Then open class wizard select dialog ID and then select WM_TIMER event. Click on add function button.
Click here for coding part