The best way I can think of to use this sensor is to power one wire and read the other wire for pulses. Use any digital pin to read the sensor other then 0 and 1 (rx and tx) because that will keep you from using the usb port.
For counting the pulses I would suggest a hardware interrupt. Anytime the port is triggered it will execute some code you choose. You can keep a counter running and use the time in between pulses to calculate the speed.
This arduino gas meter project uses a similar method.
- void setup() {
- Serial.begin(9600);
- attachInterrupt(0, check, CHANGE); // attach an interrupt (interrupt 0 = digital pin 2)
- }
-
- void loop() {
- }
-
- void check() {
- /*
- stop timer
- start timer
- calculate and output speed
- */
- }
No comments:
Post a Comment