Hello community,
So, I'm finished the code to run the KEMET vibration sensor. I did attach it below. I have also attached 2 videos of everything working.
The experiment review:
My proposal was to use the KEMET Vibration Sensor as a machine safety device. The sensor would get the average vibration of the machine, the user would enter the shutdown limit and if this limit is reached, the machine would shut down. With machines that I use at work, unbalanced machines can be deadly. I couldn't actually use the machines at work for this experiments (Boss wouldn't let me wire into them as we run 660v).
So instead, I wired in my laser CNC at home. It proved to work very well. If the laser tries to over-travel the x-axis or y-axis the servo belt skips and makes a bad vibration. When I use the KEMET sensor with the setup I created, the CNC shut down after 1 gear/belt skip. Usually when this happens I spend the next hour re-calibrating the machine, with this I didn't have to re-calibrate.
How the program works:
Once you have the sensor in place you turn on the Vibration sensor controller.
The title screen appears.
Then it gives you a choice:
A - Machinery Safety
B - Test Sensor : I did this so the sensor can be used for machinery safety or just using the sensor for experimenting, your choice.
If "A" is chosen: (Set-up with push buttons)
Starts the "Machinery Safety program".
- First you are asked to enter the maximum percent above average vibration allowable.
-This is done by pressing push button "C" until your % limit is correct.
- If you make an error in your %, there is a "reset" to 0 button, "B".
- When your limit is correct you press the "enter" push button, "A". (As you can see I use these buttons for multiple purposes).
- The calibration starts (16 vibration checks in 10 seconds)
- The program then takes the sum of the 16 checks and divides it by 16 to get the average.
- It now takes your % limit to get the shutdown limit.
e.g.
- You input 8% for your limit.
- The KEMET Vibration Sensors machine average vibration is 513.
- The shutdown limit will be 554.04
- All information is displayed on the LCD.
- CAL= "Calibrated average"
- CR= "Current vibration read"
- HR= "Highest recorded vibration"
- SDL= "Shut down limit"
- When the Vibration Sensor reads vibrations at or above this limit, it shuts down the machine.
- The reset button must be pressed to continue. This will reset the program.
If "B" is chosen:
Starts the "Test program".
- It will do a calibration only. It will display the data received, but won't shut down from to much vibration since there is no limit set.
- Reset button can be used to exit this mode.
Arduino MEGA Code:
#include <LiquidCrystal.h> const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; LiquidCrystal lcd(rs, en, d4, d5, d6, d7); int vib = A0; //Vibration sensor pin int onlt = 8; //Assign Power On LCD int safelt2 = 9; //Assign warning LED int warnlt1 = 10; //Assign warning LED int warnlt2 = 13; //Assign warning LED int shutdwnlt = 14; //Assign warning LED int shutdwnsw = 7; //Assign shutdown switch int data; //Sensor reading int average = 0; //Average reading int averageA = 0; int averageB = 0; int x = 0; //Loop count int y = 0; //Creates infinate loop int z = 0; int tread = 0; //Temporary read int hread = 0; //Highest reading float a = 0; float b = 0; const byte modeButton1 = 18; //Assign choice as button A and enter const byte modeButton2 = 19; //Assign choice as button B and erase const byte selectButton = 20; //Assigned to % selection void setup(){ pinMode(modeButton1, OUTPUT); pinMode(modeButton2, OUTPUT); pinMode(shutdwnsw, OUTPUT); pinMode(selectButton, OUTPUT); digitalWrite(shutdwnsw, LOW); digitalWrite(modeButton1, LOW); digitalWrite(modeButton2, LOW); digitalWrite(selectButton, LOW); digitalWrite(onlt, HIGH); delay(1000); lcd.clear(); lcd.begin(16, 2); lcd.setCursor(0,0); lcd.print("KEMET Vibration"); lcd.setCursor(1,1); lcd.print("Sensor VSBV20"); delay(2500); pinMode(vib, INPUT); //initialize vib sensor as INPUT Serial.begin(9600); //begin the serial monitor at 9600 baud lcd.clear(); } void loop(){ lcd.setCursor(0,0); lcd.print("A-Machine Safety"); //Choose which program to run lcd.setCursor(0,1); lcd.print("B-Test Sensor"); //Choose which program to run // if button A pressed if(digitalRead(modeButton1) == HIGH) { lcd.clear(); delay(500); programOne(); } // if button B pressed if(digitalRead(modeButton2) == HIGH) { lcd.clear(); testTwo(); } } //Run the vibration program void programOne() { pinMode(vib, INPUT); //initialize vib sensor as INPUT z = 16; Serial.begin(9600); //begin the serial monitor at 9600 baud lcd.clear(); lcd.setCursor(0,0); lcd.print("Set sensitivity"); lcd.setCursor(0,1); lcd.print(a); lcd.setCursor(3,1); lcd.print("% Above Ave"); do{ //Input sensitivity % if(digitalRead(selectButton) == HIGH){ a = a + 1; lcd.setCursor(0,1); lcd.print(a); lcd.setCursor(3,1); lcd.print("% Above Ave"); delay(500); } if(digitalRead(modeButton2) == HIGH) //Press modeButton2 to restart { a = 0; digitalWrite(modeButton2, LOW); lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(0,1); lcd.print(a); lcd.setCursor(3,1); lcd.print("% Above Ave"); } } while (digitalRead(modeButton1) == LOW); lcd.clear(); do{ //Calibrate average vibration for 10 seconds x = x + 1;; averageA = analogRead(vib); averageB = averageB + averageA; Serial.println("Calibrating"); Serial.println(averageA); lcd.setCursor(0,0); lcd.print("Calibrating"); lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(0,1); lcd.print(z); delay(625); z = z - 1; } while (x < 16); lcd.clear(); average = averageB/16; Serial.println(average); Serial.println(averageB); a = a/100; b = (a * average); Serial.println(a); Serial.println(b); do{ data=analogRead(vib); Serial.println(data); tread = data; lcd.setCursor(0,0); lcd.print("Cal="); // Calibrated Average lcd.setCursor(4,0); lcd.print(average); lcd.setCursor(10,0); lcd.print("CR="); //Current recorded lcd.setCursor(13,0); lcd.print(data); lcd.setCursor(10,1); lcd.print("HR="); //Highest recorded lcd.setCursor(13,1); lcd.print(hread); lcd.setCursor(0,1); lcd.print("SDL="); //Shut down limit lcd.setCursor(4,1); lcd.print(round(average + b)); // Set highest reading if(hread < tread) { hread = tread; } if(data <= (average)){ digitalWrite(safelt2, LOW); digitalWrite(warnlt1, LOW); digitalWrite(warnlt2, LOW); digitalWrite(shutdwnlt, LOW); Serial.println("Within Limits"); } else if(data <= (average + (b / 4))){ digitalWrite(warnlt1, LOW); digitalWrite(warnlt2, LOW); digitalWrite(shutdwnlt, LOW); Serial.println("Within Limits High"); digitalWrite(safelt2, HIGH); } else if(data <= (average + (b / 3))){ digitalWrite(warnlt2, LOW); digitalWrite(shutdwnlt, LOW); Serial.println("Warning Limits"); digitalWrite(safelt2, HIGH); digitalWrite(warnlt1, HIGH); } else if(data <= (average + (b / 2))){ digitalWrite(shutdwnlt, LOW); Serial.println("Warning Limits High"); digitalWrite(safelt2, HIGH); digitalWrite(warnlt1, HIGH); digitalWrite(warnlt2, HIGH); } else if(data <= (average + b)){ Serial.println("Shut Down Level Reached"); digitalWrite(safelt2, HIGH); digitalWrite(warnlt1, HIGH); digitalWrite(warnlt2, HIGH); digitalWrite(shutdwnlt, HIGH); } else if(data > (average + b)){ Serial.println("Shutting Down"); digitalWrite(safelt2, HIGH); digitalWrite(warnlt1, HIGH); digitalWrite(warnlt2, HIGH); digitalWrite(shutdwnlt, HIGH); digitalWrite(shutdwnsw, HIGH); delay(1500); lcd.clear(); lcd.setCursor(4,0); lcd.print("Warning"); lcd.setCursor(0,1); lcd.print("Limit Exceeded"); delay(2000); lcd.clear(); lcd.setCursor(0,0); lcd.print("Shutting Down"); delay(1000); lcd.clear(); lcd.setCursor(0,0); lcd.print("SDL="); //Shut down limit lcd.setCursor(4,0); lcd.print(round(average + b)); lcd.setCursor(0,1); lcd.print("Max="); lcd.setCursor(4,1); lcd.print(data); delay(4000); lcd.clear(); lcd.setCursor(0,0); lcd.print("Press Button to"); lcd.setCursor(2,1); lcd.print("Reset Sensor"); while(0 == 0); // Causes infinate loop {} } delay(50); }while (y == 0); } //Test the vibration sensor void testTwo() { z = 16; do{ //Calibrate average vibration for 10 seconds x = x + 1; averageA = analogRead(vib); averageB = averageB + averageA; Serial.println("Calibrating"); lcd.setCursor(0,0); lcd.print("Calibrating"); lcd.setCursor(0,1); lcd.print(" "); lcd.setCursor(0,1); lcd.print(z); delay(625); z = z - 1; } while (x < 16); average = averageB/16; do{ data=analogRead(vib); Serial.println(data); tread = data; // Set highest reading if(hread < tread) { hread = tread; } lcd.clear(); lcd.setCursor(0,0); lcd.print("Cal="); lcd.setCursor(4,0); lcd.print(average); //Display average calibrated vibration lcd.setCursor(9,0); lcd.print("CR="); lcd.setCursor(12,0); lcd.print(data); //Displays current vibration lcd.setCursor(0,1); lcd.print("HR="); lcd.setCursor(4,1); lcd.print(hread); //Displays highest vibration read delay(50); }while (y == 0); }
I set up the code this way so I could run 2 different tests in the same program. This way I don't have to run two different Arduino's or re-load a different code every time I wanted to test the sensor without limits.
Video #1
Video #2
Final thoughts:
It is hard to describe how impressed I am with the KEMET Vibration Sensor. It far passed my expectations, the use could be unlimited. The next experimenting I want to do with the sensor is in the medical field. Just because my Machinery Safety experiment is coming to an end, I don't want to stop with just that.
I am extremely grateful for being chosen to compete in this challenge, I've learned so much. Every challenge I participated in has taught me something. Each one made me push my comfort zone. But that is how you learn. If there is member who doesn't apply for challenges due to their abilities, I encourage them to apply. If you get in and you find yourself overwhelmed, you have the whole Element14 community to help. As a competitor, I've been there, and the community was there for me!!
To our sponsor KEMET, I have to thank you so much for sponsoring this challenge. I learned so much and have to say how grateful I am to be a participant. I have learned so much about your Vibration Sensor and its uses.
Element14, thank you for hosting these challenges and everything you do.
Element14 Community, thank you for all the help I got over the years, it has been priceless!!
Laser CNC key-chain (Front)
Laser key-chain (Back)
Thank you,
Dale Winhold