In purpose of making a swing door by control a servo motor with Bluetooth module and show some info on LCD, referring to the project Example Link
Software and Material used:
Design and Preparations:
When it comes to electronic parts, it is recommended to look at the datasheet of each components to know the operating voltage and current ranges, polarity and if it is connected with more than 2 terminals, and this is very important to avoid damage that can affect all the circuits components.
This circuit consist of a LCD , Servo motor and a Bluetooth module so lets get more information about them.
Action Components:
LCD(I2C):
The LCD with I2C consists of 4 terminals 2 for the power and ground and 2 for data (SDA,SCL).
i used a library to operate the LCD called "LiquidCrystal_I2C". which is designed to connect SDA,SCL to A4,A5 respectively.
Servo motor:
The Servo motor is a 3 terminals component (vcc, ground and signal) which allows us to control the angle within the motor range(here it is 180 degree).
I used a library to operate the servo motor called "Servo". which is designed to send the correct signal with the desired degree.
Bluetooth module:
The Bluetooth module is a 4 terminals component (vcc, groung ,TX and RX) which make it easy to access the serial communication through TX and RX bins in the Arduino.
controlling the communication with Bluetooth module an App called Arduino BlueControl is used.
To simulate this project with Fritzing app, then create a new circuit design, and by drag and drop you can easily bring all of the components to your design.
We can go to implement the whole circuit on the breadboard, which is a board that is make circuits testing very easy, by fitting male terminals into it's female bins which are connected together as shown.
LCD connection and code:
the 4 bins in the I2C make it more easy to connect the LCD screen, SDA,SCL to A4,A5 respectively, Vcc to 5volts bin and ground to ground.
first thing we need to include the LCD library "#include <LiquidCrystal_I2C.h>" the define that this library has 2 rows and 12 column "LiquidCrystal_I2C lcd(0x27, 16, 2);" and setting back light in setup() function.
by this LCD is ready to use "lcd.clear()" & "lcd.print()"
Servo:
similarly the keypad require to connect the signal bin and include the "#include <Servo.h>" library then determine the bin number as following:
By implementing the circuit exactly the same as the simulation it will look like this:
The Bluetooth control is all about getting the characters sent along TX & RX bins with "Serial.read()"
as this function returns a "char" and I will need to use it as "integer" to make operations on it, So wrote this 'nested if' to transfer "char" to "int".
Then the loop to control the servo and make it rotate depending on the char sent by the phone to the Bluetooth.
after implementing all of these parts together and combining all these code together the final code can be found here:
This project is designed to control the servo and show it on the LCD.
Mapping the characters sent by the Bluetooth module to be use it by the servo function was a challenging, as serial communication datatype is 'char' but the servo function uses 'int' Thanks to my peers in group who helped me debug the code.to get the nested if condition as following: