Hooking the arduino into the reed switch of an electronic device

Hi everybody! I have a few questions regarding something I would like to do with my Arduino (I'm a newbie even if I have been messing around with the Arduino for a while :confused: ).

What I have
I have a basic indoor rower ("ergometer") which uses a hall sensor in order to count the number of strokes performed. This sensor is connected to the electronic board of the rower, which gives the number of strokes, a timer and calories supposedly burnt(). The wires of the Hall sensor are soldered on the board and protected by some kind of hot glue. I have no access on this side. But there is a connector along the wires, which allows to disconnect the Hall sensor. I can measure about 1.5V on its pins when the sensor is not triggered (and 0v when it is :slight_smile: )
(
) even if I don't really understand how you can derive that from a timer and a counter...

What I would like to do
I would like to "hijack" the Hall sensor by hooking into this connector in order to be able to send the pulse to the Arduino and compute the number of strokes per minute (and not just a count). And I don't want to disable the counter of the rower by completly disconnecting it.

How should I do it ?
That's where I need your help! Since this counter of the rower is already powered (by a 1.5V battery), I think I should isolate it from the Arduino (anyway, they don't have a common ground).

I was thinking of an optocoupler, in series after the hall sensor, with the transistor part connected to an Arduino digital input. But the circuit is only powered by 1.5V and I fear the voltage will not be enough to power the LED of the optocoupler, or the drop too important for the counter to keep working. I have a couple of 4N35 from the starter kit. Do you think this optocoupler, or optocouplers in general, are appropriate ?

Also, I was wondering of the response time of optocouplers. Is it OK to use them with Hall sensors when the trigger period is very short ?

Thank you in advance for your answers and your ideas !

I'm not totally clear on your requirement but using optocouplers doesn't seem right.

Given that the output of a Hall Effect Sensor is either HIGH or LOW (some latch, others do not) I don't see why you could not use this 1.5V output to drive the input to a transistor and from there to a digital input pin on your Arduino.

Using an Analog pin on the Arduino (without a transistor) may also work if you include a high value pull down resistor (try 10K first) and see whether it upsets the original counter. Additionally, a 1K series resistor may be sensible as you state you want the original counter to keep working so anything that removes any kind of load off that Hall Effect sensor is A Good Thing.

The ground from your project will have to connect to the ground of the original counter but that's about it for connectivity (and as it's 1.5V there is minimal risk that it could damage to the Arduino).

You could knock up a simple monitoring sketch in minutes and then experiment a bit to see what works and what doesn't - and report back here if you hit further hurdles (or report your success, of course :))

What I would like to do
I would like to "hijack" the Hall sensor by hooking into this connector in order to be able to send the pulse to the Arduino and compute the number of strokes per minute (and not just a count). And I don't want to disable the counter of the rower by completely disconnecting it.

I'm thinking the signal you'll get, even when rowing at high speed, will have ample high and low time to do multiple analog readings at each level. So catching a high or low signal using Arduino's analog input should not be an issue.

Using an analog input will allow you to set the threshold level (i.e. 0.7V) to do what you need in code. Also, the sensing will still work even with low battery.

Hi! First of all, thank you for your interest and your answers.

edit: I just figured out that what I called a "Hall effect sensor" is in fact a "reed switch".

My first requirement is to be able to hook my project to the connection pins of the Hall sensor without modifying the circuit of the rower counter. This connector is the easiest way, and moreover it is accessible.

I don't understand why it wouldn't be appropriate to use an optocoupler. I first imagined connecting directly to the Arduino, then through a transistor as you propose, but I thought that totally disconnecting the 2 circuit was best practice (though not the easiest way to do it I rekon). I have (maybe) another argument: I can envisage to connect this project to another circuit using the same principle, but I don't know the voltage yet (and I would like to be able to do it without changing anything).

While waiting for your answers, I already tested some things. There is a sketch of what I've done below. I first tried a circuit by using a 1.5V battery and a switch to simulate the sensor and test my sketch (the right part of the schema).This seems to be working fine and I can display or compute anything I want. I measured a drop of about 0.5V between the pins 1 and 2 of the optocoupler with the switch closed.
What I wanted to do next was to hook the rower counter (left part of the schema) in place of the battery (yellow wires). Unfortunately, it doesn't work: neither the rower counter not mine is counting. I measured 0.856V on the pins the pins 1 and 2. I don't understand why...

If I choose to use a transistor (therefore connecting grounds), would something like that be OK?:

As for analog reading, I didn't even thought about it. However, I still need to be sure of which voltage I will feed to the Arduino (1.5V is OK, but I may try to hook to something with a higher voltage).

The reason I queried your use of an optocoupler is that you need to send sufficient current through the LED part of the optocoupler to get a signal - more than what the Hall Effect device (now a reed relay) could stand and certainly more than is probably available in the original circuit.

Basically trying to plug in an optocoupler would be like putting a diode (or LED) in series with that reed switch - go on, try it and see what happens! Whilst your design works just fine, remember you are hijacking a totally different sensor from another circuit and you want to really pussyfoot around it so you don't upset that original circuit.

So connecting that output from the reed switch to an analogue pin (with a high value pull down resistor) would now seem to be the simplest and most risk averse solution - try it using your switch to emulate the reed switch. Put a 1K resistor in series with the 1.5V output and a 10K from A0 to ground to start with and see what analogue reading you get (somewhere in that range 0 - 1023, probably around the 125 mark I'm guessing).

Alternatively, as per your testing circuit, you could indeed connect the output from the reed switch to the base of an NPN transistor via a 1K resistor and use the transistor switching to connect to a digital IO pin. In the lower of the two diagrams you seem to have nothing connected from the collector of the transistor to a digital input on your arduino. That should also work. Remember to connect a high value resistor from the base to ground too to avoid floating pins. 10K will be fine.

If your voltages do not exceed 5V then you should not be at risk of damaging your Arduino. Post back how you're getting on! :slight_smile:

Thanks for the update! Yes, I begin to understand that an optocoupler needs a lot more current that what's circulating in the circuit (I should try to measure it on the "original" circuit, just to see).

I'm going to try the analogue solution (I probably won't have the time today).

