Pir sensor and touch sensor code - help

Good afternoon group!
Is there anyone in the group who can help me with a code for this project How to wire Capacitive Touch Sensor Module, Basic Red LED 5mm, Basic Green LED 5mm, LCD 16x2, Infrared PIR Motion Sensor Module, Buzzer to Arduino Uno from A to Z I received some of these components as a gift and I thought of making a security system just because I'm not very good with such a complex code. I want the alarm to go off and the red light to flash when motion is detected, but the alarm can only be turned off by scanning one of the RFID cards. When I plug it in, it turns on and the green light comes on. I ask someone to help me with the code and see if the wires in the diagram are connected correctly.

Thank you in advance !

Start by posting your code. Format it in the IDE first , using Auto Format and use code tags when you post it

Post a schematic of your project, a 'photo of a pencil and paper drawing is OK

Your post was MOVED to its current location as it is more suitable.

1 Like

Hi,
Is this thread part of this;
https://forum.arduino.cc/t/security-system-with-arduino-uno-pir-sensor-rfid-lcd-buzzer-and-leds/932423/4

Tom... :grinning: :+1: :coffee: :australia:

1 Like

Yes but that is with RFID and now I will make with touch sensor because is easyest

This is my code without touch sensor. Can help me someone with a code with touch sensor(when press touch sensor alarm stops)????



#include <LiquidCrystal.h>     


int ledPin = 13;                // choose the pin for the LED
int led1 = 8;
int led2 = 9;
int led3 = 6;
int inputPin = 7;               // choose the input pin (for PIR sensor)
int pirState = LOW;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status
int pinSpeaker = 10;           //Set up a speaker on a PWM pin (digital 9, 10, or 11)

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);                          // initialize the library with the numbers of the interface pins



void setup() {  pinMode(ledPin, OUTPUT);      // declare LED as output  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(pinSpeaker, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  digitalWrite(led3, LOW);
  digitalWrite(led1, LOW);
  digitalWrite(led2, HIGH);
  delay(80);
  Serial.begin(9600);
  lcd.begin(16, 2); 
  lcd.setCursor(2, 0);                                            // Set LCD cursor position (column, row)
  lcd.print("P.I.R Motion");                                      // Print text to LCD
  lcd.setCursor(5, 1);                                            // Set LCD cursor position (column,row) 
  lcd.print("Sensor");                                            // Print text to LCD
  delay(4000); // wait 4s                                      // Delay to read text
  lcd.clear(); // clear LCD display                               // Clear the display
  lcd.setCursor(2, 0);                                            // Set LCD cursor position (column, row)
  lcd.print("Developed By");                                     // Print text to LCD
  lcd.setCursor(2, 1);                                            // Set LCD cursor position (column, row) 
  lcd.print("  Serafim");                                         // Print text to LCD                                                                                                                                                                                                                                                                                                                                                                                                                       
delay(5000);                                                      // Delay to read text
lcd.clear();                                                    // Clear LCD    
lcd.setCursor(0, 0); 
      lcd.print("Processing Data.");
      delay(5000);
      lcd.clear(); 
      lcd.setCursor(3, 0);
      lcd.print("Waiting For");
      lcd.setCursor(3, 1);
      lcd.print("Motion....");
      digitalWrite(led2, LOW);      

  
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(led1, LOW);
    delay(80);
    digitalWrite(ledPin, HIGH); // turn LED On
    playTone(1500, 10);
    digitalWrite(ledPin, LOW);
    digitalWrite(led3, HIGH);
    delay(500);
    playTone(1500, 10);
    digitalWrite(ledPin, HIGH);
    digitalWrite(led3, LOW);
    delay(500);
    playTone(1500, 10);
    digitalWrite(ledPin, LOW);
    digitalWrite(led3, HIGH);
    delay(500);
    playTone(1500, 10);
    digitalWrite(ledPin, HIGH);
    digitalWrite(led3, LOW);
    delay(500);
    

    
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      lcd.clear() ;
      lcd.setCursor(0, 0);                                           // Set LCD cursor position (column 0, row 0)
      lcd.print("Motion Detected!"); 
      delay(2000);  
      digitalWrite(led1, HIGH);
      
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
      digitalWrite(ledPin, LOW); // turn LED OFF
      digitalWrite(led1, HIGH);
      playTone(0, 0);
      delay(300);    
      if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      lcd.clear() ;
      lcd.setCursor(3, 0); 
      lcd.print("Waiting For"); 
      lcd.setCursor(3, 1);
      lcd.print("Motion....");      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
// duration in mSecs, frequency in hertz
void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 100000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(pinSpeaker,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}