In: Electrical Engineering
Mr. Ndugu is using a HC-SR505 PIR motion sensor module in a lab project. Please suggest Mr. Ndugu a proper way to connect this sensor to the Open1768 development board (i.e. to which pins, etc …) and to configure the selected pins! (4 points) Write a c code and let us assume that Mr. Ndugu wants to detect a rising edge of a signal generated by the sensor over the pin P2.7 (Pin 7 of Port2) (6points). later change the c code lines in such a way tat the LED0 &LED1 on the Open 1768 development board are switched ON while LED1 and LED2 are switched OFF if a rising edge is detected on pin P2.7(5points)
a)This is the code to detect a rising edge of a signal generated by the sensor over the Pin2.7
#define pirPin 2
#define ledPin 13
// Create variables:
int val = 0;
bool motionState = false; // We start with no motion detected.
void setup() {
  // Configure the pins as input or output:
  pinMode(ledPin, OUTPUT);
  pinMode(pirPin, INPUT);
  // Begin serial communication at a baud rate of 9600:
  Serial.begin(9600);
}
void loop() {
  // Read out the pirPin and store as val:
  val = digitalRead(pirPin);
  // If motion is detected (pirPin = HIGH), do the following:
  if (val == HIGH) {
    digitalWrite(ledPin, HIGH); // Turn on the on-board LED.
    // Change the motion state to true (motion detected):
    if (motionState == false) {
      Serial.println("Motion detected!");
      motionState = true;
    }
  }
  // If no motion is detected (pirPin = LOW), do the following:
  else {
    digitalWrite(ledPin, LOW); // Turn off the on-board LED.
    // Change the motion state to false (no motion):
    if (motionState == true) {
      Serial.println("Motion ended!");
      motionState = false;
    }
  }
}