Go Down

Topic: Source code required..HELP!!! (Read 1 time) previous topic - next topic

edifiedsprit

Jan 06, 2013, 07:02 pm Last Edit: Jan 06, 2013, 07:08 pm by edifiedsprit Reason: 1
I am working on a project which requires detecting speed of a motorbike and do execute some changes based on speed. The speed sensor gives 8 pulses per wheel revolution. I need to calculate the speed by detecting the pulses and display it on an LCD. I am using an LCD which uses I2C interface and it works fine. But I do not know how to: 1) Calculate the speed on the arduino and the display it on the LCD.
  Please help me as I do not know much about coding or hardware. Please provide me a code that I can use to calculate the speed and
then displaying it on the LCD (one revolution of wheel gives 8 pulses and I can connect the speed sensor input to any pin on arduino).                                                                                  
                                                                                     

abrookfield

#1
Jan 06, 2013, 07:17 pm Last Edit: Jan 06, 2013, 07:20 pm by abrookfield Reason: 1
what is outside diameter of tyre or revs/mile etc?

Chaul

#2
Jan 06, 2013, 07:28 pm Last Edit: Jan 07, 2013, 07:52 pm by Chaul Reason: 1
When you know the diameter of the tyre, you can use that to estimate how far the bike has travelled. Then you just divide that by elapsed time between the pulses and get m/s, km/h or mph or whatever you prefer. Eight pulses would equal the diameter of the tyre, 1 pulse would be 1/8th of the diameter in this case. Multiple pulses are good for accuracy. There could be some coding tips you could need for not missing any pulses. Maybe running it through interrupt service routines might help.

I'd like to know how to control an LCD too, but there's a probably a datasheet or a tutorial and a library somewhere, so I would start with that. Sorry, but I can't help with LCD's.

Edit: And of course I was thinking circumference when I was writing diameter somewhere up there.. circumference = PI * diameter. 8 pulses equals the circumference in travelled distance.

robtillaart

Some starter code
Code: [Select]


#include<lcd.h>

float numberofpulsesperrotation = 8.0;
float wheeldiameter = 1; // assume 1 meter BIG wheel
float wheelsize = 3.14159265 * wheeldiameter; // or 2* PI * radius)

void setup()
{
...
}

void loop()
{
 ...
 if (timetorefreshscreen())
 {
   float distance = numberofpulses * wheelsize / numberofpulsesperrotation;
   float speed = 60 * wheelsize * numberofpulsesinlastminute/numberofpulsesperrotation/1000; // KM/h
   lcd.print(distance);
   lcd.print(speed);
 }
}

bool timetorefreshscreen()
{
...
 return true;
}


What code do you have sofar?

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

edifiedsprit

I do not have any code to get to the speed part. I have just opened programming textbooks!! I know nothing about coding as of now.
However I want to say a thing, which is, a few days back one of my friends did this coding for a PIC mC on the same bike using the same sensor. I dont have terms with him anymore. That guy didn't use diameter of the wheel.
  The project was to actuate some solenoids once a certain bike speed is reached. All I know is he used some time period calculations to calculate and display the speed on the LCD and the best part was the speed which he got displayed on project LCD was same as the one being displayed on the bike manufacturer's LCD instrument cluster(its a 150 cc motor bike).
  Now I need such a code which can give me the speed on my project lcd. As I had said, I could use any I/O pin on Arduino for speed detection.
I have the I2C LCD library etc and I can display anything on it from a sketch(I copy pasted the codes from net!).

Go Up