Need help with noise, hall sensor and solenoids

i got my code running great and a clean hall input to the uno. the problem comes in when i have the 2x 12 volt VVT solenoids powered up and functioning.

i put 1kΩ Resistor to 5v and 0.1 µF Capacitor to ground for the analog 1 input but it is not enough to get it back to clean.

i have shielded cable this is running through now too

top one is with solenoids working and bottom is with clean input and no output

const byte analogPin  = A0;   // Analog pin connected to the Hall sensor
const float threshold = 4.5;  // Voltage threshold for the cycle
const int numCycles   = 4;    // Number of cycles to count

unsigned long cycleStartTimes[numCycles]; // Array to store start times for each cycle
unsigned long cycleEndTimes[numCycles];   // Array to store end times for each cycle
int cycleCount = 0;
bool aboveThreshold = false;

// Define output pin for PWM
const byte VVT1 = 9;
const byte VVT2 = 10;

void setup() {
  Serial.begin(115200);
  cycleStartTimes[0] = millis(); // Record the initial start time

  // Initialize the PWM output pin
  pinMode(VVT1, OUTPUT);
  pinMode(VVT2, OUTPUT);
}

void loop() {
  // Read the voltage from the analog pin
  float voltage = analogRead(analogPin) * (5.0 / 1023.0);

  // Detect the transition from below to above threshold
  if (!aboveThreshold && voltage > threshold) {
    aboveThreshold = true; // We're above the threshold
  }

  // Detect the transition from above to below threshold
  if (aboveThreshold && voltage < threshold) {
    aboveThreshold = false; // We're below the threshold

    // Record the end time of the current cycle
    cycleEndTimes[cycleCount] = millis();
    cycleCount++; // Increment the cycle count

    // If we have completed the required number of cycles
    if (cycleCount >= numCycles) {
      unsigned long totalTime = 0;

      // Calculate the total time for the cycles
      for (int i = 0; i < numCycles; i++) {
        unsigned long cycleTime = cycleEndTimes[i] - cycleStartTimes[i];
        totalTime += cycleTime;
      }

      // Calculate the average time per cycle
      float averageTime = totalTime / (float)numCycles;
      float averageTimeSeconds = averageTime / 1000.0; // Convert milliseconds to seconds
      float rpm = 60.0 / averageTimeSeconds; // Calculate RPM based on average cycle time

      // Divide the RPM by 2
      rpm /= 2;

      // Convert RPM to a whole number
      int wholeRpm = (int)(rpm + 0.5); // Simple rounding without math.h

      Serial.print("RPM: ");
      Serial.println(wholeRpm);

      int pwmValue = 0;

      // Map the RPM value to the desired PWM range based on the RPM range
      if (wholeRpm >= 800 && wholeRpm <= 1500) {
        pwmValue = map(wholeRpm, 800, 1500, 20, 240);  // Off idle
      } else if (wholeRpm > 1500 && wholeRpm <= 5000) {
        pwmValue = map(wholeRpm, 1501, 5000, 240, 20); // Full RPM range
      }

      // Ensure the PWM value is within the range
      pwmValue = constrain(pwmValue, 20, 240);

      // Set the PWM output
      analogWrite(VVT1, pwmValue);
      analogWrite(VVT2, pwmValue);

      Serial.print("PWM %");
      Serial.println(pwmValue / 2.55);

      // Reset for next measurement
      cycleCount = 0;
      cycleStartTimes[0] = millis(); // Record the new initial start time
    } else {
      // Record the start time for the next cycle
      cycleStartTimes[cycleCount] = millis();
    }
  }
}

  • Why are you using a analog Hall sensor,

  • Suggest you use the digital version in your projects.

sadly this is all i can do on my own. i tried digital and got no progress
it is a factory ford cam sensor if that makes any difference
i likely have 100 hours into this so far from the past 30 days

  • Always show us a good schematic of your proposed circuit.
    Show us good images of your ‘actual’ wiring.
    Give links to components.

  • Do you have kickback diodes across the solenoids ?

1 Like

Where does the Uno get it's power from?
Is the sensor ground connected to the Uno GND?

1 Like

yes on fly back diodes
uno is powered off clean straight off battery same as megasquirt

1 i had the hall grounded to the clean battery ground! i ran it to here and now it is way cleaner. the hall gets 12v from clean positive
2 / 3 VVT outputs to solenoids
4 clean battery ground
5 hall input with 1kΩ Resistor to 5v and 0.1 µF Capacitor to ground

  • Draw this circuit out and its connection to the Arduino.

hall is powered by clean straight off battery power
now grounded straight to uno ground
signal goes to analog A0 with 1k to uno 5v and has cap to uno ground

runs nice now for analog right???? i am pretty stoked now

incase you want to see proof of life

  • Without seeing an all inclusive schematic, showing all connections, I will let others take over.
1 Like

i thank you profusely and claim this pretty much figured out!

why does so much noise come from the battery ground unlike the uno ground?
the uno does not power the hall, so i figured the ground would go back to the power ground directly

are you saying the hall should ground to the same ground as the VVT solenoids are grounding to from the FET's?
image

  • We can only guess where these red drawn wires connect.
    You know where these wires are connected outside the Arduino, we do not.

Good luck.

i posted a legend?

anyways it works perfect now!
a nice clean signal and output through all the rpm's
on to tuning the VVT curve

again, i cant thank you guys enough

1 Like

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