0% found this document useful (0 votes)
11 views50 pages

Arduino Learning

Uploaded by

Tihomir Mihaylov
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
11 views50 pages

Arduino Learning

Uploaded by

Tihomir Mihaylov
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 50

ARDUINO LEARNING

ABOUT THE AUTHOR


I was born in 1984. I am a university graduate in the field of
health. I am married and a child's
mother. I am working as a research writer in human health,
developmental psychology, food,
technological fields because my child grows up and my wife
is an educator. I participate in
conferences at universities in these fields and give lectures to
students.
As an investigative writer, I give daily information and useful
information about my books.
ARDUINO LEARNING
Why Arduino?

Arduino is a ready-made circuit board used by Atmel brand processors. It


is open source and
the person requesting can make his own Arduino. Arduino provides ease
of use in projects and enabling projects to be done more quickly and
stably. According to Arduino structure and properties It is composed of
various species. We will use the Arduino Uno model in our project.

Arduino has USB connection, power connection and input / output


pins. USB
sending the program to the connection card, transferring the information
between the computer and the card, Used to feed. The power connection is
also used for external feeds. 9 Voltage supply is recommended. Feeding
from USB is more risky than this feeding. Because the USB output of the
computer may not provide enough current for Arduino (in motor
applications especially). Before we start programming with Arduino, we
have some basic electronic information go through the eye.

Basic Electronics
breadboard
As you can see in the picture, There are holes extending. These holes are
in our feed channel. Descending the holes corresponding to the lines are
short-circuited. That is, a cable connected from red wires with cables to
connect over the same line It is associated. The holes corresponding to the
horizontal lines in the middle of the bear are linked to each other. If you
notice a slit from the middle of the horizontal lines pass. We can easily fit
our intentional inte It is that it provides

Resistance

You will also keep our knowledge known by almost everyone. V = I * R


formula
examine; if we increase our resistance under a constant voltage according
to this formula. It decreases. With this feature, resistance to elements that
we do not want to draw excess current We need to put.

Voltage Splitter

It is the inverter which reduces the input voltage to the desired voltage. Set
up like this. Exit The voltage depends on the resistances of R1 and
R2. Vout = Vg * R2 / (R1 + R2). for example If R1 = 10k R2 = 10k ohms
and the input voltage is 5 volts, then my output voltage = 5 * 10K / (10K +
10K) = 2.5 volts.

diodes

There are various diodes according to usage areas. Led, photocell, and
solar diodes
for example. As we know from our high school knowledge, the diodes
pass in one direction.

The illustration shows the direction of current flow. But unfortunately in


the real world the diodes they do not behave as ideal as on paper. Even if
the diode is used in the current passing direction. This voltage difference
varies with the nature of the diode

It is between 0,6 - 0,7 Volt.


Zener Diodes
They are usually connected in reverse to the other diodes. Reverse
(blocking) direction the tension on the arm is fixed by the voltage
difference they create. On circuit
as shown in the figure. The voltage difference depends on the diode
structure.
We will usually use 5.1 volt diodes. With these diodes, the excess voltage
on the circuit and we hope to avoid any possible fluctuations.

transistor

It is a circuit element that amplifies the signal applied to the


input. Switching at the same time It is also used as a member.

Basic Software Information

Before we go to Arduino, let's look at the basic software codes. our


projects
We will introduce some functions and code structures that we will use.

Conditions (if-else-elseif): The software is one of the most basic


commands for languages. A situation in your hand and if this is true, if you
want to do a job, if it is wrong, you want to do the job b
the code system is right for this job. Let's look at the code diagram briefly.
If (a == 5) {
// Code to work in the correct state here
} else {
Code to work if A is not 5

}
a == 5 here constitutes our condition. It should be noted that two equals
It is used. It means that it is equivalent. I can use it in the condition field
phrases,
==
Denk is
!=
If not equal
<
great is
>
small is
<=
Greater than or equal to
>=
Small or equal
Condition1 && Condition2 And
Condition1 | Condition2
Or
Our conditions are not obligatory to use else. Only iF can be used, so the
condition
If not, an extradan code will not work. New conditions with elseif if we
have more than one condition
We can add.
If (a == 1) {
// this works if a = 1
}

elseif (a == 2) {
// this works in case of a = 2
}
elseif (a == 3) {
// this works if a = 3
}
For loop: We may want the codes we write to repeat for a certain period
of time. For this
we must use cycles.
For (int i = 0; i <10; i ++) {
// this will be read 10 times
// the program will be incremented every time i get here
// loop will continue until i reaches 10

}
While loop: While loops like For are also used for looping.
b = 20;
while (b> 10) {
// Loop continues if b variable is greater than 10
b = b - 1; // reduce the value of b in each cycle by one
// be careful that if we did not change the value of b
// the loop condition will always be correct so the program will stay here
}

Arduino Setup and Arduino Program


We're starting to use Arduino. First of all, my army's USB cable goes to
arduino
let's tie. Then I put my computer on. Arduino of Win 7 and higher it will
be automatically installed. After waiting a little longer then arduino
computer
It will be recognized. To see if the Arduino has been recognized by the
computer, and let's keep the COM Port that Arduino is connected to (
device manager: right click on the computer -> manage -> device
manager)
While introducing Arduino, we will use the program on the one hand to
download the program. For this Go to
http://arduino.cc/en/Main/Software and download the Arduino program
download and schedule the program. After installing the program without
error, let's open the program.
When the program is running, the screen will meet you. This screen to the
middle part of our codes We are writing. At the bottom right of the
program place us over Arduino Uno and arduino is COM1 port. If this is
not the case, we need to change first.

Tools menu: From here we use arduino Let's choose the COM port. If we
do not know this, we can look at it from the device manager. Program
compile: With this button we can check the program we have written. If
the error in the code if there is an error, we will make an orange line in the
black section below.
Reminder: The number of lines that we find is left-justified.

