Saturday 14 February 2015

Arduino DC Motor Driving

Arduino Motor Driving

Arduino and L293B

       We will make another simple project with Arduino. This project's name is Arduino motor driving! We will learn how to control a motor with Arduino. Firstly we will control the motor's speed by a potentiometer. Then we will learn what is the PWM and how to change the motor's speed by the PWM.

We need,
  • Potentiometer
  • An Arduino board
  • L293D Motor Driver
  • 9V Battery
to make this project. I used L293D motor driver and 5K potentiometer but you can use L293B motor driver and any other potentiometer. This is the sketch of the circuit.


The difference between L293D and L293B is the current limit. L293D's current limit is 0.5 A and L293B's current limit is 1A. Now, we can see the code.



void setup() {
//we arrange pins, which we will use, as output 
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(11, OUTPUT);
}

//loop function will repeat while Arduino is powered on

void loop() {

/* 8th and 9th pins are input pin to motor driver.
 we arrange 8th pin as HIGH to get 5V output and 9th LOW to get 0V.
 if we arrange both of them as HIGH or LOW, motor will not work. 11th pin is PWM pin. 
 we arranged it as HIGH to make it disabled. */

digitalWrite(8, HIGH); 
digitalWrite(9, LOW);
digitalWrite(11, HIGH);

}

       When we load this code to Arduino, we will arrange the speed of the motor with potentiometer.

       Now, we will change the motor direction with code. Do not use the potentiometer for this time. Directly connect the motor to the motor driver's output pin. Look at the sketch.





void setup() {
//we arrange pins, which we will use, as output 
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(11, OUTPUT);
}

//loop function will repeat while Arduino is powered on

void loop() {

/* 8th and 9th pins are input pin to motor driver.
 we arrange 8th pin as HIGH to get 5V output and 9th LOW to get 0V.
 if we arrange both of them as HIGH or LOW, motor will not work.

 11th pin is PWM pin. 
 we arranged it as HIGH to make it disabled. */

digitalWrite(8, HIGH); 
digitalWrite(9, LOW);
digitalWrite(11, HIGH);

// motor will work for 3 seconds 

delay(3000);

//we should let the motor to stop
digitalWrite(11, LOW);
delay(1000);


//we will change the 8th and 9th pins' values. then motor will change its direction 

digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(11,HIGH);

delay(3000);

}


Now, we will change the motor speed by changing the PWM value in the code. We will use a special function for this: " analogWrite() ". Let's see the code


void setup() {
//we arrange pins, which we will use, as output 
 
 pinMode(8, OUTPUT);
 pinMode(9, OUTPUT);
 pinMode(11, OUTPUT);
}

//loop function will repeat while Arduino is powered on

void loop() {

/* 8th and 9th pins are input pin to motor driver.
 we arrange 8th pin as HIGH to get 5V output and 9th LOW to get 0V.
 if we arrange both of them as HIGH or LOW, motor will not work.

 11th pin is PWM pin. 
 We will use analogWrite() function to arrange the motor's speed. */

digitalWrite(8, HIGH); 
digitalWrite(9, LOW);
analogWrite(11, 255);  //This function has a range from 0 to 255


}


Let's watch the video to see how it works. We finished that project. As an idea, you can control the motor with a button. We will make an other project in a short time. Keep in touch!

If you liked this post please subscribe it to reach more people! Thank you :)


Sunday 1 February 2015

Arduino Serial Port

Arduino Serial Port

UART/USART

       We will speak about Serial Communication on Arduino. Serial Communication means transmitting and receiving data on the same cable. To provide this we use UART (Universal Asynchronous Receiver Transmitter)/USART(Universal Synchronous Asynchronous Receiver Transmitter) communication units. Roughly, serial communication is the process to send data with starting bit, data bit, parity bit and stop bit. We can adjust the communication speed with the unit of bit speed which is called as BAUD RATE. Now, let's learn how to do it.
       Arduino lets us to communicate with a computer or any other device by using serial port. Actually, we use the serial port uncounsciously while loading the code to the Arduino. We can use serial port in different projects. We will make a simple application for this. Arduino presents us special codes to use for serial communication. Firstly, we should specify begining, baud rate and then the data which we will send or receive. Of course we want to see the results and Arduino has a screen to see them. We can see it by clicking on the burning glass on the main screen of Arduino IDE. It is on the upper right corner.



When we connected Arduino board to pc and clicked on the glass, this screen will be on.


It is possible to see the value of BAUD RATE on the lower right corner. We can adjust it from there. Pay attention BAUD RATE values on the screen and in the code must be same to send and receive data properly.

We will make an application to see the time on the serial port screen.



// we declare time variable to show the time
int time=0;

void setup() {

/* starting to serial communication use Serial.begin comand.
 The value which is between paranthesis, shows the baud rate */ 

Serial.begin(9600);

}

void loop() {
  
/* we use Serial.print command to have write what we want to see on the screen */
  
    Serial.print("Connection Time: "); 
  
/*Serial.println command has a small difference. it passes to next line after
ownself */

  
   Serial.println(time);
   time++;
  
  /* arduino uses milisecond as the time unit. 
 we use 1000 milisecond delay command for 1 second */
   delay(1000);

}

After loading the code to Arduino, we will see the connection time on the screen. We just added serial communication application to our projects. We will make higher level projects about this issue. Keep in touch!

If you liked this post please subscribe it to reach more people! Thank you :)

Thursday 29 January 2015

Arduino 7 Segment

Arduino 7segment

       One of the simple projects with the Arduino is 7 segment project. 7 segment is a display device to show numbers. It includes 7 or 8 LED and this is where its name comes.



       There are two type of 7 segments; common anode, common cathode. When we want to use common cathode(-), we should connect the common pin to ground and other pins to Arduino and we should arrange the output as 5V for which LED's we want to turn on. If we want to use common anode(+), we should connect the common anode(+) pin to another digital pin adn its output voltage must be 5V. Than we should arrange the output as 0V for which LED's we want to turn on. And of course we should use a resistor to protect LED's. Connect the resistor to common pin instead of using resistor for every pin. As a result of this common cathode(-) is more usable. There is a schematic for a common cathode(-) 7 segment.



       There are some borders for Arduino. Current border for Arduino is 40mA for a pin and the total upper border is 200mA. We should compute the current to protect Arduino. I do not suggest you to force theese borders especially for the clon Arduino.
       If we do not know the type of 7 segment, we can learn it with a simple test. Use a cable and 1KΩ resistor. Connect the resistor to cable and the cable to Arduino's 5V pin. Use another cable and connect this cable to ground pin. First of all choose a pin and connect the ground cable to this pin. Then start to check other pins with 5V cable. If you see the light, your 7 segment is common cathode(-) and the ground connected pin is common pin. If you cannot see the light, change the pin for ground. If you still do not see the light, hold the 5V pin and start to check with ground pin. If you see the light, your 5V pin is the common anode(+) pin.



Theese are the pin connection numbers for 7 segment. It makes easier the codding. 













The code should be like this for the common cathode(-) 7 segment

/*First of all we decide the pins for 7 segment and we arrange them as output pin. */ 

void setup() {
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}

void loop() {
  /* We decided the pins in SETUP function.
 Now, we are arranging the values of pins to turn the LED's on*/
  
//for the number 0
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);
//number 1
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
  delay(1000);

//number 2
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 3
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13,LOW);
  delay(1000);
 
//number 4
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
  delay(1000);

  
//number 5
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 6
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 7
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, LOW);
  delay(1000);
//number 8
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//number 9
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
digitalWrite(12, HIGH);
digitalWrite(13, LOW);
  delay(1000);

//for dot
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
digitalWrite(13, HIGH);
delay(1000);
}

       We should see the numbers in an order as a result of this project. Making different projects with 7 segment is possible. You can increase or decrease the numbers with a button. We are here for your suggestions and questions. Keep in touch!


If you liked this post please subscribe it to reach more people! Thank you :)

Tuesday 27 January 2015

Arduino LED

Arduino LED

       There is no border to do samething with Arduino. Everything is about over dreams. But, however we cannot run when we born, we should start to try with Arduino from the beginning. The first project with other development boards  and Arduino is LED lighting process. Even though being a simple project, it is very helpful to learn basics about coding and electronics. We will write our codes and make our circuit. After that, we will see the code in Arduino Library. One of the reasons what makes Arduino the most popular development board is its library. We can use codes from the library directly and we can learn how to code from there.
       We need the Arduino interface program to use Arduino. We will load our codes to it with this program which is called as IDE(Integrated Development Environment). You can download it from this 

