DVDdoug:
Are you using an analog input? Run the [u]Analog Read Serial[/u] to see what kind of readings you're getting.
And, I assume you're using a pull-down resistor? A higher value resistor (maybe 1M) will allow a bigger signal from the piezo.
Hey DVDdoug, well I guess I'm glad I started in the right spot. I was using a 1M resistor before the piezo's ground and signal wire and using an analogue input for the reading. Below is the code I was using. With just the straight reading I was getting 1.0, sometimes 2.0 but it was very inconsistent. Most of the time it was just 0. I was using a threshold also because I thought I would have a range and had heard the piezo could pick up other vibrations so I wanted to limit the signal. I then tried dividing the signal by 100 and was getting a much more consistent reading, things like .02, .40, .35, .10 etc but it was overall still inconsistent, still reading 0 about 1/2 the time. I tried adding more resistors to see if it would boost the voltage more but no luck, hence why I started thinking about the amplifier. The dragging of these screws against the ceramic is very light obviously.
On a side bar, I'm not set on the piezo, its just like I said some stuff I had on hand. I know there are vision systems that can distinguish this kind of difference but I was trying to build something for a couple hundred bucks tops, not spend $2000+. I thought about something like the Pixy cam through a magnifying glass or something, but that's really best for identifying color differences it seems, where as these two screws are both silver (titanium) so that seems out.
I had tried the KY-036 touch sensor externally from the setup and thought it was good to go, holding the screws by the head with needle nose pliers making sure to only touch the rubber grips but I guess my hand was still conducting enough through to trigger the sensor? When I put the touch sensor in the setup and the belt was driving the sensor wouldn't read.
I had also thought of a load cell that could measure grains, as these are very light parts, but looking into a couple videos on how to make one like some of the YouTube "weigh an eyelash" ones it seems pretty tough for me to do with such limited electronic experience and I would have to redesign the mechanics of the setup and the scales seems pretty finicky too.
As you can see I am open to any practical solution haha.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int ledRedPin = 13; // longParts red LED signal
const float redKnockSensor = A0; // input for long parts piezo
const int thresholdMin = 2.0; // min piezo voltage
const int thresholdMax = 25.00; // max piezo voltage
float longParts = 0; // Counter reset for long parts.
float redSensorReading = 0;
int ledRedState = LOW;
void setup() {
lcd.begin(16, 2);
lcd.setCursor(0,1);
lcd.print("Long parts:");
lcd.setCursor(13,1);
lcd.print(longParts);
pinMode(ledRedPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
lcd.setCursor(0,1);
lcd.print("Long Parts:");
lcd.setCursor(13,1);
lcd.print(longParts);
redSensorReading = analogRead(redKnockSensor);
//redSensorReading = redSensorReading /100 ;
Serial.println(redSensorReading);
if ((redSensorReading > 0) && (redSensorReading < thresholdMax))
{
++longParts;
ledRedState = HIGH;
digitalWrite(ledRedPin, ledRedState);
redSensorReading = 0;
ledRedState = LOW;
delay(1000);
digitalWrite(ledRedPin, ledRedState);
}
delay(300);
}