Jumat, 25 Desember 2015

Menyimpan data dengan Arduino Data Logger

Data logger merupakan data penyimpanan ke external memory atau ke SD Card, penggunaan data logger ini biasanya untuk menganalisa/mendapatkan data dari suatu kondisi di tempat tertentu. Misal untuk perubahan suhu per satuan waktu di tempat tertentu.

Pada percobaan kali ini modul yang di gunakan adalah modul dari deek-robot

 

Selain data logger, Modul ini juga langsung ada RTC (Real Time Clock) untuk pencatat waktu.
Mancoba data logger,

Konfigurasi data logger dengan arduino menggunakan koneksi SPI, maka untuk pin di arduino UNO bisa menggunakan pin sebagai berikut :
MOSI - pin 11
MISO - pin 12
CLK - pin 13
CS - pin 10





#include <SPI.h>
#include <SD.h>

const int chipSelect = 10;

void setup() {
  Serial.begin(9600);
  Serial.print("Initializing SD card...");
  // inisialisasi card
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop() {
  String dataString="okelah";
  // membuka file, hanya satu file yang dibuka pada penggunaan data logger

  File dataFile = SD.open("datalog.txt", FILE_WRITE);

  // menulis data:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print ke serial port:
    Serial.println(dataString);
  }
  else {
    Serial.println("error opening datalog.txt");
  }
}

Kamis, 09 Juli 2015

Membuat Tampilan Pada LCD Nokia 5110 Menggunakan Arduino

Akses LCD Nokia 5110 dengan Arduino uno

Holaaaa sobat arduino indonesia, dan para penghobi arduino. Kali ini kami akan memberikan tutorial akses LCD Grafik Nokia 5110 menggunakan arduino uno. Lcd 5110 mempunyai 8 pin. yaitu:

RST, CE, Din, Clk, Vcc, Bl, Gnd

 berbeda dengan lcd grafik seperti biasanya yang menggunakan level TTL 5V, 5110 menggunakan level tegangan TTL 3.3V dan VCC 3.3V. Sehingga, jika arduino sobat masih menggunakan tegangan logika 5v, perlu diberi IC 4050.

Skema rangkaiannya..


ini source codenya:

// Nokia 5110 LCD-Display (84x48 Sekolah Robot Indonesia)
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// D7 - Serial clock out (CLK oder SCLK)
// D6 - Serial data out (DIN)
// D5 - Data/Command select (DC oder D/C)
// D4 - LCD chip select (CE oder CS)
// D3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

static const unsigned char PROGMEM sri[] = {
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00001000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00011000,B00000000,B00000000,B00000000,B00001000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B10000011,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B01111111,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000111,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00001000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00111000,B00000000,B00000000,B00000010,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00011111,B11111000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00011111,B10001000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00001111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000001,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000010,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B01000000,B00000000,B00000000,B00000000,B00001000,B00000000,B10000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000010,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000100,B00000000,B00000000,
B00000000,B00000100,B00000000,B00000000,B10000000,B00000000,B00000000,B00000000,B00000100,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B10000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00101100,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000011,B11000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
};



static const unsigned char PROGMEM logo[]= {                                              // width 40, height 32
B00000000,B00000000,B00000000,B00000000,B01111110,
B00000000,B00000000,B00000000,B00000000,B00101110,
B00000000,B00000000,B00000000,B00000000,B00101010,
B00000001,B11111000,B00000000,B00001111,B10000000,
B00000111,B11111110,B00000000,B00111111,B11100000,
B00011111,B11111111,B10000000,B11111111,B11111000,
B00111111,B00000111,B11000001,B11110000,B11111100,
B00111100,B00000011,B11100011,B11100000,B00111100,
B01111000,B00000000,B11110111,B10000000,B00011110,
B01110000,B00000000,B01110111,B00000110,B00001110,
B11100000,B00000000,B00111110,B00000110,B00000111,
B11100001,B11111000,B00111110,B00011111,B10000111,
B11100001,B11111000,B00011100,B00011111,B10000111,
B11100000,B00000000,B00111110,B00000110,B00000111,
B11110000,B00000000,B00111110,B00000110,B00001111,
B01110000,B00000000,B01110111,B00000000,B00001110,
B01111000,B00000000,B11110111,B10000000,B00011110,
B00111100,B00000011,B11100011,B11100000,B00111100,
B00111111,B00001111,B11000001,B11110000,B11111100,
B00011111,B11111111,B00000000,B11111111,B11111000,
B00000111,B11111100,B00000000,B00111111,B11100000,
B00000001,B11110000,B00000000,B00001111,B10000000,
B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,
B01110011,B11001111,B00100010,B11100100,B01001110,
B10001010,B00101000,B10100010,B01000100,B01010001,
B10001010,B00101000,B10100010,B01000110,B01010001,
B11111011,B11001000,B10100010,B01000101,B01010001,
B10001010,B10001000,B10100010,B01000100,B11010001,
B10001010,B01001000,B10100010,B01000100,B01010001,
B10001010,B00101111,B00011100,B11100100,B01001110,//40x32};
};

static const unsigned char PROGMEM sri_logo[]={
  B00000000,B00000000,B00000000,B00001111,B11111101,B11111100,B11110011,B10000011,B10001110,B11100000,B00000000,
B00000000,B00000000,B00000000,B00011111,B01111101,B11011001,B11111011,B10000011,B10001110,B11100000,B00000000,
B00000000,B00000001,B00000000,B00011000,B01101001,B10110011,B10011001,B10000011,B10001100,B11000000,B00000000,
B00000000,B00000010,B00000000,B00011100,B01110001,B11100011,B00001101,B10000011,B11001111,B11000000,B00000000,
B00000000,B00010010,B00000000,B00000111,B01110001,B11110011,B00001101,B10000111,B11001111,B11000000,B00000000,
B00000000,B00001010,B00000000,B00010011,B01101101,B10111011,B10011001,B10100111,B11001100,B11000000,B00000000,
B01110000,B00000111,B11000000,B00011111,B11111101,B11111101,B11111011,B11111110,B11111110,B11100000,B00000000,
B10011000,B00001111,B00010000,B00011110,B01111001,B11000000,B11100001,B11111110,B01111110,B11100000,B00000000,
B10001000,B00011110,B00000010,B00001100,B10000000,B00000000,B00000000,B00000010,B00000000,B00110000,B00000000,
B01111000,B00100110,B01001110,B00011111,B11100001,B11111100,B11111110,B00011111,B11001111,B11110000,B00000000,
B00011100,B00000010,B00001110,B00011111,B11110011,B11111110,B11111111,B00111111,B11001111,B11110000,B00000000,
B00001110,B01001011,B00011110,B00001110,B01110011,B10001110,B01110111,B00111000,B11101101,B10110000,B00000000,
B00000111,B00000011,B11111110,B00001110,B01110111,B00000111,B01111110,B01110000,B01100001,B10000000,B00000000,
B00000111,B11110111,B11111000,B00001111,B11110111,B00000111,B01111110,B01110000,B01110001,B10000000,B00000000,
B00000001,B11111111,B11110010,B00000111,B11100111,B00000111,B01111111,B01110000,B01110001,B10000000,B00000000,
B00000000,B11111111,B11100010,B00001111,B11000111,B00000111,B01110011,B11110000,B11110001,B10000000,B00000000,
B00000000,B00101111,B10000110,B00001111,B11100111,B10011110,B01110111,B01111001,B11100001,B10000000,B00000000,
B00000000,B01100000,B00001110,B00011111,B01110011,B11111110,B11111111,B00111111,B11000011,B11000000,B00000000,
B00000000,B01110000,B00111110,B00011110,B01110001,B11111100,B11111110,B00011111,B11000011,B11000000,B00000000,
B00000000,B01111111,B11111110,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B01111111,B11111110,B00011101,B00011111,B10000011,B00010001,B10111000,B11011101,B11000000,B00000000,
B00000000,B01111111,B11000110,B00011101,B10111111,B11100111,B10011011,B11111101,B11111101,B11000000,B00000000,
B00000000,B00111111,B10000010,B00001001,B11010010,B00111100,B11011101,B00110001,B00001000,B11000000,B00000000,
B00000000,B00000001,B10000000,B00001001,B11110010,B00111000,B01011111,B00111000,B11001001,B11100000,B00000000,
B00000000,B00000001,B10000000,B00001001,B10110010,B00111000,B11011011,B00110000,B01101001,B11100000,B00000000,
B00000000,B00000000,B00000000,B00011101,B10110011,B11101111,B10011011,B00111111,B11111111,B10110000,B00000000,
B00000000,B00000000,B00000000,B00011101,B10010011,B10000111,B00011001,B00111001,B11001111,B00110000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000011,B11111111,B11111111,B11111111,B11100000,
B00000000,B00000000,B00000000,B11111111,B11111111,B11111111,B11111111,B11111111,B11011100,B10000000,B11000000,
B00000000,B00000000,B00000001,B11111111,B11111101,B10110010,B11101010,B00100000,B00000001,B10000000,B11100000,
B00000000,B00000000,B00000001,B10100100,B00010010,B10010010,B11101000,B00100001,B00000001,B11111111,B11110000,
B00000000,B00000000,B00000001,B10100100,B10010010,B10010000,B10101000,B10111111,B11111111,B11111110,B00000000,
B00000000,B00000000,B00000001,B11000100,B10010010,B11111011,B11111111,B11111111,B11000000,B00000000,B00000000,
B00000000,B00000000,B00000001,B10110111,B11111111,B11111111,B11111000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000001,B11111111,B11111111,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
B00000000,B00000000,B00000001,B11100000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,B00000000,
};

