one Arduino with three door sensors and one buzzer sensor



  • Dear All :
    I have been looking around the forum for a solution, but haven't found. I have one Adruino uno, three door/window sensors , one buzzer sensor. One door sensor will be on my apartment front door, one door sensor will be on my bathroom door, one sensor will on window.

    The problem is that I don't know how to make the three sensor works independently? when someone open the door or window, the buzzer should be trigger and the Computer will show"Door 1/2 is opening" or "window is opening ".

    Now the three sensor is series. The code is that:


    const int buzzer = 3;
    const int sensor = 4;

    int state; // 0 close - 1 open wwitch

    void setup()
    {
    pinMode(sensor, INPUT_PULLUP);
    }

    void loop()
    {
    state = digitalRead(sensor);

    if (state == HIGH){
    	tone(buzzer, 400);
    }
    else{
    	noTone(buzzer);
    }
    delay(200);
    

    }


    What i am trying to do is have 3 door sensors running from one arduino uno as they will be in different door. I realise that this is probably some thing but how would i go about changing the code to make this happen?

    I appreciate any help. Thanks

    Best Regrads;



  • @henry-liu So, you are saying that you want 3 different sensors ( 2 doors and a window) to connect to a single arduino uno, and you want to power it with batteries, correct? If that is the case, there are some issues you should think about:
    first, you would end up running a lot of wire to these sensors. Not that that can't be done, but you would probably be better off with individual sensors.
    Second, unless you are using larger batteries to power the Uno, you are not going to get much life out of your batteries running an uno.
    Third, you don't have any of the MySensors code in the sketch that you posted.



  • @dbemowsk
    Thank about using ESP8266 (wifi sensor ) hook to each sensor , you can easily use battery's for them. Then Just setup the Arduino with it own ESP8266 this way your Arduino can be powered for a wall plug and you sensor can send a single when the door or windows sensors are moved.
    You can find a large list of different ESP8266 shields and a lot of code on the net to help you program them.



  • @schlog I agree with you. I was responding to the original post.


Log in to reply
 

Suggested Topics

  • 8
  • 3
  • 1
  • 5
  • 90
  • 7

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts