Challenge

The challenge, if you choose to accept it, is to add an LED to this project and have the LED light up when the motion sensor detects motion. In the first few chapters, we will give either the code or circuit diagram for the challenges to make it easier to troubleshoot any issues if the project does not work when first built.

For this challenge, we will give the code and let you figure out how to connect the LED to the project. One hint, do not forget about the resistor for the LED.

The following is the code that will light up an LED connected to pin 5 of the Arduino when the motion sensor detects nearby motion:

#define MOTION_SENSOR 3 #define LED 5 void setup() { pinMode(MOTION_SENSOR, INPUT); pinMode(LED, OUTPUT); digitalWrite(LED, ...

Get Mastering Arduino now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.