In this project, I will talk about Phototransistor Optical Interrupter Switches (Opto Coupler) Module, how this module works and helps in determining the speed of a rotating object and finally I will show you how to Interface Optical Interrupter Switch Sensor with Arduino and measure the speed of a motor in second , Minute and revolution encoder Slot count.
Circuit Diagram:
Components Required
Arduino Uno
Optical Endstop Light Control Limit Optical Switch (H21A1)
LCD display 20x4
BO Motor with Revolution Encoder for Measurement
Optical Endstop Light Control Limit Optical Switch
Actually, This fully assembled plug and play Optical Endstop Light Control Limit Optical Switch is very suitable for your 3D printing or CNC project. The Optical Endstop Switch will immediately output the digital control when the light is blocked and turn the LED on.
The optical end-stop is a reliable end-stop / switch solution for any type of 3D printers and other CNC and 3D tools. Using optical transmission principle designed, no loss, no noise, and longer service life reached more than one hundred thousand times.
H21A1 Optical Interrupter
The H21A and H22A series of opaque photointerrupters are single channel switches consisting of a Gallium Arsenide infrared emitting diode and a NPN silicon phototransistor mounted in polycarbonate housing. The package is designed to optimize the mechanical resolution, coupling efficiency, ambient light rejection, cost and reliability. Operating on the principle that objects opaque to infrared will interrupt the transmission of light between an infrared emitting diode and a photo sensor switching the output from an "ON" state to an "OFF" state.
The main aim of this project is to measure the rotational speed of a motor using an Arduino. In order to measure the speed of a rotating device like a simple DC Motor for example, we need a special device like a speed sensor.
The combination of BO motor + wheel and a encoder disc with 20 slots and 24mm outer diameter along with encoder slit sensor module for detecting the number of counts moved by the wheel. The digital output can be fed to a microcontroller for find the rpm of the bo motor. The encoder wheel consists of 20 holes (this number becomes important in the program part
These rotary encoders fit Motors and Encoder Counters. Use them to feedback speed and distance, or make your own anemometer or wind speed meter..
Installing the Arduino_Library
LiquidCrystal_I2C.h : you need to Downloadand install the LiquidCrystal_I2C library.
In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded.
After installing the required libraries, copy the following code to your Arduino IDE.
Subscribe and Download code.
Arduino Code
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
int sensor = 11;
unsigned long start_time = 0;
unsigned long end_time = 0;
int steps=0;
float steps_old=0;
float temp=0;
float RPS=0;
float RPM=0;
void setup()
{
Serial.begin(9600);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
pinMode(sensor,INPUT_PULLUP);
lcd.setCursor(0,0);
lcd.print("Tacho Meter&Counter");
}
void loop()
{
start_time=millis();
end_time=start_time+1000;
while(millis()<end_time)
{
if(digitalRead(sensor))
{
steps=steps+1;
while(digitalRead(sensor));
}
}
temp=steps-steps_old;
steps_old=steps;
RPS=(temp/20); //change yoursRevolution encoder slot here Example: 20
RPM=(RPS*60);
lcd.setCursor(0,3);
lcd.print("RPS:");
lcd.setCursor(5,3);
lcd.print(RPS);
lcd.setCursor(0,2);
lcd.print("RPM:");
lcd.setCursor(5,2);
lcd.print(RPM);
lcd.setCursor(0,1);
lcd.print("Rev.Count:");
lcd.setCursor(11,1);
lcd.print(steps);
}
Comments