void setup()   {

  // Inisialisasi Tampilan
  display.begin();

  // Kontras
  display.setContrast(60);
  display.clearDisplay();   // clears the screen and buffer

}


void loop() {

  display.setTextSize(1); //ukuran teks

  //  (Baris,Kolom,"Teks",warna);

  //set_text(0,0,"Hallo apa kabar?? ",BLACK);
  //delay(500);
  //display.clearDisplay();
  //delay(500);

  //display.drawBitmap(Baris,Kolom,nama_char,pixel_X,pixel_Y,warna);
  display.drawBitmap(0, 0, sri_logo, 84, 39, BLACK);
  display.display();


   }

void set_text(int x,int y,String text,int color){

  display.setTextColor(color); // Warna teks
  display.setCursor(x,y);      // posisi kursor text (Baris, Kolom)
  display.println(text);       // tulisan
  display.display();           // menampilkan hasil
}

------------------------------------------------------------------------------------------------------------
Hasilnya:




------------------------------------------------------------------------------------------------------------
Tips-tips nya bikin tampilan di lcd 5110
1. Ubah gambar dengan format .bmp
2. ukuran pixel gambar <= 84 x 48
3. konversi gambar .bmp manjadi berbentuk kode BINER.
4. Copy kode BINER ke dalam sketch arduino.
5. dengan format "static const unsigned char PROGMEM nama_gambar" (tanpa tanda petik saat diketik pada sketch)
6. Ukuran gambar dengan pixel pada sketch harus sama. misal, gambar ukuran 30 x 20. Maka pada sketch diketik "display.drawBitmap(0, 0, nama_gambar, 30 x 20, BLACK);" (tanpa tanda petik saat diketik pada sketch)


image to binner:
https://github.com/Rodot/BitmapEncoder/blob/master/BitmapEncoder.jar


library pcd8544:
https://github.com/adafruit/Adafruit-PCD8544-Nokia-5110-LCD-library

library grafiknya GFX:
https://github.com/adafruit/Adafruit-GFX-Library

Senin, 22 Juni 2015

Mobile Robot Omni Wheel dengan Arduino

Hallo Sobat Arduino Indonesia, pada puasa kan :). Puasa-puasa gini enaknya ngerjain apa ya? berhubung di Workshop  ada roda omni wheel yang terpakai, kita coba buat mobile Robot yang pake roda omni wheel yuk!

oke yang perlu di siapkan sebagai berikut
Untuk mekanik mobile robot




  1. omni wheel 3 buah
  2. motor dc flying 3 buah
  3. bracket motor akrilik 3 buah
  4. shaft motor dengan roda omni 3 buah
  5.  mekanik robot bisa di bikin dari cutting akrilik

untuk elektronik

  1. Arduino Uno
  2. Driver 3 channel (untuk kali ini kita bikin sendiri driver ic l293 sebanyak 2 buah, atau sobat bisa pake motor shield driver yang banyak di jual type Adafruit motor shield)
Kemudian bisa dirakit sebagai berikut



Pada gambar diatas, ada tulisan 1, 2 dan 3. 1 untuk motor 1, 2 untuk motor 2 dan 3 untuk motor 3. Logika sederhana menggerakkan roda omniwheel seperti gambar diatas.

Robot bergerak kedepan (maju).
motor 1 bergerak CCW, motor 2 bergerak CW dan motor 3 Diam

Robot bergerak kebelakang (mundur).
motor 1 bergerak CW, motor 2 bergerak CCW dan motor 3 Diam

Robot bergerak Kekanan.
motor 1 bergerak CW dengan kecepatan lebih kecil daripada motor 2, motor 2bergerak CCW kecepatan lebih kecil daripada motor 3 dan motor 3 CW

Robot bergerak Kekiri.
motor 1 bergerak CCW dengan kecepatan lebih kecil daripada motor 3, motor 2bergerak CW kecepatan lebih kecil daripada motor 2 dan motor 3 CCW

untuk pergerakan ke kanan dan kekiri, kecepatan motor 1 dan 2 bisa diatur ulang untuk mendapatkan pergerakan robot yang pas sesuai dengan yang di inginkan.

Robot Belok kiri
motor 1 bergerak CW, motor 2 bergerak CW dan motor 3 CW

Robot Belok kanan
motor 1 bergerak CCW, motor 2 bergerak CCW dan motor 3 CCW


program Arduino untuk mobile robot  dengan omni wheel bisa di lihat sebagai berikut

/*omni wheel program*/
/*www.sekolahrobot.com*/
/*cw
motor 1. 1A->HIGH - 1B->LOW
motor 2. 2A->HIGH - 2B->LOW
motor 4. 4A->LOW - 4B->HIGH
*/

#define dir1a 2
#define dir1b 4
#define pwm1 3
#define dir2a 7
#define dir2b 6
#define pwm2 5

#define dir3a 8
#define dir3b 10
#define pwm3 9
#define dir4a 12
#define dir4b 13
#define pwm4 11


void setup()
{
  pinMode(dir1a,OUTPUT);
  pinMode(dir1b,OUTPUT);
  pinMode(pwm1,OUTPUT);
  pinMode(dir2a,OUTPUT);
  pinMode(dir2b,OUTPUT);
  pinMode(pwm2,OUTPUT);
}

void loop()
{
  maju(255);
  delay(2000);
  stopped();
  delay(2000);
  mundur(255);
  delay(2000);
  stopped();
  delay(2000);
  kanan(255);
  delay(2000);
  stopped();
  delay(2000);
  kiri(255);
  delay(2000);
  stopped();
  delay(2000);
  belokkanan(255);
  delay(2000);
  stopped();
  delay(2000);
  belokkiri(255);
  delay(2000);
  stopped();
  delay(2000);
 
 
 
}

