This week's assignment was to build a simple smart circuit that contains at least tow action components that can be control wirelessly via a Bluetooth module to, using either the Android GUI or PC GUI
I wanted to redesign the function for the tower crane project I did during Week 5 but this time more smart, and also with LCD that shows direction of the motor
Software Used for sketching the
Circuit: Fritzing
Software Used for downloading the code to the Arduino UNO: Arduino IDE
Application Used to control over Bluetooth:
Arduino Bluetooth Control
List of Components Used:
DC Motor with gearbox
LCD with I2C module
L298N Dual motor driver
Bluetooth Module HC-05
Breadboards
Plug wires
2.1mm DC plug female with screw terminals
Circuit Design
starting with connecting all the components together, first connecting the motor to the L298N H-Bridge, and connecting the 2 controlling pins to the Arduino,
then connecting the LCD to A4 & A5 pins corresponding to SDA & SCL, and also connecting the GND and the 5V to the Arduino
and for the Bluetooth module, I connected it on the mini breadboard , connected the GND and the 5V to the Arduino , and Pins TXD to RX, and Pin RXD to TX
finally connected the power adapter, and made sure that the Arduino and the H-bridge have common GND
I used fritzing software for the graphical wiring of the circuit, and searched for the missing components online to make a typical circuit to the actual one
Coding
Lines 1 to 8:
Starting by adding the LCD screen in the code according to steps in this link:
Identifying the motor drivers; driver1 attached to pin 5 and drive2 attached to pin 6 which are connected to the H-Bridge component
starting the serial for communication
setting both drivers to low
starting the LCD
Lines 18 to 23:
coding the message that will be presented on the LCD to select 1 for Up, and 2 for Down
waiting for the input on the serial monitor
store the input inside "direct"
Lines 25 to 45:
starting if function to start the motor in one direction and present the word "up" on the LCD if the input equals to 1
else, if input equals to 2, start the motor in the reversed direction and present the word "down" on the LCD
else if input doesn't equal to q or 2 no action will happen
Circuit prototyping
I made the circuit connection typical to the above design, then uploaded the code to the Arduino
first I tried the serial monitor for simulation to make sure every thing worked fine before adding the Bluetooth module
then I connected the Bluetooth module to start simulation
I installed the "Arduino Bluetooth Control" app on my android phone, paired the phone to the Bluetooth module first, then started the application and connected to the Bluetooth module, I used the arrows keys for simulation, where up corresponds to 1, and down corresponding to 2
The Final Outcome
during the end of week session, and while preparing for the Hackathon, we designed a code to control multiple servo motors, and used Bluetooth module to control them using Arduino,
while using the Arduino application it seemed like the buttons don't always work, or if the motor doesn't always response correctly to the orders
I managed to identify the problem regarding the code used , it didn't have any condition to limit the angle of the servo between 0 and 180,
so if the rule used was to increase the angle by 30 degrees for each input for example, starting from 0 and after 6 consecutive inputs the angle will be 180, but any additional input in the same direction will not be understood by the servo, yet the value of the stored angle will keep increasing, and it will require an equal number of inputs in the reversed direction until it reaches 180 again and the servo start responding again
so, I proposed an additional if conditions to limit the angle stored to be always between 0 and 180, and it worked fine
I faced a hard time trying to control the circuit from the phone,
the phone paired successfully to the Bluetooth, and I could notice the flashing led goes steady when connected, yet when I press on any keys "1 or 2" nothing happened at all
I tried to connect a simple circuit of only a LED, but also didn't work,
every thing seemed to work fine using the serial monitor, but once I connect the Bluetooth module it stopped working after multiple trials,
after discussing the problem with the instructor, we agreed the problem maybe either from the Bluetooth module itself, or that maybe the Arduino pins 0 & 1 have some kind of problem
finally changed the Bluetooth module with another one and finally it worked fine