I want to add 2nd sensor for my project. example pir sensor 1 is for gsm and relay and 2nd sensor is for buzzer, I dont know how to do it please help!

#include <SoftwareSerial.h>
SoftwareSerial SIM900(2, 3);
String textForSMS;

int pirsensor = 10;
int buzzer = 9;
int relay = 11;

void setup() {
randomSeed(analogRead(0));
Serial.begin(9600);
SIM900.begin(9600);
Serial.println(" logging time completed!");
pinMode(pirsensor, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(relay, OUTPUT);
digitalWrite(buzzer, LOW);
digitalWrite(relay, HIGH);
delay(100);

}

void loop() {

if ( digitalRead(pirsensor) == HIGH) //
{
textForSMS = "\Warning Motion Detected!!";
sendSMS(textForSMS);
Serial.println(textForSMS);
Serial.println("message sent.");
delay(2000);

digitalWrite(relay, LOW);
digitalWrite(buzzer, HIGH);
             noTone(9);
delay(50); tone (9, 261);

delay (1000);

tone (9, 3000);
delay (500);

tone (9, 3000);
delay (500);
tone (9, 3000);
delay (500);
tone (9, 3000);
delay (500);
tone (9, 3000);
delay (500);
tone (9, 3000);
delay (500);
tone (9, 3000);
delay (500);
tone (9, 3000);
delay (500);

noTone(9);
delay(5000);

}
if ( digitalRead(pirsensor) == LOW) //
{
digitalWrite(buzzer, LOW);
delay(100);

digitalWrite(relay, HIGH);
delay(300);

}

}

void sendSMS(String message)
{
SIM900.print("AT+CMGF=1\r");
delay(1000);
SIM900.println("AT + CMGS = "+639914466199"");

delay(1000);
SIM900.println(message);
SIM900.println((char)26);
delay(1000);
SIM900.println();

}

Welcome to the Forum! Read the forum guidelines to see how to properly ask a question and some good information on making a good post. You will get faster and better help if you post all your code as requested by the forum guidelines. Also please describe what the hardware do you use.

Please go back and fix your original post.

1 Like

Please help us help you.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Please post a schematic.

Please post an image of your project.

Please describe the problem better then you just did.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.