Tachometer works with Arduino Uno, but not with the Nano Every, I can't figure out how to solve it

Hello all from a mechanical guy who knows just enough about Arduino to adjust others code to my needs.

I am trying to make a tachometer to constantly monitor the RPMs of the propellor shaft in a friend's 80 year old boat.

The chinese digital tachometers don't really fit the analog gauges in the dashboard, and are hard to read when the sun is shining on them. Of the shelf analog gauges are not available in the rpm range we need (0 to 1200 rpm) and the engine itself doesn't have a rev-counter.
So I decided to create my own analog tachometer, using an Arduino Nano Every because the 14,4V of the alternator is below the 18V voltage limit, I had it laying around and it makes the whole meter quite compact. The propellor shaft gets a magnet mounted to it and a hall sensor is used to detect when the magnet passes by.

That's it for the introduction and background info.

To test this I used an Arduino Uno R3 powered with USB from my pc, as that had a breadboard connected to it. The schematic below shows how everything is connected.

For the code, I used this video: Arduino Tutorial: Tachometer (RPM Counter) - YouTube
His code is shown below with the lines I have added to show the RPM value on the 7 segmented display, and to control the servo, which moves the needle inside the tachometer.

/*
Tachometer using micros

On this sketch we are going to measure the period between pulses using the micros() function to get the RPM
(Revolutions Per Minute) from a sensor on pin 2.
This way of measuring RPM makes it accurate, responsive and versatile. No matter how fast or slow the loop is
running, the reading accuracy is not going to be affected. Although, the faster you run the loop, the more amount
of readings you are going to be able to display every second.

It's coded in a way that the micros rollover doesn't create glitches every 71 minutes, so it can run forever
without problems.

We use an interrupt for the input so you have to choose pin 2 or 3 (for Arduino Uno/nano). In this example we
use pin 2.

This sketch was made for my video tutorial shown here: https://www.youtube.com/watch?v=u2uJMJWsfsg

Made by InterlinkKnight
Last update: 05/23/2019
*/

#include <TM1637Display.h>
#define CLK 13
#define DIO 12
TM1637Display display(CLK, DIO);

int LED = 11;                       //The green LED is connected to pin 11, blinks when the magnet passes by.
int HALL = 2;                       //The HALL sensor is connected to pin 2. 
int SERVO = 10;                     //The SERVO is connected the pin 10. 

volatile byte Magnetdetected = 0;

#include <Servo.h>
Servo RPMneedle;                    // create servo object to control a servo
int RPMneedleValue;

///////////////
// Calibration:
///////////////

const byte PulsesPerRevolution = 1;  // Set how many pulses there are on each revolution. Default: 2.


// If the period between pulses is too high, or even if the pulses stopped, then we would get stuck showing the
// last value instead of a 0. Because of this we are going to set a limit for the maximum period allowed.
// If the period is above this value, the RPM will show as 0.
// The higher the set value, the longer lag/delay will have to sense that pulses stopped, but it will allow readings
// at very low RPM.
// Setting a low value is going to allow the detection of stop situations faster, but it will prevent having low RPM readings.
// The unit is in microseconds.
const unsigned long ZeroTimeout = 200000;  // For high response time, a good value would be 100000.
                                            // For reading very low RPM, a good value would be 300000.


// Calibration for smoothing RPM:
const byte numReadings = 10;  // Number of samples for smoothing. The higher, the more smoothing, but it's going to
                              // react slower to changes. 1 = no smoothing. Default: 2.





/////////////
// Variables:
/////////////

volatile unsigned long LastTimeWeMeasured;                        // Stores the last time we measured a pulse so we can calculate the period.
volatile unsigned long PeriodBetweenPulses = ZeroTimeout + 1000;  // Stores the period between pulses in microseconds.
                                                                  // It has a big number so it doesn't start with 0 which would be interpreted as a high frequency.
volatile unsigned long PeriodAverage = ZeroTimeout + 1000;        // Stores the period between pulses in microseconds in total, if we are taking multiple pulses.
                                                                  // It has a big number so it doesn't start with 0 which would be interpreted as a high frequency.
unsigned long FrequencyRaw;                                       // Calculated frequency, based on the period. This has a lot of extra decimals without the decimal point.
unsigned long FrequencyReal;                                      // Frequency without decimals.
unsigned long RPM;                                                // Raw RPM without any processing.
unsigned int PulseCounter = 1;                                    // Counts the amount of pulse readings we took so we can average multiple pulses before calculating the period.

unsigned long PeriodSum;  // Stores the summation of all the periods to do the average.

unsigned long LastTimeCycleMeasure = LastTimeWeMeasured;  // Stores the last time we measure a pulse in that cycle.
                                                          // We need a variable with a value that is not going to be affected by the interrupt
                                                          // because we are going to do math and functions that are going to mess up if the values
                                                          // changes in the middle of the cycle.
unsigned long CurrentMicros = micros();                   // Stores the micros in that cycle.
                                                          // We need a variable with a value that is not going to be affected by the interrupt
                                                          // because we are going to do math and functions that are going to mess up if the values
                                                          // changes in the middle of the cycle.

// We get the RPM by measuring the time between 2 or more pulses so the following will set how many pulses to
// take before calculating the RPM. 1 would be the minimum giving a result every pulse, which would feel very responsive
// even at very low speeds but also is going to be less accurate at higher speeds.
// With a value around 10 you will get a very accurate result at high speeds, but readings at lower speeds are going to be
// farther from eachother making it less "real time" at those speeds.
// There's a function that will set the value depending on the speed so this is done automatically.
unsigned int AmountOfReadings = 1;

unsigned int ZeroDebouncingExtra;  // Stores the extra value added to the ZeroTimeout to debounce it.
                                   // The ZeroTimeout needs debouncing so when the value is close to the threshold it
                                   // doesn't jump from 0 to the value. This extra value changes the threshold a little
                                   // when we show a 0.

// Variables for smoothing tachometer:
unsigned long readings[numReadings];  // The input.
unsigned long readIndex;              // The index of the current reading.
unsigned long total;                  // The running total.
unsigned long average;                // The RPM value after applying the smoothing.

const uint8_t zoef[] = {                  //'ZOEF' is the name of the boat
  SEG_A | SEG_B | SEG_G | SEG_E | SEG_D,           // Z
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
  SEG_A | SEG_F | SEG_G | SEG_E | SEG_D,           // E
  SEG_A | SEG_F | SEG_G | SEG_E,                   // F
};



void setup()  // Start of setup:
{ pinMode(HALL, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(SERVO, OUTPUT);

  Magnetdetected = 0;
  
  display.setBrightness(7, false); 
  display.setSegments(zoef);
  delay(250); 

  RPMneedle.attach(SERVO);
  RPMneedle.write(0);
  delay(250);

  RPMneedle.write(150);  //150° seems to be 180° in real life.
       
  for(int s = 0; s < 7; s++) {  //Let 'ZOEF' fade in on the 7-segment display.
    display.setBrightness(s);
    display.setSegments(zoef);
    delay(30);
    }
  
  delay(1750);

  for(int s = 7; s > 1; s--) {  //Let 'ZOEF' fade out on the 7-segment display.
    display.setBrightness(s);
    display.setSegments(zoef);
    delay(20);
    }

  
  RPMneedle.write(0);   //Tachometer back to 0

  
  display.setBrightness(7, false); //Turn the 7 segment display off.
  display.setSegments(zoef);

  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED, LOW);


  Serial.begin(9600);                                              // Begin serial communication.
  attachInterrupt(digitalPinToInterrupt(HALL), Pulse_Event, RISING);  // Enable interruption pin 2 when going from LOW to HIGH.

  display.setBrightness(7); //Helderheid van het scherm weer naar volle sterkte voor de toerenteller

  delay(1000);  // We sometimes take several readings of the period to average. Since we don't have any readings
                // stored we need a high enough value in micros() so if divided is not going to give negative values.
                // The delay allows the micros() to be high enough for the first few cycles.

}  // End of setup.