void maju(int pwm)
{
  digitalWrite(dir1a,LOW);
  digitalWrite(dir1b,HIGH);
  analogWrite(pwm1,pwm);
 
  digitalWrite(dir2a,HIGH);
  digitalWrite(dir2b,LOW);
  analogWrite(pwm2,pwm);
 
  digitalWrite(dir4a,LOW);
  digitalWrite(dir4b,LOW);
  analogWrite(pwm4,0);
}

void mundur(int pwm)
{

  digitalWrite(dir1a,HIGH);
  digitalWrite(dir1b,LOW);
  analogWrite(pwm1,pwm);
 
  digitalWrite(dir2a,LOW);
  digitalWrite(dir2b,HIGH);
  analogWrite(pwm2,pwm);
 
  digitalWrite(dir4a,LOW);
  digitalWrite(dir4b,LOW);
  analogWrite(pwm4,0);
}

void kanan(int pwm)
{

  digitalWrite(dir1a,LOW);
  digitalWrite(dir1b,HIGH);
  analogWrite(pwm1,pwm/3.5);
 
  digitalWrite(dir2a,LOW);
  digitalWrite(dir2b,HIGH);
  analogWrite(pwm2,(pwm*6)/10);
 
  digitalWrite(dir4a,LOW);
  digitalWrite(dir4b,HIGH);
  analogWrite(pwm4,pwm);

}

void kiri(int pwm)
{

  digitalWrite(dir1a,HIGH);
  digitalWrite(dir1b,LOW);
  analogWrite(pwm1,(pwm*6)/10);
 
  digitalWrite(dir2a,HIGH);
  digitalWrite(dir2b,LOW);
  analogWrite(pwm2,pwm/3.5);
 
  digitalWrite(dir4a,HIGH);
  digitalWrite(dir4b,LOW);
  analogWrite(pwm4,pwm);
}

void belokkiri(int pwm)
{

  digitalWrite(dir1a,HIGH);
  digitalWrite(dir1b,LOW);
  analogWrite(pwm1,pwm);
 
  digitalWrite(dir2a,HIGH);
  digitalWrite(dir2b,LOW);
  analogWrite(pwm2,pwm);
 
  digitalWrite(dir4a,LOW);
  digitalWrite(dir4b,HIGH);
  analogWrite(pwm4,pwm);
}

void belokkanan(int pwm)
{

  digitalWrite(dir1a,LOW);
  digitalWrite(dir1b,HIGH);
  analogWrite(pwm1,pwm);
 
  digitalWrite(dir2a,LOW);
  digitalWrite(dir2b,HIGH);
  analogWrite(pwm2,pwm);
 
  digitalWrite(dir4a,HIGH);
  digitalWrite(dir4b,LOW);
  analogWrite(pwm4,pwm);
}

void stopped()
{
  digitalWrite(dir3a,LOW);
  digitalWrite(dir3b,LOW);
  analogWrite(pwm3,0);
 
  digitalWrite(dir4a,LOW);
  digitalWrite(dir4b,LOW);
  analogWrite(pwm4,0);

 digitalWrite(dir1a,LOW);
  digitalWrite(dir1b,LOW);
  analogWrite(pwm1,0);
 
  digitalWrite(dir2a,LOW);
  digitalWrite(dir2b,LOW);
  analogWrite(pwm2,0);
}

Oke selamat Mencoba,
kesulitan mendapatkan bahan-bahan diatas, bisa kontak ke kita melalui comment berikut

Salam

Sabtu, 30 Mei 2015

Belajar Arduino Bluetooth HC-05

Hallo Sobat Arduino Indonesia, hari ini akan sharing tentang Arduino koneksi ke bluetooth module (HC-05). kebetulan ada modul bluetooth yang gak terpakai di Workshop. Kedepannya nanti sobat bisa gunakan untuk kendali robotik dengan menggunakan handphone Android. Yang perlu di siapkan untuk projek kali ini adalah



  1. Arduino UNO
  2. Bluetooth HC-05
  3. Projectboard
  4. Kabel jumper male to male
  5. Handphone Android
Langkah - langkahnya sebagai berikut :
  • susun kabel jumper seperti berikut ini
HC05:TX ke UNO:pin1
HC05:RX ke UNO:pin0
HC05:GND ke UNO:Gnd
HC05:5V ke UNO:5V
 



  • program sesuai dengan yang ada di bawah ini, dan upload ke arduino
//arduino bluetooth
//sekolahrobot.com

int led=13;
int DataBluetooth;

void setup() {
  Serial.begin(9600);
  Serial.println("Menyalakan dan mematikan led dengan bluetooth");
  Serial.println("1 : ON, 0 = Off");
  pinMode(led,OUTPUT);
}

void loop() {
  if (Serial.available()){
   DataBluetooth=Serial.read();
   if(DataBluetooth=='1'){  
     digitalWrite(led,HIGH);
     Serial.println("LED On");
   }
   if (DataBluetooth=='0'){
      digitalWrite(led,LOW);
      Serial.println("LED Off");
  }
}
delay(100);
}
  • install aplikasi android 
untuk percobaan kali ini menggunakan aplikasi Arduino Bluetooth Controller. Bisa di download di playstore,
sambungkan ke bluetooth yang sudah di sambungkan ke arduino
 





  • amati hasilnya ketika kirim 1 atau 0 pada aplikasi di android

Selasa, 17 Maret 2015

Belajar Arduino untuk Mengerakan Roda Mecanum

Hallo-Hallo, bagaimana kabarnya sobat AWI'ers, Kali ini kami akan membahas tentang Roda mecanum dan bagaimana cara menggerakkannya dengan menggunakan Arduino. Berikut pokok pembahasan tentang topik hari ini
  • Apa Itu Mecanum
  • Bahan-bahan apa saja yang di butuhkan
  • Bagaimana cara pemrogramannya
Oke langsung saja

Mecanum
Mecanum atau Mecanum wheel menurut om Wikipedia "The Mecanum wheel is one design for a wheel which can move a vehicle in any direction". Kalau versi Indonesianya kurang lebih sebagai berikut : Salah satu jenis roda yang di desain bisa bergerak ke segalah arah. "SEGALA ARAH" yap, sobat sobat bisa menggerakkan maju, mundur, geser kiri, geser kanan tanpa merubah sudut posisi Mobile Robot yang menggunakan roda tipe ini.

Contohnya seperti ini

