In this tutorial is shown how to use the PIR sensor and the buzzer integrated on the Lucky Shield to create a presence alarm.
This example uses the Lucky.h library.
If you are using the Arduino IDE 1.8.x,  then download the Lucky library here and import it into the IDE.



Mount the Lucky Shield on an Arduino board.
Finally connect the board to PC using a USB cable.
lucky shield circuit


Now upload the code below, using the Arduino IDE:

Presence Alarm

A simple Arduino sketch that play a sound with the on board buzzer when a presence is
detected by the PIR

The buzzer is directly connected on the digital pin 5

The following pins are defined in the Lucky Shield library, they directly map the digitals
of the Lucky Shield

LED1: on board first LED
LED2: on board second LED

REL1: on board first Relay
REL2: on board second Relay

JOYR: on board Joystick - moved right
JOYL: on board Joystick - moved left
JOYU: on board Joystick - moved up
JOYD: on board Joystick - moved down
JOYC: on board Joystick - central pressed

PIR: on board (Passive Infrared Sensor) Presence Sensor

PB1: on board first Push Button
PB2: on board second Push Button

created Mar 2016

#include <Lucky.h>
#include <Wire.h>

#define BUZ 5
#define NOTE_1 220
#define NOTE_2 300

void setup() {



void loop() {

if(lucky.gpio().digitalRead(PIR) == LOW ){
for(int i = 0; i < 5; i++){
tone(BUZ, NOTE_2);
tone(BUZ, NOTE_1);



The buzzer will play when a presence is detected by the PIR sensor integrated on the shield.