Pages: [1]   Go Down
Author Topic: Learn how to control 8 LED's with 74HC595 IC  (Read 1390 times)
0 Members and 1 Guest are viewing this topic.
Porto
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys this was first tutorial,  I've just started a few months ago learning electronics (previously I've just knew how to program in C and Python). When I finished this project (took me about 5 hours or something) I've decided to share to help anyone that is starting in electronics.

What’s this project about?
Basically we have an Ultrasonic sensor that measures the distance and the LED’s bar graph will light up according to our distance from the sensor and as we get closer the buzzer beeps in a different way.
I think that it's a good project to learn how 8 bit shift registers work! (74HC595 IC in this case)

Check out the YouTube video and my website for all the information !

http://randomnerdtutorials.com/arduino-ultrasonic-sensor-with-leds-and-buzzer/

Thanks!



If you have any questions or suggestions, leave a comment!
« Last Edit: March 27, 2013, 06:52:07 pm by RuiSantos » Logged

For some Awesome Arduino Projects  click -> www.randomnerdtutorials.com

Portugal
Offline Offline
Edison Member
*
Karma: 37
Posts: 1575
Pretending you know everything then you will learn nothing.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post the code
Logged

Debian,Mint,Ubuntu
Arduino Mega 2560
Arduino Nano
Arduino Duemilanove
MAC OS Montain Lion
Raspberry PI Model B


Porto
Offline Offline
Newbie
*
Karma: 0
Posts: 30
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The code is on instructables... but I will post here too smiley

int tonePin = 4;    //Tone - Red Jumper
int trigPin = 9;    //Trig - violet Jumper
int echoPin = 10;   //Echo - yellow Jumper
int clockPin = 11;  //IC Pin 11 - white Jumper
int latchPin = 12;  //IC Pin 12 - Blue Jumper
int dataPin = 13;   //IC Pin 14 - Green Jumper

byte possible_patterns[9] = {
B00000000,
B00000001,
B00000011,
B00000111,
B00001111,
B00011111,
B00111111,
B01111111,
B11111111,
};
int proximity=0;
int duration;
int distance;

void setup() {
  //Serial Port
  Serial.begin (9600);
 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  pinMode(tonePin, OUTPUT);
}

void loop() {
  digitalWrite(latchPin, LOW);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1000);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
 
  /*if (distance >= 45 || distance <= 0){
    Serial.println("Out of range");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }*/
 
  proximity=map(distance, 0, 45, 8, 0);
  //Serial.println(proximity);
 
  if (proximity <= 0){
    proximity=0;
  }
  else if (proximity >= 3 && proximity <= 4){
    tone(tonePin, 200000, 200);
  }
  else if (proximity >= 5 && proximity <= 6){
     tone(tonePin,5000, 200);
  }
  else if (proximity >= 7 && proximity <= smiley-cool{
    tone(tonePin, 1000, 200);
  }
  shiftOut(dataPin, clockPin, MSBFIRST, possible_patterns[proximity]);
  digitalWrite(latchPin, HIGH);

 
  delay(600);
  noTone(tonePin);
}
Logged

For some Awesome Arduino Projects  click -> www.randomnerdtutorials.com

Pages: [1]   Go Up
Jump to: