In this tutorial, LED Brightness Control using arduino PWM pins and Bluetooth HC-05 device for LED Brightness slider using android application. Here 4 PWM pins used to control 4 LEDs and 1 PWM pin for bluetooth communication of arduino nano.
Circuit diagram
Components Required
Arduino Nano - 1 no
Bluetooth module HC-05 - 1no
LED 5mm/10mm - 4 nos
Resistor 300E - 4 nos
PWM
Pulse Width Modulation, or PWM, is a technique for getting analog results with digital means. Digital control is used to create a square wave, a signal switched between on and off. This on-off pattern can simulate voltages in between the full Vcc of the board (e.g., 5 V on Uno, 3.3 V on a MKR board) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. The duration of "on time" is called the pulse width. To get varying analog values, you change, or modulate, that pulse width. If you repeat this on-off pattern fast enough with an LED for example, the result is as if the signal is a steady voltage between 0 and Vcc controlling the brightness of the LED.
In the graphic, the green lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time) for example.
Once you get this example running, grab your arduino and shake it back and forth. What you are doing here is essentially mapping time across the space. To our eyes, the movement blurs each LED blink into a line. As the LED fades in and out, those little lines will grow and shrink in length. Now you are seeing the pulse width.
Bluetooth HC-05 Module
HC-05 is a Bluetooth module which is designed for wireless communication. This module can be used in a master or slave configuration. Bluetooth serial modules allow all serial enabled devices to communicate with each other using Bluetooth.
It has 6 pins,
Key/EN- NC
VCC to Connect 5 V power
GND to power Ground
TXD to Arduino Nano Rx (D0)
RXD to Arduino Nano Tx (D1)
State- NC
HC-05 module Information
HC-05 has red LED which indicates connection status, whether the Bluetooth is connected or not. Before connecting to HC-05 module this red LED blinks continuously in a periodic manner. When it gets connected to any other Bluetooth device, its blinking slows down to two seconds.
This module works on 3.3 V. We can connect 5V supply voltage as well since the module has on board 5 to 3.3 V regulator.
As HC-05 Bluetooth module has 3.3 V level for RX/TX and microcontroller can detect 3.3 V level, so, no need to shift transmit level of HC-05 module. But we need to shift the transmit voltage level from microcontroller to RX of HC-05 module.
HC-05 Default Settings
Default Bluetooth Name: “HC-05”
Default Password: 1234 or 0000
Download Datasheet
Installing the Arduino Library
No need any special libraries.
Arduino Code
#include<SoftwareSerial.h>
SoftwareSerial Bluetooth(10,11); // RX, TX
int PWMLED1=3;
int PWMLED2=5;
int PWMLED3=6;
int PWMLED4=9;
void setup(){
pinMode(PWMLED1,OUTPUT);
pinMode(PWMLED2,OUTPUT);
pinMode(PWMLED3,OUTPUT);
pinMode(PWMLED4,OUTPUT);
Bluetooth.begin(9600);
}
void loop(){
if (Bluetooth.available()){
int value1=Bluetooth.parseInt();
int value2=Bluetooth.parseInt();
int value3=Bluetooth.parseInt();
int value4=Bluetooth.parseInt();
if (Bluetooth.read() =='\n'){
analogWrite(PWMLED1,value1);
analogWrite(PWMLED2,value2);
analogWrite(PWMLED3,value3);
analogWrite(PWMLED4,value4);
}}
}
ANDROID APPLICATION
The Android app developers generally use JAVA language, but this Android app can also build without knowing the Java language. This app inventor is specially designed for Block programmers those who don’t know the JAVA language.
MIT main page
MIT Block
Demo
Comments