Go Down

Topic: 7 segment reed switch speedometer help (Read 5280 times) previous topic - next topic

AWOL

Yes, that's normal for a floating input.
"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.

firestork

#16
Aug 23, 2010, 06:16 pm Last Edit: Aug 23, 2010, 06:18 pm by herot Reason: 1
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: [Select]
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?

Marsheng

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.

Marsheng

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

firestork

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

Marsheng


firestork

#21
Aug 26, 2010, 02:46 am Last Edit: Aug 26, 2010, 02:47 am by herot Reason: 1
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.

bullethole

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.  

firestork

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

firestork

#24
Aug 29, 2010, 11:59 pm Last Edit: Aug 30, 2010, 12:01 am by herot Reason: 1
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.

firestork

#25
Aug 30, 2010, 03:59 am Last Edit: Aug 30, 2010, 04:00 am by herot Reason: 1
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: [Select]
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

PaulS

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

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

firestork

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/

PaulS

Quote
time is an unsigned long and gesch is an int.

Code: [Select]
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.

firestork

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.


Go Up