){.nav-menu .menu-item-has-children a{padding-right:20px}.nav-menu .menu-item-has-children a:after{position:absolute;right:7px;top:10}}.vce-ad-container{margin:30px auto;display:block;clear:both;width:728px;position:relative;max-width:100%}.vce-ad-below-header{margin-bottom:0}@media only screen and (max-width:1200px) and (min-width:1024px){.vce-ad-container{width:630px}.vce-ad-below-header{width:728px}}@media only screen and (max-width:1023px){.vce-ad-below-header,.vce-ad-container{width:728px}}@media (max-width:767px){.vce-ad-container{width:375px}}@media (max-width:400px){.vce-ad-container{width:300px}}@media (max-width:320px){.vce-ad-container{width:280px;max-width:100%}}:root .main-navigation ul ul{opacity:1}@media only screen and (min-width:1024px) and (max-width:1200px){.container{max-width:1000px}.vce-main-content{width:700px}.main-navigation ul ul{display:none}.top-header{overflow:hidden}.main-navigation a{padding:15px 9px 15px}.search-header-wrap a{padding:15px}.header-3-wrapper .site-branding{max-width:300px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (min-width:670px) and (max-width:1023px){.header-3-wrapper .site-branding{max-width:300px}.header-3-wrapper .nav-menu>li>a{padding:0 15px}h1.entry-title{width:540px}.entry-title{display:block}}@media only screen and (max-width:1023px){.container{max-width:90%}.vce-main-content{width:100%;padding:15px 0!important}.main-navigation ul ul{display:none}.vce-res-nav{float:left;position:absolute;left:0}.header-3-wrapper{height:50px!important;padding-top:0!important;text-align:center}.header-3-wrapper .site-branding{position:relative;float:none;top:0!important;left:initial!important;text-align:center;max-width:initial;padding:3px 0 7px}.site-branding{padding:4px 0 7px;display:inline-block}.site-branding img{max-width:120px;max-height:28px}.main-header .header-3-wrapper .site-title,.main-header .header-3-wrapper .site-title a.has-logo{line-height:40px!important;font-size:26px!important}.sidebar{margin:0 auto 20px;float:none!important;display:block;clear:both;padding-top:0!important;width:100%;max-width:300px}h1.entry-title{max-width:100%}.vce-responsive-nav{display:block;margin:10px 0 9px}.nav-menu,.top-header{display:none}.main-header .site-title,.main-header .site-title a{line-height:36px!important;font-size:40px!important}li>ul{margin:0}}@media only screen and (min-width:200px) and (max-width:670px){html{margin-top:0!important;overflow-x:visible}html body,button,input,textarea{font-size:14px;line-height:22px}.container{max-width:95%}.vce-main-content{padding:0 0 10px!important}.main-box,.sidebar .widget{margin-bottom:10px}.vce-wrap-right{width:100%;max-width:100%;text-align:center}.vce-single .entry-header{margin:20px 0}.vce-wrap-right{text-align:center}body h1.entry-title{font-size:24px;line-height:30px;padding:0 20px}body p{margin-bottom:20px}body h1{font-size:24px;line-height:34px;margin-bottom:10px}body h4{font-size:18px;line-height:28px;margin-bottom:10px}.sidebar .widget-title{line-height:22px}.vce-wrap-right>ul{float:none;display:inline-block;margin:10px 0 0}}#cookie-notice *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}#cookie-notice .cookie-notice-container{display:block}#cookie-notice.cookie-notice-hidden .cookie-notice-container{display:none}.cookie-notice-container{padding:15px 30px;text-align:center;width:100%;z-index:2}.cn-close-icon{position:absolute;right:15px;top:50%;margin-top:-10px;width:15px;height:15px;opacity:.5;padding:10px;outline:none}.cn-close-icon:before,.cn-close-icon:after{position:absolute;content:' ';height:15px;width:2px;top:3px;background-color:#fff}.cn-close-icon:before{transform:rotate(45deg)}.cn-close-icon:after{transform:rotate(-45deg)}#cookie-notice .cn-button{margin:0 0 0 10px}.cn-button.bootstrap{font-family:-apple-system,BlinkMacSystemFont,Arial,Roboto,"Helvetica Neue",sans-serif;font-weight:400;font-size:13px;letter-spacing:.25px;line-height:20px;margin:0;text-align:center;text-transform:none;display:inline-block;touch-action:manipulation;white-space:nowrap;outline:none;box-shadow:none;text-shadow:none;border:none;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;text-decoration:none;padding:8.5px 10px;line-height:1}.cn-button.bootstrap{color:#fff;background:#20C19E}.cn-text-container{margin:0 0 6px 0}.cn-text-container,.cn-buttons-container{display:inline-block}@media all and (max-width:900px){.cookie-notice-container #cn-notice-text{display:block}.cookie-notice-container #cn-notice-buttons{display:block}#cookie-notice .cn-button{margin:0 5px 5px 5px}}@media all and (max-width:480px){.cookie-notice-container{padding:15px 25px}}

Arduino Tachometer

Here’s a simple Arduino Tachometer project for measuring and displaying speed of rotation. You can find similar projects everywhere on the web but this one has some unique features. First off, the idea is based on a square type inductive proximity sensor SN04-N from RiKo. The SN04-N is a low cost, stable, and waterproof inductive proximity sensor with a normally-open (N/O) NPN transistor output, surprisingly with an internal pull-up resistor that’s not clearly mentioned in the datasheet!

Hardware: This project requires three key hardware parts as listed below.

  • Inductive Proximity Sensor (SN04-N)
  • Arduino (Rev3)
  • Arduino LCD Shield (DFR0009)

As can see in the below diagram, the hardware frame-up is extremely simple, and calls only one bare I/O of Arduino (Pin 2) to complete the entire setup. Pin 2 of Arduino Uno, used here as the ‘Pulse Input’ pin, is its ‘Interrupt 0’ pin that enables us to run some code only when a level change happens there. The second interrupt – ‘Interrupt 1’ of Uno is on Pin 3. Just to recap, interrupts are a nice way to make the system more tractable to time tender tasks. They also helps to free up the main loop to look at the primary task in the system. For more details, check out this documentation on interrupts – https://www.arduino.cc/en/Reference/attachInterrupt


The code strictly follows the common Arduino Sketch style and uses the standard interrupt 0 on pin 2 (D2). As you can see in the code, the interrupt triggers on ‘falling’ edge of the input pulse. Copy the below code in your Arduino IDE software to program your Arduino.

 * Arduino Tachometer (for beginners)
 * uC Hardware: Arduino Uno R3 & DFR0009 LCD Shield 
 * Sensor: SN04-N Inductive Proximity Sensor
 * Prepared & Tested by T.K.Hareendran
 * Publisher: Codrey Electronics
 #include <LiquidCrystal.h>

LiquidCrystal lcd(8, 9, 4, 5, 6, 7); // Pins assigned for DFR0009

volatile uint32_t rev; // Revolution Count
unsigned long measureTime = 0;

void setup() {
  pinMode(2, INPUT); // Interrupt 0
 // pinMode(2, INPUT_PULLUP); // Internal Pull Up*

  lcd.begin(16, 2);

  attachInterrupt(0, addRevolution, FALLING);

void addRevolution() {

void loop() {

  uint32_t rpm = rev * 60000 / (millis() - measureTime);
  rev = 0;
  measureTime = millis();

  lcd.setCursor(0, 1);
  lcd.print(" RPM        ");

In the code, the interrupt will increment a variable each time the signal at INT0 is falling, and interrupts are disabled during the computation time. Take note on the code line ” uint32_t rpm = rev * 60000 / (millis() – measureTime);” as it’s tailored for interrupts occurred once per revolution. You can modify this line to suit your specific ‘sensor and target’ setup. The given code works better only if the RPM is greater than 60 as at least one rotation per second must happen for accurate RPM display.

Rotational Speed Monitor

As stated, an inductive proximity sensor is used for rotational speed monitoring here by counting relevant pulses in a non-contact way. Sensing range of SN04-N is 4mm but a distance (gap) close to 3.2mm is recommended between the stationary head (proximity sensor) and the orbiting target (ferrous object).

The entire setup must be powered from a regulated 5V dc supply. First of all, route the ground lead of the power supply to the ground rail (GND) of Arduino, and to the ground wire (blue) of SN04-N. Similarly extend the positive lead to the regulated dc input (5V) pin of Arduino, and to the positive wire (brown) of SN04-N. Finally, connect the output (black) of SN04-N to D2 (INT0) of Arduino (refer next figure). For short-time experiments, powering up the Arduino through its dc input jack (or Vin) by a 9-12V unregulated dc supply lets you take the regulated 5V output from Arduino board to run the inductive proximity sensor (be careful).

According to “Automation Insights” blog (https://automation-insights.blog), the best target in general for an inductive proximity sensor is a flat piece of ferrous metal. Other non-ferrous target materials can still be detected by an inductive sensor (of course with lesser sensitivity), but ferrous steel is a proven target material with a cheerful sensing range.

Don’t Kill Your Arduino! Somebody might wonder why I wanted to run SN04-N sensor from a 5V regulated dc supply instead of the recommended 10-30V dc input. It’s because I noticed that output (black) of the SN04-N sensor (what I got from an online seller is a cheap one, may be another clone) is internally tied to its unregulated positive rail through a 10K pull-up resistor. So its output will give the same inputted positive voltage in idle state and that will kill the Arduino. Although with a little trick it’s easy to drop down the output voltage to TTL level, my laziness forced me to try a 5V regulated dc supply input for SN04-N, and it worked.

(casual snap from author’s workbench)

More Interrupts?

If you want one more sensor in the same setup, luckily Arduino Uno has 2 external interrupts, so you can try the same strategy as in the code, i.e. just make another interrupt function for the second sensor and attach it on interrupt 1 (pin 3). Thankfully, using the “PinChange Interrupt” library, we can configure any pin on Arduino an interrupt pin. As always you can go through the external link for more details https://www.brainy-bits.com/make-any-arduino-pin-an-interrupt-pin/

And, here’s a useful documentation especially for those interested to learn more about Arduino RPM measurement techniques http://elimelecsarduinoprojects.blogspot.com/2013/06/measure-rpms-arduino.html

Leave a Comment X