Need Help with IR Sensor Speed Control for Large DC Motor

Hello all,

I'm having some issues with the speed sensor subsystem for a shaker I'm building. I'm using a 180VDC motor to move a shelf between 60 and 240 rpm. At the end of the shelf I have an IR emitter and photo-transistor which is interrupted by a metal plate attached to the shelf. For now, my code just counts the number of times the sensor is interrupted, but with a few calculations it will display the rpm.

When the motor is turned off, and the sensors turned on; I am able to interrupt the senors with a notecard and the count works immaculately. However, when the motor is turned on (regardless of speed), I am unable to display anything on the serial monitor.

The following is the code I'm currently implementing on the Arduino

#include <avr/interrupt.h>

float Motor_Speed = 0; //Speed Control, range 0 - 255, 255 being fastest speed

void setup() 
{ 
  Serial.begin(9600);
  pinMode(9,OUTPUT); //PWM output for speed control
  pinMode(2,INPUT); //IR sensor input
  digitalWrite(2,HIGH); //Assign Pull-up Resistor for PWM output
  analogWrite(9,255-Motor_Speed); //Write speed to motor
  attachInterrupt(0, speed_calc, RISING); //Activate interrupt 
}

void loop() 
{
}

void speed_calc()
{
static int count = 0; //Count the number of times the sensors are interrupted
Serial.println(count);
count++;
}

The following are the specs of all related equipment for this problem

Micro:
Arduino Mega

Motor:
180VDC
1/2HP
2.25A

Speed Control:
http://www.kbelectronics.com/manuals/kbwd_13_16_manual.pdf

Speed Sensors:

(I've attached an image of how the speed sensors are set up without their enclosure)

Any help or input anyone has would be greatly appreciated, thank you!

Why would that code display anything? It is going to run that loop with nothing in it, never calling the speed_calc() function.

Looks like it is working as written to me.

speed_calc() runs when pin2 recieves a falling edge. It's an ISR triggered by an external interrupt on Pin2, which is in turn connected to the sensor output. The attachInterrupt line in void setup() is where the ISR name is declared.

Maybe it is a noise issue.

Can you try running the motor on its own- not controlled by nor connected to the Arduino at all? If the Arduino will read the sensors then, it would suggest a motor noise issue I would think.

I can give that a shot. I'll attach a 5k pot to control the speed of the motor, and disconnect the PWM signal from the speed control. I'll let you know how it turns out. I've had a couple more ideas while trouble shooting this.

The motor is controlled by a +5V signal into an optoisolater, and the PWM attached to the other side, i.e. PWM goes low, motor turns on. The senors are also powered from a +5V source. The +5V for both of these circuits is supplied from the Arduino. Would the PWM running effect the current going into the speed control circuit enough to keep it from getting a signal?

+5V,GND, and Sensor wires are in pretty close proximity to the 120Vrms going into the speed control. As well as the DC line to the motor. Would the flux have any effect on the signal? Power electronics is definitely not my forte.

Thank you very much for you help!

Well I was able to look at the sensor output on an oscilloscope, and there is definitely some noise. I've attached the oscilloscope output here. I connected a 1uF filter capacitor between the +5V and GND of the sensors, however that didn't solve the issues. Does anyone have any ideas on how I could reduce the noise? Thank you everyone for your help!