Arduino Workshop-Shift Register 8-Bit Binary Counter
In this project, we are going to use additional ICs in the form Shift Register 8-Bit Binary Counter, to enable us to drive LEDs to display a binary counter. In this project, we will drive eight LEDs independently using just three output pins from the Arduino.Required Component :
1.Arduino
2. Resistors
3. 5mm LED
7. Breadboard\
Circuit diagram Shift Register 8-Bit Binary Counter:
Examine the diagram carefully. Connect the 5V to the top rail of your breadboard and the ground to the bottom. The chip has a small dimple on one end; this dimple goes to the left. Pin 1 is below the dimple, pin 8 at bottom right, pin 9 at top right, and pin 16 at the top left. You now need wires to go from the 5V supply to pins 10 and 16, as well as wires from the ground to pins 8 and 13. A wire goes from digital pin 8 to pin 12 on the IC. Another one goes from digital pin 12 to pin 11 on the IC, and finally, one from digital pin 11 to pin 14 on the IC. The 8 LED’s have a 560Ω resistor between the cathode and ground. The anode of LED 1 goes to pin 15. The anode of LEDs 2 to 8 goes to pins 1 to 7 on the IC. You will need a bypass capacitor (otherwise known as a decoupling capacitor) to go between the power supply pin and the ground. Make sure its voltage rating is higher than the supply voltage being used. The leads should be kept short, with the capacitor as close to the chip as possible. The purpose of this capacitor is to reduce the effect of electrical noise on the circuit. Once you have connected everything up as in Figure , check that your wiring is correct and the IC and LEDs are the right way around. Then enter the code.Shift Register 8-Bit Binary Counter[/caption]
Code Shift Register 8-Bit Binary Counter :
int latchPin = 8; //Pin connected to Pin 12 of 74HC595 (Latch) int clockPin = 12; //Pin connected to Pin 11 of 74HC595 (Clock) int dataPin = 11; //Pin connected to Pin 14 of 74HC595 (Data) void setup() { //set pins to output pinMode(latchPin, OUTPUT); pinMode(clockPin, OUTPUT); pinMode(dataPin, OUTPUT); } void loop() { //count from 0 to 255 for (int i = 0; i < 256; i++) { shiftDataOut(i); //set latchPin low then high to send data out digitalWrite(latchPin, LOW); digitalWrite(latchPin, HIGH); delay(1000); } } void shiftDataOut(byte dataOut) { // Shift out 8 bits LSB first, clocking each with a rising edge of the clock line boolean pinState; for (int i=0; i<=7; i++) { // for each bit in dataOut send out a bit digitalWrite(clockPin, LOW); //set clockPin to LOW prior to sending bit // if the value of DataOut and (logical AND) a bitmask // are true, set pinState to 1 (HIGH) if ( dataOut & (1<<i) ) { pinState = HIGH; } else { pinState = LOW; } //sets dataPin to HIGH or LOW depending on pinState digitalWrite(dataPin, pinState); //send bit out before rising edge of clock digitalWrite(clockPin, HIGH); } digitalWrite(clockPin, LOW); //stop shifting out data }
No comments