Skip to content

PIR and LED

Required items

  1. SODAQ SARA SFF
  2. SODAQ SARA SFF BASEBOARD
  3. PIR
  4. LED
/*macro definitions of PIR motion sensor pin and LED pin*/
#define PIR_MOTION_SENSOR 8 //Use pin 8 to receive the signal from the module
#define LED 0 // Use pin 0 to activate the buzzer
#define POWER_SWITCH 3 // Use pin 3 to enable the switch row on the baseboard

void setup()
{
  SerialUSB.begin(9600);

  pinMode(PIR_MOTION_SENSOR, INPUT);
  pinMode(LED, OUTPUT);
  pinMode(POWER_SWITCH, OUTPUT);

  // Turn on the switched row
  digitalWrite(POWER_SWITCH, HIGH);
}

void loop()
{
  if (digitalRead(PIR_MOTION_SENSOR)) {
    SerialUSB.println("Movement detected!");
    digitalWrite(LED, HIGH);
  }
  else {
    digitalWrite(LED, LOW);
  }

  delay(200);
}
Back to top