Sketch working on Arduino Nano but not MKR 1300

Hey guys,

I'm a beginner and I'm working on a project where I have to transmit data from a tachometer sketch from an MKR 1300. Before dealing with the LoRa transmission, I decided to test out a hall effect tachometer sketch made by Pawel Hernik (link to his Arduino tachometer tutorial

After slightly modifying the sketch so that I can observe from the serial monitor rather than an OLED, I tested out the program on an Arduino Nano and it works perfectly. I just got my Arduino MKR 1300 yesterday, successfully uploaded the same sketch to the board, but the serial monitor shows no changes (everything stays at 0). I've also made sure that the A3144 sensor output connects to digital pin 2, and a pull-up resistor connected to the same pin.

I also have not installed any library for the MKR 1300. As far as I know, the MKRWAN library is only needed to connect to the network, so a simple tachometer sketch should work fine. Should I be using a different pin? I have also included my code below just in case.

I'd appreciate any help from you guys :slight_smile:
Thanks in advance!

// Fidget Spinner counter and tachometer
// 27.08.2017 Pawel A. Hernik
// source code for the video:

 - Hall sensor 3144
 - Neodymium magnet for fidget spinner
 - OLED SSD3106
 - Arduino Pro Mini/Nano
 3144 pinout from front:
 1 - VCC
 2 - GND
 3 - DATA (0 when close to magnet)

const int hallPin = 2; // pin 2 = int 0
volatile unsigned long cntTime=0;
volatile unsigned long cnt=0;
float spd;
float dis;
unsigned int up;

void doCount()
  if(digitalRead(hallPin) == LOW)
    cntTime = millis();

// --------------------------------------------------------------------------

void setup()
  attachInterrupt(digitalPinToInterrupt(hallPin), doCount, FALLING);  // hall pin on interrupt 0 = pin 2
  cntTime = millis();

// --------------------------------------------------------------------------

volatile unsigned long rpm=0,maxrpm=0;
int dispRotTime=0, rotTime=0;
unsigned long measureTime=0,curTime,startTime=0;
int dispCnt=0,measureCnt=0;

const int resetTime = 2000;
const int minRotNum = 1;  // 1 - calc after every rotation

void loop()
  curTime = millis();
  if(curTime-cntTime>resetTime) { // reset when less than 30RPM (dt>2s)
    cnt = measureCnt = 0;
    rpm = 0;
  if(cnt==1) startTime = cntTime;
  if(cnt-measureCnt>=minRotNum) {
    rpm = 60000L*(cnt-measureCnt)/(cntTime-measureTime); //Serial.println(String("Cnt=")+cnt+" dcnt="+(cnt-measureCnt)+" dtime="+(cntTime-measureTime));
    measureCnt = cnt;
    measureTime = cntTime;
  rotTime = (cntTime-startTime)/1000; // time in seconds
  if(cnt>1 || !dispRotTime) {  // keep previous time on the OLED until new rotation starts
    dispRotTime = rotTime;
    dispCnt = cnt;
  //Calculate distance
  dis = up*0.66*3.1415926; //number of pulses multiplied by circumference
  spd = 0.1885*rpm*0.66;
  if(rpm>maxrpm) maxrpm=rpm;
  Serial.print("\tRotations: ");
  Serial.print("\tRPM: ");
  Serial.print("\tSpeed (km/h): ");
  Serial.print("\tDistance (m): ");
  Serial.print("\tTime Elapsed: ");   

// --------------------------------------------------------------------------

First thing to do is check that the MKR can read the signals from the hall sensor. Use a simple sketch that reads the pin and prints the result to serial monitor. No interrupts, no calculations. Just read and print. Can you see the pin changing from 0 to 1 and back to 0 as the rotation occurrs?

Im also having the same problem with my MKR1300....

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.