Project 2 – controlling LED

In this project, we will turn an LED that is connected to the Arduino on or off depending on the input from the phone. The first thing we will need to do is to add the LED to our circuit. The following diagram shows the new circuit:

The LED is connected to the digital 5 pin on the Arduino through a 330-ohm resistor. Now we need to write the code to control the LED. We will start by setting up the SoftwareSerial library for the Bluetooth module and defining the pin that the LED is connected to. The following code will do this:

#include <SoftwareSerial.h>
#define LED_PIN 5
SoftwareSerial HM10(10, 11);

We can see that ...

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.