Help: relay PIR sensor, relay on-off with bluetooth

Hello guys. I am new with arduino. I want a programme, in which when the PIR sensor detects motion then the relay 1 will turn on. This works, but the relay 2 that I would like to control with bluetooth is always on, but I want it to be off when i connect it to bluetooth.
i enclose the code.

#include <SoftwareSerial.h>
SoftwareSerial Bluetooth(0, 1);
int rel1 = 6; //relay 1 connected here
int rel2 = 3; //relay2
int PIRinput = 10; //PIR connected here
int motion = 0; //pir status
char Data;
void setup() {

pinMode(PIRinput, INPUT);//PIR as input
pinMode(rel1, OUTPUT); //relay as output
pinMode(rel2, OUTPUT); relay as output


void loop() {

motion = digitalRead(PIRinput); //reading the PIR status and stores to variable motion
if (motion == HIGH) {
digitalWrite(rel1, LOW); //relay turn ON
Serial.println(“Motion detected!”);
else {
digitalWrite(rel1, HIGH); //relay turn OFF
Serial.println(" No motion ");

if (Bluetooth.available()) {
Data =;
if (Data == (‘1’)) {
digitalWrite(rel2, HIGH); ///relay turn ON

if (Data == (‘2’)) {
digitalWrite(relay2, LOW); //relay turn OFF



8 posts and you do not know how to post code, use the IDE autoformat tool or use white space. Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code.

Please read this.

On most Arduinos pins 0 and 1 are the hardware RX and TX pins. It is silly to use them for a software serial port (and it won't work right, either).

So what Arduino are you using? From where is the bgluetooth data coming?

im using arduino uno r3 atmega328p,and hc-05 bluetotth module and i did application with mit app inventor.
what do you suggest?

Don't know anything about App Inventer.

Use any 2 free pins, besides 0 and 1, for your software serial port.