circuit wiring on fritzing (online platform)
Task as described on the portal: communicate wirelessly with a Smart Circuit via a Graphical User Interface (GUI) on your phone or PC.
Build a simple smart circuit that contains at least TWO action components that you can control wirelessly.
Use either the Android GUI or PC GUI to control the action components
Ideation: the whole point of this assignment is to use the Bluetooth module as a controlling method for two action components. I will be using the "button" option on the Android GUI app to control a buzzer and a LED bulb.
The applications of this simple circuit are really endless; it could be integrated into a puzzle game or be used in an alarm system.
Arduino Bluetooth control App to connect components wirelessly
Arduino IDE for coding and circuit testing
electric components to build the circuit
basic Arduino code to establish serial communication
code to control a LED through a serial monitor (USB/wireless)
Controlling a LED through a serial monitor (USB)
Controlling a LED through a serial monitor (wireless)
The focus of this week as mentioned on the portal to program an Arduino Uno board to do serial communication which means transmitting and receiving data between two mediums. This connection occurs using a wire/USB or wirelessly via Bluetooth. After knowing the basics of serial connection, we will be experimenting with a simple Graphical user interface on a PC or phone to control a smart circuit via Bluetooth. In other words, we will know how to control a smart device using a mobile application/interface on the phone.
Takeaways for video tutorials (more on serial monitor):
The serial monitor is the language that establishes a connection between two devices (software) and the USB cable is to connect them (hardware). A serial monitor is a place on the computer where I can write data on it and send it to Arduino.
Understanding the codes:
Serial.begin(9600)://boud rate bit/sec
I am telling the Arduino that I want to use your serial communication option.
char incomingData = ‘0’;
A box where I am going to store my data in.
incomingData = Serial.read();
To read data that is stored in the “incomingData” box.
Serial.println(incomingData);
Print/return data
(Serial.available() == 0);
Do not read data until you receive data
After establishing a successful serial connection, it is time when I should be adding more conditions to my code to control components like the LED.
if(incomingData == '1') {
digitalWrite(LED, HIGH);
} else if (incomingData == '0') {
digitalWrite(LED, LOW);
} else {
Serial.println("Invalid Value!");
}
Serial.print("You entered: ");
Serial.println(incomingData);
I also have to define the PIN number at the beginning of the code:
#define LED 9
And consider it as an output under a void setup:
pinMode(LED, OUTPUT);
Moving to wireless communication, we will be using a module called HC-05 Bluetooth Module.
RXD and TXD for sending and receiving data.
GND and VCC for powering the component.
Important note: when wiring we use a voltage divider circuit to reduce the 5 voltage that comes from Arduino to 3.5 voltage that the Bluetooth can tolerate.
The second category of video tutorials is about using GIU (Graphical User Interface) on a phone or computer to control two action components. I started by listing down the options I had in the kit: motor (movement)- LED bulb (light) - screen (light).
But then I came to the conclusion that the main focus of this assignment was not on how complex the circuit is but rather on the controlling method used which is the HC-05 Bluetooth module so I kept it simple and I decided to build a simple circuit using a buzzer and one LED bulb.
Below are the components used to build the circuit besides the above-mentioned ones.
Resistors.
Jumpers.
Arduino Uno Board.
USB Cable.
Mini-Breadboard.
Writing the code started by defining the two pins' numbers and defining them as outputs. Also. giving Arduino notice that I am using the serial connection option and where I want to store my data.
char incomingData = '0';
#define LED 4
#define buzzer 13
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);//boud rate bit/sec.
pinMode(LED, OUTPUT);
pinMode(buzzer, OUTPUT);
}
Then came to the if condition which included action every time I press a button on the app screen. This varies from LOW (turn off) or HIGH (turn on) the LED or the Buzzer, or both. And what will happen if the wrong button is pressed?
void loop() {
// put your main code here, to run repeatedly:
while(Serial.available() == 0);
incomingData = Serial.read();
Serial.println(incomingData);
if(incomingData == '1') {
digitalWrite(LED, HIGH);
digitalWrite(buzzer,LOW);
} else if (incomingData == '2') {
digitalWrite(LED, LOW);
digitalWrite(buzzer,HIGH);
} else if (incomingData == '3') {
digitalWrite(LED, LOW);
digitalWrite(buzzer,LOW);
} else if (incomingData == '4') {
digitalWrite(LED, HIGH);
digitalWrite(buzzer,HIGH);
} else {
Serial.println("Invalid Value!");
}
Serial.print("You entered: ");
Serial.println(incomingData);
}
circuit wiring on fritzing (online platform)
connecting the Bluetooth module to Arduino board
code on Arduino IDE
circuit assembly after following the wiring plan
choosing the Bluetooth module to pair with
After uploading the code to the Arduino board and downloading the Arduino Bluetooth control App from this link: play.google.com/store/apps/details?id=com.broxcode.arduinobluetoothfree
I activated the Bluetooth option on the phone to be able to pair the module (HC-05) with the device (phone).
After the pairing step, I started trying if my code works using the button option on the app.
Testing the code went very well, however, the buzzer was really annoying! I think it will lead to a heart attack if someone uses it as an alarm. Hopefully..not! :D
the "buttons" options on the app
controlling the LED and the Buzzer (code in action)
I could not find the HC-05 Bluetooth module on Thinkercad which was a bit challenging for me. In addition, the wiring of the voltage divider was not shown clearly in the videos so I had to google it.
Knowing the fact, after several failed attempts, I should be disconnecting TXF and RXD pins from the Arduino board before uploading the code as they use the same serial port which will prevent the data transfer from the computer to the board successfully.
disconnecting the TXF and RXF before uploading code
The Bluetooth module will give me the option to control my game from a distance while offering a more user-friendly interface to the game participants.
HC-05 Bluetooth module
controlling the LED in the assignment using the Bluetooth module
Building smart products that can be controlled using mobile apps will let me explore the world in-between physical and digital products and understand more about the service design set of skills.