You are on page 1of 227

ANDROID APP

DEVELOPMENT WITH
ROBOTICS APPLICATIONS
TRAINING
Day 1 Morning Topics
 INTRODUCTION TO ARDUINO MICROCONTROLLER
 INTRODUCTION TO ARDUINO IDE
 INTERFACING LIGHTS TO ARDUINO
1. BLINKING LED
2. TRAFFIC LIGHTS
3. LIGHTS WITH SWITCH
4. AUTOMATIC STREET LIGHTS
5. RGB LIGHTS
Day 1 Afternoon Topics
INTERFACING LIGHTS TO ARDUINO
1. Clap Switch with Sound Sensor
2. Gas Leakage Indicator Using Gas Sensor
3. Light with Ultrasonic Sensor
4. Light with PIR Sensor
5. Light with Flame Sensor
Introduction to Arduino Microcontrollers
What is an Arduino Microcontroller?
 Arduino is a single-board microcontroller, intended to
make the application of interactive objects or environments
more accessible.
 It integrates hardware and software.
 It comes with a simple integrated development
environment (IDE) that runs on regular personal computers
and allows users to write programs for Arduino using C or
C++.
Brief History of Arduino
Introduced in 2005, as a project for students at
the Interaction Design Institute Ivrea in Ivrea, Italy. At that time
program students used a "BASIC Stamp" at a cost of $100,
considered expensive for students. Massimo Banzi, one of the
founders, taught at Ivrea..Arduino platform was designed to
provide an inexpensive and easy way for hobbyists, students
and professionals to create devices that interact with their
environment using sensors and actuators.
Brief History of Arduino
A hardware thesis was contributed for a wiring design by
Colombian student Hernando Barragan. After the Wiring platform
was complete, researchers worked to make it lighter, less expensive,
and available to the open source community. The school eventually
closed down, so these researchers, one of them David Cuartielles,
promoted the idea.
The current prices run around $30 and related "clones" as low
as $9. A simple Arduino Mini Pro clone may be had from China for
less than $4, post paid
Parts of Arduino Uno
Parts of Arduino Uno
 DigitalPins (pin 0 to pin 13)- They are used to connect input
and output devices. It reads digital signals 0 and 1, HIGH and
LOW.
 Examples of Input Devices: Temperature sensor, Motion
Sensor, Light Dependent Resistor, Button
Examples of Output Devices- LED, Buzzer, DC Motor
 Analog Pins (pin A0- A5) – They are use to connect also input
and output devices. It can be a reserved pins. It reads analog
data that can vary.
Parts of Arduino Uno
Power Pins- They are use to have the power in the circuit
connected to the Arduino.
 VIN (Voltage Input)- The positive polarity of the battery is
connected to it. (Maximum voltage of Arduino Uno is up to 12 volts
only)
 GND (Ground)- The negative polarity of battery and other
