#define TRIG A0 //Module pins
#define ECHO A1
#define TRIG1 A2 //Module pins
#define ECHO1 A3
#define Buzzerpin 13
int ctn = 0;
void setup() {
Serial.begin(9600); // Serial monitoring
pinMode(TRIG, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO, INPUT_PULLUP);
pinMode(TRIG1, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO1, INPUT_PULLUP);
pinMode(Buzzerpin, OUTPUT);
}
void loop() {
digitalWrite(TRIG, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG, HIGH); // Send a 10uS high to trigger ranging according to specs
delayMicroseconds(20);
digitalWrite(TRIG, LOW); // Send pin low again
delayMicroseconds(2);
digitalWrite(TRIG1, LOW); // Set the trigger pin to low for 2uS. Give a short LOW pulse beforehand to ensure a clean HIGH pulse
delayMicroseconds(2);
digitalWrite(TRIG1, HIGH); // Send a 10uS high to trigger ranging according to specs
delayMicroseconds(20);
digitalWrite(TRIG1, LOW); // Send pin low again
delayMicroseconds(2);
int distance = pulseIn(ECHO, HIGH,26000); // Read in times pulse
int distance1 = pulseIn(ECHO1, HIGH,26000); // Read in times pulse
distance= distance/58;
distance1= distance1/58;
if (distance < 25) {
Serial.print("\r");
delay(1000);
Serial.print("AT+CMGF=1\r");
delay(1000);
/*Replace XXXXXXXXXX to 10 digit mobile number & ZZ to 2 digit country code*/
Serial.print("AT+CMGS=\"+YYXXXX\"\r"); // YY is the country code XXX is the number
delay(1000); //
//The text of the message to be sent.
Serial.print("HELLO There");
delay(1000);
Serial.write(0x1A);
delay(1000);
}
else{}
if (distance1 < 25 && ctn < 150) {
ctn += 1;
digitalWrite(Buzzerpin, HIGH);
}
else{
digitalWrite(Buzzerpin, LOW);
}
if (distance1 > 25 && ctn >= 150) {
ctn = 0;
digitalWrite(Buzzerpin, HIGH);
}
}```
#define TRIG A0 //Module pins
#define ECHO A1
#define TRIG1 A2 //Module pins
#define ECHO1 A3
#define Buzzerpin 13
int ctn = 0;
void setup() {
Serial.begin(9600); // Serial monitoring
pinMode(TRIG, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO, INPUT_PULLUP);
pinMode(TRIG1, OUTPUT); // Initializing Trigger Output and Echo Input
pinMode(ECHO1, INPUT_PULLUP);
pinMode(Buzzerpin, OUTPUT);
}
void loop() {
digitalWrite(TRIG, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(TRIG, HIGH); // Send a 10uS high to trigger ranging according to specs
delayMicroseconds(20);
digitalWrite(TRIG, LOW); // Send pin low again
delayMicroseconds(2);
digitalWrite(TRIG1, LOW); // Set the trigger pin to low for 2uS. Give a short LOW pulse beforehand to ensure a clean HIGH pulse
delayMicroseconds(2);
digitalWrite(TRIG1, HIGH); // Send a 10uS high to trigger ranging according to specs
delayMicroseconds(20);
digitalWrite(TRIG1, LOW); // Send pin low again
delayMicroseconds(2);
int distance = pulseIn(ECHO, HIGH, 26000); // Read in times pulse
int distance1 = pulseIn(ECHO1, HIGH, 26000); // Read in times pulse
distance = distance/58;
distance1 = distance1/58;
if (distance < 25) {
Serial.print("\r");
delay(1000);
Serial.print("AT+CMGF=1\r");
delay(1000);
/*Replace XXXXXXXXXX to 10 digit mobile number & ZZ to 2 digit country code*/
Serial.print("AT+CMGS=\"+YYXXXX\"\r"); // YY is the country code XXX is the number
delay(1000); //
//The text of the message to be sent.
Serial.print("HELLO There");
delay(1000);
Serial.write(0x1A);
delay(1000);
}
else {}
if (distance1 < 25 && ctn < 150) {
ctn += 1;
digitalWrite(Buzzerpin, HIGH);
}
else {
digitalWrite(Buzzerpin, LOW);
}
if (distance1 > 25 && ctn >= 150) {
ctn = 0;
digitalWrite(Buzzerpin, HIGH);
}
}