Communicate wirelessly with a Smart Circuit via a Graphical User Interface (GUI) on your phone or PC.
Description:
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
Technical Requirements:
The smart circuit contains at least TWO action components connected to an Arduino UNO board (Include a wiring diagram from Tinkercad, Fritzing, or any other tool). ALL action components are acceptable EXCEPT for single color LEDs
The smart circuit communicates wirelessly via a Bluetooth module to a PC or phone
The smart circuit is programmed using Arduino C to perform serial communication (Provide a screenshot of your Arduino C code and *.ino code file)
A Graphical User Interface (GUI) on Phone or PC is used to send data to Arduino to control the action component.
This week I want to try following a project because I struggled connecting the bluetooth device following the EOW exercises. In the end of week session instructor Mego said that the practice videos were made on earlier versions of software so that might be the reason why some didn't work.
So I would like to be able to make a working setup to feel like I understand and am able to execute this week's knowledge.
UPDATE: I didn't find a suitable project to follow, so I decided to make a simple setup representing a gate/door opening for a building with a buzzer when you press the right number. I tried finding open source codes to use and combine.
Tinkercad for testing the circuits.
Arduino software to write the code and upload the code to the Arduino Uno board
Arduino bluetooth control app on android device
BT terminal app to make android device communicate with bluetooth module.
I borrowed a tablet to be able to use the android application, arduino control
For the physical circuit I used the arduino uno, 9 volt adaptor, servo motor, 5 volt regulator, buzzer, jumper wires, breadboard, bluetooth module.
Tinkercad drawing
I could not find the HC-05 bluetooth module in tinkercad, so I googled and found someone else who used a similar bluetooth device in their circuit. I added the 9 volt power source, servo motor, buzzer, 5 volt regulator and connected the wires.
First code - not working
#include <Servo.h> //servo to pin 13
const int buzzer = 8; //buzzer to arduino pin 8
Servo myservo;
int pos = 0;
int angle = 90;
int minAngle = 0;
int maxAngle = 90;
void setup() {
myservo.attach(13); // set servo - pin 13
pinMode(buzzer, OUTPUT); // Set buzzer - pin 8 as an output
}
void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
if (command == '1') {
angle += 90; // Increase angle by 90 degrees
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 500); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 400); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
}
}
Third code - semi working (used the servo motor code from Saturday session
#include <Servo.h>
const int buzzer = 8; //buzzer to arduino pin 8
Servo servo; // create servo object to control a servo
int angle = 90;
int pos = 10; // variable to store the servo position
void setup() {
Serial.begin(9600);
servo.attach(12); // attaches the servo on pin 12 to the servo object
pinMode(buzzer, OUTPUT); // Set buzzer - pin 8 as an output
servo.write(angle);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
if (command == '1') {
angle += 90;
servo.write(pos); // tell servo to go to position in variable 'pos'
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 500); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 400); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
}
}
Second code - semi working
#include <Servo.h>
const int buzzer = 8; //buzzer to arduino pin 8
Servo servo; // create servo object to control a servo
int pos = 10; // variable to store the servo position
void setup() {
Serial.begin(9600);
servo.attach(12); // attaches the servo on pin 12 to the servo object
pinMode(buzzer, OUTPUT); // Set buzzer - pin 8 as an output
}
void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
if (command == '1') {
servo.write(pos); // tell servo to go to position in variable 'pos'
delay(15);
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 500); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 400); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
if (command == '1') {
servo.write(pos); // rotate servo
} }
}
Fourth code - updated after tips lecturer Asker - working (removed angle, as there was already pos)
#include <Servo.h>
const int buzzer = 8; //buzzer to arduino pin 8
Servo servo; // create servo object to control a servo
int pos = 10; // variable to store the servo position
void setup() {
Serial.begin(9600);
servo.attach(12); // attaches the servo on pin 12 to the servo object
pinMode(buzzer, OUTPUT); // Set buzzer - pin 8 as an output
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
char command = Serial.read();
if (command == '1') {
servo.write(pos); // tell servo to go to position in variable 'pos'
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 500); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 400); // Send 1KHz sound signal...
delay(1000);
tone(buzzer, 1000); // Send 1KHz sound signal...
delay(1000); // ...for 1 sec
noTone(buzzer); // Stop sound...
delay(1000); // ...for 1sec
}
}
}
Code I used and adapted: arduino forum
First trial failed. I started the next day with renewed energy.
Second trial with new code and some changes in the circuit. The buzzer is now activated when I press 1 on the tablet. The stepper motor still doesn't react.
EOW videos and connection problems
We had some issues with the EOW videos and codes. Me and a colleague student reached out on Slack and also decided to go an hour early to the Saturday session to ask for help with the errors and connection problems. Unfortunately there was no time.
There was possibly an error in the code since the EOW videos were made in the past and the software has been updated since then.
I asked help with one practice video to a fellow student. Toka helped me by proposing to connect the tx and rx cables of the HC-05 wrong and it actually worked. We connected tx to tx arduino, rx to rx arduino.
Coding
I tried following instructors advice to use existing code and make some changes. But I was unable to make the stepper motor and buzzer work in the first days.
I took a small break and tried again the next day. With the new code the buzzer works and is activated by pressing 1 on the app. Yet the stepper motor doesn`t work.
I will not use the bluetooth device for my final project. Working together with my colleague students and helping each other when we face difficulties will help in the final project.
Making the robot arm in the EOW session on Saturday. It was nice a nice fishing game which reminded me of my childhood.