void loop()  // Start of loop:
{

  // The following is going to store the two values that might change in the middle of the cycle.
  // We are going to do math and functions with those values and they can create glitches if they change in the
  // middle of the cycle.
  LastTimeCycleMeasure = LastTimeWeMeasured;  // Store the LastTimeWeMeasured in a variable.
  CurrentMicros = micros();                   // Store the micros() in a variable.





  // CurrentMicros should always be higher than LastTimeWeMeasured, but in rare occasions that's not true.
  // I'm not sure why this happens, but my solution is to compare both and if CurrentMicros is lower than
  // LastTimeCycleMeasure I set it as the CurrentMicros.
  // The need of fixing this is that we later use this information to see if pulses stopped.
  if (CurrentMicros < LastTimeCycleMeasure) {
    LastTimeCycleMeasure = CurrentMicros;
  }





  // Calculate the frequency:
  FrequencyRaw = 10000000000 / PeriodAverage;  // Calculate the frequency using the period between pulses.





  // Detect if pulses stopped or frequency is too low, so we can show 0 Frequency:
  if (PeriodBetweenPulses > ZeroTimeout - ZeroDebouncingExtra || CurrentMicros - LastTimeCycleMeasure > ZeroTimeout - ZeroDebouncingExtra) {  // If the pulses are too far apart that we reached the timeout for zero:
    FrequencyRaw = 0;                                                                                                                         // Set frequency as 0.
    ZeroDebouncingExtra = 2000;                                                                                                               // Change the threshold a little so it doesn't bounce.
  } else {
    ZeroDebouncingExtra = 0;  // Reset the threshold to the normal value so it doesn't bounce.
  }





  FrequencyReal = FrequencyRaw / 10000;  // Get frequency without decimals.
                                         // This is not used to calculate RPM but we remove the decimals just in case
                                         // you want to print it.





  // Calculate the RPM:
  RPM = FrequencyRaw / PulsesPerRevolution * 60;  // Frequency divided by amount of pulses per revolution multiply by
                                                  // 60 seconds to get minutes.
  RPM = RPM / 10000;                              // Remove the decimals.





  // Smoothing RPM:
  total = total - readings[readIndex];  // Advance to the next position in the array.
  readings[readIndex] = RPM;            // Takes the value that we are going to smooth.
  total = total + readings[readIndex];  // Add the reading to the total.
  readIndex = readIndex + 1;            // Advance to the next position in the array.

  if (readIndex >= numReadings)  // If we're at the end of the array:
  {
    readIndex = 0;  // Reset array index.
  }

  // Calculate the average:
  average = total / numReadings;  // The average value it's the smoothed result.


  display.showNumberDec(average, false);              //Write the RPM average to the 7-segment display

  RPMneedleValue = map(average, 0, 1200, 0, 150);     //Scale the RPM average to use it with the servo. The dial shows 0 up to 1200 rpm, 150° seems to be 180° in real life.
  RPMneedleValue = constrain(RPMneedleValue, 0, 150); //Constrain the servo movement, maybe it is not needed, but it solved the problem that the servo was making noise when the RPM of my drill was above 1200 rpm during testing.
  RPMneedle.write(RPMneedleValue);                    // sets the servo position according to the scaled value
  delay(15);


  // Print information on the serial monitor:
  // Comment this section if you have a display and you don't need to monitor the values on the serial monitor.
  // This is because disabling this section would make the loop run faster.
  Serial.print("Period: ");
  Serial.print(PeriodBetweenPulses);
  Serial.print("\tReadings: ");
  Serial.print(AmountOfReadings);
  Serial.print("\tFrequency: ");
  Serial.print(FrequencyReal);
  Serial.print("\tRPM: ");
  Serial.print(RPM);
  Serial.print("\tTachometer: ");
  Serial.println(average);

  if(Magnetdetected == 1){      //When the magnet is detected by the interrupt, the green LED needs to blink once.
  Magnetdetected = 0;
  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED, LOW);
  }



}  // End of loop.





