- Fri Jan 20, 2017 10:01 am
#192981
I need to reset knock sensor after a hit.Can you tell me if that's possible with out physically hitting the sensor.Thanks
Where electronics enthusiasts find answers.
#include <SoftwareSerial.h>
unsigned long start, stop;
const int knockSensor = A1;
const int ledPin = 13;
const int softwareTx = 8;
const int softwareRx = 7;
SoftwareSerial s7s(softwareRx, softwareTx);
unsigned int counter = 0; // This variable will count up to 65k
char tempString[10]; // Will be used with sprintf to create strings
void setup() {
randomSeed(analogRead(0));
pinMode(ledPin, OUTPUT);
s7s.begin(9600);
}
void loop() {
while (analogRead(knockSensor) <=10);// wait until sensor greater than 10
delay(1000);
for (int i=0; i<3; i++)// declares i, tests if less
{// than 10, increments i by 1 until i equals 3
digitalWrite(13, HIGH);// turns pin 13 on
delay(500);// pauses for 1/2 second
digitalWrite(13, LOW); // turns pin 13 off
delay(500);//pauses for 1/2 second
}
delay(random(2000, 5000)); // delay from 2 to 5 seconds
digitalWrite(ledPin, HIGH);// light turns on
start = millis();
while (true) {
s7s.print((long)(millis() - start) / 1000.0);
if (analogRead(knockSensor) >= 10) { // if sensor greater than 10 counter stops
stop = millis();
break; // stop's while loop
}
}
digitalWrite(ledPin, LOW);
s7s.print((long)(stop - start) / 1000.0); // calculate's time time
delay(3000);
{
s7s.write(0x76); // Clear display command
}
}
I need to reset knock sensor after a hit.Since you can't be bothered to identify the sensor, check for a reset button.