๐Ÿ’ก์•„๋‘์ด๋…ธ ๊ธฐ๋ณธ ์ฝ”๋“œ ๊ตฌ์„ฑ

๐Ÿ“ขPIR(์ธ์ฒด๊ฐ์ง€์„ผ์„œ) ์ •์ƒ๋™์ž‘ ํ™•์ธ

์ƒํƒœ ๊ฐ’ LED ๋™์ž‘
๊ฐ์ง€๋˜์—ˆ์„ ๋•Œ 1 ON
๊ฐ์ง€๋˜์ง€ ์•Š์•˜์„ ๋•Œ 0 OFF

ํšŒ๋กœ ๋ฐฐ์„  ํ™•์ธ

๐Ÿ“ขBluetooth ์ •์ƒ๋™์ž‘ ํ™•์ธ

  1. ์œ„ ์ฝ”๋“œ๋ฅผ ์—…๋กœ๋“œํ•˜๊ณ  ๊ฐ ๋ณด๋“œ์˜ ์‹œ๋ฆฌ์–ผ ๋ชจ๋‹ˆํ„ฐ๋ฅผ ์ผญ๋‹ˆ๋‹ค.
  2. ์‹œ๋ฆฌ์–ผ ๋ชจ๋‹ˆํ„ฐ ์ž…๋ ฅ์ฐฝ์— ์•„๋ฌด ๋ฐ์ดํ„ฐ๋ฅผ ์“ฐ๋ฉด ๋‹ค๋ฅธ ์ชฝ ์‹œ๋ฆฌ์–ผ ๋ชจ๋‹ˆํ„ฐ์— ํ•ด๋‹น ๋ฐ์ดํ„ฐ๊ฐ€ ๊ทธ๋Œ€๋กœ ์ถœ๋ ฅ๋˜์–ด์•ผ Bluetooth๊ฐ€ ์ œ๋Œ€๋กœ ์—ฐ๊ฒฐ๋œ ๊ฒƒ์ž…๋‹ˆ๋‹ค.

'๋…ธ๋งˆ๋“œ์—ฐ๊ตฌ์‹ค'์—์„œ ์—…๋กœ๋“œํ•œ ๋™์˜์ƒ

pin ๋‹ค์‹œ ๊ฝ‚์•„๋ณด๊ธฐ, ํ†ต์‹  ์†๋„ ๋ณ€๊ฒฝํ•ด๋ณด๊ธฐ, rx&tx ๋ฐ”๊ฟ”๋ณด๊ธฐโ€ฆ

1๏ธโƒฃMaster

void setup()
{
    Timer1.initialize(CLK1_PERIOD);
    Timer1.attachInterrupt(getSWPosition); // set Interrupt
    Serial.begin(9600);

    pinMode(LED, OUTPUT);
    pinMode(PIR, INPUT);
    pinMode(SW, INPUT);

    configBt.begin(9600);
}
void loop()
{
    if (prev != SW_position)
    {
        prev = SW_position;
        Serial.println(SW_position);
    }

    // Get Current states of PIR sensors
    PIR_state = digitalRead(PIR);
    if (BT.available())
    {
        Slave_PIR_state = BT.read();
    }

    switch (SW_position)
    {
    case SW_POS1:
        if (LED_state)
        { // ON
            if (PIR_state || Slave_PIR_state)
            {                        // either sensor is detected
                counter = CNT_PERIOD; // initialize counter
            }
            else
            {
                if (counter == 0)
                {
                    analogWrite(LED, 0); // OFF
                    BT.write((byte)0);         // Slave LED OFF
                    LED_state = false;
                }
            }
        }
        else
        { // OFF
            if (PIR_state || Slave_PIR_state)
            {                // either sensor is detected
                LedGradOn(); // Gradually turns on LEDs
                LED_state = true;
                counter = CNT_PERIOD; // initialize counter
            }
        }
        break;
    case SW_POS2:
        LedGradOff(); // Gradually turns off LEDs
        LED_state = false;
        break;
    default:
        Serial.println("Wrong switch position");
        break;
    }
}

2๏ธโƒฃSlave