void Pulse_Event()  // The interrupt runs this to calculate the period between pulses:
{
  PeriodBetweenPulses = micros() - LastTimeWeMeasured;  // Current "micros" minus the old "micros" when the last pulse happens.
                                                        // This will result with the period (microseconds) between both pulses.
                                                        // The way is made, the overflow of the "micros" is not going to cause any issue.

  LastTimeWeMeasured = micros();  // Stores the current micros so the next time we have a pulse we would have something to compare with.

  if (PulseCounter >= AmountOfReadings)  // If counter for amount of readings reach the set limit:
  {
    PeriodAverage = PeriodSum / AmountOfReadings;  // Calculate the final period dividing the sum of all readings by the amount of readings to get the average.
    PulseCounter = 1;                              // Reset the counter to start over. The reset value is 1 because its the minimum setting allowed (1 reading).
    PeriodSum = PeriodBetweenPulses;               // Reset PeriodSum to start a new averaging operation.


    // Change the amount of readings depending on the period between pulses.
    // To be very responsive, ideally we should read every pulse. The problem is that at higher speeds the period gets
    // too low decreasing the accuracy. To get more accurate readings at higher speeds we should get multiple pulses and
    // average the period, but if we do that at lower speeds then we would have readings too far apart (laggy or sluggish).
    // To have both advantages at different speeds, we will change the amount of readings depending on the period between pulses.
    // Remap period to the amount of readings:
    int RemapedAmountOfReadings = map(PeriodBetweenPulses, 40000, 5000, 1, 10);  // Remap the period range to the reading range.
    // 1st value is what are we going to remap. In this case is the PeriodBetweenPulses.
    // 2nd value is the period value when we are going to have only 1 reading. The higher it is, the lower RPM has to be to reach 1 reading.
    // 3rd value is the period value when we are going to have 10 readings. The higher it is, the lower RPM has to be to reach 10 readings.
    // 4th and 5th values are the amount of readings range.
    RemapedAmountOfReadings = constrain(RemapedAmountOfReadings, 1, 10);  // Constrain the value so it doesn't go below or above the limits.
    AmountOfReadings = RemapedAmountOfReadings;                           // Set amount of readings as the remaped value.
  } else {
    PulseCounter++;                               // Increase the counter for amount of readings by 1.
    PeriodSum = PeriodSum + PeriodBetweenPulses;  // Add the periods so later we can average.
  }

  Magnetdetected = 1;        //Value to let the green LED in behind the dial blink, so the user can see when the magnet passes by. This was handy during testing. 

 
}  // End of Pulse_Event.

This code works with the Arduino Uno R3. On the Arduino Nano Every (powered via USB of my pc) it seems to work at first sight. After a minute or so, it starts to do it´s own thing: the RPM value is jumping to random values, the LED doesn´t blink when the magnet passes the hall sensor, etc.

In an attempt to find out where this goes wrong, I have created this test program to see if the hall sensor triggers the interrupt correctly with the Nano Every. If the magnet passes by the hall sensor the LED blinks, which works as it should. So I concluded that the interrupt is working fine.

int LED = 11;
int HALL = 2;

volatile byte Magnetdetected = 0;


void setup() {
  // put your setup code here, to run once:
pinMode(HALL, INPUT);
pinMode(LED, OUTPUT);

Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(HALL), blink, RISING);  // Enable interruption pin 2 when going from LOW to HIGH.

}

void loop() {
  // put your main code here, to run repeatedly:
if(Magnetdetected == 1){
  Magnetdetected = 0;

  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED, LOW);
  }
}

void blink(){
Magnetdetected = 1;
}

After double checking the connections and fiddling around with the code, disabling everything that has something to do with the servo in the main code seems to solve it. Then the RPM value is shown in the serial monitor of IDE, the LED is blinking when the magnet passes, and the Nano Every doesn't do it's own thing. But with the servo disabled, the analog tachometer doesn't work anymore of course.

I don't get why the exact same code works on the Arduino Uno R3, but doesn't on the Nano Every. I've googled quite a bit, found quite some topics about conflicts between servo libaries and interrups, and about adjusting timers, but I don't have the knowledge to really understand what's causing this behaviour or to translate this info into my code.

I hope that somebody here can explain me how to get the Nano Every working (if that's even possible). Or tell me if it's smarter to switch to the Arduino Uno R3. (Then I need to buy another Uno, as I don't want to use the one connected to the breadboard. With the Uno the meter is not very compact anymore, and I need to add a voltage regulator as well.)

Digispark is smaller as Nano Every. arduino mini too.
1200RPM=20RPS=2 rotation pro 100milliseconds, so slow events not need interrupts at all


#include <TM1637Display.h>
#define CLK 13
#define DIO 12
TM1637Display display(CLK, DIO);
#include <Servo.h>
Servo RPMneedle;

const int LED = 11;                       //The green LED is connected to pin 11, blinks when the magnet passes by.
const int HALL = 2;                       //The HALL sensor is connected to pin 2.
const int SERVO = 10;                     //The SERVO is connected the pin 10.
const unsigned long ZeroTimeout = 1000;  // For high response time, a good value would be 100000.

const uint8_t zoef[] = {                  //'ZOEF' is the name of the boat
  SEG_A | SEG_B | SEG_G | SEG_E | SEG_D,           // Z
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F,   // O
  SEG_A | SEG_F | SEG_G | SEG_E | SEG_D,           // E
  SEG_A | SEG_F | SEG_G | SEG_E,                   // F
};



void setup()  // Start of setup:
{ pinMode(HALL, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(SERVO, OUTPUT);

  display.setBrightness(7, false);
  display.setSegments(zoef);
  delay(250);

  RPMneedle.attach(SERVO);
  RPMneedle.write(0);
  delay(250);

  RPMneedle.write(150);  //150° seems to be 180° in real life.

  for (int s = 0; s < 7; s++) { //Let 'ZOEF' fade in on the 7-segment display.
    display.setBrightness(s);
    display.setSegments(zoef);
    delay(30);
  }

  delay(1750);

  for (int s = 7; s > 1; s--) { //Let 'ZOEF' fade out on the 7-segment display.
    display.setBrightness(s);
    display.setSegments(zoef);
    delay(20);
  }

  RPMneedle.write(0);   //Tachometer back to 0

  display.setBrightness(7, false); //Turn the 7 segment display off.
  display.setSegments(zoef);

  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED, LOW);
  delay(100);
  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED, LOW);

  display.setBrightness(7); //Helderheid van het scherm weer naar volle sterkte voor de toerenteller
}  // End of setup.

void loop() {
  static bool lastPinState = false;
  static uint8_t Angle = 0;
  static uint16_t RPM = 0;
  static uint32_t LastTiming = millis();

  bool Pin = digitalRad(HALL)==HIGH;
  digitalWrite(LED, Pin);
  if (lastPinState != Pin)
    if (pin) {
      if (millis() - LastTiming < ZeroTimeout) {
        RPM = 60000UL / (millis() - LastTiming);
        if (RPM > 10)display.showNumberDec(RPM, false);           //Write the RPM to the 7-segment display
        Angle = RPM / 8;
        if (Angle > 150)Angle = 150;
        RPMneedle.write(Angle);
      }
      else RPMneedle.write(0);
      LastTiming = millis();
    }
  lastPinState = Pin;


}  // End of loop.

Vehicle electrical systems are horrendously noisy. Alternators are one of the big culprits(as is the ignition spark) as sources of EMI( ElectroMagnetic Interference) not only that while it has a 18v limit it is far better to power it with 5 - 7v. as the regulator must burn off the extra voltage as heat.

Since you are only powering the system from the vehicle and not connecting I/O pins you can probably get away with just using a car phone charger to power the Nano. That will provide cleaner power at the right voltage.

Other things you can do to protect against radiated EMI is to keep your wires as short as possible and use a twisted pair of wires for the Hall sensor. Of course keep everything far away from ignition wires.

Are powering the Nano via USB or VIN?
If VIN what is the voltage?

Have you tried running the full code, but with the servo disconnected? The display and the servo both need considerable amounts of power, powering those from the voltage regulator on the Arduino is generally not a good idea.

Thanks for the tips.

Thanks for the suggestion, I´ll use a phone charger instead when I install it in the boat.

I have only used USB-power from my PC. As soon as it works reliably on the workbench, we'll install it in the boat.

Yes, in the beginning I ran the Arduino Uno (with the breadboard attached to it) without the servo. The display was the only thing showing the RPM. When that worked, I connected the servo to it, and ran the display and the servo simultaniously for just a minute to check that both showed the same RPM-value. After that I removed the display, so the Arduino Uno only powers the servo. The servo is from the Arduino Starter Kit by the way, in the manual of that kit they also power it straight from the Arduino's 5V (without anything else connected to it).

The Arduino Nano Every, which is running the same full/main code, does not have a display connected to it. Only the servo (and the hall sensor of course :slightly_smiling_face:).

I used the Arduino Uno with the breadboard to get the code working. When that worked I wired everything up to the Nano Every exactly the same and uploaded the exact same code to the Arduino Nano Every with the expectation that that would just work, which it didn't. I hope that clearifies it a bit.

This has caused Many beginners to have problems when they find out it doesn't work very well in the real world.

Grasping at straws but pin2 on the nano is connected to PA0 which can also be configured for an EXTCLK.

Try a different pin for the hall sensor.

That's quite confusing indeed.

I just moved the hall sensor wire from digital pin 2 to digital pin 3 on the Arduino Nano Every, and guess what? It works! Even after 5 minutes without a magnet near the hall sensor, the tachometer still shows 0 RPM and the LED hasn't blinked on its own yet. As soon as I spin the magnet close to the sensor with the drill, the tachometer starts to work. And when I stop, it goes back to 0 RPM. After houres of fiddling around, this is quite a relief.

I hope it stays this way. I'll keep an eye on it, and let it know if this solved it.

Quick update: tried the tachometer with the Arduino Nano Every out with the magnet attached to the drill chuck again today. It worked for quite a while, but then suddently stopped.

At first, I thought that I had broken the hall sensor in some sort of way. But when testing it as a magnetic switch with just 5V, a LED and a 330 ohm resistor, the LED lights up when a magnet is close by. The hall sensor is just fine.

Testing out the same thing, but now with the Arduino Nano Every in between with just the hall sensor (with a 10k pullup resistor) and the LED wires connected (I've de-soldered the other wires). Running this code, it works as well.

int LED = 11;
int HALL = 3;


void setup() {
  // put your setup code here, to run once:
pinMode(HALL, INPUT);
pinMode(LED, OUTPUT);

Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
int Hallsensor = digitalRead(HALL);  
Serial.println(Hallsensor);
  
if(Hallsensor == HIGH){
  digitalWrite(LED, LOW);
}
if(Hallsensor == LOW){
  digitalWrite(LED, HIGH);
}

}

So I guess I can conclude that the Arduino Nano Every does detect the signal from the hall sensor.
Next step was to check if this also works with a interrupt, so I got the code from my first post:

int LED = 11;
int HALL = 3;

volatile byte Magnetdetected = 0;


void setup() {
  // put your setup code here, to run once:
pinMode(HALL, INPUT);
pinMode(LED, OUTPUT);

digitalWrite(LED, LOW);

Serial.begin(9600);
attachInterrupt(digitalPinToInterrupt(HALL), blink, RISING);  // Enable interruption when going from LOW to HIGH.

}

void loop() {
  // put your main code here, to run repeatedly:
if(Magnetdetected == 1){

  Magnetdetected = 0;

  digitalWrite(LED, HIGH);
  delay(50);
  digitalWrite(LED, LOW);
}
}

void blink(){
Magnetdetected = 1;
}

When I upload this, the LED stays on, even without a magnet near the hall-sensor. I don't really get it.

Using a Uno, I've got this and it's a Go --

const byte LED = 13;
const byte HALL = 2;
volatile byte Magnetdetected = 0;

void setup() 
{
  pinMode(HALL, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
  attachInterrupt(digitalPinToInterrupt(HALL), blink, RISING);
}

void loop() 
{
  if(Magnetdetected)
  {
    Magnetdetected = 0;
    digitalWrite(LED, HIGH);
    delay(100);
    digitalWrite(LED, LOW);
  }
}

void blink()
{
  Magnetdetected = 1;
}

I ran that on my 'Every', too
and
It Worked
(used HALL = 3, like yours).

As runaway_pancake said, you need:

pinMode(HALL, INPUT_PULLUP);

Or a 10k pullup resistor from pin 3 to Vcc.

You can try moving the LED from pin 11. That pin is on the same timer as generates the servo pulse in the Nano Every. PWM on that pin 11 is disabled, but It should still work as general i/o and not impact the servo pulse.
Anyway, see if moving makes a difference.

You really can’t drive the servo direct from a nano pin , especially when you start driving it with 12v plus - the regulator will shutdown/burn out .

You need to build a power supply and drive the servo and nano direct .

Why not use a small stepper motor to drive the gauge needle ?

Yes, on my Uno it works as well.

Thanks for testing it. I now at least know that the code should be working.

Yeah, the hall-sensor still had the 10k pullup resistor in it, forgot to mention that, sorry.

Allright, are there more pins that are sharing certain things with the servo side of things? I'll now just move the wire for the LED over to a lower numbered pin, and repeat that until something changes/it works.

Thanks for the info, I'll make something with this tutorial and an adjustable voltage regulator.

The servo I had laying around already, so I used that.

I am trying to upload this to the Nano Every, howevery it doesn't seem to cooperate, which I find strange.

const byte LED = 13;
const byte HALL = 3;
volatile byte Magnetdetected = 0;

void setup() 
{
  pinMode(HALL, INPUT_PULLUP);
  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);
  attachInterrupt(digitalPinToInterrupt(HALL), blink, RISING);
}

void loop() 
{
  if(Magnetdetected)
  {
    Magnetdetected = 0;
    digitalWrite(LED, HIGH);
    delay(100);
    digitalWrite(LED, LOW);
  }
}

void blink()
{
  Magnetdetected = 1;
}

In fact, I can't even upload anything anymore. IDE only gives me error codes, basically to the point I'm pretty much done with all together. I'll just upload my main code to the Uno and call it done.

Sketch uses 3504 bytes (7%) of program storage space. Maximum is 49152 bytes.
Global variables use 370 bytes (6%) of dynamic memory, leaving 5774 bytes for local variables. Maximum is 6144 bytes.
avrdude: jtagmkII_initialize(): Cannot locate "flash" and "boot" memories in description
avrdude: jtagmkII_reset(): timeout/error communicating with programmer (status -1)
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude: jtagmkII_close(): timeout/error communicating with programmer (status -1)
avrdude: jtagmkII_close(): timeout/error communicating with programmer (status -1)
Failed uploading: uploading error: exit status 1

Sorry, I don't know what that jtagmkII stuff is about really. I'm still using Arduino 1.8.19 - maybe you're using "Arduino 2 (whatever it is)"?
It's not the sketch that's making it crater though.

After reviewing all 18 posts, I think hat your nano Every had problems from the very beginning and now it won't even upload code.
If you need something small that's almost identical to the UNO, buy a plain Arduino Nano

No worries, I'm using version IDE version 2.1.

That's also what I was thinking, as the same code just works as it should when I upload it to the Uno.

It came new, unused out of its cardboard box though and it's a genuino Arduino also. But after googling the jtagmkII error codes, I read that more people do have problems with the Every, also unused new ones.

Thanks for the tip, I'll have a look at a plain Nano later this week and try again (with external power (with a shared ground) for the servo).