I want to do a project where the temperature sensor turns on the PIR(motion) sensor when a certain ambient temperature is reached. After the PIR sensor is turned on, it should activate the buzzer when it detects motion. I don't know how to merge the three codes to make this happen. It would be great if i could get some guidance on how to merge the codes and also set up the circuit.
Motion sensor code:
const int ledPin = 13;
int buttonState = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
Serial.begin(9600);
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
Serial.println(buttonState);
delay(500);
}
Temperature sensor code:
define analogPin A0 //the thermistor attach to
#define beta 4090 //the beta of the thermistor
#define resistance 10 //the value of the pull-down resistor
float sensorValue, Celsius, Fahrenheit;
void setup() {
//Define the vaults
Serial.begin(9600);
//Define pin A0 as input
pinMode(A0, INPUT);
//Define pins 10, 11, as output
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}
void loop() {
//read thermistor value
long a = analogRead(A0);
//the calculating formula of temperature
float tempC = beta /(log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 273.0;
Serial.print("Temp: ");
Serial.print(tempC);
Serial.print(" C");
Serial.println();
//If temperature greater than 250 turn red led and buzzer on
if(tempC >= 250){
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
}
Buzzer code:
int buzzer = 13;//the pin of the active buzzer
void setup()
{
pinMode(buzzer,OUTPUT);//initialize the buzzer pin as an output
}
void loop()
{
unsigned char i;
while(1)
{
//output an frequency
for(i=0;i<80;i++)
{
digitalWrite(buzzer,HIGH);
delay(1);//wait for 1ms
digitalWrite(buzzer,LOW);
delay(1);//wait for 1ms
}
//output another frequency
for(i=0;i<100;i++)
{
digitalWrite(buzzer,HIGH);
delay(2);//wait for 2ms
digitalWrite(buzzer,LOW);
delay(2);//wait for 2ms
}
}
}