Arduino UNO and PIR sensor

Hello all.
I'm trying to make alarm system by using PIR sensor when it detects motion buzzer is triggered and astarts to alert. While buzzer is beeping I need to turn it off by using Android Devices BLUETOOTH tool. Now PIR detects motion and triggers buzzer to alert but I can't turn it off bu Android. Here is the code, is there any slack or what I have to do to solve problem? Thanks.

char incomingByte;
int sensor = 8;
void setup()
{
Serial.begin(9600);
pinMode(sensor,INPUT);
pinMode(3,OUTPUT);
}
void loop()
{
if (Serial.available()>0)
{
incomingByte=Serial.read();
}
int sensor= 8;
delay (500);
if (digitalRead(sensor) == HIGH)
{
tone();
}
if (incomingByte == '8')
{
digitalWrite(sensor,LOW);
}
}
void tone()
{
tone (3,500,4000);
delay(1000);
}

tips: Arduino Bluetooth Basics - YouTube

Thanks for reply my post. Now I have a new program but I can turn off my buzzer only in first use, after when I receve an ''off'' command from my Android Device it doesn't turning off. Here is code; Why?

char incomingByte;
int val;
int sensor =2;
int ledpin = 13;
void setup()
{
pinMode(ledpin = 13, OUTPUT);
pinMode (2, INPUT);
Serial.begin(9600);
}
void loop() {
if( Serial.available()>0 )
{
val = Serial.read();
}
if( digitalRead (sensor)==HIGH)
{
tone();
}
if( val == '8' )
{
digitalWrite(ledpin = 13, LOW);
delay(1000);
Serial.println("13 off");
}
}
void tone()
{
tone (13,500,4000);
delay(1000);
}

    userpicture
    Buy
    Download
    Products
    Learning
    Forum
    Support
    Blog

    LOG IN
    SIGN UP

    Arduino Forum
    > Using Arduino
    > Sensors
    > Arduino UNO and PIR sensor

Print
Go Down
Pages: [1]
Topic: Arduino UNO and PIR sensor (Read 192 times) previous topic - next topic
Evgenii_Litvinenko

    avatar_Evgenii_Litvinenko
    *
    Newbie
    Posts: 2
    [add Karma]
    [add Karma]

Arduino UNO and PIR sensor
Mar 18, 2015, 09:32 pm
Hello all.
I'm trying to make alarm system by using PIR sensor when it detects motion buzzer is triggered and astarts to alert. While buzzer is beeping I need to turn it off by using Android Devices BLUETOOTH tool. Now PIR detects motion and triggers buzzer to alert but I can't turn it off bu Android. Here is the code, is there any slack or what I have to do to solve problem? Thanks.

char incomingByte;
int sensor = 8;
void setup()
{
  Serial.begin(9600);
pinMode(sensor,INPUT);
pinMode(3,OUTPUT);
}
void loop()
{
  if (Serial.available()>0)
    {
      incomingByte=Serial.read();
      }
int sensor= 8;
delay (500);
if (digitalRead(sensor) == HIGH)
{
tone();
}
if (incomingByte == '8')
{
  digitalWrite(sensor,LOW);
}
}
void tone()
{
  tone (3,500,4000);
  delay(1000);
  }
 
 
knut_ny

    avatar_knut_ny
    *
    Edison Member
    Posts: 1,293
    [add Karma]
    electronics engineer, teacher.
    [add Karma]

Re: Arduino UNO and PIR sensor
#1
Mar 23, 2015, 10:18 pm
tips: https://www.youtube.com/watch?v=sXs7S048eIo
Ny
Evgenii_Litvinenko

    avatar_Evgenii_Litvinenko
    *
    Newbie
    Posts: 2
    [add Karma]
    [add Karma]

Re: Arduino UNO and PIR sensor
#2
Apr 03, 2015, 08:20 pm
Thanks for reply my post. Now I have a new program but I can turn off my buzzer only in first use, after  when I receve an ''off'' command from my Android Device it doesn't turning off. Here is code; Why?

char incomingByte;
int val; 
int sensor =2;
int ledpin = 13; 
void setup()
{
  pinMode(ledpin = 13, OUTPUT);
 pinMode (2, INPUT);
  Serial.begin(9600);       
}
void loop() {
  if( Serial.available()>0 )       
  {
    val = Serial.read();       
 }
  if( digitalRead (sensor)==HIGH)               
{
   tone();   
  }
if( val == '8' )               
 {
    digitalWrite(ledpin = 13, LOW); 
    delay(1000);                 
    Serial.println("13 off");
  }
}
void tone()
{
  tone (13,500,4000);
  delay(1000);
  }

try this

int val=0,sensor =2, state = LOW, ledpin = 13;

void setup()
{
  pinMode(ledpin, OUTPUT);
 pinMode (sensor, INPUT);
  Serial.begin(9600);       
}
void loop() {
  
    val = digitalRead(sensor);       

  if( val==HIGH) {  
      digitalWrite(ledpin, HIGH);   
    tone();   
    if (state == LOW)
    { Serial.println("PIR activated! Led + tone");
    
    state = HIGH;
    
  }
  }
 else { digitalWrite(ledpin, LOW);   
       noTone(8);     
if (state == HIGH) {
  Serial.println(" led on pin 13 and buzzer off");
  state = LOW;
  }
}
}


void tone()
{
  tone (8,500,4000); // hook up your buzzer to pin 8 
  delay(1000); // how did you get this tone?
  }

after you have done something like this

int sensor =2;
int ledpin= 13;

you just use

ledpin

no need to say

pinMode(ledpin=13, OUTPUT);

I just think the sensor is triggered it is high

if it is not triggered it is low

thanks a lot, I have one more quastion. ledpin is a ''buzzer'' pin so how can I made my buzzer to tone infinite?