components are connected to it.
NOTE: (Choose only one source of power supply. Either battery
connected to VIN or using powerbank/ DC Power Jack.
Parts of the Arduino Uno
 USB Jack and RS232 Cable- They are use to connect the
Arduino Uno to the computer for uploading the program.

 Memory (ATMEGA328 IC)- It is use to store the program.


It is an EEPROM memory. The old programs will be erased
when new program is uploaded to it.
Different Methods to Power Up the
Arduino

Battery and
Battery Strap
Different Methods to Power Up the
Arduino
Different Methods to Power Up the
Arduino

AC to DC
Adapter
Different Methods to Power Up the
Arduino
Different Methods to Power Up the
Arduino

Power
bank
and
RS232
Cable
Arduino Integrated Development
Environment (IDE)
This open-source software is use to program
the Arduino Uno. It is downloadable to their
website www.arduino.cc Once it was installed in
the PC, you need to install also the CH341 driver
installer to read the port of Arduino by the
computer.
How to Install Arduino IDE
How to Install Arduino IDE
How to Install Arduino IDE
How to Install Arduino IDE
How to Install Arduino IDE
How to Install Arduino IDE
How to Install Arduino IDE
How to Install Arduino IDE
Parts of Arduino IDE
1. Verify- Checks if the code/program is correct. If
the code is wrong, there is a orange color at
the bottom.
2. Upload – Uses to upload/transfer the code to
Arduino Uno
3. New – Uses to create new Window
4. Open – Uses to open recent sketch or saved
sketch
5. Save – saves the sketch/program
2 3 4 5
1 Note: The program will not be transferred if it has
errors or the port of Arduino Uno is not
read/connected to the computer
Parts of the Arduino IDE
Example: To import or
add Library, you need to
click Sketch>Import
Library>SoftwareSerial.
Other hardware requires
library to operate and
function. Libraries are
downloadable from the
internet.
Parts of the Arduino IDE
It is nice to select the
Board and Port of the
Arduino Uno before
uploading the code.
When the port is not read
by the computer, then
install the CH341 driver.
Installation of CH341SER DRIVER
Installation of CH341SER DRIVER
Installation of CH341SER DRIVER
Installation of CH341SER DRIVER
BLINKING LED
BREADBOARD
RESISTOR COLOR CODE
LETS FIND THE VALUE!
Circuit Diagram
PROGRAM/CODE
TRAFFIC LIGHTS
Circuit Diagram
Program/Code
LIGHT WITH SWITCH
LIGHT WITH SWITCH
LIGHT WITH SWITCH

2-CHANNEL RELAY MODULE


LIGHT WITH SWITCH
LIGHT WITH SWITCH

LIGHT BULB LIGHT BULB


RECEPTACLE/HOLDER
LIGHT WITH SWITCH

AC MALE/FEMALE PLUG AC WIRE


PROGRAM/CODE
PROGRAM/CODE
AUTOMATIC STREET LIGHTS

LIGHT DEPENDENT RESISTOR


AUTOMATIC STREET LIGHTS
AUTOMATIC STREET LIGHTS

2-CHANNEL RELAY MODULE


AUTOMATIC STREET LIGHTS
AUTOMATIC STREET LIGHTS

LIGHT BULB LIGHT BULB


RECEPTACLE/HOLDER
AUTOMATIC STREET LIGHTS

AC MALE/FEMALE PLUG AC WIRE


PROGRAM/CODE
RGB LIGHTS
RGB CHART
RGB CHART
RGB CHART
RGB CHART
RGB CHART
RGB CHART
PROGRAM/CODE
PROGRAM/CODE
PROGRAM/CODE
PROGRAM/CODE WITH SERIAL
PROGRAM/CODE WITH SERIAL
PROGRAM/CODE WITH SERIAL
Day 1 Afternoon Topics
INTERFACING LIGHTS TO ARDUINO
1. Clap Switch with Sound Sensor
2. Gas Leakage Indicator Using Gas Sensor
3. Light with Ultrasonic Sensor
4. Light with PIR Sensor
5. Light with Flame Sensor
LIGHTS WITH SOUND
SENSOR (CLAPSWITCH)
PROGRAM/CODE
PROGRAM/CODE
LIGHTS WITH GAS
SENSOR
PROGRAM/CODE
PROGRAM/CODE
Light with Ultrasonic Sensor
Ultrasonic Sensor
Features
Power Supply :+5V DC
Quiescent Current : <2mA
Working Current: 15mA
Effectual Angle: <15°
Ranging Distance : 2cm – 400 cm/1″ – 13ft
Resolution : 0.3 cm
Measuring Angle: 30 degree
Trigger Input Pulse width: 10uS
Ultrasonic Sensor
It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or
obstacle on its path It will bounce back to the module. Considering the travel time and the
speed of the sound you can calculate the distance. In order to generate the ultrasound you need
to set the Trig on a High State for 10 µs. That will send out an 8 cycle sonic burst which will travel
at the speed sound and it will be received in the Echo pin. The Echo pin will output the time in
microseconds the sound wave traveled.
Ultrasonic Sensor
For example, if the object is 10 cm away from the sensor, and the speed of the sound is 340 m/s
or 0.034 cm/µs the sound wave will need to travel about 294 u seconds. But what you will get
from the Echo pin will be double that number because the sound wave needs to travel forward
and bounce backward. So in order to get the distance in cm we need to multiply the received
travel time value from the echo pin by 0.034 and divide it by 2.
Testing Ultrasonic Sensor
Testing Ultrasonic Sensor
Testing Ultrasonic Sensor 2
Testing Ultrasonic Sensor 2
LIGHTS WITH
PIR SENSOR
LIGHTS WITH PIR SENSOR

2-CHANNEL RELAY MODULE


LIGHTS WITH PIR SENSOR
LIGHTS WITH PIR SENSOR

LIGHT BULB LIGHT BULB


RECEPTACLE/HOLDER
LIGHTS WITH PIR SENSOR

AC MALE/FEMALE PLUG AC WIRE


PROGRAM/CODE
PROGRAM/CODE
LIGHT WITH FLAME SENSOR
CODE
DAY 2 MORNING TOPICS
 CONTROLLING DC MOTORS USING ARDUINO
1. DC MOTOR SPEED AND DIRECTION CONTROL
2. DC MOTOR AND ULTRASONIC SENSOR
3. DC MOTOR AND PIR SENSOR
4. COMPUTER CONTROLLED DC MOTORS
DAY 2 AFTERNOON TOPICS
 CONTROLLING DC MOTORS USING ARDUINO
1. DC Motor Control Using Improvised Joystick
2. DC Motor and Ultrasonic Sensor
3. Servo Motor
4. IR Remote Controlled Light
5. RFID Door Lock
DC MOTOR SPEED AND DIRECTION
CONTROL (ONE DC MOTOR)
DC MOTOR SPEED AND DIRECTION
CONTROL (ONE DC MOTOR)

L298 MOTOR
DRIVER
DC Motor Logic
IN1 IN2 IN3 IN4 ENA &ENB DIRECTION

0 0 0 0 STOP

1 0 1 0 HIGH FORWARD

0 1 0 1 HIGH REVERSE

1 0 0 1 HIGH RIGHT

0 1 1 0 HIGH LEFT
PROGRAM/CODE
DC MOTOR SPEED AND DIRECTION CONTROL
(TWO DC MOTORS)
DC MOTOR SPEED AND DIRECTION CONTROL
(TWO DC MOTORS)
DC MOTOR SPEED AND DIRECTION CONTROL
(TWO DC MOTORS)
DC MOTOR AND ULTRASONIC SENSOR
For example, if the object is 10 cm away from the sensor,
and the speed of the sound is 340 m/s or 0.034 cm/µs the
sound wave will need to travel about 294 u seconds. But
what you will get from the Echo pin will be double that
number because the sound wave needs to travel forward
and bounce backward. So in order to get the distance in cm
we need to multiply the received travel time value from the
echo pin by 0.034 and divide it by 2.
TEST THE ULTRASONIC SENSOR

Ultrasonic Sensor Arduino

VCC 5V

GND GND

ECHO 10

TRIGGER 9
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
DC MOTOR AND ULTRASONIC SENSOR
DC MOTOR AND
ULTRASONIC SENSOR
DC MOTOR AND
ULTRASONIC SENSOR
COMPUTER CONTROLLED DC MOTORS
COMPUTER CONTROLLED DC MOTORS
PROGRAM/CODE
DAY 2 AFTERNOON TOPICS
DC MOTORS AND AUTOMATION USING ARDUINO
1. DC Motor Control Using Improvised Joystick
2. DC Motor and Joystick
3. Servo Motor
4. IR Remote Controlled Light
5. RFID Door Lock
DC Motor Control Using Improvised
Joystick
DC MOTOR AND JOYSTICK
DC MOTOR AND JOYSTICK
Joystick Test
DC MOTOR AND JOYSTICK
Servo Motor
IR Remote Controlled Light
IR REMOTE
CODE
PROGRAM/CODE
RFID Door Lock
DAY 3 MORNING TOPICS
BUILDING HOME AUTOMATION ANDROID APP
HARDWARE CONNECTION
CREATING/LOGGING IN AT GOOGLE ACCOUNT
INTERFACING TO APP INVENTOR
BUILDING THE APP
TESTING THE APP TO THE HARDWARE
ANDROID CONTROLLED LIGHTS

2-CHANNEL RELAY MODULE


ANDROID CONTROLLED LIGHTS
ANDROID CONTROLLED LIGHTS
ANDROID CONTROLLED LIGHTS

LIGHT BULB LIGHT BULB


RECEPTACLE/HOLDER
ANDROID CONTROLLED LIGHTS

AC MALE/FEMALE PLUG AC WIRE


CIRCUIT
DIAGRAM
Connections of Relay Module to Arduino
and Light Bulb
Relay Module Arduino Light bulb
Signal Pin
VCC 5v
GND GND
NO (Normally Open) One pin of Bulb
COM (Common) One pin of AC Socket
NC (Normally Close)

Note: The other pin of AC Socket is connected to the other


pin of Light Bulb. Please be careful in connections. We are
talking AC Power.
ANDROID CONTROLLED LIGHTS

HC-05/HC-06
BLUETOOTH
MODULE
Connection of Bluetooth to Arduino

Bluetooth Arduino

VCC 5V

GND GND

RX TX

TX RX
PROGRAM/CODE
PROGRAM/CODE
Android Controlled Robot Car
PROGRAM/CODE
Building Android App
1. Open your browser. Go to Google.com.
Building Android App
2. In the google, search app inventor 2.
3. Click installing app inventor 2 setup
4. Click Create Apps!
5. Choose an account, if you don’t have any Google account then you have to create an account.
6. Sign in with your Google account.
7. Click Start new project
8. Make your own project name. NOTE: Project names cannot contain spaces.
9. You can make your own Android Apps now !
10. From Palette located at left side, there is Layout section, from there you can
drag horizontal alignment. Go to the Properties located at right side, change the
width to Fill parent.
11. Click User Interface section, Drag the Listpicker component inside the
horizontal alignment. Then go to the horizontal alignment properties. Change
the alignhorizontal to Center.
12. Click the Listpicker component inside the Horizontal
Arrangement. Then go to the properties and from Text section,
delete the name Listpicker 1. Hit enter button. Go to the image
section from Properties. Then click Upload image. Browse and
select image from computer files. Change the height to 50 pixels
and the width to 290 pixels.
13. From Palette located at left side, there is Layout section, from
there you can drag horizontal alignment. Go to the Properties
located at right side, change the width to Fill parent. Click User
Interface section, Drag the Label component inside the horizontal
alignment. Then go to the horizontal alignment properties. Change
the alignhorizontal to Center. Click the Label component inside the
Horizontal Arrangement. Then go to the properties and from Text
section, delete the name Text for Label1. Hit enter button. Change
the font size in to 19.
14. From Palette located at left side, there is Layout section, from there you can
drag two horizontal alignment.
15. Click User Interface section, Drag the Label, two buttons component inside
the horizontal alignment.
16. Click the Label2, then change the text to “Bulb 1” Then
change the fontsize to 20. For button 1, change the Text to “ON”
and change the height and width to 80 pixels. Repeat this
process to the button 2 then the text is “OFF”.
17. Repeat steps 15 and 16 to do the “Bulb 2”.
18. In Components section, rename the buttons from Bulb 1 to on1 and off1.
For the Bulb 2, rename it to on2 and off2.
19. From Connectivity section located at the left side, choose drag
BluetoothClient inside the screen. Go to the Sensors section and drag the clock
component to the screen. Next, go to the media and drag the TextToSpeech
component to the screen.
20. From the upper right side, click the Blocks Button to build the Code of the App.
21. From Blocks Section, set the codes below. It is easy to identify the codes because of the
functions.
22. Now Go to the Build section, you can build your own Android app. After building your app,
go to the Downloads folder of the computer and select the app that you build. Send it to your
Android phone and install. Enjoy your new app! 
Building the App
1. Open your browser. Go to Google.com.
2. In the google, search app inventor 2.
3. Click installing app inventor 2 setup
4. Click Creat Apps!
5. Choose an account, if you don’t have any Google account then you have to create an account.
6. Sign in with your Google account.
7. Click Start new project
8. Make your own project name. NOTE: Project names cannot contain spaces.
9. You can make your own Android Apps now !
10. From Palette located at left side, there is Layout section, from there you
can drag horizontal alignment. Go to the Properties located at right side,
change the width to Fill parent.
11. Click User Interface section, Drag the Listpicker component inside the
horizontal alignment. Then go to the horizontal alignment properties. Change
the alignhorizontal to Center.
12. Click the Listpicker component inside the Horizontal Arrangement. Then go to the properties
and from Text section, delete the name Listpicker 1. Hit enter button. Go to the image section
from Properties. Then click Upload image. Browse and select image from computer files. Change
the height to 50 pixels and the width to 290 pixels.
13. From Palette located at left side, there is Layout section, from there you can drag horizontal
alignment. Go to the Properties located at right side, change the width to Fill parent. Click User
Interface section, Drag the Label component inside the horizontal alignment. Then go to the
horizontal alignment properties. Change the alignhorizontal to Center. Click the Label
component inside the Horizontal Arrangement. Then go to the properties and from Text section,
delete the name Text for Label1. Hit enter button. Change the font size in to 19.
14. From Palette located at left side, there is Layout section, from there you can drag three
horizontal alignment.
15. From User Interface section, drag the buttons inside the HorizontalArrangement.
16. To arrange the buttons in a Center, click the click and go to the Properties and click the
AlignHorizontal. Select Center. Add another horizontal arrangement between label1 and button
1 to make a space. Change the height of the added horizontal arrangement to 20 pixels.
17. Select the button1 and rename it to “forward” then go to the properties and delete the text
from text section. Upload image from your computer files. Next, change the height and width to
80 pixels.
18. Repeat steps 17 to change other buttons.
19. From Connectivity section located at the left side, choose drag “BluetoothClient” inside the
screen. Go to the Sensors section and drag the “clock” component to the screen. Next, go to the
media and drag the “TextToSpeech” component to the screen.
20. From the upper right side, click the Blocks Button to build the Code of the App.
21. From Blocks Section, set the codes below. It is easy to identify the codes because of the
functions.
22. Now Go to the Build section, you can build your own Android app. After building your app,
go to the Downloads folder of the computer and select the app that you build. Send it to your
Android phone and install. Enjoy your new app! 
Presented by:
Engr. Noli Mark A. Paala
John Paul College CpE Adviser

You might also like