Skip to main content
Improved formatting
Source Link
Craig
  • 2.1k
  • 10
  • 11

I'm building a basic program that when a button is pressed, a buzzer comes on.

I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds).

Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

// Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;         // the number of the LED pin

// variables:
int touchsensorState = 0;      // variable for reading the touchsensor status

void setup() {
  // initialize the buzzer as an output:
  pinMode(buzzer, OUTPUT);
  // initialize the touchsensor as an input:
  pinMode(touchsensor, INPUT);
}

void loop() {
  // read state of the pushbutton value:
  touchsensorState = digitalRead(touchsensor);

  // check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
  if (touchsensorState == HIGH) {
    // buzzer will emit sound:
    digitalWrite(buzzer, HIGH);
  } else {
    // buzzer will not sound:
    digitalWrite(buzzer, LOW);
  }
}

I'm building a basic program that when a button is pressed, a buzzer comes on.

I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds).

Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

// Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;         // the number of the LED pin

// variables:
int touchsensorState = 0;      // variable for reading the touchsensor status

void setup() {
// initialize the buzzer as an output:
pinMode(buzzer, OUTPUT);
// initialize the touchsensor as an input:
pinMode(touchsensor, INPUT);
}

void loop() {
// read state of the pushbutton value:
touchsensorState = digitalRead(touchsensor);

// check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
if (touchsensorState == HIGH) {
// buzzer will emit sound:
digitalWrite(buzzer, HIGH);
} else {
// buzzer will not sound:
digitalWrite(buzzer, LOW);
}
}

I'm building a basic program that when a button is pressed, a buzzer comes on.

I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds).

Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

// Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;         // the number of the LED pin

// variables:
int touchsensorState = 0;      // variable for reading the touchsensor status

void setup() {
  // initialize the buzzer as an output:
  pinMode(buzzer, OUTPUT);
  // initialize the touchsensor as an input:
  pinMode(touchsensor, INPUT);
}

void loop() {
  // read state of the pushbutton value:
  touchsensorState = digitalRead(touchsensor);

  // check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
  if (touchsensorState == HIGH) {
    // buzzer will emit sound:
    digitalWrite(buzzer, HIGH);
  } else {
    // buzzer will not sound:
    digitalWrite(buzzer, LOW);
  }
}

Stop ArdinoArduino Timer after some seconds

I'm relatively new to this Arduino Yun I am using. I'm building a basic program that when a button is pressed, a buzzer comes on. 

I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds). 

Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

// Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;         // the number of the LED pin

// variables:
int touchsensorState = 0;         // variable for reading the touchsensor status

void setup() {
 
// initialize the buzzer as an output:
pinMode(buzzer, OUTPUT);
// initialize the touchsensor as an input:
pinMode(touchsensor, INPUT);
}

void loop() {
// read state of the pushbutton value:
touchsensorState = digitalRead(touchsensor);

// check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
if (touchsensorState == HIGH) {
// buzzer will emit sound:
digitalWrite(buzzer, HIGH);
} else {
// buzzer will not sound:
digitalWrite(buzzer, LOW);
}
}

Stop Ardino Timer after some seconds

I'm relatively new to this Arduino Yun I am using. I'm building a basic program that when a button is pressed, a buzzer comes on. I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds). Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

//Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;      // the number of the LED pin

// variables:
int touchsensorState = 0;         // variable for reading the touchsensor status

void setup() {
 
// initialize the buzzer as an output:
pinMode(buzzer, OUTPUT);
// initialize the touchsensor as an input:
pinMode(touchsensor, INPUT);
}

void loop() {
// read state of the pushbutton value:
touchsensorState = digitalRead(touchsensor);

// check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
if (touchsensorState == HIGH) {
// buzzer will emit sound:
digitalWrite(buzzer, HIGH);
} else {
// buzzer will not sound:
digitalWrite(buzzer, LOW);
}
}

Stop Arduino Timer after some seconds

I'm building a basic program that when a button is pressed, a buzzer comes on. 

I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds). 

Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

// Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;         // the number of the LED pin

// variables:
int touchsensorState = 0;      // variable for reading the touchsensor status

void setup() {
// initialize the buzzer as an output:
pinMode(buzzer, OUTPUT);
// initialize the touchsensor as an input:
pinMode(touchsensor, INPUT);
}

void loop() {
// read state of the pushbutton value:
touchsensorState = digitalRead(touchsensor);

// check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
if (touchsensorState == HIGH) {
// buzzer will emit sound:
digitalWrite(buzzer, HIGH);
} else {
// buzzer will not sound:
digitalWrite(buzzer, LOW);
}
}
Source Link
Chris
  • 13
  • 3

Stop Ardino Timer after some seconds

I'm relatively new to this Arduino Yun I am using. I'm building a basic program that when a button is pressed, a buzzer comes on. I would like however to make it so that the buzzer stops after a short period of time (e.g. 5-7 seconds). Here is the code I have so far which is pretty basic I know forgive me but I have no clue on how to go forward.

//Setting The Pin Numbers
const int touchsensor = 2;     // the number of the touchsensor pin
const int buzzer =  4;      // the number of the LED pin

// variables:
int touchsensorState = 0;         // variable for reading the touchsensor status

void setup() {

// initialize the buzzer as an output:
pinMode(buzzer, OUTPUT);
// initialize the touchsensor as an input:
pinMode(touchsensor, INPUT);
}

void loop() {
// read state of the pushbutton value:
touchsensorState = digitalRead(touchsensor);

// check if the touch sensor is pressed. If it is, the touchsensorState is HIGH:
if (touchsensorState == HIGH) {
// buzzer will emit sound:
digitalWrite(buzzer, HIGH);
} else {
// buzzer will not sound:
digitalWrite(buzzer, LOW);
}
}