connection

 .  When we download this IDE, we get the library. Theese codes are developed inspiring from C/C++ language. Knowing basics about this language has advantages. This is basic screen of IDE.





     
       Different versions of software are available. Older versions screen is empty but in the new versions Setup and Loop functions are writed by IDE with small explanations.

When we click on the FOLDER, we can choose the NEW to open a new folder. If we want to open an older file, we can use the OPEN for this. Also, we can choose Examples to reach the library. We use USB cable to connect Arduino with the PC. We use B type USB for this. Lights will be on after connection. We can see the port number when we open the IDE.

       Our first step is LED lighting with Arduino. We need basic electronical information for this. We will use red LED and we should know its voltage and current border to decide our resistor's ohm. LED means Lighting Emitting Diode. It is used to understand current existence. In addition, it is used for the illumination.

       There is a sketch for the connection.


       We should connect the anode(+) pin to digital I/O pin and cathode(-) pin to ground. We will get 5V as a digital output from the 8th pin. But this voltage is high for the LED. So we should use a resistor. Theoretically LED 's current border is 20mA but mostly it is not same in real. So we will choose the resistor for 10mA. Red LED's voltage is 1.7V. To calculate the resistor, 5-1.7=3.3V 3.3:0.01=330 ohm. We get the valeu of the resistor with basic formula V=IR. Resistor's value is 330 ohm. we can connect it to anode or cathode, it does not matter. Now we can write our code. We choose 8th pin for the connectionto cathode.
     

void setup() {

  // we make the 8th pin as output

  pinMode(8, OUTPUT);

}

// the code in loop function repeats during Arduino power on.

void loop() {

  digitalWrite(8, HIGH);   // Make 8th pin HIGH to get digital HIGH
                           // It gives 5V output to turn LED on

  delay(1000);             // To decide LED's working time
                           

  digitalWrite(8, LOW);    // Gives 0V output to turn LED off.

  delay(1000);              // To decide LED'S off time

}

       Our code is ready but we should load it to Arduino. We will use the right sided arrow on the upper left corner of the screen.




       We made our first project with Arduino. You can make a project with more LED. You can change their on/off time to get something interesting. We will meet with next project again. Keep in touch!

Friday 16 January 2015

Arduino World

Arduino World

Arduino Development Boards




       We mentioned about Arduino development boards in the last writing. Now, let's meet the Arduino family closer. Though, Arduino mostly uses for hobby projects, it is useable for high level projects. To meet with this demand, Arduino family has many different members. Arduino provides that flexibity not only electronical but also physical changings.
       We will mention interesting and common members of Arduino family. We spoke about Arduino Uno in the first writing.




       Arduino Uno is the most common model of Arduino. Creaters of Arduino suggest Uno for beginners. Arduino Uno is produced for general usage. It has an average clock speed and memory. It does not have many pin to connect and this resists its usage for projects with many sensors and motors. But, it is good for the projects, which need small quantity of component, based on software. Of course,  we should take the clock speed and memory into account.

Technical Properties
  • 16 Mhz clock speed
  • 32 KB Memory
  • 7-12 V Power supply Range (Operating Voltage 5 V)
  • 2 KB RAM
  • 14 Digital I/O(Input/Output) Pin, (6 of them are PWM Pin)
  • 6 Analog Input Pin

 
Detailed technical information:  Arduino UNO


Roughly, we can say Arduino Uno is very good for begining and projects like line follower robot, mini sumo robot. We said its price is between 20-25$ for the original and 7-8$ for the clon Arduino. It is very cheap on the websites like www.alibaba.com. But clon Arduino is not reliable and durable like original Arduino.

Kabaca Arduino Uno için başlangıç adına oldukça güzel bir kart olduğunu, çizgi izleyen, labirent çözen, sumo, merdiven çıkan gibi basit robotların yapılmasında rahatlıkla kullanılabileceğini söylemek en doğrusu. Fiyat aralığının orijinal ürün için 20- 25$ civarlarında gezindiğini söylemekte fayda var. Ancak yurt dışı kaynaklı sitelerde, özellikle de www.alibaba.com gibi internet sitelerinde oldukça uygun fiyatlara kopya üretimlerini bulmak mümkün. Fiyatın 7- 8$ düzeylerine kadar düştüğü oluyor. Ama ucuz etin yahnisi yavan olur derler, aldığınız kopya, diğer adıyla klon arduinoların güvenilirliği ve kullanılan malzemelerin kalitesi elbette ki orijinalinin yerini tutmuyor.

