Go Down

Topic: Using M74HC595B1 with 7-Seg LED and Hall sensors? (Read 1 time) previous topic - next topic

Uber-Ne

Dec 06, 2013, 04:38 am Last Edit: Dec 06, 2013, 05:15 am by Uber-Ne Reason: 1
Hello everyone,

So I plan to make a shift light indicator for my car that has a 5 speed manual. I already made a concept idea with some toggle buttons before the hall effect sensors come. Essentially, the 7 segment LED will loop around in circles when it is in Neutral. When it goes to the dedicated gear, it will display that gear.

Here is what I have so far.

http://www.youtube.com/watch?v=8pJt5wYwUCE&feature=youtu.be



Pins 9-13 controll the buttons, 2-8 are connected to the 7-segment LED.

Here is my code:
Code: [Select]

//initializes the buttons
const int firstPin = 9;
int button1st = 0;
const int secondPin = 10;
int button2nd = 0;
const int thirdPin = 11;
int button3rd = 0;
const int fourthPin = 12;
int button4th = 0;
const int fifthPin = 13;
int button5th = 0;

//initializes the LED screen
void setup()
{              
 pinMode(2, OUTPUT);  
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);
 pinMode(7, OUTPUT);
 pinMode(8, OUTPUT);
 
 pinMode(button1st, INPUT);
 pinMode(button2nd, INPUT);
 pinMode(button3rd, INPUT);
 pinMode(button4th, INPUT);
 pinMode(button5th, INPUT);
}
 
void loop()
{
 button1st = digitalRead(firstPin);
 button2nd = digitalRead(secondPin);
 button3rd = digitalRead(thirdPin);
 button4th = digitalRead(fourthPin);
 button5th = digitalRead(fifthPin);
 
//if the button for 1st gear is pressed, display 1
 if ( button1st == HIGH )
 {
   digitalWrite(6, 1);
   digitalWrite(8, 0);
   digitalWrite(4, 0);
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(5, 0);
   digitalWrite(7, 1);
 }
 else if ( button2nd == HIGH ) //if button for gear 2 is pressed, display 2
 {
   digitalWrite(6, 1);
   digitalWrite(8, 1);
   digitalWrite(4, 0);
   digitalWrite(2, 1);
   digitalWrite(3, 1);
   digitalWrite(5, 1);
   digitalWrite(7, 0);
 }
 else if ( button3rd == HIGH)//display 3
 {
   digitalWrite(6, 0);
   digitalWrite(8, 1);
   digitalWrite(4, 1);
   digitalWrite(2, 1);
   digitalWrite(3, 1);
   digitalWrite(5, 1);
   digitalWrite(7, 0);
 }
 else if ( button4th == HIGH) //display 4
 {
   digitalWrite(6, 0);
   digitalWrite(8, 1);
   digitalWrite(4, 1);
   digitalWrite(2, 0);
   digitalWrite(3, 1);
   digitalWrite(5, 0);
   digitalWrite(7, 1);
 }
 else if ( button5th == HIGH) //display 5
 {
   digitalWrite(6, 0);
   digitalWrite(8, 1);
   digitalWrite(4, 1);
   digitalWrite(2, 1);
   digitalWrite(3, 0);
   digitalWrite(5, 1);
   digitalWrite(7, 1);
 }  
 else //If no buttons are pressed, clear the screen and loop
 {
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 0);
   digitalWrite(5, 0);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 0);
   
   digitalWrite(3, 1);
   delay (100);
   digitalWrite(3, 0);
   digitalWrite(4, 1);
   delay (100);
   digitalWrite(4, 0);
   digitalWrite(5, 1);
   delay (100);
   digitalWrite(5, 0);
   digitalWrite(6, 1);
   delay (100);
   digitalWrite(6, 0);
   digitalWrite(7, 1);
   delay (100);
   digitalWrite(7, 0);
   digitalWrite(2, 1);
   delay (100);
   digitalWrite(2, 0);
 }
}

