Loop help

I am using a piezo vibro sensor to activate an alarm. I need my alarm to be on for 2 seconds then stop an turn on next time it has vibration here is my code so far.

const int sensorPin = A0;
int value = 0;
const int alarm = 13;

void setup(){
pinMode (alarm, OUTPUT);
pinMode (sensorPin, INPUT);

void loop(){
value = analogRead(sensorPin);
digitalWrite(alarm, HIGH);
else {
digitalWrite(alarm, LOW);

So, after you turn the alarm on, you need a two second delay()? I'm not sure if there is a function for that, or not.

I think you'll find that you get a lot more feedback if you:

  1. Read the first two posts (i.e., "sticky notes") on this forum that tell you how to get the most out of this forum.
  2. With the cursor in the Source Code window of the IDE, press Ctrl-T to format your code in a form preferred by most readers.
  3. Use the source code tags (using the '#' character you see when you post a comment) to encompass your formatted code.

This will make it easier for everyone to help you.