Senin, 11 November 2013

Arduino & PIR Sensor

Bismillahirrahmanirrahim...


halo agan2 yg hobi dgn arduino,update lg nih...
Kemarin lusa ada kawan nyuruh buat sensor gerak utk ngawasi 
gudang ,klau ada yg masuk lgsung bunyi loudspeaker di kmr nya
jd saya gunakan PIR(Passive Infrared Receiver) yg sebgai pendetek gerakan
oke..lgsng aja ke skemanya



di skema saya pake Buzzer aja,buzzer bs di ganti dgn led,kamera,jg perangkat lain

ini sketch nya:

int Buzzer_Pin = 2;//pin buzzer di pin 2 arduino
int Pir_pin = 3;
int Var_Pir = LOW;//nilai awal  pir sensor
int val = 0;

void setup(){

pinMode(Buzzer_Pin, OUTPUT);
pinMode(Pir_pin, INPUT);
Serial.begin(9600);
}
//untuk beep
void Beep(long durasi, int freq){
durasi *=1000;
int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < durasi) {
        digitalWrite(Buzzer_Pin,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(Buzzer_Pin, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}

void loop(){

 val = digitalRead(Pir_pin);  //baca nilai pir sensor ke val
  if (val == HIGH) {            // jika nilai HIGH
    Beep(300, 160);
    delay(150);

    //jika terdetek
    if (Pir_pin == LOW) {
    SerialPrintln("terdetek");
     Pir_pin = HIGH;
    }
  } else {
 
     Beep(0, 0);
      delay(300);  
      if (Pir_pin == HIGH){
     SerialPrintln("Kosong");
      Pir_pin = LOW;
    }
  }
}

trus upload ke board arduino,liat hasilnya...oke sekian dulu tentang pir sensor nya
..

Rabu, 06 November 2013

Arduino jam lcd



bismillahirrahmanirrahim................

halo agan2 yg suka dgn microcontroller ,update lg nihh..
pas jln2 saya ngeliat ada jam digital dgn 7segment,jd pengin ngebuat ........jd saya putuskan buat dgn LCD 16x2 aja...hehehehe..soal nya itu yg lagi ada
stok nya..
oke,kita masuk ke skema nya..




Part List nya:

1.Arduino
2.RTC ds1307
3.SHift Register 595
4.trimpot 10k ohm
5.restan 10k ohm = 3 pcs
6.restan 220 ohm
7.battrey backup 3v
8.LCD 16x2
9.switch = 3 pcs
10.crystal 32.768 khz



klau bahan sdh lengkap ,lsng masuk ke sketch nya:

#include <LiquidCrystal595.h>
#include "Wire.h"
#define DS1307_ADDRESS 0x68

const int LM35 = A0;

byte derajat[8] = {
  B01110,
  B01010,
  B01110,
  B00000,
  B00000,
  B00000,
  B00000,
  B00000};

LiquidCrystal595 lcd(2, 3, 4);

void setup(){
  Wire.begin();
  Serial.begin(9600);
  lcd.begin(16,2);  //inisialisasi lcd 16 baris 2 kolom
}

void loop(){
  tulis_TGL();
  sensor_suhu();
  delay(1000);

}

byte bcdToDec(byte val)  {
// Convert binary coded decimal to normal decimal numbers
  return ( (val/16*10) + (val%16) );
}

void tulis_TGL(){

  // Reset the register pointer
  Wire.beginTransmission(DS1307_ADDRESS);

  byte zero = 0x00;
  Wire.write(zero);
  Wire.endTransmission();

  Wire.requestFrom(DS1307_ADDRESS, 7);

  int Detik = bcdToDec(Wire.read());
  int Menit = bcdToDec(Wire.read());
  int Jam= bcdToDec(Wire.read() & 0b111111); //24 hour time
  int Hari = bcdToDec(Wire.read()); //0-6 -> minggu - sabtu
  int Tgl = bcdToDec(Wire.read());
  int Bulan = bcdToDec(Wire.read());
  int Thn = bcdToDec(Wire.read());


  lcd.setCursor(0,1);
    switch (Hari)               // tulis hari
  {
    case 1:
      lcd.print("Sen,");
     // Serial.print("Sen  ");
      break;
    case 2:
      lcd.print("Sel,");
     // Serial.print("Sel ");
      break;
    case 3:
      lcd.print("Rab,");
      //Serial.print("Rab  ");
      break;
    case 4:
      lcd.print("Kam,");
      //Serial.print("Kam  ");
      break;
    case 5:
      lcd.print("Jum,");
     // Serial.print("Jum  ");
      break;
    case 6:
      lcd.print("Sab,");
    //  Serial.print("SAb ");
      break;
    case 7:
      lcd.print("Min,");
      // Serial.print("Min  ");
      break;
  }

  Serial.print(Tgl);
  Serial.print("/");
  Serial.print(Bln);
  Serial.print("/");
  Serial.print(Thn);
  Serial.print(" ");
  Serial.print(Jam);
  Serial.print(":");
  Serial.print(Menit);
  Serial.print(":");
  Serial.println(Detik);
  
   lcd.setCursor(4,1); //tulis di baris 4 kolom 2
  lcd.print(Tgl);
  lcd.print("/");
  lcd.print(Bln);
  lcd.print("/");
  lcd.print(Thn);
  
  lcd.setCursor(0,0);
  
   if( Detik == 0)
  {
   lcd.print("       ");
   lcd.setCursor(0,0);
   } 
  
  lcd.print(Jam);
  lcd.print(":");
  lcd.print(Menit);
  lcd.print(":");
  lcd.print(Detik);  
}

void sensor_suhu(){
  
 int suhu = analogRead(LM35);
 int milivolt = (suhu / 1024.0) * 5000;
 int celcius = milivolt / 10;

 lcd.setCursor(11,0);
 lcd.print(celcius);

 lcd.createChar(0,derajat);
  lcd.setCursor(13,0);
 lcd.write(0);
 lcd.print(" C");



}

langsung upload ke board arduino,lsng jadi deh........

ini sdh saya pakai sensor suhu,jd bsa tau kondisi suhu di kamar saya,,

maaf,jika kata2 nya ada yg kurang pas,maklum baru pertama buat blog..

oke sekian dl,kapan 2 saya update lagi ya...






tes tes tes

Assalamualaikum wr.wb..

salam blogger semua,ini tulisan pertama saya dan hal terbaru buat saya,
jadi mhn maaf klau corat coret nya kurang bagus
rcn nya buat blog utk nyimpan hasil kerja aja ....yah sekalian berbagi
mudah2 an bs menambah wawasan saya ....................aaamiiinnnnnnnnnnnnnnnnnnn