So essentially what I want to do is use shift registers on the M74HC595B1 so I can add an extra sensor for the reverse gear. All the tutorials I've seen online with shift registers dont use buttons and thats where I get lost on how to implement it with my code/circuit.

Thanks.

Grumpy_Mike

Read the how to use the forum sticky to learn how to post code correctly.

You need resistors in line with each segment of that display.

Quote
All the tutorials I've seen online with shift registers dont use buttons

Look for "shift In" tutorials not "shift out" ones.

CrossRoads

You've not hooked anything up to D14 to D19 (A0 to A5). Why not use those instead of adding a shift register?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Uber-Ne

#3
Dec 07, 2013, 12:13 am Last Edit: Dec 07, 2013, 12:27 am by Uber-Ne Reason: 1

You've not hooked anything up to D14 to D19 (A0 to A5). Why not use those instead of adding a shift register?


I didnt realize I could use the Analog inputs for digital outputs. If thats the case that'll be great for adding just the reverse light indicator.

Edit*

Thanks CrossRoads and Grumpy Mike. The circuit works and now I will just wait until the hall effect sensors come to implement it to the circuit and eventually to my car.

I will post any progress on youtube if anyone is interested.

Grumpy_Mike

Just use pin14 for analog 0, pin 15 for analog 1 and so on.
You still need resistors on that display.

Uber-Ne


Just use pin14 for analog 0, pin 15 for analog 1 and so on.
You still need resistors on that display.


Oh yeah, dont want to burn out the display. I will probably get a Arduino NANO if I feel that the UNO is too big to fit in the car (under the dash) and get a PCB made just to make everything look pretty and neat.

scottyjr

Quote
I will post any progress on youtube if anyone is interested.


Please do. I am particularly interested in how the mounting arrangement of the magnets and switches will be managed.

Quote
and get a PCB made just to make everything look pretty and neat.


If you're going to do that, you might consider creating a board that includes  an ATMega 328 and a few other support components to have everything except the switches in one package.

- Scotty

Uber-Ne


Quote
I will post any progress on youtube if anyone is interested.


Please do. I am particularly interested in how the mounting arrangement of the magnets and switches will be managed.

Quote
and get a PCB made just to make everything look pretty and neat.


If you're going to do that, you might consider creating a board that includes  an ATMega 328 and a few other support components to have everything except the switches in one package.

- Scotty


Nah, I feel that the Nano is cheap enough ($16). Plus the Nano supports 12v so I just need to wire it up to the car or just use a 5v regulator.

Oh and Im installing this on my 2002 RSX and there is plenty of room in the center console. Probably going to use  brackets to hold up the sensors.

Uber-Ne


Quote
I will post any progress on youtube if anyone is interested.


Please do. I am particularly interested in how the mounting arrangement of the magnets and switches will be managed.

- Scotty


See part 2 with working hall effect sensors and H pattern gears.

https://www.youtube.com/watch?v=CVIbi-ujtC0

Uber-Ne



Quote
I will post any progress on youtube if anyone is interested.


Please do. I am particularly interested in how the mounting arrangement of the magnets and switches will be managed.

Quote
and get a PCB made just to make everything look pretty and neat.


If you're going to do that, you might consider creating a board that includes  an ATMega 328 and a few other support components to have everything except the switches in one package.

- Scotty


Nah, I feel that the Nano is cheap enough ($16). Plus the Nano supports 12v so I just need to wire it up to the car or just use a 5v regulator.

Oh and Im installing this on my 2002 RSX and there is plenty of room in the center console. Probably going to use  brackets to hold up the sensors.


Alright so there wasnt enough room in the RSX as I initially thought. The boot really sinks in so there is no way to effectively put 6 hall effect sensors in that small space.

So there was a redesign where I would only use 2 toggle switches and 2 hall effect sensors. There is a second lever that goes forward and back when I move the stick left and right .  Of course the driver doesnt see this second level because it is inside the center console.

