Pages: 1 [2] 3 4   Go Down
Author Topic: 7 segment reed switch speedometer help  (Read 4339 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25834
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes, that's normal for a floating input.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Correct me if I am wrong, but does the below code add one to rps once & only once, when analogRead is greater than 1000 and then wait till analogRead is less than 1000 to initiate chk();?

Code:
void reed(){
  while (analogRead(0) >= 1000){}  //Checked ob ein magnet orbei ist. determies if magnet is present
  rps = rps + 1;
  
  while(analogRead(0) < 1000){}
  chk();  
  }

because it seems like it is adding 1 to rps multiple times and I have no idea why. If the code is not doing what I stated above, what would I have to do to get it to do that?
« Last Edit: August 23, 2010, 11:18:22 am by herot » Logged

New Zealand
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Motorcycle racing rocks.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think your input is floating. You need something like this !!!

I can't seem to add the jpg file. Send your email and I'll send it directly to you.
Logged

New Zealand
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Motorcycle racing rocks.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I added an FTP site to my web.



This is what you need to start with. The micro switch should switch to ground so if there is a problem with the wring, you dont blow the 5 volt supply.

Cheers Wallace
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry I dont know what you mean by adding !!!! where do I have to put them?
Logged

New Zealand
Offline Offline
Jr. Member
**
Karma: 0
Posts: 69
Motorcycle racing rocks.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

See the new drawing.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I rewrote the code a bit differently

code: http://ubuntuone.com/p/DuL/

and then wrapped the arduino and most of the wire leading to the reed switch in this electromagnetic protecting tape. The result was that the speedometer worked for speeds lower than 30 or 40 mph, staying pretty consistent. but as I drove faster, the values started to jump all over the place. So I guess ill just have to play around with this on my own. Thank you so much for all your help and ideas.
« Last Edit: August 25, 2010, 07:47:25 pm by herot » Logged

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 74
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are using a switch, why are you using an analog input, each time the magnet passes the switch, you should get a 1 pulse.  Could you not tie this to an interrupt with a rising trigger, and use a digital input and a couter that increases in the interrupt handler.  Then in the loop() you can just sample the counter value every X ms and do your conversion from Rotation to MPH.   Look at the tachometer code example in this forum.  
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That was my original plan, but for some reason, i couldnt get it to work out. I would have loved to use the pulseIn() function, but I couldnt get it to work.
Thanks for the advice though
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi everyone,

I finally figured out what the problem with my project was. For some reason, the arduino wasnt happy when I had connected my reed switch directly from the 5v to the analog input 0. I knew that this speedometer was working before, so I set it up the same way I did before. The difference was that I had put a resistor and LED in the circuit coming from the reed switch as shown below.


I ended up putting three magnets on the wheel itself and setting the refresh rate to half a second in my final code. And the speed is shown in km/h. The only problem is that it only displays the speed in increments of 4 or 5 km/h. Any ideas of how to make it more accurate?
If anyone wants to replicate my project here is the final code:
http://ubuntuone.com/p/EJ4/

When I have more time I am also going to implement a switch to change from mph to km/h.

Thank you for your time and help Marsheng, bullethole, & AWOL.
« Last Edit: August 29, 2010, 05:01:29 pm by herot » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have been working on trying to make this speedometer more accurate, so I measured out the distance my car tire will go in one tire rotation and came up with a formula for the arduino to use in calculating the speed.

Code:
void loop(){
  //Serial.println(analogRead(0));  //drukt runden pro warten. prints rounds per warten
 time = timeend - timestart;
 time = (time / 3600000); //Ändert die zeit zu stunden. ... converts time to hours
 gesch = (0.00193 / time); //calculates velocity in km/h
 led1();
 rech();  
}

void rech(){
  while (analogRead(0) >= 440){}
  timestart = millis();
  while (analogRead(0) < 440){}
  while (analogRead(0) >= 440){}
  timeend = millis();
  loop();
}

full code: http://ubuntuone.com/p/EJn/

when I drove the car though, nothing happened, it just displayed zero kilometers per hour.

Did I make a stupid mistake in my code (please check the full code because I am not sure if my declarations are correct)?

Thanks in advance
« Last Edit: August 29, 2010, 09:00:39 pm by herot » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you calling loop() in a function that is called by loop()?

What types are time and gesch? What does led1() do?
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi PaulS,
Thank you for your reply, I will delete the loop();  time is an unsigned long and gesch is an int. led(); basically prints the speed on my seven segment displays (I know this works because I have another working code, but I wasnt happy with the refresh rate because I didnt use time in this way for calculating the speed.)

Here is a link to the full code if you have any more questions about my definitions.
http://ubuntuone.com/p/EJn/
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
time is an unsigned long and gesch is an int.
Code:
time = (time / 3600000); //Ändert die zeit zu stunden. ... converts time to hours
 gesch = (0.00193 / time);
So, you are dividing an integer (time, the unsigned long) by a constant, storing the resulting (possibly) truncated value.

Then, you are dividing a float by an int, and storing the result in an int.

Well, I can see several places where there might be issues.

Some float variables need to be used, with appropriate casts.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 71
Powered by Arduino
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the quick reply, I understand what you mean by all the different types, but I have no idea how to fix this. Would I have to convert them all to one type then convert back to an interger when it is done calculating?

How would I go about doing this, or is there a link you could direct me to on how to do this?

Thank you in advance.

Logged

Pages: 1 [2] 3 4   Go Up
Jump to: