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);}
}