Adafruit VCNL4010 proximity sensor unable to register a rotating bolt

I am using a Adafruit VCNL4010 proximity sensor register the passing of a bolt attached to a rotating flywheel. The flywheel is being driven by a 3 ph motor which in turn is powered by a variable speed drive unit. The intention is to operate some solenoids each time the bolt passes the sensor. The sensor is connected to an Uno clone with clone relay sheild that in turn is connected to a PC via a USB port. I would consider myself to be a beginner to intermediate Arduino user.

The problem is that the sensor sences the bolt when the flywheel is turned manually but as soon as the variable speed drive is turned on it doesn't appear to register the passing bolt and when variable speed drive is turned off and then turning the flywheel manually it fails to sense the bolt. Sense means print to the serial monitor and operation of the solenoid. The flywheel was turning at 1.5 Hz although I am looking for it to operate at closer to 50 Hz.

The program, code below, has been acting erratically when I tried to reset it sometimes not finding the sensor and sometimes changing the computers screen display settings.

Any thoughts and or are ther better ways of doing this.

<#include <Wire.h>
#include "Adafruit_VCNL4010.h"

Adafruit_VCNL4010 vcnl;

//Relay setup
const int RELAY_PIN_1 = 7;  // Two way solinoide
const int RELAY_PIN_2 = 6;  // High pressure inlet valve solinode
const int RELAY_PIN_3 = 5;  // Low pressure outlet valve solinode

int test = 7000;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  Serial.println("VCNL4010 test");

  if (! vcnl.begin()){
    Serial.println("Sensor not found :(");
    while (1);
  }
  Serial.println("Found VCNL4010");
  
  // initialize digital pin as an output.
  pinMode(RELAY_PIN_1, OUTPUT);
  pinMode(RELAY_PIN_2, OUTPUT);
  pinMode(RELAY_PIN_3, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
unsigned long previouTime = micros();

if ( vcnl.readProximity() > test) { //Checking for proximity switching high
pulseIn(vcnl.readProximity(), HIGH); // Registering start of revolution 
Serial.print("High: "); Serial.print(vcnl.readProximity()); Serial.println(", " ); //Check print to show that revolution is only being counted once
  digitalWrite(RELAY_PIN_1, HIGH);
  delay(50);
  digitalWrite(RELAY_PIN_1, LOW);}
}

Get a simpler sensor, light barrier or Hall sensor, to detect fast moving objects.

That delay(50) in loop() means that you can only detect the bolt a maximum of 1000/50 = 20 times per second.

How is that going to be able to detect something happening at 50Hz?

The delay() function is "blocking" - your motor can do 2½ revolutions during the delay period.

Thank you for this and I will look at other sensors but if this was the sole cause of my problems I would expect the sensor to register the bolt once I turned off the drive and returned to manually rotating it.

Thank you, I was aware of this. The program I am aim to use will calculate the opening time depending on the rotational speed. However in the process of fault isolation I substituted that for a simple delay time that is shorter than the frequency I am currently starting with.

The reason I mentioned the 50Hz was a question about the sensors reaction time which the other respondent has answered. But secondly it a question of whether the whether the Uno would be quick enough to process the code in that period of time. The final code will be 4 or 5 times longer than this. But maybe that a question for another thread.

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