United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #15 on: September 20, 2011, 05:08:26 pm » |
I can't find a datasheet for the AH34, although I found one for the AH342, which may be related.
The US1881 looks suitable to me, however it needs to see a north pole to switch one way and then a south pole to switch the other way. So you would need to use 2 magnets on the wheel, opposite ways round, so that in one rotation the sensor sees both a north pole and a south pole.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
INDIA
Offline
Sr. Member
Karma: 0
Posts: 331
Arduino rocks
|
 |
« Reply #16 on: September 24, 2011, 10:35:41 pm » |
I can't find a datasheet for the AH34, although I found one for the AH342, which may be related.
The US1881 looks suitable to me, however it needs to see a north pole to switch one way and then a south pole to switch the other way. So you would need to use 2 magnets on the wheel, opposite ways round, so that in one rotation the sensor sees both a north pole and a south pole.
I am also thinking that the US1881 is much better...The datasheet of US1881 says that it is high magnetic sensitivity, so I thing that i can keep the magnet little far too from the sensor.. I bought one AH34 which needs a magnet to be at least half a cm close to it.. I can get these sensors too.. http://www.rhydolabz.com/index.php?main_page=product_info&cPath=137_149&products_id=391Datasheethttp://www.rhydolabz.com/documents/datasheets/MH183%20Hall%20sensor.pdfhttp://www.rhydolabz.com/index.php?main_page=product_info&cPath=137_149&products_id=390Datasheethttp://www.rhydolabz.com/documents/datasheets/A3290XUA.pdfhttp://www.sunrom.com/sensors/current/hall-effect-sensor Datasheethttp://www.sunrom.com/files/WSH315.pdf
|
|
|
|
« Last Edit: September 24, 2011, 11:01:23 pm by Joy »
|
Logged
|
|
|
|
|
INDIA
Offline
Sr. Member
Karma: 0
Posts: 331
Arduino rocks
|
 |
« Reply #17 on: September 24, 2011, 10:38:51 pm » |
Another thing is what is going to be much better for whatever sensor I am using... Pick one pulse every wheel rotation (using one magnet on the wheel)  OR Pick two pulse every rotation, that is one pulse every half rotation of the wheel..(using 2 magnets)  Which is going to be much better..?
|
|
|
|
« Last Edit: September 24, 2011, 10:49:46 pm by Joy »
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #18 on: September 25, 2011, 02:24:39 am » |
If you use the US1881 then you will need two magnets anyway (one N and one S towards sensor) but still only get one pulse per revolution.
Two magnets on opposite sides of the wheel will help to avoid unbalancing it. One pulse per rev is all you need, you're only measuring km so you don't need the extra resolution that two pulses would give.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #20 on: September 25, 2011, 11:36:11 am » |
I think the latch effect is an advantage in your application. Imagine that your bike is stationary but the magnet just happens to be over the sensor. Without a latch effect, very small movements of the wheel back and forth will generate pulses, making it appear that the bike has travelled. With the latch effect of the US1881, you would have the move the wheel back and forth half a revolution to get any pulses.
The circumference of your wheel is much less than 0.1km so you don't need more than 1 pulse per revolution.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
INDIA
Offline
Sr. Member
Karma: 0
Posts: 331
Arduino rocks
|
 |
« Reply #21 on: September 25, 2011, 12:14:22 pm » |
I think the latch effect is an advantage in your application. Imagine that your bike is stationary but the magnet just happens to be over the sensor. Without a latch effect, very small movements of the wheel back and forth will generate pulses, making it appear that the bike has travelled. With the latch effect of the US1881, you would have the move the wheel back and forth half a revolution to get any pulses.
The circumference of your wheel is much less than 0.1km so you don't need more than 1 pulse per revolution.
Good point .. Even I was thinking earlier about the thing you told..But it never came to mind that the US1881 can solve the problem...
|
|
|
|
|
Logged
|
|
|
|
|
INDIA
Offline
Sr. Member
Karma: 0
Posts: 331
Arduino rocks
|
 |