Regarding the transistor solution, the collector is connected to digital pin 7 of the Arduino. I put a 10k resistor between the reed switch and the base, which is probably too much. I forgot about the pulldown resistor, though (I updated my schema).

I'll keep you informed !

edit: addition of the "analogue" schema

In the "analogue" schema, change the 1K to 100K. Then change the 10K to 1µF capacitor. This will filter the signal with 0.1 second response. It will also protect the input ... it would take a 100VDC battery to generate 1 mA of current through Arduino's internal input protection diode.

I'm sorry, but as I stated in my first post, I'm still a newbie: would you care to elaborate regarding the increase of value for the resistor and the replacement of the pulldown resistor by a capacitor ?

Sorry, I wasn't very clear: I understand how mount the components, but I would like to know how it's working, with respect to the "classic" pulldown" resistor proposed above :smiley:

Your circuit with the pulldown would work. The 1K/10K divided signal will let through 90% of the signal. It will draw 1.5/11K=136µA from the battery when the switch is on. It will be very responsive and let through noise and contact bounce from the switch (can be dealt with in software). You'll need to keep the voltage within about 7V at the battery.

The 100K/1µF circuit will let through 100% of the signal (when the capacitor is charged). It will draw 1.5/100K=15µA max (7.5µA avg) from the battery when the switch is on. It will have 0.1 second response (time constant) and filter noise and contact bounce from the switch. You'll need to keep the voltage within about 100V at the battery so as not to overload Arduino's protection diodes.

Thanks for the explanation! Why is not always used instead of pulldown resistor, then ?

Regarding my project, I just had the time to try with a transistor since it's basically the same sketch as with the optocoupler. While it works when I'm using a 1.5V battery, it won't when I plug it to the rower counter.

I took some measurements and I have 0.87V across the 1K resistor (see schema using the transistor, above) and 0.7V between the base and the emitter (the transistor I'm using is a BC547B).

I totally disconnected the rower counter and plug the multimeter into: I've got 0.65mA :o This seems very low, no ? Could it be the reason why it doesn't work ? I'm not sure how to read the datasheet...

I don't know if I did something wrong but I didn't have the time to look further today :confused: ...

The voltage into the base of a fully-on transistor is always 0.7V (for a silicon NPN transistor); current will be very low. If it's not then you have either not provided any voltage or your transistor is foobar. It's the base-emitter current that controls the collector-emitter current.

However, ANY voltage above zero will be reliably detectable by the analog A0 input on your Arduino (which is why it's the simplest solution, both component-wise and coding-wise too).

The 1uF could (I would have thought?) remain charged between rowing strokes so I'd try a lower one (eg 0.1uF) first to see if that sorts out bounces & noise etc or you do it in code (I've previously used the simplistic delay(50) to good effect). I reckon some experimentation may be called for here.

"The voltage into the base of a fully-on transistor is always 0.7V (for a silicon NPN transistor); current will be very low."
Current can be high enough to blow an Arduino output pin. Always use a current limit resistor.
(5V - 0.7V)/.02A = 215 ohm, so a standard 220 or 270 would be good.

CrossRoads:
"The voltage into the base of a fully-on transistor is always 0.7V (for a silicon NPN transistor)..."

That's nice to know!

Regarding the possibility that the transistor is "foobar", it worked when directly using my 1.5V battery. So I don't thnk so.

I'll try again, probably not before this week-end, and I will test analogue :slight_smile:

CrossRoads:
Current can be high enough to blow an Arduino output pin.

In my case, I'm using the transistor to "drive " the input pin of the Arduino. Is there a risk if I remove the pullup resistor connected between the 5V and the collector ?

Simple test using analog input.
Just connect a jumper from pin 2 to A0.
Simulates a rower going at 4 strokes per second.
Instead of jumper, could use 10K/1K divider to get 0-0.5V signal.

void setup() {
  pinMode(2, OUTPUT);  // Connect to A0
  pinMode(13, OUTPUT); // LED
}

void loop() {
  digitalWrite(2, millis() & 0x40);  // 4Hz signal
  if (analogRead(A0) > 200) {
    digitalWrite(13, HIGH);
  } else {
    digitalWrite(13, LOW);
  }
}

For an NPN open collector design to pull an input pin low, something needs to be pulling the pin high when the transistor is off.
That can be the internal pullup resistor, turned on in setup() with pinMode(pinX, INPUT_PULLUP);
or it can be an external pullup to 5V with say a 10K or so resistor.

dlloyd:
Simple test using analog input...

Thanks for the sketch. I'm confident that direct connection to Analog pin will work for my rower.

By the way, 4Hz is a very high rate for a rower :smiley: . Even if you consider that 4Hz is in fact 2 strokes per second: the Reed switch is not located at the end of the rower, but in the middle. Therefore one movement back and forth will generate 2 pulses (which I'm taking into account in the code to compute the number of stroke per minute). That said, 2Hz is still very high :wink:

CrossRoads:
For an NPN open collector design to pull an input pin low, something needs to be pulling the pin high when the transistor is off...

That makes sense. I need to work on my pullup-pulldown :slight_smile:

By the way, 4Hz is a very high rate for a rower :smiley: .

Are you sure?

:smiley: I don't have this kind of problem indoor...