reed switch module program to get speed

Hi, I have reed switch module with 3 outputs, 5V GND and Digital. How to get speed, how fast magnet goes on module ? I try to google it, but can't find anything what works. I need to know speed becouse, my led will blink by speed. I need program like bicycle speedometer works. Can anyone help me? Module is G123-08 Dry reed pipe sensor module magnetron module dry reed switch magnetic control switch

figo wrote:

"...Dry reed pipe sensor module magnetron module dry reed switch magnetic control switch"

I don't know what this means, but if there really is a magnetron involved then we have a big problem. However, I get that vendors on the web are using this description. I looked up this part and could only get information that was poorly translated from another language, probably Chinese. I could not understand most of it. Perhaps if I knew Chinese?

The Arduino can measure the time from one output by the reed switch module to the next. However, if you believe that the reed switch module has "...3 outputs..." then you need to understand your hardware better first.

From the time between outputs and the circumference of the wheel (and any gearing between the sensor and the wheel, and knowing how many magnets you have used) you can calculate the speed. However, it is not clear that the module performs any debouncing, so you may have to learn to do this in software as well.

At the very least, you will need to use digitalRead(...) and millis().

What do you have so far, in hardware built, in electrical connections (schematic or other wiring diagram), and in software code?

What is your ability in coding in C/C++ ?
What examples have you tried?

I found an item with the same description here.

I think the word magnetron came from some poor translation from Chinese.
A Magnetron is a high powered valve/(tube) used for generating microwave frequencies. Used in Radar and microwave ovens amongst other things.

To answer your question, a reed switch can be operated at frequencies of up to a few hundred Hertz when surrounded by a coil fed with an ac signal.
When operated by a magnet, as this one appears to be, I think the operating speed is likely to be a bit less, and will probably be determined by how fast you can approach with, and withdraw the magnet.

It looks to me as though the manufacturers have used the same PCB as they use with some other type of sensor.
The reed switch leads have been crudely formed to connect to the PCB.

Last month I finished a project for an anemometer using a rotating cup sensor that rotated a bar magnet over a reed switch. The switch closes twice per revolution. So far we have had wind gusts over 40 MPH and reed switch worked fine. I think the manufacturer rated the device for over 100 MPH.

I used the logic of the tutorial at the beginning of this forum. “code for several things at a time”, as well as an interrupt to count the switch closures. I would like to recommend this method of programming to the OP for his bicycle speedometer program.

The bicycle speed problem seems to be a common class assignment. I think I read a very similar request from someone else.


I see, now. He posed almost the same question in the programming forum. Once he gets the electronics working, the speed calculation should become obvious.


Here is a copy of my anemometer program. It is based on the scheme of doing many things at one time, as shown in the first sticky post at the beginning of this forum. You should be able to use the logic to program your speed calculation for
a bicycle.

/*Anemometer program using a Met One anemometer. A reed relay is closed twice per revolution.
  Wind speed, in MPH, is computed based on a formula from the company web site.
  MPH is stored in a array of 15 which is averaged over 15 seconds to give average MPH.
  Results are displayed at 1 second intervals.
  Paul Drahn March 2016

volatile unsigned int counter = 0;  // interrupt count from anemometer reed switch closing/opening
unsigned long currentMillis = 0;  // milliseconds since beginning.
unsigned long previousRPMmillis = 0;  // milliseconds from previous elapsed time test.
unsigned long interval = 1000;  // compute and display wind MPH each second.

float MilesperHour;  // wind speed
float HighestMPH;  // Highest wind speed found since prog start.
float AverageMPH;  // average for last 15 seconds
float peakMPH[15]; // array used to compute 15 second average MPH
int i = 0;  // index for average calc
int next = 0;  // index for storing next peak MPH

unsigned int revs = 0;  // difference between current interrupt count and previous count.
unsigned int previousCounter = 0;  // interrupt count at previous 1 second process
unsigned int cnt = 0;  // copy of interrupt counter

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

/*-----( Declare Constants )-----*/
/*-----( Deefine objects )-----*/
// set the LCD address to 0x27 for a 20 chars 4 line display
// Set the pins on the I2C chip used for LCD connections:
//                    addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address
#define LCDROWSIZE        2
#define LCDCOLSIZE       16

void setup()
  lcd.begin(LCDCOLSIZE, LCDROWSIZE);   // initialize the lcd for 16 chars 2 lines, turn on backlight

  lcd.setCursor(0, 0);                  // Splash screen
  lcd.setCursor(0, 1);

  pinMode(2, INPUT_PULLUP);  // pin is LOW when anemometer switch is closed
  attachInterrupt(0, anemoCount, FALLING);  // interrupt when anemometer magnet closes switch. Twice per rev.

void loop()
  // make a working copy of the counter while disabling interrupts
  cnt = counter; // Two interrupts per revolution.

  // when 1 second has elapsed, compute and display wind speed.
  currentMillis = millis();  // milliseconds since prog start.

  if (previousRPMmillis == 0)
    previousRPMmillis = currentMillis;  // first time through loop.

  if (previousCounter == 0)
    previousCounter = cnt; // beginning value

  if ((currentMillis - previousRPMmillis) >= interval)  // compute and print results once per second
    previousRPMmillis = currentMillis;  // save current value of milliseconds
    revs = cnt - previousCounter;  // compute # revolutions of the aneometer
    previousCounter = cnt;  // save current anemometer count

    computeMPH();  // compute wind speed in miles per hour

// interrupt code is executed when anemometer magnet closes reed relay.
void anemoCount()
  static unsigned long last_interrupt_time = 0;
  unsigned long interrupt_time = millis();
  if (interrupt_time - last_interrupt_time > 200)
    counter++; // count reed relay closing'

void computeMPH()    // computation function....
  MilesperHour = (revs / 0.5589) + 1.0;  // formula based on 014 anemometer calibration web page
  if (MilesperHour == 1.0)  // if anemometer is not rotating, show zero wind speed
    MilesperHour = 0.0;

  if (MilesperHour > HighestMPH) // Save speed of greatest gust of wind.
    HighestMPH = MilesperHour;

  peakMPH[next] = MilesperHour;  // save current MPH in averaging array.
  if (++next == 15)
    next = 0;  // Start over at beginning of averaging array

  AverageMPH = 0.0;  // Compute average wind speed.
  for (i = 0; i < 15; i++) // add up all 1 second readings
    AverageMPH += (peakMPH[i]);
  AverageMPH /= 15.0;   // divide to get average wind speed over 15 seconds.

void displayMPH()
  lcd.setCursor(9, 0); // blank out any display residue.
  lcd.print("      ");
  lcd.setCursor(9, 1);
  lcd.print("      ");
  lcd.setCursor(9, 0);  // now, print new stuff.
  lcd.setCursor(9, 1);

Thanks! If someone need to get speed from reed switch module, use this link