Tag Archives: led

Controlling an LED light using a mobile app and Bluetooth

This tutorial will show you how to control an LED light on an Arduino using a mobile app and a Bluetooth wireless connection.

Parts required

Here is what you’ll need:

  • An Android phone or iPhone
  • A free mobile app
  • Arduino Uno board
  • Breadboard
  • 220 Ohm resistor
  • 6 male-to-male jumper wires
  • HM-10 BLE Bluetooth 4.0 module (see bottom of page for exact model used in this tutorial)
  • An LED light
  • Arduino IDE software

Wiring it up

Wire up the project using jumper wires by following these instructions or checking out the circuit diagram and images below.

  1. Connect VCC on Bluetooth module to 3.3V on Arduino
  2. Connect GND on Bluetooth module to GND on Arduino
  3. Connect TXD on Bluetooth module to digital pin 7 on Arduino
  4. Connect RXD on Bluetooth module to digital pin 8 on Arduino
  5. Connect the long pin from the LED on the breadboard to digital pin 2 on Arduino
  6. Connect the short pin from the LED on the breadboard to a 220 Ohm resistor and from there to GND on the Arduino

Note: The STATE and EN pins on the Bluetooth module do not need to be connected to anything in this project.

Bluetooth

Here are some images showing the LED turned on and everything wired up.

IMG_1905

IMG_6092

IMG_5111

Arduino code

Create a new sketch in the Arduino IDE and add the following code. Then upload the sketch to your Arduino board.

#include <SoftwareSerial.h>
int led = 2;

SoftwareSerial Bluetooth(7, 8);

void setup() {  
  Serial.begin(9600);
  Bluetooth.begin(9600);
  pinMode(led, OUTPUT);
}

void loop() {  
  int command;
  
  if (Bluetooth.available()) {
    command = Bluetooth.read();  
    Serial.println("Input received:");
    if (command != 0)
    {
      // A non-zero input will turn on the LED
      Serial.println("0 / ON");
      digitalWrite(led, HIGH);
    }
    else
    {
      // A zero value input will turn off the LED
      Serial.println("1 / OFF");
      digitalWrite(led, LOW);
    }  
  }
}

Controlling the Arduino via Bluetooth

To connect your Android or iOS mobile device to the Arduino you will need to download a free app (or you could also make your own app) that can connect to the HM-10 Bluetooth module and send commands. You can search your device’s app store to find a free app that will work for this project but for this example we will use the free Bluetooth Terminal app on iOS.

Tip: If you search the iOS App Store or Google Play app store using the keywords “bluetooth arduino” or “bluetooth hm-10” you should be able to find a suitable app.

The steps below are for the Bluetooth Terminal app on iOS but will be similar for other apps on other devices:

  1. Open the app and connect to the Bluetooth module (in this case it is called CC41-A but the name will vary depending on the model you have).
    IMG_4901
  2. Tap ‘Select characteristic’ and then select FFE1 (at the bottom of the list).
    IMG_4902
  3. Select Decimal.
  4. Using the on-screen keypad, you can enter different decimal values. Enter 1 and tap the Send button. The LED light should turn on. Enter 0 and tap the Send button. The LED should then turn off. If you don’t see anything happen, click Tools > Serial Monitor in the Arduino IDE and then set the baud date to 9600 bauds. Check if any input is being received and displayed in the serial monitor when you send the 0 or 1 commands to the Arduino from the app.
    IMG_4903

Where to from here?

You can use Bluetooth to control other projects such as a robot or car. You can also try receiving data from the Arduino – eg. send sensor readings to your phone.

Which Bluetooth module should I use?

There are several different Bluetooth modules that should work with this tutorial. The one used in this project was purchased on eBay and is called “HM-10 CC2540 CC2541 BLE Bluetooth 4.0 Wireless Module“.

Christmas Lights Arduino project

The project

This project involves green and red LED lights which flash in an alternating pattern. In this project, you will use two LEDs but you can add as many as you want if you have enough jumper wires and LEDs.

Scroll down to view the instructions or click here to download a PDF copy of the instructions.