Program Compile & Upload: This button compiles the code we wrote
first. If the error in the code otherwise the code is translated into the
language Arduino understands and automatically dropped into Arduino.

During the process, you can see the progress of the process from the
progress bar. Full program rollout the Tx and Rx LEDs on the Arduino
will flash rapidly.
Once you have the program, you will have to hire Arduino.

Serial Monitor: This button opens a new window to send the data we
send from Arduino we can see. We will use this button frequently in our
future issues.
I wish you success in your Arduino work already ... So let's start.

Blinking Led Production with Arduino

Let me first learn the LED connection. When looking at the LED's feet
it seems that one of the long ones is short. We understand from here
What you need to do is to connect the long leg + to the short leg - on the
short leg should. So we will tie our long feet to arduino. But If there is no
connection between the feet, the short foot + tip, other foot - tip. Operating
current of our LED has. To do this and not to draw too much current with
the LED's
we must connect a 220 ohm resistor between the arduino (+ 5 volts
supply). Otherwise Our LED could explode. The resulting gas may be
harmful to health.

Now we can log in to the program. Arduino programs consist of two main
functions.

void setup () function: This function runs once when the program is first
opened, calibration, setup commands. void loop () function: the main ()
function we are used to from other programming languages like
this. Differently, the loop function starts from the beginning when the
function is finished,
it is actually a loop.

Arduino Programming Scheme:

// We can add libraries at first


// Global cinst we can define our variables
// We can write our functions here
void setup () {
// the code we want to run at first is written here
}
void loop () {
// main function in infinite loop
// we write the program here
}
We can do this project to test Arduino and write our first program. 1
second
our LED will blink with intervals.
int LED = 10; // here we connect our lead to the 10th foot of the army
we say
void setup () {
pinMode (LED, OUTPUT ); // LED pini, Arduino's 10th foot output
done
}
void loop () {
digitalWrite (LED, HIGH ); // 5 volt voltage from which the LED is
connected
provided
delay (1000); // 1000 ms or 1 second program stops
digitalWrite (LED, LOW ); // LED is off
delay (1000); // wait a second
}

Black Lightning Circuit With Arduino

A sample consisting of parallel connected LEDs, which is practically


referred to as Arduino. Let's start with the cycle. We can create the episode
as many LEDs as we want. In this example we have 5 units We will
pretend to have installed with leds.

void setup () {
pinMode (13, OUTPUT );
pinMode (12, OUTPUT );
pinMode (11, OUTPUT );
pinMode (10, OUTPUT );
pinMode (9, OUTPUT );
}
void loop () {
digitalWrite (9, HIGH );
delay (10);
digitalWrite (9, LOW );
digitalWrite (10, HIGH );
delay (10);
digitalWrite (10, LOW );
digitalWrite (11, HIGH );
delay (10);
digitalWrite (11, LOW );
digitalWrite (12, HIGH );
delay (10);
digitalWrite (12, LOW );
digitalWrite (13, HIGH );
delay (10);
digitalWrite (13, LOW );
}
The codes given above for comprehension of the working principle of the
black lightning application
I think it is explanatory. But these codes are at the beginning level,
Each led is individually checked. As the next step,
Let's write a program that does it but is more professional.
const int ledPini [] = {9,10,11,12,13};
void setup () {
for ( int i = 0; i <5; i ++)
{
pinMode (ledPini [i], OUTPUT ); // We defined the LED pins as output
}
}
void loop () {
for ( int i = 0; i <5; i) {
digitalWrite (ledPini [i], HIGH );
delay (50);
digitalWrite (ledPini [i], LOW );
}
for ( int j = 4; j & gt; -1; j--)
{
digitalWrite (ledPini [j], HIGH );
delay (50);
digitalWrite (ledPini [j], LOW );
}

Using the Button with Arduino

We will use buttons for various tasks in our applications. First of all,
Let's examine the logic. When the user clicks on the button, the button
becomes short-circuited so that the current begins to flow. When the user
takes the hand grip, pull-up / pull-down resistance system is used. With
these resistances used, the button rescued from being electrically
depressed.
Pull-Down Resistance

When the buton is pressed, the 5 Volt arduinon input reach the
foot. However,
5 volt voltage at arduinoun pin when we remove It remains. To get rid of
this
usually a resistance of 10K ohms arduinoun from the input foot to the
ground.

Pull-up Resistance

If the button is not pressed, the army's input


foot is 5 volts. Current when button is pressed instead of the input foot of
the army
reach. The opposite of the pull-down resistor system.
Reason for putting resistance When the button is pressed 5 Volts direct to
the ground (- flight). Generally 10K resistance is used.
I think that this theoretical knowledge is enough. When we hit Butona, the
lamp
Let's write a program that will let it burn and we will extinguish when we
get it
const int buttonPin = 2; // Button pin number
const int ledPin = 13; // The pin number that the ledge is connected to
int buttonState = 0; // Button state
void setup () {
pinMode (ledPin, OUTPUT ); // The output of the pin that the wire is
connected to
upfront.
pinMode (buttonPin, INPUT ); // The button is bound to the pini output
upfront.
}
void loop () {
buttonState = digitalRead (buttonPin); // Whether the button is pressed
we are checking.
// If the button is pressed, it returns to LOW if it is not HIGH (1 or
0)
if (buttonState == HIGH ) { // Is the button pressed?
digitalWrite (ledPin, HIGH ); // ledi yak
}
else {
digitalWrite (ledPin, LOW ); // no button pressed
}
}
A little wait can be given after digitalWrite codes to prevent arc events,
delay (100).
Now that we know how to control the button, go one step further and make
a counter.
But first of all, let's look at how to communicate computer and arduino.

Arduino to Computer via SerialPort

If you need to check the values ​you need to transfer the processed values ​
to the user we need to communicate between our army and our
computer. This communication RX and TX feet of the army will take
place. As always for communication It is enough if we connect my
computer via USB. Setup for communication let's not forget to write the
initialization code for our function. With the following code, second.
void setup () {
Serial . begin (9600); // communication between computer and arduino
We are launching.
// We wrote 9600 to run your computer and the army at the same speed.
// So at the moment there will be 9600 bit transfers.
}
int counter = 0;
void loop () {
Serial . print ("Counter Digit ="); // We are printing our message on the
screen.
Serial . println (counter); // print our counter value on screen and add new
line
We are going through.
delay (1000);
// Wait a second
}
The whole process is that easy. It's up to you now. What you write with
this link
you can easily test and debug the program.
Now we know that the button we have previously learned is in control,
Let's make an incremental counter when pressed.
const int buttonPin = 2; // Button pin number
int counter = 0; // Our counter
int buttonState = 0; // Button state
void setup () {
pinMode (buttonPin, INPUT );
Serial . begin (9600);
}
void loop () {
buttonState = digitalRead (buttonPin);
if (buttonState == HIGH ) {
counter ++; // counter = counter + 1;
Serial . print ( "Counter Digit =" ); // Display message
We are printing.
Serial . println (counter); // print our counter value on screen and add new
line
We are going through.
while (buttonState == HIGH ) { // Butondan hand pick up program
it stays here
// Thus, each time the button is pressed, the value is incremented only once
buttonState = digitalRead (buttonPin);
}
}
}
I will always send data to arduino, let's expect some data from the other
side. With this code,
the incoming data are processed in arduin. Do not forget that all the data is
It comes.
int incomingByte = 0; // incoming data
void setup () {
Serial . begin (9600);
}
void loop () {
if ( Serial . available ()> 0) { // expect data from the computer
incomingByte = Serial . read (); // read incoming data
Serial . print ( "incoming data:" );
Serial . println (incomingByte, DEC ); // return the incoming data to the
computer
send
}
}

Bluetooth Communication with Arduino

Basically, the work we do is analogous to communicating over computer


and arduino. Single the difference is that we will connect the bluetooth
module to our hardware. Various in the market Modules bluetooth
modules usually have 4 legs. From the writers on As you can see, there are
2 feeds and 2 communication feet. Feeds modüle Let's connect it to 5 or
3.3 volts according to the datasheet. In case of incorrect connection our
module may be garbage. The remaining 2 feet will be connected to our
arm. As the first application
Let's tie this foot to our feet Rx and Tx. Bluetooth Tx foot Rx foot of the
army, Rx foot of the Bluetooth will be connected to the Tx foot of the
army. So
it has to be connected in reverse. There is a mistake that has always been
made and will continue to do so here. When something is connected to the
feet of your armpit Rx and Tx, you will get an error. Because these feet are
also the computer and any other modules connected to it will corrupt your
communication. If this Do not forget to disconnect these cables when we
are going to use the legs.

The part on the arduino is not so difficult. But our bluetooth module
we need to match. After you have connected your Bluetooth tunnels
the red light will flash. This means that the light is waiting for the
connection.
Let's find our module by searching our computer's bluetooth. Match the
devices.
If you ask for a password, usually the first conviction is 1234. If we are
properly connected the red light will always be on. More detailed
information on this part is available from the link below You can reach. A
new COM Port will be opened for the module, we will use it in our
programs.
http://www.mcu-turkey.com/stm8s-hc-06-bluetooth-modul-ile-
haberlesme-uygulamasi/
Let's write the code now. In fact, we will not do anything very
different. Serial communication we can download the sample code to my
arduinumuza.

void setup () {
Serial . begin (9600);
}
int counter = 0;
void loop () {
Serial . print ( "Counter Digit =" );
Serial . println (counter);
delay (1000);
}
We programmed our program and carefully touched the Tx and Rx feet of
the bluetooth module
We connected the arduino. The red light in the module is still
flashing. Because the computer module (Master -> Slave connection)
In this step, we need an additional program. This program allows the COM
ports
listening program. There is no need to have a very special program.
There are programs. My suggestion is Tera Term. You can download from
the link below.
http://download.cnet.com/tera-term/3000-20432_4-75766675.html
Let's run the program and connect it modularly. In the connection settings,
Let's choose the COM port we introduced to the computer. If everything is
true now the red light is continuous burning and data exchange occurs. If
there is no data flow control our settings
Let me choose the other bluetooth COM port and try again. I hope the data
flow
Provide Abilmişsinizdir. All steps must be done carefully.
Now you can ask 'Do we have to deal with Tx Rx cables every time?' Our
answer is NO.
We can define new communication legs in your army. Thus, by computer
communication a conflict does not occur.
With the following code, we will connect our module now with feet 10 and
11.

#include < SoftwareSerial .h>


SoftwareSerial newCommunicationWeek (10, 11); // 10 = RX, 11 = TX ie
10 -
> bluetooht to Tx 11 -> Rx
void setup ()
{
Serial . begin (9600); // do not communicate with the computer
The yenihaberlesmekanal. begin (4800); // our new communication
channel
}
void loop ()
{
Serial . println ( "This is a computer" );
The yenihaberlesmekanal. println ( "This article is bluetootha" );
delay (100);
}
With the help of the above code, arduino and bluetootha both computer
different messages are ways. Tera Term to see the messages and the
alarm's own Serial Monitor You can open.
Analogue Data Reading with Arduino

Everything in the real world is analog. But this is not possible in the digital
world. Analogue digital to store and process data. More theoretical
I do not plan to enter but how I have to share the picture on the side for
you to understand. As I think it is an attempt from 0 to 5 volts
there is. To introduce the values ​of this input to Arduino, use the ADC
(Analog Digital Convert) We'll use. We will give 0 Volta 0 and we will
give 1023 in 5 Volta. So 10 bits we will use a resolution ADC. Oran
continues as a liner. So,
A change of 0.004 volts will correspond to 1 digit digitally. That is, 0.44
Volt => 100. Arduino makes this transformation for us himself. But the
cables we will measure We need to link to the analog legs of the
Arduino. The analog value in the enterprise is digital

Let's read from the computer as:


void setup () {
Serial . begin (9600);
}
void loop () {
int sensorDegeri = analogRead (A0); // Connected to A0 foot of Arduino
voltage on cable is measured
Serial . println (sensorDegeri); // The value we read is printed on the
screen
delay (1); // We give a short wait for it to work properly.
}
Black and White Control with Arduino

Almost everyone thinks firsthand application


which constitutes the base stone of the line-following robot
Let's examine black and white sensors. In our book used for this business
in the market and we will examine the CNY70 sensor you can find.
Other sensors on the market are also the same It is working.

CNY70 How it works: emitting infrared light on and there are two LEDs
that can recollect this light. The beam from the infrared LED strikes the
surface and
the collector LED. The LED measures the intensity of this light. If the
surface is black or white, the reflected light it changes its severity. This is
what we need
black and white separation. Our sensor analog.
That is to say, the analog-to-analogue reading function
We'll use. First of all, we need to set up a vacation. For this reason, we
recommend perilaks My rule. When placing the sensor, be careful that the
feet are shaped like this.
As an example, let's start with a connection of one sensor at first and a
project with one sensor I'm of carrying. 3 lines combine our advanced
projects following a simple one sensor The robot will do.
No links in our rules breadboard. Beware of false connections
Binding. The tile-shaped diamond sensor would be put on the wiring
breadboar
Easier.
Let's start writing code that we perform the installation as in the picture.
int referansdeger = 800; // threshold for black and white
void setup () {
Serial . begin (9600);
}
void loop () {
int sensordeger U = analogread (A1); // Connect to A1 foot Arduino
tension on the cable is measured
Serial . print (sensordeger a); // value is printed on the screen we read
if (sensordeger of> referansdeger a) {
Serial . println ( "Black" );
}
else {
Serial . println ( "White" );
}
delay (1); // we give a short wait to work properly.
}
referansdeger in the program constitutes our threshold. The value of your
sensor, you
You will need to adjust accordingly. You can run the program examined
the value you get. in black You divide the value by picking up the value in
white. This new value is yours you referansdeger'i
It will create.
If you believe that your sensor is working control for Android-based phone
Keep toward the camera sensor (not work on some android and iPhone). If
the light sensor If you see your feed illuminates the connection is
correct. You still will not operate analog sensors Check the sensor
connection with his foot once more.

Using the LCD with Arduino

I do not use often, even with the Arduino would be useful to learn to use
the LCD. Always Find the computer may not be able to show our data. In
such cases using lcd'miz You can get print status screen. Cable
connections can be a bit complicated and first

LCD may not use your experiment and make mistakes properly. That's
why
Make your careful circuit connection.
If we've carefully Circuit can now no longer our programming. All
characters
previously defined for us. Our library is primarily to reach these characters
We will include in our program. Then we made our initial settings and the
lcd'miz
We'll start using it.
Come on let's write something to our screen.
#include < liquidcrystal .h> // we add our library
Liquidcrystal LCD (12, 11, 5, 4, 3, 2); Cable connection to our program //
We introduced
void setup () {
LCDs. The burner (16, 2); // lcdmiz we enter the number of columns and
rows
LCDs. print ( "Hasbi Joy" ); // Display to something I've written
}
void loop () {
LCDs. setCursor is (0, 1); // 2. We have reduced our cursor line
LCDs. print ( Millis () / 1000); The time elapsed since the beginning of the
program //
}

EEPROM Writing and Reading

We found our results and variable values ​even if the power is interrupted
in the Arduino We may want to save. built-in EEPROM for the Arduino
that we can provide There. Variable values ​that can hold about our
program EEPROM, electrical It is written as a small removable storage. on
the Arduino microcontroller It varies according to the type EEPROM
capacity. 1024 bytes of ATmega328, and ATmega168 atmega8 512 bytes,
whereas the ATmega1280 and atmega2560 has 4 KB of storage.

This storage space is sufficient for storing the values ​required for our
program.
Let's Let's write a sample program

#include < EEPROM .h> // Adding the library to use EEPROM


int yazdirilacakadres is yazdirilacakdeg;
int okunacakadres is okunandeg;
void setup ()
{
Serial . begin (9600); // to send data to the computer
}
void loop ()
{
int yazdirilacakadres = 10; // we enter the address between 0-255
yazdirilacakdeg R = 50; // Our value will be saved
EEPROM . write (yazdirilacakadres is yazdirilacakdeg); // now at 10
Our stored value 50
okunacakadres = is yazdirilacakdeg; Read address // 10
okunandeg R = EEPROM . read (okunacakadres); // address and we read
10
We are installing the variable readings there dğer
// we print the results to the screen
Serial . print (okunacakadres);
Serial . print ( "Value = s Address" );
Serial . print (the okunandeg);
Serial . println ();
delay (500); // Let's wait a bit
}

Using servo with the Arduino

We begin our slow arduino to control the outside world. servo motor with
an Arduino rides compared to other microcontrollers (especially based on
PICs) is easier. weeks with PIC It takes time minutes with the servo motor
control arduino.

Servo Motors: movable between 0-180 degrees employees to a precision


of 1 degree The engine variants. As I said, just rotate between 0 and 180
degrees. So a full tour It is assignment. It is often used in the robot
arm. Servo varieties usually It is determined by the load bearing
capacity. 1.4 kg * cm torque servo generally in the market There. This
means that the motor shaft is connected to a rod end of a length of 1 CM
load connected to the engine's power is not more than 1.4 kg feed shaft
rotation. If your bar The CM 140 can remove 10 grams. Many people
make the mistake here. you'll use to load You must select the servo
based. There are more powerful servo motors running at the same logic in
the market.
So how would you say the servo motor control, can theoretically be
summarized as follows. PWM There is what we call the square wave
signal. According to this signal is HIGH and LOW The position of our
power is changing.
3 has servo cable. Red wire to tie us to +5 volts, our brown earth cable (-
end) and orange wires us in our arduino PWN (~) Let's connect to by
foot. Our orange wire is our position and our data cables It is transmitted
over the cable. servo, etc. should be noted that mechanical elements with
more flux
It is working. Arduino situations where our 5-volt output is sufficient to
supply our power can. In addition, the servo circuit due to noise may
occur. That's why our circuit the + and - Our capacity to bind to the ends
can block this noise.

#include < Servo .h> // We have included the program our servo library
Servo servonesne of; // we create an object for servo control
void setup ()
{
The servonesne. attach (9); // 9 pin cable to power our orange
We say we wear
}
void loop ()
{
The servonesne. write (100);
// Servo our 100 degree
We return
delay (1000);
// Let's wait a bit
The servonesne. write (20);
// we rotate 20 degrees to power our
delay (1000);
// Let's wait a bit
}

DC Motor Driver with Arduino


Our motor current required for output of direct motor coupling pin
Arduino
It does not provide. Arduino pin output, but provides current through a
LED fuel.
But we use the trigger function of this current DC motors in forward or
reverse direction We can run. Circuit boards are ready for this. easily take
one of these
We can use. Example prepaid card can be accessed from the link.

http://www.aliexpress.com/item/special-promotions-5pcs-lot-l298n-motor-
driver-board-module-L298-for-arduino-stepper-motor-smart-car /
1827893830.html

I'll tell you soon can you get this card and cable connections as your
engine
You can easily check.

But if you want to make this business a bit challenging yourself and the
entire circuit can be complex.
But to understand how the system works at least once in the establishment
of circuit useful can. To control for motor drive and motor to strengthen
the current L298 We will use the integrated. Similar integrated and serves
the same task. most of integrated L298 important features is able to
withstand up to 2 amps and the presence of two H-bridge.

H Bridge:
H bridge and the engine of our future driving in the reverse direction
providing structure. 4 consists of transistors .
Our integrated There are a total of 15 feet. Some of these engines to our
feet
Some will be connected to the Arduino and some feed. Integrated pin for
structuring You can use pictures.

In short, we want to introduce the pins connect;

INPUT 1 and INPUT 2 (5 and 7 feet): We'll connect our Arduino these
pins. Input 1 to 5 When we give our engine-volt input 2 to 0 volts forward,
when we do the opposite Will go backwards.

INPUT INPUT 3 and 4 (10 and 12 feet): These pins also works as
INPUT 1 and INPUT 2.

OUTPUT 1 and OUTPUT 2 (2 and 3 feet) being connected to two ends


of the two pin motor is required.

OUTPUT OUTPUT 3 and 4 (13 and 14 feet) being connected to two


ends of the two pin other motor is required.
ENABLE and ENABLE B (6 and 11 feet): These two pins are the pins
will set our pace. It So we need to connect these pins on the Arduino's
PWM feet. Given the PWM signal It will be determined by the speed of
our feet or we give and we give to INPUT 5 volts by the The engine will
be a certain direction.

Speed Control PWM:

PWM signal LOGIC HIGH (5 volts) and the LOGIC-LOW (0 volts)


It consists of the signal. HIGH and LOW It is given by the ratio of average
signal Through our engine speed output signal 0- It may take the values ​
255.

VSS (LOGIC VOLTAGE SUPPLY - 9. Leg):

As the name suggests, this pin 5 volts It should be connected. between the
soil to reduce the instability of the circuit, this pin 100nf'lık connected
capacitor.

GND (8 foot) are required to connect these pins to ground. Also integrated
on topmetal is the soil. Why mention that you do not accidentally shorted
my
It is for.

VS (4 feet): Integrated feed our feet is the main engine provides the
energy to go on. Here we give our motor control will be in line with the
engine. our engine
12 Volt here we connect our properties considering the application.
Let's start building our integrated circuit As we learned from our pin
structured. Test You can use to integrate on a breadboard. However, use in
other applications If you want, and constantly crowded the cable / cable
due to lack of contact makes full Do not yield. After testing circuit so
perforated or printing pertinaks You may want to play. I'm ready to take
my advice or circuit board. from abroad You can get 2-3 $ 'a.
When you get ready, you will see card or via pins I mentioned just now.

Rank came to writing the Arduino software. The following code in other
functions formed, We will also use our application. First INPUT variables
for our feet We define.
const int milking of = 9;
const int sagger 8 =;
const int soli in = 12;
const int Solger = 13;
const int solenabl A = 11;
const int sagenabl = 10;
void forward ( int hizsag, int hizsol) {
analogwrit A (sagenabl A, hizsag);
digitalwrit A (milking of, HIGH );
digitalwrit A (sagger is LOW );
analogwrit A (solenabl A, hizsol);
digitalwrit A (soli are HIGH );
digitalwrit A (Solger is LOW );
}
void reverse ( int hizsag, int hizsol) { // the second right motor, our first
variable
It shows the speed of the left motor.
// our engine speed should be between 0-255.
However, some of the engine torque by deficiencies // 60-
255 works.
// If you need to increase the speed of your engine coming off a high-
pitched voice

analogwrit A (sagenabl A, hizsag);


digitalwrit A (milking of, LOW );
digitalwrit A (sagger is HIGH );
analogwrit A (solenabl A, hizsol);
digitalwrit A (soli are LOW );
digitalwrit A (Solger is HIGH );
}
void stop ()
{
digitalwrit A (milking of, HIGH );
digitalwrit A (sagger is HIGH );
digitalwrit A (soli are HIGH );
digitalwrit A (Solger is HIGH );
}
void setup () {
In pinmo (milking of, OUTPUT );
In pinmo (sagger of OUTPUT );
In pinmo (soli, the OUTPUT );
In pinmo (Solger of OUTPUT );
In pinmo (sagenabl A, OUTPUT );
In pinmo (solenabl A, OUTPUT );
}
void loop () {
forward (100,100); // we are going forward
delay (1000);
Stop(); // we stopped
delay (1000);
forward (150.100) // We're heading slightly to the left
delay (1000);

Stop(); // we stopped
delay (1000);
forward (100.150) // we are going the right light
delay (1000);
Stop(); // we stopped
delay (1000);
return (100,100); // We're going back
delay (1000);
Stop(); // we stopped
delay (1000);
}
I hope has been useful codes. Now, a code that we wrote with the Arduino
software The tables show a connection between the motor drive our feet
with his feet.

