Environment Analyzer Report
Environment Analyzer Report
SEMESTER 2 2021/2022
The project's goal is to create an Android interface, an Arduino bot, and software for the Arduino
microcontroller. The Arduino automobile is equipped with an Arduino microcontroller and basic
mobility characteristics. Arduino programs provide instructions that act as a bridge between the
android controller and the Arduino automobile. To oversee mobility, the Android mobile controller
employs a variety of mobile sensors. To interface with the android controller, an appropriate
program in the Arduino microcontroller must be written. The software was successfully compiled
using the Arduino IDE. We must develop an Android application that will allow the user to interact
with the Arduino-powered automobile. The interface is simple to use and provides feedback from
the Arduino microcontroller over Bluetooth after instructing the Arduino for different activities
using the interface via Bluetooth module. As a result of the testing that has been carried out, the
project has worked well and has achieved the construction objectives of this invention. With the
result of this invention, indirectly it can be an innovation to consumers in the future.
i|Page
TABLE OF CONTENTS
CHAPTER 1 INTRODUCTION
1.1 Introduction Project 1
1.2 Problem Statement 2
1.3 Objectives 2
1.4 Scopes 2
CHAPTER 3 METHODOLOGY
3.1 Introduction 15
3.2 Block Diagram 16
3.3 Circuit Diagram 16 - 17
3.4 Flowchart 17 - 18
3.5 Components List 19
ii | P a g e
CHAPTER 5 CONCLUSION AND RECOMMENDATION
5.1 Introduction 27
5.2 Recommendation 27 - 28
5.3 Conclusion 28
REFERENCE
APPENDIX
iii | P a g e
LIST OF FIGURES
LIST OF TABLES
iv | P a g e
CHAPTER 1
INTRODUCTION
Line-following robots are well recognized in the fields of robotics, electronics, and electrical
engineering due to contests that stimulate learning in this medium. Each tournament has its own set of
regulations that govern the degree of programming and electronics with which the robots must
compete. The regulations indicate which electrical components may or may not be merged into the
robot, and the established programming may or may not be progressed based on how the assembly is
built and what equipment is employed. The better it is to build a structure that responds in the best
possible way depending on the devices that are employed. Among the components that may be used
in the robot's creation are infrared (IR) sensors, motor drives, ultrasonic sensors, and the Arduino
programming platform.
An autonomous robot can move on its own in an unfamiliar and unstructured environment. An
autonomous robot is an outfit with software intelligence that allows it to assess its surroundings,
recognize impediments in its route, and navigate an unfamiliar area while overcoming difficulties.
Many robotic designs are used in the creation of autonomous robots. These designs are repeatedly
created with the actual environment in mind where the robot will be deployed in mind. Snake robots,
walking robots, autonomous drones, and autonomous robotic automobiles or rovers are examples of
autonomous robots.
1|Page
1.2 Problem Statement
1.3 Objectives
1.4 Scopes
This research focused on finding out the function and connectivity for many things in this robot such as
ultrasonic sensor, color sensor, infrared sensor, temperature sensor, ESP32, Arduino Mega, HC-05 Bluetooth
Module and also I2C OLED display. Ultrasonic sensor is only used as the rangefinder to stop the robot from
running to others and also obstacles. This limits the to become a sensor to be actuated by the motors. Color
sensor acts as the switch to give data to the microcontroller. When the robot runs in the automatic mode it has
already arrived at the destination. Color frequency of the floor will be taken and will be displayed on MIT app
inventor, displayed in the Firebase and also OLED I2C.
Infrared Sensor is one of the automation parts for the project because Infrared will act as a sensor to
control the movement of robots following the black line and navigate them to the desired location. Next the
scope of a temperature sensor will collect data of temperature and humidity on the 1st stations and other
colored floor stations after automation. ESP32 will act as a WIFI client to dispatch data from the Arduino to
the Firebase to be displayed in MIT. Arduino Mega is a microcontroller that will be used as the main
automation and all the sensors will connect to the Arduino Mega. This part of Arduino acts as the main
contributor for the robot because Arduino Mega has 54 digital and has 4 Serial Communication Port. HC-05
Bluetooth Module is a communication device connecting Arduino Mega to the MIT and also Arduino
Mega to ESP32. The OLED display will display the data collected from the sensor.
2|Page
This research will not extend to the advanced factors that affect the robot condition and performance.
Such as the complex design of the component itself. The basic structure of the robot will be displayed by the
body and it will show the relation of the factor with one another
3|Page
CHAPTER 2
LITERATURE REVIEW
2.1 Introduction
A literature review is a preliminary strategy for investigating a completed project and its history.
Through this literature study, researchers will obtain detailed information on selected themes. One
of the first steps in being acquainted with more in-depth and thorough information regarding the
issue at hand is to do a literature study. The same prior study is also emphasized to determine the
study design, study objectives, and study purpose for researchers to comprehend and use in doing
this study. As a result, to guarantee the full execution of this study, the studies were last evaluated.
The findings of investigations connected to the Bluetooth control robot automobile will be
investigated in this part as a system that may facilitate a work system. Among the topics that will
be covered are the findings of study on a work system chosen to attain the project's results. This
part also includes a detailed explanation of the components that will be used in the Bluetooth
control robot vehicle project, including the function and operation of each component.
The world is entering a smartphone era in which everything in our daily lives is connected to and
controlled by a smartphone. The primary goal of this project is to develop a wireless remote
interface for controlling robots. Remote communication with a robot is required to regulate robot
movement and to relay crucial information in both directions. The Arduino will be connected to a
Bluetooth module to create communication, and it will also be connected to a motor driver to
regulate the motor speed. The user will be able to control the robot automobile using Android-
programmed software. This robot automobile will travel in accordance with the instructions
4|Page
supplied by the user via the Android application. Another advantage of the suggested form of robot
automobile is that it can function on any type of surface. This is also less expensive and easier to
implement than other existing solutions. The proposed approach is more appropriate for the present
period.
Robot navigation problems can be signalized as global or local, depending on the conditions in which the
robot is operating. The environment surrounding the robot is familiar in worldwide navigation, and a
course that avoids obstacles is chosen. Graphical maps inclusive of information about barriers are utilized
in one example of global navigation algorithms to find a suitable path. The environment surrounding the
robot is unknown, or only partially known in local navigation, accordingly, sensors must be utilized to
identify the robot to avoid the obstacles. One of the well-known strategies created for this aim is the
artificial potential field approach. Krogh, for example, avoided obstacles using an extended potential field
technique. Instead, Kim and Khosla employed harmonic potential functions to overcome obstacles. Krogh
and Fang, on the other hand, employed dynamic development of sub-objectives based on the local
feedback information.
The primary goal of this project is to develop a wireless remote interface for controlling a robot. It is
obligatory to communicate with a robot remotely to regulate its movement and convey essential
information in both directions. A Bluetooth-powered robotic automobile is a reasonably affordable, easy-
to-use, and successful approach to ease the trouble of handling robots. The stand-out goal is to create an
Arduino microcontroller with the necessary navigation functions. Arduino applications include
instructions for mediating between the Arduino controller and the Arduino vehicle. To detect movement,
the Arduino mobile controller employs a variety of mobile sensors. To interface with the Arduino
controller, the right program in the Arduino microcontroller must be written.
5|Page
2.3.3 Wi-Fi Controlled Arduino Based Robot Car
The robotic system is an electromechanical device composed of hardware and software. It can be
programmed to execute any specified operation; industrial manipulators, robotic arms, and shortly are
examples of a robotic system that can be readily controlled and reprogrammed to accomplish any duty.
Robots are helpful in jobs where a human cannot fulfill their duties, such as in a workplace impacted by
toxic radiation, but the robot can do so without causing a piece of harm. Robots are particularly useful in
industrial regions nowadays for the mass production of jobs and many other tasks. The advancement of
robotic systems has made it feasible for humans to undertake previously impossible tasks with the
assistance of robotic machines. Internet, Wi-Fi, and other networks are also connected with this system,
and the control range is increased as a result, making it extremely easy for the operator.
This project established two types of communication channels to communicate with robots wirelessly.
First, establish a wireless communication channel between the ESP8266 node and Database Server
MySQL DataBase). Second, communication between controller (user) and Data Base Station (MySQL
Databases) using <html> page.
The project will be founded on a study and references on the Environment Analyzer. This project's circuit
is simply made up of a variety of components and tools, including ultrasonic sensors, color sensors, an
infrared sensor, a motor driver, a Bluetooth module, and Arduino software. Consequently, Arduino are used
to keep the circuit working and the project goals accomplished. There are, of course, several connection
tactics and approaches that may be used. As a result, some of these components are more appropriate since
they are easier to use than other electrical equipment. Furthermore, journal reference materials are essential
for conducting research comparisons during the project's creation. To increase the quality and efficiency
of an existing project, a good project may be established using knowledge gathered from references
or journals.
6|Page
2.5 Arduino Mega (2560)
The Arduino Mega 2560 is an ATmega2560-based microcontroller board (datasheet). It contains 54 digital
input/output pins (14 of which may be used as PWM outputs), 16 analog inputs, 4 UARTs (hardware serial
ports), a 16 MHz crystal oscillator, a and USB connection, a power connector, an ICSP header, and a reset
button. It includes everything needed to support the microcontroller; simply connect it to a computer through
USB or power it with an AC-to-DC converter or battery to get started. Most shields built for the Duemilanove
or Diecimila are compatible with the Mega.
The Arduino Mega may be powered through USB or by an additional power supply. The power source
is automatically selected. External (non-USB) power can be supplied by either an AC-to-DC adaptor (wall-
wart) or a battery. Connect the adapter by inserting a 2.1mm center-positive connector into the board's power
port. Battery leads can be put into the POWER connector's Gnd and Vin pin headers. The board may be powered
by an external source ranging from 6 to 20 volts. However, if less than 7V is given, the 5V pin may deliver less
than five volts and the board may become unstable. When more than 12V is applied, the voltage regulator may
overheat and destroy the board. The suggested voltage range is 7 to 12 volts.
7|Page
2.6 HC-05 Bluetooth Module
The HC-05 Bluetooth Module is a simple Bluetooth SPP (Serial Port Protocol) module designed for
setting up a wireless serial connection. It communicates through serial transmission, making it simple
to interface with a controller or PC. The HC-05 Bluetooth module allows you to switch between master
and slave mode, which means you may utilize it for neither receiving nor transmitting data.
8|Page
The L298N module is a twin full-bridge motor driver module with high voltage and current for
controlling DC and stepper motors. It could adjust the speed as well as the rotation direction of two
DC motors. This module contains an L298 dual-channel H-Bridge motor driver IC. This module
employs two approaches for controlling the speed and rotation direction of DC motors. These are
PWM (for regulating speed) and H-Bridge (for controlling rotation direction). At the same time, these
modules may control two DC motors or one stepper motor.
2.8 ESP32
Espressif Systems created the ESP32 line of SoCs (System on Chip). They have a Tensilica Xtensa
LX6 CPU, Wi-Fi, and Bluetooth built in. It was created with low consumption and cheap cost in
mind, and it is a very appealing solution for product designers or developers. It comes in a variety of
forms, ranging from the chip through modules and development boards. To begin, using development
boards is usually the best solution because it needs the least amount of circuitry for maintaining the
ESP32, which (while very little) is already accessible. There is also the convenience of employing
USB-Serial converters on these development boards, which greatly simplifies connection with the
ESP32. Development boards are also available on a variety of types, some comparable and others
with highly unique features.
9|Page
2.9 IR Sensor Module
The IR Sensor Module, often known as an infrared (IR) sensor, is the most basic and widely used
sensor in electronics. It is utilized in wireless technology for purposes such as remote control and
detection of nearby objects/obstacles. IR sensors are primarily composed of an Infrared (IR) LED and
a Photodiode; this pair is referred to as the IR pair.
An IR LED is a special purpose LED that emits infrared radiation with wavelengths ranging
from 700 nm to 1 mm. These rays are not visible to human sight. A photodiode or IR Receiver LED,
on the other hand, detects infrared radiation.
10 | P a g e
2.10 Ultrasonic Sensor
Ultrasonic sensors (sometimes called as transceivers when sending and receiving data, but more
commonly as transducers) work in a similar way to radar or sonar, which evaluate target attributes by
detecting echoes from radio or sound waves, respectively. Ultrasonic sensors generate high-frequency
sound waves and evaluate the echo received by the sensor. Sensors calculate the time delay between
sending the signal and receiving the echo to estimate the distance to an object.
This approach may be used to calculate wind speed and direction (anemometer), tank or
channel level, and speed via air or water. A device that measures speed or direction utilizes many
detectors and estimates speed based on the relative distances to particles in the air or water. To assess
tank or channel level, the sensor measures the distance from the fluid's surface. Other applications
include humidifiers, sonar, medical ultrasonography, burglar alarms, and non-destructive testing.
11 | P a g e
2.11 Color Sensor
The color of the substance is detected using a color sensor. This sensor recognizes color in the RGB
scale. This sensor can distinguish between red, blue, and green colors. These sensors are also outfitted
with filters that block out undesired IR and UV radiation.
Temperature and Humidity Sensor is a temperature and humidity sensor complex with a digital signal
output that has been calibrated. It provides excellent long-term stability and reliability by utilizing a
novel digital-signal-acquisition technique as well as temperature and humidity sensor technology. This
sensor is made up of a resistive-type humidity measurement component and an NTC temperature
12 | P a g e
measuring component that are linked to a high performance 8-bit microcontroller, which provides
excellent quality, fast response, anti-interference capabilities, and cost-effectiveness.
2.13 DC Motor
A direct current motor is any motor in a class of electrical equipment that converts direct current
electrical power into mechanical power. This sort of motor frequently relies on the forces produced by
magnetic fields. DC motors, regardless of kind, contain some form of internal mechanism, which can
be electrical or electromechanical. In both circumstances, the direction of current flow in a portion of
the motor is altered on a regular basis.
A DC motor's speed is adjusted by varying the supply voltage or adjusting the intensity of the
current within its field windrings. Smaller direct current (DC) motors are often employed in the
manufacture of appliances, tools, toys, and automobile mechanics such as electric car seats, but bigger
direct current (DC) motors are used in hoists, elevators, and electric vehicles. A 12v DC motor is
compact and affordable, but powerful enough to be employed in a variety of applications. Because
selecting the proper DC motor for a certain application can be difficult, it is critical to deal with the
right provider.
13 | P a g e
2.14 OLED Module
An organic light-emitting diode (OLED or organic LED), also known as an organic electroluminescent
(organic EL) diode, is a light-emitting diode (LED) with an organic electroluminescent layer that
generates light in response to an electric current. This organic layer is sandwiched between two
electrodes, at least one of which is transparent. OLEDs are used to make digital displays for devices
like television screens, computer monitors, and portable systems like smartphones and handheld
gaming consoles. The development of white OLED devices for use in solid-state lighting applications
is a prominent field of study.
OLED differs fundamentally from LED, which is built on a p-n diode structure. Doping is used
in LEDs to form p- and n-regions by altering the conductivity of the host semiconductor. A p-n
structure is not used in OLEDs. OLED doping is used to improve radiative efficiency by directly
modifying the quantum-mechanical optical recombination rate. Doping is also used to determine
photon emission wavelength.
14 | P a g e
2.15 Servo Motors
A servo motor is an electrical device that can precisely push or spin an item. A servo motor is used
when we wish to rotate an object at a specified angle or distance. It is just a motor that is controlled by
a servo system. If the motor is DC powered, it is referred to as a DC servo motor; if it is AC powered,
it is referred to as an AC servo motor. A very high torque servo motor may be obtained in tiny and
thin configurations. Because of these characteristics, they employ them at odds applications such as
toy automobiles, RC helicopters, aircraft, Robotics, piece of machinery, and so on and so forth. An
electrical pulse determines the position of a servo motor, and its electronics are located near the motors.
The servo system of today has several industrial uses. Servo motor uses are also popular in
remote-controlled toy vehicles for regulating the direction of motion, as well as that motor that moves
the tray of a CD or DVD player. Aside from these, there are hundreds of servo motor uses that we
witness in our daily lives. The major rationale for utilizing a servo is that it gives angular accuracy,
which means that it will only spin as far as we want it to before stopping and waiting for the next signal
to take action. This is in contrast to a standard electrical motor, which begins to rotate as soon as
electricity is provided to it and continues to rotate until we turn off the power. We cannot regulate the
rotational movement of an electrical motor; nevertheless, we can control its speed and switch it on and
off.
15 | P a g e
CHAPTER 3
METHODOLOGY
3.1 Introduction
This methodology chapter will go through each component of the research, theories and methodologies
will be demonstrated in a logical manner, and the building process of this Environment Analyzer model
will be thoroughly detailed. A study's methodology is the manner through which it is carried out. The
researcher can decide the study's production process in structured and planned techniques to aid the
researcher in constructing the model in line with the objectives mentioned at the outset of this
investigation. This chapter will go through the researcher's method for putting together the kit in further
detail. Researchers must address several challenges while utilizing the Environment Analyzer model.
This part discusses experimental design, a detailed explanation of the subjects studied, and a list
of the materials used, including technical specifications, quality, and so on. Furthermore, methodology
is the result of a research used to gather facts by seeking the truth via the application of certain
techniques that are depending on the reality to be explored.
16 | P a g e
3.2 Block Diagram
A block diagram is a system diagram in which the main pieces or functions are represented by
blocks connected by lines that illustrate the block connections. They are extensively used in
engineering, particularly in hardware design, electronic design, software design, and process flow
diagrams. The Environment Analyzer is linked to the Arduino Mega as shown in Figure 3.1.
17 | P a g e
Figure 3.2 Circuit Diagram
18 | P a g e
Figure 3.3 Flowchart
19 | P a g e
3.5 Components Lists
NO COMPONENTS QTY
1. Arduino Mega 1
2. Motor Driver 2
3. ESP32 1
5. DHT11 1
6. IR Sensor Module 4
8. Ultrasonic Sensor 1
9. OLED Module 1
10. DC Motor 2
19 | P a g e
CHAPTER 4
4.1 Introduction
In this chapter, the results of the Environment Analyzer project are presented and discussed
concerning the project objective, which can build robots that work manually and autonomously.
The robots can collect data on temperature/humidity and send it to Firebase, and the robots can
communicate with other robots. The project was successfully developed as planned and based on
several studies that have been carried out. These aspects have been done out in the previous chapter
which presented the technique utilized in the study.
4.2 Result
Environment Analyzer robot is a success and has passed the requirement for this project
masterpiece. Temperature and humidity can be determined by using the DHT11 as the sensor
for this part. Temperature is really stable and also the humidity will be more perfect with more
powerful sensors. Color sensor has met the requirements needed for this project. This color sensor
detects the frequency of the color on this platform and the RGB data will be used to determine
what color is the platform. Infrared sensors help a lot in this project to keep the robot moving on
the black line to arrive at its desired destination. The data received from the HC-05 Bluetooth
module using Serial Com also has been transferred to the ESP32 and the Database is safely
transferred and saved into the cloud to be monitored using the Firebase console.
20 | P a g e
4.2.1 Environmental Analyzer Robot :
21 | P a g e
Figure 4.3 Below Side
22 | P a g e
4.3 Cost Analysis
Cost is one of the most significant aspects to consider while producing a product. As a result, a
cost analysis for a product is necessary. This study will have an influence on the design that is
created, for example, in terms of safety and the simplicity with which users may implement the
system or product generated. To guarantee that the cost of producing a product is cheap and
effective, researchers try to reduce the overall cost of manufacturing. As a result, the researcher
has separated this cost study into three major sections, namely:
This circuit analysis involves the cost of providing components for the Environment
Analyzer circuit developed. Table 4.2 lists the prices for each component used.
23 | P a g e
4.3.2 Model Cost Analysis
Each product must have a model or prototype to demonstrate the functionality of a system
that has been created. The Environment Analyzer model is automatically designed using
NO List Total
1 Circuit Cost RM 328.70
2 Model Cost RM 29.00
Overall Total RM 357.70
24 | P a g e
4.4 Discussion
Many stuff needs to be taken aware of before doing this project or during the building process of
this project. A simple thing to be aware of is to make sure the workstation is clean and has easy
access to exit if any emergency happens to the laboratory. If the workstation is inside a small or
compact room make sure the room has free airflow for better refreshment. Above is only the
environmental consent that needs to be taken seriously.
For the component as usual we need to make sure to read the datasheet because this thing will
save a lot of money if there is a small silly mistake occurred. For a color sensor, you really need
to take care of it because the sensor is expensive. If the Ground node and VCC node are wrongly
connected it will cause the color sensor in the middle of the LED to blow off because it is so
sensitive. Some power voltage needs to be considered for some sensors. because some sensors will
not work properly with low 3.3V. The sensor mentioned is all the sensors in this project and HC-
05.
ESP32 is new for most BVI students, and this is a really interesting and also confusing thing
to learn. The ESP32 board needed to be added to the board manager inside the Arduino IDE. And
there is one condition when this error shows.
25 | P a g e
This error can be fixed with some easy hands-on work. After uploading the BOOT button, you
need to press and wait until it finishes uploading and to start the program in ESP32. The EN button
or Enable button need to be pressed to start the program.
26 | P a g e
CHAPTER 5
5.0 Introduction
This chapter contains findings as well as recommendations for completed projects. The
Environment Analyzer discussion and complete conclusion to answer the given objectives. The
conclusion refers to the talks that have taken place as a result of the analysis of the data. Following
that, ideas for improvement are provided so that the model might evolve more successfully in the
future. Furthermore, this chapter delves further into the issues that arise throughout the
construction of a model, as well as the steps used to address the issue.
5.1 Recommendation
This is a big recommendation for this project because this color will be more precise and can
make a major difference for the color detection on this robot project. The best of the best of
this sensor because it uses fiber optic as a medium to detect color. Fiber optic has high
performance in data transferring and network.
The 12 Volt DC motor will make a big difference because the motor itself can carry more
weight than the DC motor used right now. With the great power comes great responsibility
this one of the Spiderman quotes that can be used to explain this recommendation of DC motor.
27 | P a g e
However a 12 volt power supply is needed to power this motor to obtain the best function..
5.1.3 Database to PLX
Microsoft Excel's Parallax Data Acquisition Tool (PLX-DAQ) software add-in collects data
from up to 26 channels from any Parallax microcontroller and puts the information into
columns as it comes in. In addition to lab analyses of sensors and real-time equipment
monitoring, PLX-DAQ offers a simple spreadsheet analysis of field data. The database can be
stored on the Monitoring PC and can be accessed anytime. With the use of Microsoft Excel,
we can make graphs to analyze data from time to time.
5.2 Conclusion
The procedure begins with gathering information and identifying materials needed and ends
with the fabrication of this confusing model. This is because if there is no observation and proper
analysis, this model will operate correctly.
The creation of this project for the teaching and learning process will ideally serve as a guide
and assistance to everyone in providing an authentic image of the electric power system and
electronics. It is foretold that this model would be implemented as effectively as feasible in work
operations, significantly reducing the burden imposed by all Malaysian customers.
28 | P a g e
REFERENCES
Chauhan, Dhananjay. “Paper on WiFi Controlled Arduino Based Robot Car.” International
Journal for Research in Applied Science and Engineering Technology, vol. 9, no. VII, 15 July
“ESP32 Send Sensor Readings to Google Firebase and Display on Android App.”
Gupta, Meenu, et al. “IoT Based Voice Controlled Autonomous Robotic Vehicle through Google
19 June 2022.
www.academia.edu/31646219/A_Project_Report_On_Android_Guided_Arduino_Car.
29 | P a g e
APPENDIX 1 – MANUAL APPS
APPENDIX 2 – AUTONOMOUS APPS
APPENDIX 3 – ARDUINO CODING
#include <Servo.h>
#include <NewPing.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_Sensor.h>
#include "DHT.h"
#define DHTPIN A0
//Define Pins
#define enA 2
#define in1 3
#define in2 4
#define in3 5
#define in4 6
#define enB 7
#define s1 27
#define s2 33
#define s3 32
#define out 25
float h,t;
const char* a;
char inz = 0;
//sensor pins
int pwmOutput;
int pwmOutput2;
int Sensor1 = 0;
int Sensor2 = 0;
int Sensor3 = 0;
int Sensor4 = 0;
int motorSpeedA = 0;
int motorSpeedB = 0;
void setup()
dht.begin();
//Serial.begin(9600);
Serial1.begin(9600);
Serial.begin(38400);
delay(500);
//Serial2.begin(9600);
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enB, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(s1,OUTPUT);
pinMode(s2,OUTPUT);
pinMode(s3,OUTPUT);
pinMode(out,INPUT);
APPENDIX 3 – ARDUINO CODING
int Sensor1 = 0;
int Sensor2 = 0;
int Sensor3 = 0;
int Sensor4 = 0;
digitalWrite(s0,HIGH); //Putting S0/S1 on HIGH/HIGH levels means the output frequency scalling is
at 100% (recommended)
servo_motor.write(90);
delay(2000);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
distance = readPing();
delay(100);
void loop()
//Serial.flush();
//Serial.println("n");
inz = Serial1.read(); //Read the incoming data and store it into variable data
if(inz == 'a'){
GetColors();
APPENDIX 3 – ARDUINO CODING
h = ((hum)+30);
t = ((tem)-8);
Serial1.print(",");
Serial.print("!");
Serial1.print(",");
Serial.print("@");
if (Red <=15 && Green <=15 && Blue <=15){ //If the values are low it's likely the white color (all
the colors are present)
Serial1.print("White");
Serial1.println(",");
Serial.print("White");
Serial.println("#");
else if (Red<Blue && Red<=Green && Red<23) { //if Red value is the lowest one and smaller
thant 23 it's likely Red
Serial1.print("Red");
Serial1.println(",");
Serial.print("Red");
Serial.println("#");
else if (Blue<Green && Blue<Red && Blue<120){ //Same thing for Blue
Serial1.print("Blue");
Serial1.println(",");
Serial.print("Blue");
Serial.println("#");
else if (Green<Red && Green-Blue<= 8){ //Green it was a little tricky, you can do it using the
same method as above (the lowest), but here I used a reflective object
Serial1.print("Green");
APPENDIX 3 – ARDUINO CODING
Serial1.println(",");
Serial.print("Green");
Serial.println("#");
else {
Serial1.print("Unknown");
Serial1.println(",");
Serial.print("Unknown");
Serial.println("#");
delay(200);
pwmOutput = 55;//70;
pwmOutput2 = 55;//61;
analogWrite(enA, pwmOutput);
analogWrite(enB, pwmOutput2);
int distanceRight = 0;
int distanceLeft = 0;
delay(50);
moveStop();
delay(300);
//moveBackward();
//delay(400);
//moveStop();
//delay(300);
distanceRight = lookRight();
delay(300);
distanceLeft = lookLeft();
delay(300);
APPENDIX 3 – ARDUINO CODING
//turnRight();
Gerak();
moveStop();
else{
//turnLeft();
Gerak();
moveStop();
else{
//moveForward();
Gerak();
distance = readPing();
GetColors();
h = ((hum)+30);
t = ((tem)-8);
//Serial2.print("!");
Serial1.print(",");
Serial.print("!");
Serial1.print(",");
Serial.print("@");
if (Red <=15 && Green <=15 && Blue <=15){ //If the values are low it's likely the white color (all
the colors are present)
APPENDIX 3 – ARDUINO CODING
Serial1.print("White");
Serial1.println(",");
Serial.print("White");
Serial.println("#");
else if (Red<Blue && Red<=Green && Red<23) { //if Red value is the lowest one and smaller
thant 23 it's likely Red
Serial1.print("Red");
Serial1.println(",");
Serial.print("Red");
Serial.println("#");
else if (Blue<Green && Blue<Red && Blue<120){ //Same thing for Blue
Serial1.print("Blue");
Serial1.println(",");
Serial.print("Blue");
Serial.println("#");
else if (Green<Red && Green-Blue<= 8){ //Green it was a little tricky, you can do it using the
same method as above (the lowest), but here I used a reflective object
Serial1.print("Green");
Serial1.println(",");
Serial.print("Green");
Serial.println("#");
else {
Serial1.print("Unknown");
Serial1.println(",");
Serial.print("Unknown");
Serial.println("#");
delay(200);
xAxis = Serial1.read();
APPENDIX 3 – ARDUINO CODING
delay(10);
yAxis = Serial1.read();
//Serial.print(xAxis);
//Serial.print(",");
//Serial.println(yAxis);
delay(10);
if (xAxis > 130 && xAxis <150 && yAxis > 130 && yAxis <150){Stop();}
}else{
}
APPENDIX 3 – ARDUINO CODING
}else{
motorSpeedB = 255;
motorSpeedA = 255;
//Serial.print(motorSpeedA);
//Serial.print(",");
//Serial.println(motorSpeedA);
int lookRight(){
servo_motor.write(10);
delay(500);
delay(100);
servo_motor.write(90);
return distance;
int lookLeft(){
servo_motor.write(170);
delay(500);
delay(100);
servo_motor.write(90);
return distance;
delay(100);
void Gerak()
Sensor1 = digitalRead(8);
Sensor2 = digitalRead(9);
Sensor3 = digitalRead(10);
Sensor4 = digitalRead(11);
if(Sensor4 == HIGH && Sensor3 == HIGH && Sensor2 == LOW && Sensor1 == LOW){
//Turn LEFT
//motor A Backward
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
//analogWrite(enA, enASpeed);
//motor B Forward
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
//Serial.println("kiri");
//analogWrite(enB, enBSpeed);
else if (Sensor4 == LOW && Sensor3 == LOW && Sensor2 == HIGH && Sensor1 == HIGH){
//Turn RIGHT
//motor A Forward
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
//analogWrite(enA, enASpeed);
//motor B Backward
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
APPENDIX 3 – ARDUINO CODING
//Serial.println("kanan");
//analogWrite(enB, enBSpeed);
else if (Sensor4 == LOW && Sensor3 == LOW && Sensor2 == LOW && Sensor1 == LOW){
//Turn RIGHT
//motor A Forward
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
//analogWrite(enA, enASpeed);
//motor B Backward
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
//Serial.println("benti");
//analogWrite(enB, enBSpeed);
else{
//else if(Sensor4 == LOW && Sensor3 == HIGH && Sensor2 == HIGH && Sensor1 == LOW){
//FORWARD
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
//Serial.println("terus");
//analogWrite(enA, enASpeed);
//analogWrite(enB, enBSpeed);
int readPing(){
delay(70);
int cm = sonar.ping_cm();
if (cm==0){
cm=250;
return cm;
APPENDIX 3 – ARDUINO CODING
void moveStop(){
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
void GetColors()
digitalWrite(s3, LOW);
Red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH); //here we wait until "out" go LOW,
we start measuring the duration and stops when "out" is HIGH again, if you have trouble with this
expression check the bottom of the code
delay(20);
delay(20);
digitalWrite(s2, HIGH);
delay(20);
void forword(){//Serial.println("forword");
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
void backword(){//Serial.println("backword");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
APPENDIX 3 – ARDUINO CODING
void turnRight(){//Serial.println("turnRight");
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
void turnLeft(){//Serial.println("turnLeft");
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
void Stop(){
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
//Serial.println("stop");