What you need:

  • 1 x Arduino Uno or compatible board
  • 1 x red LED
  • 1 x green LED
  • 2 x 470 Ohm resistor (yellow-violet-black-black-brown, or yellow-violet-brown-gold)
  • 1 x Solderless breadboard
  • 3 x jumper wires

Photos

Picture1 Picture2 Picture3

Wiring it up

Picture4
The LEDs are connected to pins 12 and 13 and each one has a 470 Ohm resistor connect to GND via the breadboard.

The code

Here is the Arduino sketch code:

/*
Christmas lights - blinking red and green LEDs
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int redLED = 13;
int greenLED = 12;
 
// the setup routine runs once when you press reset:
void setup() { 
 // initialize the digital pin as an output.
 pinMode(redLED, OUTPUT);
 pinMode(greenLED, OUTPUT); 
}
 
// the loop routine runs over and over again forever:
void loop() {
 digitalWrite(redLED, HIGH); // turn the LED on (HIGH is the voltage level)
 digitalWrite(greenLED, LOW); // turn the LED off by making the voltage LOW
 delay(100); // wait for a second
 digitalWrite(redLED, LOW); // turn the LED off by making the voltage LOW
 digitalWrite(greenLED, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(100); // wait for a second
}

Use the Arduino IDE to write this code, verify it and then upload it to the Arduino board. For an extra challenge, why not add a light sensor so that the lights only come on when it’s dark, or a button so that the lights can be switched on and off easily? You can also use a chain of LEDs instead of separately wiring them up to a breadboard.

Making an LED Sensor Night Light with Arduino

This video tutorial explains how to use an Arduino Uno to make an LED night light. The project involves an Arduino Uno board, an LED, a light sensor which can detect different levels of light and return a value, a breadboard with jumper wires and resistor.

Basically the way the project works is as follows. Use the light sensor to get light readings constantly. You can specify a value which, when the light is less than this value an LED light will be turned on, and when the light is greater than this value the LED light will be turned off.

This project allows you to work with getting readings from a sensor (input), use if statements to test conditions, and use an LED to produce some form of output.

Watch the video below or click here to view it on YouTube.

Downloads:

The source code is also available here:

int lightLevel;
int led = 13;
void setup()
{
 pinMode(led, OUTPUT);
 Serial.begin(38400); // Go to Tools > Serial Monitor and change to 38400 bauds to see light value readings
}
 
// this loop will turn the light on when light reading is below value of 10
// there is a delay of 1 second between checking the light value
void loop()
{
 lightLevel = analogRead(A0);
 Serial.println(lightLevel, DEC); // this shows the light level reading in Arduino IDE (go to Tools > Serial Monitor)
 
 if (lightLevel < 50) // change this value to suit light conditions. Ranges from 0 (very dark) to 1023 (very bright).
 {
 digitalWrite(led, HIGH); // turns the light on
 } 
 else
 {
 digitalWrite(led, LOW); // turns the light off
 }
 delay(1000);
}

Photos

1

2 3 4

Light sensor readings
Light sensor readings

Blinking LED Arduino project

This video tutorial has been designed for those just starting out with Arduino. For this beginner project you will need an Arduino Uno board (or compatible board), an LED of any colour, a 470-Ohm resistor, two jumper wires, a breadboard, a male A-B USB cable, and a computer (Mac/Windows) with the Arduino IDE software installed.

This project involves programming your Arduino Uno to make an LED light blink on and off. To get started, watch the video below or click here to view it on YouTube. Access the links below to get a copy of the code, printed instructions, schematic, and a guide to resistors.

Downloads:

The source code is also available here:

/*
 Blink
 Turns on an LED on for one second, then off for one second, repeatedly.
*/
 
// Give the LED a name - it will be connected on PIN 13
int led = 13;
 
// the setup routine runs once when you press reset:
void setup() { 
 // initialize the digital pin as an output.
 pinMode(led, OUTPUT); 
}
 
// the loop routine runs over and over again forever:
void loop() {
 digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
 delay(1000); // wait for a second (1000 = 1 sec.)
 digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
 delay(1000); // wait for a second
}

Photos

1 2 3 4