Arduino
Motorcycle driver
8
INPUT 1
9
INPUT 2
13
INPUT 3
12
INPUT 4
11th
ENABLE A
10
ENABLE B
Engine
Motorcycle driver
motor1 +
OUTPUT 1
motor1 -
OUTPUT 2
Motor2 +
OUTPUT 3
Motor2 -
OUTPUT 4
(Motor + or - does not matter which one end of)

Feed
Motorcycle driver
+12 Volts
VCC
Ground (- end)
GND
+5 Volt
ETC

Distance sensor with Arduino

In our book we do not practice with the HC-SR04 Distance Sensor. This
sensor market in abundance which it is expensive, but a sensor located in
our country. Out of the $ 1-2 China 'You get a. It measures the distance
between the sensor 2-200 CM. But 200 cm right sensor quality It is
impaired.
Roads can hear sound at a frequency of the sensor human ear. Sound if hit
somewhere back and our revenue neutral sensor. The sensor calculates the
commute time so that voice and body
Find the distance. So this sensor is also called ultrasonic sound sensor.
You can look at the image below for the circuit diagram.
wiring diagram as shown in the picture

Sensor -> Arduino


VCCI -> 5 Volts
GND -> GND
Timing -> 8 (may vary)
Echo -> 7 (subject to change)
Now we take away from the sensor to the computer screen I should
program an application that prints.
int trigp to 6; // trigger pin to be connected to sensor pins Arduino
int echop's = 7; // echo sensors connected to the pin Arduino pin
long olcum;
long cm; // we read from our sensors you
void setup () {
In pinmo (trigp's, OUTPUT );
In pinmo (echop's, INPUT );
Serial . begin (9600);
}
void loop ()
{
digitalwrit A (trigp's, LOW ); // sensor're sending sound at first
delaymicroseconds (5);
digitalwrit A (trigp's, HIGH ); // Here we send the sound waves
delaymicroseconds (10);
digitalwrit A (trigp's, LOW ); // not send a single sound wave
olcum = pulse (echop's, HIGH ); // If the sound comes back to the echo
pins
Will return.
// Here we calculate elapsed time.
cm = olcum /29.1/2; // measurements of the time -> We translate cm
Serial . println (cm); // result of the computer to see the Serial Monitor
we're sending
delay (100);
}

If there is no obstacle in front of the sensor sensor will be a slight


slowdown. From this We need to get rid of are waiting to enter the MAX
value. This value increase by reducing their You can apply your
sensor. you need to change the code: digitalwrit A (trigp is,
HIGH, 2895 ); // You can change the number in 2895.

Acceleration Measurement with Arduino

Adxl345 we will use the most widely used in the market for acceleration
measurement. 3 axes of this sensor angular acceleration can be
measured. Sensor I 2 C and SPI communicates through line. Come on
link our rules:
As we can now connect to our programming circuits. Before using our
Sensor
Let's get ready for the ADXL345 where the library functions. You can
download the form.
http://code.bildr.org/download/959.zip
Library files into the program the Arduino libraries files between folders
Let's take. According to examine the sample code library complete the
installation.

#include < Wire .when>


#include <adxl345.h>
ADXL345 adxl; // We create object named adxl
void setup () {
Serial . begin (9600);
adxl.powero the (); // We are running sensor
}
void loop () {
int x, y, z;
adxl.readaccel (& x, & y, & z); // we read values from the sensor
Serial . print (x);
Serial . print (y);
Serial . println (z); // we print sensor values to the screen.
Delay (10);
// gives the gravitational acceleration sensors and active momentum in
both
}

Arduino APPLICATIONS

Traffic lights

Let's start with a simple project as our first application. It project in 3


pieces (red, yellow, green) will use LEDs. More As we mentioned before,
the long leg of the LED to the arduino, The short leg must be inserted into
the soil. 3 LEDs respectively Arduino 11, 12 and 13. Takala the pin. Each
LED about 220 ohm connection between the Arduino My orange fruit
resistance.

Objective: The red light will illuminate for 5 seconds. Later After half a
second yellow light and a green light for 3 seconds Lights. But a second,
and then the yellow light turns red
Light is passed.

int red = 13;


int Yellow = 12;
int green = 11;
void setup ()
{
In pinmo (red, OUTPUT );
In pinmo (yellow, OUTPUT );
In pinmo (green OUTPUT );
}
void is lambadegis ( int light) // red = 1, yellow = 2, green = 3
{
digitalwrit A (red, LOW );
digitalwrit to (Yellow, LOW );
digitalwrit A (green, LOW );
switch (lamp) {
case 1:
digitalwrit A (red, HIGH );
break ;
case 2:
digitalwrit to (Yellow, HIGH );
break ;
case 3:
digitalwrit A (green, HIGH );
break ;
}
}
void loop ()
{
Is lambadegis (1);
delay (5000);
Is lambadegis (2);
delay (500);
Is lambadegis (3);
delay (3000);
Is lambadegis (2);
delay (1000);
}
Robot Making voltmeter with Arduino

In this project we will design a voltmeter capable of measuring values ​


between 0 and 5 volts.

Our goal is to better understand ADC. We will only use two of our cable
connection.

First let's connect the ground wire to the Arduino our feet. A0 our feet on
the second cable Let's tie. What you can establish test circuit to test the
voltmeter and its various You can measure the voltage in place.
Now let's software. Unlike this time corresponding to the numerical value
of our ADC sample We will print the voltage is calculated on the computer
screen.

void setup () {
Serial . begin (9600);
}
void loop () {
int sensordeger U = analogread (A0); // numerical value of the voltage at
the A0
float voltage = (5/1023) * sensordeger of; // 5 volt max. by 1023
It was measured. We do 5/1023 So step process to find the range.
We multiply the value of this result, we have found so ADC voltage.
Serial . print (voltage);
Serial . println ( "V" );
delay (100);
}
Where you want to measure the voltage measurement cable from the A0,
in the circuit of your soil Connect the ends from GND.

CAUTION: Never, never try to measure values ​over 5 volts. Such an


error
5 volts to a Zenner diode circuit to prevent reverse to link helpful
can.

Temperature measurements with LM35


One of the most basic applications that let measurement with LM35
temperature sensor. LM35 There are three pins of the sensor. These are +
5V, GND and DATA are the feet. Value from Data feet we need to convert
to digital by the ADC.

Let's make connections as illustrated. When you look at the location of the
sensor core in a row, so write us see when the first pin 5 volts, the middle
pin Arduino analog input pin 3 and the ground (GND) It must be
connected.

Come on, let's move on software ... read analog signals and we need to do
with mathematical operations to translate the temperature. Translate value
that we'll send to the computer.
float temperature;

void setup ()
{
Serial . begin (9600);
}
void loop ()
{
Temperature = analogread (A0);
Temperatures * Temperature = 0.48828125;
Serial . print ( "TEMPERATURE =" );
Serial . print (heat);
Serial . println ( "C" );
delay (500);

Making Impact Robot with Arduino

Let's start making our first robot. we see from the course to make our robot
We will use our sensor on our and DC motor drives. If have information
about these topics Do not be useful to review these issues again.
Come on, Let's get started ... First, let's get our materials list:
- 1 chassis: a plate to secure all materials and engines
- 2 DC motors
- 2 wheels: DC motor end must fully comply
- 1 motor drive: is it made our own
- 1 wheel drunk: Or a rod to reduce friction with the surface (I usually
I use the LED head)
- Battery: 11.1 Volt LiPo batteries would be appropriate. 9-volt battery is
inadequate for engines
Try going to need
- 3 x HC-SR04 Distance Sensor
- And of course, an Arduino
Let's first robot mechanics. our chassis Let's place behind the two
engines. The front of the robot Let's put our drunk one. If we Drunk LEDs
underneath the robot so as to ensure a balance Let's put. and our DC
motor's put our wheels
Let 's stand in the balance of our robot. Now a nice place for our Arduino
and motor drives Let's set. Do good robot comfortable wiring test It will
allow you to. Finally sensors 0-90-180 Let's place as degrees. placement of
the robot will be like in the picture. Electronic connections in previous
issues Let's carefully as we speak.
Let's go to the software that we've finished the wiring, and let us test our
robot.

const int milking of = 9;


const int sagger 8 =;
const int soli in = 12;
const int Solger = 13;
const int solenabl A = 11;
const int sagenabl = 10;
/*
trigpin1 from our sensor on the left and echopin1 =
Our distance sensor on the front trigpin2 and echopin2 =
Our sensor on right away and echopin3 trigpin3 =
*/
int trigpin1 = 6;
int echopin1 = 7;
int trigpin2 = 4;
int echopin2 = 5;
int trigpin3 = 2;
int echopin3 = 3;
float distance ( int trigp of, inter echop a) {
float olcum;
float cm;
digitalwrit A (trigp's, LOW );
delaymicroseconds (5);
digitalwrit A (trigp's, HIGH );
delaymicroseconds (10);
digitalwrit A (trigp's, LOW );
olcum = pulse (echop's, HIGH );
cm = olcum /29.1/2;
return cm;
}
void forward ( int hizsag, int hizsol) {
analogwrit A (sagenabl A, hizsag);
digitalwrit A (milking of, HIGH );
digitalwrit A (sagger is LOW );
analogwrit A (solenabl A, hizsol);
digitalwrit A (soli are HIGH );
digitalwrit A (Solger is LOW );
}
void reverse ( int hizsag, int hizsol) {
analogwrit A (sagenabl A, hizsag);
digitalwrit A (milking of, LOW );
digitalwrit A (sagger is HIGH );
analogwrit A (solenabl A, hizsol);
digitalwrit A (soli are LOW );
digitalwrit A (Solger is HIGH );
}
void stop ()
{
digitalwrit A (milking of, HIGH );
digitalwrit A (sagger is HIGH );
digitalwrit A (soli are HIGH );
digitalwrit A (Solger is HIGH );
}
void setup () {
In pinmo (milking of, OUTPUT );
In pinmo (sagger of OUTPUT );
In pinmo (soli, the OUTPUT );
In pinmo (Solger of OUTPUT );
In pinmo (sagenabl A, OUTPUT );
In pinmo (solenabl A, OUTPUT );
In pinmo (trigpin1, OUTPUT );
In pinmo (echopin1, INPUT );
In pinmo (trigpin2, OUTPUT );
In pinmo (echopin2, INPUT );
In pinmo (trigpin3, OUTPUT );
In pinmo (echopin3, INPUT );
}
void loop () {
while (distance (trigpin2, echopin2) <10) { // until the front obstacle
go straight
forward (100,100);
}
Stop(); // stop barrier after arriving
delay (1000); // Wait 1 second
if (distance (trigpin1, echopin1)> 10) { // left bond
forward (150.0); // turn left or obstacles
delay (500); // will pass while returning up to 90 degrees. This time
yourself
Adjust
Stop(); // stop
delay (1000);
} Else if (distance (trigpin3, echopin3)> 10) { // if left to the right look full
forward (0.150); // Return obstacles or right
delay (500); // will pass while returning up to 90 degrees. This time
Adjust yourself
Stop(); // stop
delay (1000);
} Else { // If there are obstacles left and right let's go back
return (100,100);
delay (1000);
forward (150.0);
delay (500);
Stop();
delay (1000);
}
}

Creatng some changes to the code and the code of robots to work in
accordance with You may need to make.
This can be done by robots robot that solves the maze. Here, it is exactly
90 degrees robot That he can return.

Making Simple Line Follower Robot with Arduino

Let's design a robot similar to a previous project we have. But, this time
from sensors sokelee and facing the front of the robot and the floor to be 1-
2 cm above the ground, black / white Let's put our sensors. This robot will
use our CNY70 3 units. That's why 3 to tie one of these sensors in the way
we told before. First I must say that we have seen in a line following robot
competition quality up We will not do. That way we need to use the PID to
make a robot. But we need it We will do more than a simple robot without.
Come on, Let's get started ... First, let's get our materials list:
- 1 chassis: a plate to secure all materials and engines
- 2 DC motors
- 2 wheels: DC motor end must fully comply
- 1 motor drive: is it made our own
- 1 wheel drunk: Or a rod to reduce friction with the surface (I usually
I use the LED head)
- Battery: 11.1 Volt LiPo batteries would be appropriate. 9-volt battery is
inadequate for engines Try going to need
- 3 CNY70: Connections can use on a card making
- And of course, an Arduino
Let's start with the programming. In previous issues we have learned
through our project codes
We will write.

const int milking of = 9;


const int sagger 8 =;
const int soli in = 12;
const int Solger = 13;
const int solenabl A = 11;
const int sagenabl = 10;
int sensorp to [3] = {A0, A1, A2}; // links of our sensors
int digitalized ( int value, int sensor) {
int esikdeger of;
switch (sensor) {
Remember to set the threshold value according to your own sensor on //
// Threshold values ​for "Black and White Control with the Arduino" topic
You can see
case 0:
esikdeger of = 900;
break ;
case 1:
esikdeger U = 820;
break ;
case 2:
esikdeger U = 820;
break ;
}
if (esikdeger of <value)
return 1;
else
return 0;
}
void forward ( int hizsag, int hizsol) {
analogwrit A (sagenabl A, hizsag);
digitalwrit A (milking of, HIGH );
digitalwrit A (sagger is LOW );
analogwrit A (solenabl A, hizsol);
digitalwrit A (soli are HIGH );
digitalwrit A (Solger is LOW );
}
void setup () {
In pinmo (milking of, OUTPUT );
In pinmo (sagger of OUTPUT );
In pinmo (soli, the OUTPUT );
In pinmo (Solger of OUTPUT );
In pinmo (sagenabl A, OUTPUT );
In pinmo (solenabl A, OUTPUT );
}
void loop () {
if (digitalized ( analogread (sensorp in [1]), 1)) {
forward (100,100);
}
if (digitalized ( analogread (sensorp the [0]), 0)) {
forward (0.100);
while (! digitalized ( analogread (sensorp the [0]), 0));
}
if (digitalized ( analogread (sensorp of [2]), 2)) {
forward (100.0);
while (! digitalized ( analogread (sensorp of [2]), 2));
}
}

Making Bluetooth Controlled Robot with Arduino

First, make sure you understand the issues that we do Arduino and
Bluetooth control. It We will manage our TERA TERM via bluetooth
using the robot program in the project. One Robot rules we set in our
previous projects. Our sensors and bluetooth draw Let's connect our
module.
- 1 chassis: a plate to secure all materials and engines
- 2 DC motors
- 2 wheels: DC motor end must fully comply
- 1 motor drive: is it made our own
- 1 wheel drunk: Or a rod to reduce friction with the surface (I usually
I use the LED head)
- Battery: 11.1 Volt LiPo batteries would be appropriate. 9-volt battery is
inadequate for engines Try going to need
- Bluetooth module
- And of course, an Arduino
If the Bluetooth module will be blinking light if we do everything
right. Speaking of more I want to get programming from the
extension. The robot is to act It will wait for commands from the
computer. This command keyboard out of our program TERA TERM
We'll give. The robot is the 'w' advanced, 'x' will go back; 'A' left, 'd' to
turn right and 's' key will stop by.
So let's start…

const int milking of = 9;


const int sagger 8 =;
const int soli in = 12;
const int Solger = 13;
const int solenabl A = 11;
const int sagenabl = 10;
void forward ( int hizsag, int hizsol) {
analogwrit A (sagenabl A, hizsag);
digitalwrit A (milking of, HIGH );
digitalwrit A (sagger is LOW );
analogwrit A (solenabl A, hizsol);
digitalwrit A (soli are HIGH );
digitalwrit A (Solger is LOW );
}
void reverse ( int hizsag, int hizsol) {
analogwrit A (sagenabl A, hizsag);
digitalwrit A (milking of, LOW );
digitalwrit A (sagger is HIGH );
analogwrit A (solenabl A, hizsol);
digitalwrit A (soli are LOW );
digitalwrit A (Solger is HIGH );
}
void stop ()
{
digitalwrit A (milking of, HIGH );
digitalwrit A (sagger is HIGH );
digitalwrit A (soli are HIGH );
digitalwrit A (Solger is HIGH );
}
void setup () {
Serial . begin (9600);
In pinmo (milking of, OUTPUT );
In pinmo (sagger of OUTPUT );
In pinmo (soli, the OUTPUT );
In pinmo (Solger of OUTPUT );
In pinmo (sagenabl A, OUTPUT );
In pinmo (solenabl A, OUTPUT );
}
void loop () {
if ( Serial . available ()> 0) { // We expect data from Bluetooth
char button = ( char ) Serial . read ();
if (key == 'w' )
forward (100,100);
if (key == 's' )
Stop();
if (key == 'a' )
forward (0.100);
if (key == 'd' )
forward (100.0);
if (key == 'x' )
return (100,100);
}
}
LAST…

You might also like