CIRCUIT TO CREATE 16 DIGITAL INPUTS FROM 5 DIGITAL PINS OF ARDUINO MEGA
If the circuit is not working, remove the potential divider resistors connected to the 9th pin of both 74165 ICs and connect the 9th pin of both 74165 ICs to corresponding digital pin of arduino mega directly without any resistors. That is, connect 9th pin of 1st 74165 to digital pin 12 of arduino mega and 9th pin of 2nd 74165 to digital pin 10 of arduino mega.
From the circuit, it is clear that A – H pins of both 74165s is connected to 5V through pull up resistors of 1K. Pull up resistors helps to keep the state of A – H pins of 74165s to HIGH when the press button switches are not pressed. Similarly, when the press button switches are pressed, corresponding pins of 74165 get grounded through the press button switches. That is, state of that pins will become LOW.
From the circuit, it is clear that A – H pins of both 74165s is connected to 5V through pull up resistors of 1K. Pull up resistors helps to keep the state of A – H pins of 74165s to HIGH when the press button switches are not pressed. Similarly, when the press button switches are pressed, corresponding pins of 74165 get grounded through the press button switches. That is, state of that pins will become LOW.
Pin out Diagram of 74165
Pin out diagram of 74165 is given below. 74165 has 16 pins out of which eight pins (A, B, C, D, E, F, G and H) are parallel data input pins. Analysis of the typical load, shift and inhibit sequence of 74165 given in page 4 of datasheet will give a clear idea about the functions of all the pins of 74165.
Connection between arduino mega and 74165 can be summarized as:
- CLK INH (Pin 15) of both 74165s is connected to the digital pin 5 of arduino mega.
- SER (Pin 10) of both 74165s is connected to ground.
- CLK (Pin 2) of both 74165s is connected to the digital pin 3 of arduino mega.
- SH/LD (Pin 1) of both 74165s is connected to the digital pin 2 of arduino mega.
- Gnd pin of Arduino mega should be connected to ground of voltage source.
- QH (pin 9) of 1st 74165 is connected to the digital pin 12 of arduino mega through a voltage divider.
- QH (pin 9) of 2nd 74165 is connected to the digital pin 10 of arduino mega through a voltage divider.
- Resistors of 1K should be connected to the digital pins to reduce the current flow from arduino mega.
int SH_LD = 2; // SH/LD (Pin 1) of 74165 is connected to the digital pin 2 of arduino mega. int CLK = 3; // CLK (Pin 2) of 74165 is connected to the digital pin 3 of arduino mega. int CLK_INH = 5;// CLK INH (Pin 15) of 74165 is connected to the digital pin 5 of arduino mega. int i=0; // the setup function runs once when you press reset or power the board void setup() { Serial.begin(9600); pinMode(0, OUTPUT); pinMode(SH_LD, OUTPUT); pinMode(CLK, OUTPUT); pinMode(CLK_INH, OUTPUT); pinMode(10, INPUT); pinMode(12, INPUT); } // the loop function runs over and over again forever void loop() { // Turn off LED 2 digitalWrite(0,LOW); digitalWrite(CLK_INH, HIGH); digitalWrite(SH_LD, LOW); digitalWrite(CLK, LOW); /******************* INHIBIT SECTION START HERE *****************/ digitalWrite(SH_LD, HIGH); /************** INHIBIT SECTION ENDS HERE ************/ /************** SERIAL SHIFT SECTION START HERE **********/ digitalWrite(CLK_INH, LOW); // Turn on LED 2 digitalWrite(0, HIGH); // LOOP TO GENERATE 8 CLOCK PULSES for(i=0;i<8;i++) { digitalWrite(CLK, LOW); Serial.print(digitalRead(12)); Serial.print(digitalRead(10)); digitalWrite(CLK, HIGH); Serial.print(" "); } Serial.println(" "); // Turn off LED 2 digitalWrite(0,LOW); }Upload this program to your arduino mega. If uploading is successful, open your serial monitor. Serial monitor will print the state of press button switches in the order 8th switch to 1st switch as shown below. State will be displayed in 8 pairs. 1st pair will be the state of 8th switches of both 74165s. 2nd pair will be the state of 7th switches of both 74165s. If the state of a switch is 0, that switch is in pressed state. Otherwise, that switch will be in released state. That is, parallel data that we entered through the A – H pins of 74165 will be serially shifted through the QH pin of 74165.
Typical load, shift and inhibit sequences of 74165, given in page 4 of the datasheet is divided into two sections. They are Inhibit and Serial Shift.
INHIBIT Section of the Sequence
During the Inhibit section of the sequence, state (HIGH or LOW) of A – H pins of 74165 (this state will be considered as the parallel data) will be stored in 74165.
SERIAL SHIFT Section of the Sequence
During the Serial Shift Section of the sequence, data stored during the inhibit section of sequence will be serially shifted through the QH pin of 74165.
SH_LD (Pin 1 of 74165)
Inhibit section occur during a LOW to HIGH transition of SH_LD pin.
CLK (Pin 2 of 74165)
During the Serial Shift section of the sequence, data stored during the inhibit section of sequence will be serially shifted through the QH pin of 74165 in each LOW to HIGH transitions ofCLK input.
CLK_INH (Pin 15 of 74165)
Serial Shift section starts during a HIGH to LOW transition of CLK_INH.
SER (Pin 10 of 74165)
SER should be LOW always. No operation will takes place if SER is HIGH.
int SH_LD = 2; // SH/LD (Pin 1) of 74165 is connected to the digital pin 2 of arduino mega. int CLK = 3; // CLK (Pin 2) of 74165 is connected to the digital pin 3 of arduino mega. int CLK_INH = 5;// CLK INH (Pin 15) of 74165 is connected to the digital pin 5 of arduino mega. int i=0; // the setup function runs once when you press reset or power the board void setup() { Serial.begin(9600); pinMode(0, OUTPUT); pinMode(SH_LD, OUTPUT); pinMode(CLK, OUTPUT); pinMode(CLK_INH, OUTPUT); pinMode(10, INPUT); pinMode(12, INPUT); } // the loop function runs over and over again forever void loop() { // Turn off LED 2 digitalWrite(0,LOW); digitalWrite(CLK_INH, HIGH); digitalWrite(SH_LD, LOW); digitalWrite(CLK, LOW); /******************* INHIBIT SECTION START HERE *****************/ digitalWrite(SH_LD, HIGH); /************** INHIBIT SECTION ENDS HERE ************/ /************** SERIAL SHIFT SECTION START HERE **********/ digitalWrite(CLK_INH, LOW); // Turn on LED 2 digitalWrite(0, HIGH); // LOOP TO GENERATE 8 CLOCK PULSES for(i=0;i<8;i++) { digitalWrite(CLK, LOW); if(digitalRead(10)==0) { Serial.print("Switch "); Serial.print(8-i); Serial.print(" of Second 74165 is Pressed"); Serial.println(" "); } if(digitalRead(12)==0) { Serial.print("Switch "); Serial.print(8-i); Serial.print(" of First 74165 is Pressed"); Serial.println(" "); } digitalWrite(CLK, HIGH); } // Turn off LED 2 digitalWrite(0,LOW); }
Upload the program to your arduino board. After uploading, open your serial monitor. Now press the switches. Identification number of the pressed switch will be displayed in the serial monitor. Output is given below.
Comments
Post a Comment