Lesson 1,
Topic 1
In Progress
Procedure
03/07/2022
Phone Controlled Disco Lights
Components required:
- Knewton board – 1
- Arduino Nano – 1
- Arduino Nano Cable – 1
- Bluetooth HC-05 – 1
- Power Bank-1
- USB to DC jack-1
Circuit diagram:
We’ll be using the Onboard RGB LED.
Arduino Code:
- Scan the QR to open the code. Copy the code and paste it in your Arduino IDE.
- Once you paste the code in Arduino IDE, Compile the code and upload it in the Arduino Nano.
- We’ll use the same App in our mobile phone to connect the HC-05 Bluetooth Module.
- In the key configuration, use “F” for up key, “B” for down key, “R” for right key and “L” for the left key as mentioned in our code.
Code:
#include <SoftwareSerial.h>
SoftwareSerial MyBlue(10,9); // RX | TX //Declaring The transmitter and receiver pin for bluetooth
char a; //Creat a variable for storing data
int RED = 11; //RED led pin is connected to digital pin 11
int GREEN = 12; //GREEN led pin is connected to digital pin 12
int BLUE = 13; //BLUE led pin is connected to digital pin 13
void setup()
{
Serial.begin(9600); //baud rate is set at 9600
*/ Phone Control Disco Lights /*
MyBlue.begin(9600);
pinMode(RED,OUTPUT);
pinMode(BLUE,OUTPUT); //Declairing all the pins of RGB as output device
pinMode(GREEN,OUTPUT);
}
void loop()
{
if (MyBlue.available())
a = MyBlue.read(); //collecting information from phone via bluetooth
if (a == 'F') //if string received via phone is F
{
digitalWrite(RED, HIGH);
digitalWrite(GREEN,LOW); //turn the RED led ON
digitalWrite(BLUE,LOW);
}
else if (a == 'B') //if string received via phone is B
{
digitalWrite(RED,LOW);
digitalWrite(GREEN,HIGH); //turn the GREEN led ON
digitalWrite(BLUE,LOW);
}
else if (a == 'R') //if string received via phone is R
{
digitalWrite(RED,LOW);
digitalWrite(GREEN,LOW); //turn the BLUE led ON
digitalWrite(BLUE,HIGH);
}
else if (a == 'L') //if string received via phone is L
{
digitalWrite(RED,HIGH);
digitalWrite(GREEN,HIGH); //turn ALL leds ON for white light
digitalWrite(BLUE,HIGH);
}
}
Output:
Once the code is uploaded, we can see on the board that the RGB LED glows in different colors like Red, Green, Blue, Cyan and many more while being able to change the color pattern through your selected device.