I used this to my advantage and lined up 2 sensors to where the second lever goes forward and back. I then installed 2 toggle switches in front and behind the main stick shift. So if the switch infront is clicked when going into 3rd gear, the Arduino will be instructed to send a 3 on the display. If I shift to 5th, the right sensor will be magnetized and the switch in front will be clicked.

See my code for a better explanation, I will post pics when I can.

Code: [Select]
const int UpButtonPin = 9;
int buttonUp= 0;
const int DownButtonPin = 10;
int buttonDown = 0;
const int LeftSensorPin = 11;
int sensorLeft = 0;
const int RightSensorPin = 12;
int sensorRight = 0;


void setup()
{               
  pinMode(2, OUTPUT); 
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(15, OUTPUT);
 
  pinMode(buttonUp, INPUT);
  pinMode(buttonDown, INPUT);
  pinMode(sensorLeft, INPUT);
  pinMode(sensorRight, INPUT);

}
 
void loop()
{
  buttonUp = digitalRead(UpButtonPin);
  buttonDown = digitalRead(DownButtonPin);
  sensorLeft = digitalRead(LeftSensorPin);
  sensorRight = digitalRead(RightSensorPin);

  //1st
  if ( buttonUp == HIGH && sensorLeft == LOW )
  {
    digitalWrite(6, 0);
    digitalWrite(8, 0);
    digitalWrite(4, 1);
    digitalWrite(2, 0);
    digitalWrite(3, 1);
    digitalWrite(5, 0);
    digitalWrite(7, 0);
  }
  //2nd
  else if ( buttonDown == HIGH && sensorLeft == LOW )
  {
    digitalWrite(6, 1);
    digitalWrite(8, 1);
    digitalWrite(4, 0);
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(5, 1);
    digitalWrite(7, 0);
  }
    //5th
  else if ( buttonUp == HIGH && sensorRight == LOW)
  {
    digitalWrite(6, 0);
    digitalWrite(8, 1);
    digitalWrite(4, 1);
    digitalWrite(2, 1);
    digitalWrite(3, 0);
    digitalWrite(5, 1);
    digitalWrite(7, 1);
  }
  //RWD
  else if ( buttonDown == HIGH && sensorRight == LOW)
  {
    digitalWrite(6, 1);
    digitalWrite(8, 1);
    digitalWrite(4, 0);
    digitalWrite(2, 0);
    digitalWrite(3, 0);
    digitalWrite(5, 0);
    digitalWrite(7, 0);
    digitalWrite(15, 1);
    delay (100);
    digitalWrite(15, 0);
    delay (100);   
  }
  //3rd
  else if ( buttonUp == HIGH)
  {
    digitalWrite(6, 0);
    digitalWrite(8, 1);
    digitalWrite(4, 1);
    digitalWrite(2, 1);
    digitalWrite(3, 1);
    digitalWrite(5, 1);
    digitalWrite(7, 0);
  }
 
  //4th
  else if ( buttonDown == HIGH)
  {
    digitalWrite(6, 0);
    digitalWrite(8, 1);
    digitalWrite(4, 1);
    digitalWrite(2, 0);
    digitalWrite(3, 1);
    digitalWrite(5, 0);
    digitalWrite(7, 1);
  }
  //Nuetral
  else
  {
    digitalWrite(2, 0);
    digitalWrite(3, 0);
    digitalWrite(4, 0);
    digitalWrite(5, 0);
    digitalWrite(6, 0);
    digitalWrite(7, 0);
    digitalWrite(8, 0);
   
   
    digitalWrite(3, 1);
    delay (100);
    digitalWrite(3, 0);
    digitalWrite(4, 1);
    delay (100);   
    digitalWrite(4, 0);
    digitalWrite(5, 1);
    delay (100);
    digitalWrite(5, 0);
    digitalWrite(6, 1);
    delay (100);
    digitalWrite(6, 0);
    digitalWrite(7, 1);
    delay (100);
    digitalWrite(7, 0);
    digitalWrite(2, 1);
    delay (100);
       
  }
}




Go Up