Hi, I have 2 separate sketches which work fine on their own. I am struggling to get them working on one arduino.
Sketch number 1:
Deals with the input from a microwave doppler sensor
Sketch number 2:
Is a piezeo buzzer
I would like the microwave sensor to activate the buzzer once a threshold it met (I have already got an LED lighting up when the threshold is met) but I cannot combine them.
Below is the code for the microwave sensor: Can anybody tell me where to put the code for my simple PWM pieze sound alarm so that
it triggers at the same time as the ledPin?
Sketch number 1:
Deals with the input from a microwave doppler sensor
Sketch number 2:
Is a piezeo buzzer
I would like the microwave sensor to activate the buzzer once a threshold it met (I have already got an LED lighting up when the threshold is met) but I cannot combine them.
Below is the code for the microwave sensor: Can anybody tell me where to put the code for my simple PWM pieze sound alarm so that
it triggers at the same time as the ledPin?
Code:
[/B]
const int analogPin = 0;
const int threshold = 500;
int ledPin = 13;
void setup()
{
Serial.begin(9600);
pinMode (ledPin, OUTPUT);
}
void loop() {
int mn = 1023; // mn only decreases
int mx = 0; // mx only increases
// Perform 10000 reads. Update mn and mx for each one.
for (int i = 0; i < 700; ++i) {
int val = analogRead(analogPin);
mn = min(mn, val);
mx = max(mx, val);
}
if (threshold > mn)
{
digitalWrite (ledPin, HIGH);
}
else {
digitalWrite (ledPin, LOW);
}
// Send min, max and delta over Serial
Serial.print("m=");
Serial.print(mn);
Serial.print(" M=");
Serial.print(mx);
Serial.print(" D=");
Serial.print(mx-mn);
Serial.println();
}