ARDUINO MICRO

       Another member of the family, the little child of the family is Arduino Micro. It is usable for the projects with small dimensions. It is smaller than its brother Uno; also, its properties are better. But the disadvantage for Micro is that the bootloader software, which is needed to make the Arduino programmable easily, uses bigger capacity from the memory. Bootloader uses 0.5 KB memory in the Uno but it uses 4 KB memory in the Micro. That causes from the processor. Uno uses another processor for the bootloader but Micro use the cpu, to be smaller.

Technical Properties
  • 16Mhz Clock Speed
  • 32 KB Memory
  • 7-12 V Power Supply Range (Operating Voltage 5 V)
  • 2.5 KB Ram
  • 20 Digital I/O Pin (7 of them are PWM Pin)
  • 12 Analog Input Pin







Detailed technical information: Arduino MICRO


If we speak about reasons which makes the Micro as Micro, Uno's dimensions are 7x5.5 cm but Micro's dimensions are aproximately 5x2 cm. Their prices are aproximately same. At the same time their performances are not so different, too. All about your choise for your usage type.  Micro'yu micro yapan boyutsal özelliklerine gelecek olursak Uno yaklaşık olarak 7x5.5 cm boyutlarındayken Micro yaklaşık olarak 5x2 cm boyutlarında. Fiyat olarak birbirlerine oldukça yakın fiyatlarda olduklarını söylemek gerek. Zaten performans olarak inanılmaz bir farka sahip değiller. Tamamen kullanım amacınıza yönelik karar vermek en doğrusu.

ARDUINO LILYPAD

       Family's madcap child is LILYPADLILYPAD is developed mostly for wearable technology. It is very small and washable. That is a new property for a technological device but you should be sure about power off. Lilypad catches up other models with its technical properties that's why it is useful for different projects. Its price is about 25$ on the original website Arduino store. Again clon models are cheaper.

Technical Properties
  • 8 Mhz Clock Speed
  • 32 KB Memory
  • 3.8-5 V Power Supply Range (Operating Voltage is 3.3 V)
  • 2.5 KB Ram
  • 9 Digital I/O Pin (4 of them are PWM Pin)
  • 4 Analog Input Pin




 
Detailed technical information:  Arduino LILYPAD


       Lilypad has a circled shape with 18 mm diameter. It is like a badge which we put to our bags. If we speak about Lillypad, it is possible to make crazy and different projects. You can watch the video which is about a project with Lilypad.





ARDUINO MEGA

        Let's continue with the older child of the family, MEGA. With its dimensions and properties, Mega is bigger than others. Mega is produced to use for complex and higher level projects.


Arduino MEGA is best for the veteran users with its high clock speed, pin numbers and memory. Of course its price becomes more expensive with higher properties. Original Mega has a price about 40$ on the Arduino store. Clon models are cheaper.

Technical Properties
  • 16 Mhz Clock Speed
  • 256 KB Memory
  • 7-12 V Power Supply Range (Operating Voltage is 5 V)
  • 8 KB Ram
  • 54 Digital I/O Pin (14 of them are PWM Pin)
  • 16 Analog Input Pin


Detailed technical information: Arduino MEGA

       Arduino has MINI, NANO, YUN, LEONARDO  and more models except UNO, MICRO, LILYPAD and MEGA. Arduino publishes every products as open source and it improves with contributions of developers from all around the world. In addition, Arduino produces many devices like gprs module, ethernet module and communication module like Xbee. Also, Arduino produces t-shirt, sticker, cup, glass, accessories for the robots like body and wheel. Besides, Arduino let's you to make your own Arduino. They sell empty shield and they publish schematics of Arduino. You can make your own Arduino by using them. You can download bootloader from the internet. You should use ARM microcontroler for Arduino and you need another programmer to load the bootloader to microcontroller.

       We mentioned about Arduino family detailed in this writing. To learn more about Arduino you can visit official website of Arduino. We will continue with the Arduino projects in the next writings. Keep in touch!