« Reply #22 on: September 25, 2011, 01:19:01 pm » |
I think the latch effect is an advantage in your application. Imagine that your bike is stationary but the magnet just happens to be over the sensor. Without a latch effect, very small movements of the wheel back and forth will generate pulses, making it appear that the bike has travelled. With the latch effect of the US1881, you would have the move the wheel back and forth half a revolution to get any pulses.
The circumference of your wheel is much less than 0.1km so you don't need more than 1 pulse per revolution.
Good point .. Even I was thinking earlier about the thing you told..But it never came to mind that the US1881 can solve the problem... Will you please help me out in writing the code for the odometer.. The thread about it is here.. http://arduino.cc/forum/index.php/topic,72801.15.html
|
|
|
|
« Last Edit: September 26, 2011, 06:27:48 am by Joy »
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #23 on: September 25, 2011, 01:26:21 pm » |
I know you are using one interrupt-enabled pin already for the RPM counter, but is the other interrupt pin still free? On the Uno it is pins 2 and 3 that can generate interrupts as standard.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
INDIA
Offline
Sr. Member
Karma: 0
Posts: 331
Arduino rocks
|
 |
« Reply #24 on: September 25, 2011, 01:31:54 pm » |
I know you are using one interrupt-enabled pin already for the RPM counter, but is the other interrupt pin still free? On the Uno it is pins 2 and 3 that can generate interrupts as standard.
yes.. My pin 3 on the arduino is free... I am trying to use it for the ODO..
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #25 on: September 25, 2011, 03:34:22 pm » |
OK, here is a first attempt, compiled but otherwise untested. #include <EEPROM.h>
const int odometerPin = 3; const int odometerInterrupt = 1; const int odometerEepromLocation = 0; // address of the first of 4 bytes in which the total wheel revs is stored const int powerPin = A0; // analog pin used to sense impending loss of power
const float wheelCircumference = 0.002035; // wheel circumference in km const int minPowerOkReading = 700; // minimum reading on the power sense analog input that indicates good power const int minPowerRestoredReading = 750; // minimum reading on the power sense analog input that indicates we have powered back up
volatile unsigned long wheelRevs; // total wheel revolutions counted, will overflow after 85 million km unsigned long lastDisplayedMs = 0UL; // time when we last refreshed the display
void setup() { // Initialise wheel revs from value stored in EEPROM wheelRevs = 0UL; for (int i = odometerEepromLocation + 3; i >= odometerEepromLocation; --i) { wheelRevs <<= 8; wheelRevs |= (unsigned long)EEPROM.read(i); } if (wheelRevs == 0xFFFFFFFFUL) { // must be the first time we have run wheelRevs = 0UL; } // Set up the odometer sensor pin and interrupt pinMode(odometerPin, INPUT); attachInterrupt(odometerInterrupt, odometerIsr, RISING); }
void odometerIsr() { ++wheelRevs; }
void loop() { // Capture the wheel revs with interrupts disabled in case it changes while we read it noInterrupts(); unsigned long savedWheelRevs = wheelRevs; interrupts(); if (analogRead(powerPin) < minPowerOkReading) { // Looks like power is going down, so write wheel revs to EEPROM (takes 13.2ms to write 4 bytes) for (int i = odometerEepromLocation; i < odometerEepromLocation + 4; ++i) { EEPROM.write(i, (unsigned char)savedWheelRevs); savedWheelRevs >>= 8; } // wait until either we die or the power comes back up while (analogRead(powerPin) < minPowerRestoredReading) { delay(200); } } else { unsigned long now = millis(); if (now - lastDisplayedMs >= 200) // update display evert 200ms { lastDisplayedMs = now; float km = wheelCircumference * savedWheelRevs; Serial.print(km, 1); Serial.println("km"); } delay(5); // repeat after 5ms so that we check for power down often enough } }
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
INDIA
Offline
Sr. Member
Karma: 0
Posts: 331
Arduino rocks
|
 |
« Reply #26 on: September 26, 2011, 06:37:29 am » |
Thank you dc42..
I tried your code and connect the hall and a magnet to a fan but there was no increments on the reading.. It kept showing 0..
I want to test it with a push button instead of the hall..and according to my wheel circumference 491 pulse = 1Km.. so what values in the code should I change so that with the push button 5 or 10 clicks make one Km... Should I change this..?? const float wheelCircumference = 0.002035;
|
|
|
|
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #27 on: September 26, 2011, 06:47:01 am » |
Yes, change the wheel circumference to something much higher for debugging. Alternatively, display wheelRevs directly instead of converting it to km. Remember that if you are using the US1881, the sensor needs to see both a north pole and a south pole per simulated wheel revolution.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
INDIA
Offline
Sr. Member
Karma: 0
Posts: 331
Arduino rocks
|
 |
« Reply #28 on: September 26, 2011, 07:22:01 am » |
Yes, change the wheel circumference to something much higher for debugging. Alternatively, display wheelRevs directly instead of converting it to km. Remember that if you are using the US1881, the sensor needs to see both a north pole and a south pole per simulated wheel revolution.
I tried these changes in the code.. #include <EEPROM.h>
const int odometerPin = 3; const int odometerInterrupt = 1; const int odometerEepromLocation = 0; // address of the first of 4 bytes in which the total wheel revs is stored const int powerPin = A0; // analog pin used to sense impending loss of power
const float wheelCircumference = 1; // wheel circumference in km const int minPowerOkReading = 700; // minimum reading on the power sense analog input that indicates good power const int minPowerRestoredReading = 750; // minimum reading on the power sense analog input that indicates we have powered back up
volatile unsigned long wheelRevs; // total wheel revolutions counted, will overflow after 85 million km unsigned long lastDisplayedMs = 0UL; // time when we last refreshed the display
void setup() { Serial.begin(9600); Serial.print("odometer"); // Initialise wheel revs from value stored in EEPROM wheelRevs = 0UL; for (int i = odometerEepromLocation + 3; i >= odometerEepromLocation; --i) { wheelRevs <<= 8; wheelRevs |= (unsigned long)EEPROM.read(i); } if (wheelRevs == 0xFFFFFFFFUL) { // must be the first time we have run wheelRevs = 0UL; } // Set up the odometer sensor pin and interrupt pinMode(odometerPin, INPUT); attachInterrupt(odometerInterrupt, odometerIsr, RISING); }
void odometerIsr() { ++wheelRevs; }
void loop() { // Capture the wheel revs with interrupts disabled in case it changes while we read it noInterrupts(); unsigned long savedWheelRevs = wheelRevs; interrupts(); if (analogRead(powerPin) < minPowerOkReading) { // Looks like power is going down, so write wheel revs to EEPROM (takes 13.2ms to write 4 bytes) for (int i = odometerEepromLocation; i < odometerEepromLocation + 4; ++i) { EEPROM.write(i, (unsigned char)savedWheelRevs); savedWheelRevs >>= 8; } // wait until either we die or the power comes back up while (analogRead(powerPin) < minPowerRestoredReading) { delay(200); } } else { unsigned long now = millis(); if (now - lastDisplayedMs >= 200) // update display evert 200ms { lastDisplayedMs = now; float km = wheelCircumference * savedWheelRevs; Serial.print(km, 1); Serial.println("km"); Serial.println(wheelRevs); } delay(5); // repeat after 5ms so that we check for power down often enough } } Changing the wheel circumference to 1 Serial.println(wheelRevs); connected push button Push button pin pin 3 of arduino and other pin to 5V+ . A 10k resistor connected to pin 3 of arduino and GND.. Still no result..  Is it because my A0 of arduino is open..??
|
|
|
|
« Last Edit: September 26, 2011, 07:24:14 am by Joy »
|
Logged
|
|
|
|
|
United Kingdom
Offline
Faraday Member
Karma: 131
Posts: 4681
|
 |
« Reply #29 on: September 26, 2011, 07:24:55 am » |
Yes, you don't have the power sense pin wired up yet, so it thinks you are powering down all the time. As a temporary measure, try connecting pin A0 to +5v.
|
|
|
|
|
Logged
|
Formal verification of safety-critical software, software development, and electronic design and prototyping. http://www.eschertech.com
|
|
|
|
|