O'Reilly logo

Mastering Arduino by Jon Hoffman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required