Pergerakan roda mecanum (gbr dari http://www.chiefdelphi.com/forums/showthread.php?p=1432211)
Bentuk mecanum, salah satunya seperti ini
Bahan-bahan apa saja yang di butuhkan
Bahan-bahan yang diperlukan untuk percobaan kali ini adalah
  • Arduino UNO
  • Arduino Adafruit Motor Shield
  • 2 Roda mecanum Right
  • 2 Roda Mecanum Left
  • 4 buah motor DC (high torsi)
  • 4 shaft motor to mecanum
  • 4 bracket L
  • Batere lippo 3 cell
  • Kabel Secukupnya

Pada projek kali ini menggunakan driver Adafruit Motor Shield karena shield ini mempunyai 4 output driver motor, sehingga pas untuk menggerakkan 4 roda.



Cara Pemrograman
  • siapkan arduino software terlebih dahulu
  • pastikan sudah terdeksi com portnya arduino
  • pilih board arduino uno pada software
  • pilih com yang sesuai dengan driver arduino yang sudah terinstall
  • tulis program seperti berikut ini
// Simple Adafruit Motor Shield sketch
// -----------------------------------
// edit by : sekolahrobot.com

// Arduino pins for the shift register
#define MOTORLATCH 12
#define MOTORCLK 4
#define MOTORENABLE 7
#define MOTORDATA 8

// 8-bit bus after the 74HC595 shift register
// (not Arduino pins)
// These are used to set the direction of the bridge driver.
#define MOTOR1_A 2
#define MOTOR1_B 3
#define MOTOR2_A 1
#define MOTOR2_B 4
#define MOTOR3_A 5
#define MOTOR3_B 7
#define MOTOR4_A 0
#define MOTOR4_B 6

// Arduino pins for the PWM signals.
#define MOTOR1_PWM 11
#define MOTOR2_PWM 3
#define MOTOR3_PWM 6
#define MOTOR4_PWM 5
#define SERVO1_PWM 10
#define SERVO2_PWM 9

// Codes for the motor function.
#define FORWARD 1
#define BACKWARD 2
#define BRAKE 3
#define RELEASE 4


void setup()
{
}


void loop()
{
  maju();
  delay(1000);
  mundur();
  delay(1000);
  geserkiri();
  delay(1000);
  geserkanan();
  delay(1000);
 
}
void maju()
{
   motore(1,200);
   motore(2,200);
   motore(3,200);
   motore(4,200);
}
void mundur()
{
   motore(1,-200);
   motore(2,-200);
   motore(3,-200);
   motore(4,-200);
}

void geserkanan()
{
   motore(1,200);
   motore(2,-200);
   motore(3,200);
   motore(4,-200);
 
}

void geserkiri()
{
   motore(1,-200);
   motore(2,200);
   motore(3,-200);
   motore(4,200);
 
}


// Initializing Library Driver
// ------------
// There is no initialization function.
//
// The shiftWrite() has an automatic initializing.
// The PWM outputs are floating during startup,
// that's okay for the Adafruit Motor Shield, it stays off.
// Using analogWrite() without pinMode() is valid.
//


// ---------------------------------
// motor
//
// Select the motor (1-4), the command,
// and the speed (0-255).
// The commands are: FORWARD, BACKWARD, BRAKE, RELEASE.
//
void motor(int nMotor, int command, int speed)
{
  int motorA, motorB;

  if (nMotor >= 1 && nMotor <= 4)
  { 
    switch (nMotor)
    {
    case 1:
      motorA   = MOTOR1_A;
      motorB   = MOTOR1_B;
      break;
    case 2:
      motorA   = MOTOR2_A;
      motorB   = MOTOR2_B;
      break;
    case 3:
      motorA   = MOTOR3_A;
      motorB   = MOTOR3_B;
      break;
    case 4:
      motorA   = MOTOR4_A;
      motorB   = MOTOR4_B;
      break;
    default:
      break;
    }

    switch (command)
    {
    case FORWARD:
      motor_output (motorA, HIGH, speed);
      motor_output (motorB, LOW, -1);     // -1: no PWM set
      break;
    case BACKWARD:
      motor_output (motorA, LOW, speed);
      motor_output (motorB, HIGH, -1);    // -1: no PWM set
      break;
    case BRAKE:
      // The AdaFruit library didn't implement a brake.
      // The L293D motor driver ic doesn't have a good
      // brake anyway.
      // It uses transistors inside, and not mosfets.
      // Some use a software break, by using a short
      // reverse voltage.
      // This brake will try to brake, by enabling
      // the output and by pulling both outputs to ground.
      // But it isn't a good break.
      motor_output (motorA, LOW, 255); // 255: fully on.
      motor_output (motorB, LOW, -1);  // -1: no PWM set
      break;
    case RELEASE:
      motor_output (motorA, LOW, 0);  // 0: output floating.
      motor_output (motorB, LOW, -1); // -1: no PWM set
      break;
    default:
      break;
    }
  }
}

void motore(int xMotor, int kecepatan)
{
  if(kecepatan >= 0 && kecepatan <= 255)
  {
      motor(xMotor, FORWARD, kecepatan);
  }
  if(kecepatan >= -255 && kecepatan <= -1)
  {
      kecepatan = map(kecepatan, -255, -1, 255, 1);
      motor(xMotor, BACKWARD, kecepatan);   
  }
}

// ---------------------------------
// motor_output
//
// The function motor_ouput uses the motor driver to
// drive normal outputs like lights, relays, solenoids,
// DC motors (but not in reverse).
//
// It is also used as an internal helper function
// for the motor() function.
//
// The high_low variable should be set 'HIGH'
// to drive lights, etc.
// It can be set 'LOW', to switch it off,
// but also a 'speed' of 0 will switch it off.
//
// The 'speed' sets the PWM for 0...255, and is for
// both pins of the motor output.
//   For example, if motor 3 side 'A' is used to for a
//   dimmed light at 50% (speed is 128), also the
//   motor 3 side 'B' output will be dimmed for 50%.
// Set to 0 for completelty off (high impedance).
// Set to 255 for fully on.
// Special settings for the PWM speed:
//    Set to -1 for not setting the PWM at all.
//
void motor_output (int output, int high_low, int speed)
{
  int motorPWM;

  switch (output)
  {
  case MOTOR1_A:
  case MOTOR1_B:
    motorPWM = MOTOR1_PWM;
    break;
  case MOTOR2_A:
  case MOTOR2_B:
    motorPWM = MOTOR2_PWM;
    break;
  case MOTOR3_A:
  case MOTOR3_B:
    motorPWM = MOTOR3_PWM;
    break;
  case MOTOR4_A:
  case MOTOR4_B:
    motorPWM = MOTOR4_PWM;
    break;
  default:
    // Use speed as error flag, -3333 = invalid output.
    speed = -3333;
    break;
  }

  if (speed != -3333)
  {
    // Set the direction with the shift register
    // on the MotorShield, even if the speed = -1.
    // In that case the direction will be set, but
    // not the PWM.
    shiftWrite(output, high_low);

    // set PWM only if it is valid
    if (speed >= 0 && speed <= 255)   
    {
      analogWrite(motorPWM, speed);
    }
  }
}


// ---------------------------------
// shiftWrite
//
// The parameters are just like digitalWrite().
//
// The output is the pin 0...7 (the pin behind
// the shift register).
// The second parameter is HIGH or LOW.
//
// There is no initialization function.
// Initialization is automatically done at the first
// time it is used.
//
void shiftWrite(int output, int high_low)
{
  static int latch_copy;
  static int shift_register_initialized = false;

  // Do the initialization on the fly,
  // at the first time it is used.
  if (!shift_register_initialized)
  {
    // Set pins for shift register to output
    pinMode(MOTORLATCH, OUTPUT);
    pinMode(MOTORENABLE, OUTPUT);
    pinMode(MOTORDATA, OUTPUT);
    pinMode(MOTORCLK, OUTPUT);

    // Set pins for shift register to default value (low);
    digitalWrite(MOTORDATA, LOW);
    digitalWrite(MOTORLATCH, LOW);
    digitalWrite(MOTORCLK, LOW);
    // Enable the shift register, set Enable pin Low.
    digitalWrite(MOTORENABLE, LOW);

    // start with all outputs (of the shift register) low
    latch_copy = 0;

    shift_register_initialized = true;
  }

  // The defines HIGH and LOW are 1 and 0.
  // So this is valid.
  bitWrite(latch_copy, output, high_low);

  // Use the default Arduino 'shiftOut()' function to
  // shift the bits with the MOTORCLK as clock pulse.
  // The 74HC595 shiftregister wants the MSB first.
  // After that, generate a latch pulse with MOTORLATCH.
  shiftOut(MOTORDATA, MOTORCLK, MSBFIRST, latch_copy);
  delayMicroseconds(5);    // For safety, not really needed.
  digitalWrite(MOTORLATCH, HIGH);
  delayMicroseconds(5);    // For safety, not really needed.
  digitalWrite(MOTORLATCH, LOW);
}

Test Robot