Translate

Membuat Permainan Elektrik Shock Line Menggunakan Arduino

Membuat Permainan Elektrik Shock Line Menggunakan Arduino


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat untuk permainan elektrik shock line menggunakan arduino sebagai kontrollernya, alat ini dilengkapi dengan buzzer jadi ketika tongkat terkena besi maka akan membunyikan suara buzzer. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. Buzzer






c. Program Arduino IDE

#include<Wire.h>

int buzzer = 8;
int tombol = 7;
int tombolx = 0;

int sensor = A0;
int sensorx = 0;

int y = 0;

void setup(){
pinMode(buzzer,OUTPUT);
digitalWrite(buzzer,HIGH);
pinMode(tombol,INPUT_PULLUP);
pinMode(sensor,INPUT_PULLUP);
}


void loop(){

 sensorx = digitalRead(sensor);

if((sensorx == 0)&&(y == 0)){
y = 1; 
digitalWrite(buzzer,LOW);
}

 tombolx = digitalRead(tombol);

if(tombolx == 0){
y = 0;
digitalWrite(buzzer,HIGH);
}





d. VIDEO HASILNYA








Arduino JAM DIGITAL dengan fitur ALARM dan fitur sensor getar PIEZOELEKTRIK untuk OFF ALARM

Arduino JAM DIGITAL dengan fitur ALARM dan fitur sensor getar PIEZOELEKTRIK untuk OFF ALARM


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk menampilkan jam dan juga sebagai ALARM saat tidur, alat ini seperti jam digital biasa yang disetting menggunakan tombol dan ada alarm berupa buzzer, uniknya alat ini yaitu untuk mematikan bunyi buzzer alarm harus menggunakan injakan atau getaran pada piezoelektrik yang diletakkan pada karpet sehingga orang yang akan mematikan bunyi alarm harus bangun dan menginjakkan kaki di karpet. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. RTC DS1307




c. LCD 16x2 + I2C




d. Sensor Getar PIEZOELEKTRIK + Amplifier






e. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h> 
#define DS3231_I2C_ADDRESS 0x68

LiquidCrystal_I2C lcd(0x3F, 16, 2);

int buzzer = 2;

int btset = 3;
int btup = A2;
int btdown = A3;
int btok = 5;
int mark = 0;

int btsetx;
int btupx;
int btdownx;
int btokx;
int jam;

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

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


void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
 
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,HIGH);
 
  pinMode(btset,INPUT_PULLUP);
  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);
 
 
  Wire.begin();
  Serial.begin(9600);
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(0,53,8,6,5,10,18); 
}


void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}


void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}



void displayTime()
{
 
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
 
  lcd.setCursor(0,0);
  // send it to the serial monitor
  lcd.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  lcd.print(":");
  if (minute<10)
  {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second<10)
  {
    lcd.print("0");
  }
  lcd.print(second, DEC);
    
}



void loop()
{
  displayTime();
  delay(1000);
   lcd.setCursor(0,1);
   lcd.print("ALRM= ");
   lcd.print(jam);
   lcd.print("        ");
   
  btsetx = digitalRead(btset);
  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btokx = digitalRead(btok);
 
  if(btsetx == LOW){
  lcd.clear();
  delay(1000);
  setting();
  }
 
  if((hour == jam)&&(mark == 0)){
  digitalWrite(buzzer,LOW);
  }

 int dataadc = analogRead(A0);

   lcd.setCursor(9,1);
   lcd.print("ADC=");
   lcd.print(dataadc);
   lcd.print("        ");
 
  if(dataadc > 10){
  digitalWrite(buzzer,HIGH);
  mark = 1;
  }
 
  if(hour == jam + 1){
  mark = 0;
  }
 
}   


void setting(){
  digitalWrite(buzzer,HIGH);
  btsetx = digitalRead(btset);
  btupx = digitalRead(btup);
  btdownx = digitalRead(btdown);
  btokx = digitalRead(btok);
 
 lcd.setCursor(0,0);
 lcd.print("SET JAM: ");
 lcd.print(jam);
 lcd.print("         ");

 if(btupx == LOW){
 delay(200);
   jam++;
 }

 if(btdownx == LOW){
 delay(200);
   jam--;
 }

 if(jam < 0){
 jam = 23;
 }

 if(jam > 23){
 jam = 0;
 }

 if(btokx == LOW){
 delay(200);
 lcd.clear();
 return;
 }

setting();
}






f. VIDEO HASILNYA









Membuat Alat Monitoring daya (Arus ACS712 dan Tegangan) DC + SUHU LM35 + LUXMETER BH1750 Menggunakan Arduino dan Datalogger SD Card

Membuat Alat Monitoring daya (Arus ACS712 dan Tegangan) DC + SUHU LM35 + LUXMETER BH1750 Menggunakan Arduino dan Datalogger SD Card


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor daya yang berupa arus dan tegangan dari sumber DC, selain itu alat ini juga bisa mengukur suhu menggunakan sensor LM35 dan mengukur intensitas cahaya atau LUXMETER dengan sensor BH1750. alat ini dilengkapi dengan penyimpanan secara berkala setiap 1 menit sekali pada SD card atau datalogger. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. Sensor Tegangan DC




c. Sensor Arus ACS712




d. LCD 16x2 + I2C




e. Sensor LUX BH1750




f. Sensor Suhu LM35




g. RTC DS1307






h. Program Arduino IDE

#include "Wire.h"
#include <LiquidCrystal_I2C.h> 
#include <BH1750FVI.h>
#define DS3231_I2C_ADDRESS 0x68
#include <SPI.h>
#include <SD.h>

LiquidCrystal_I2C lcd(0x3F, 16, 2);

BH1750FVI LightSensor;

//mosi - 11
//miso - 12
//clk - 13
//cs - 4

int cacah = 0;
File myFile;

int adcteg;
int adcarus;
float tegangan;
float arus;
float v;
int adcsuhu;
int suhu;
uint16_t lux;

byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

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


void setup()
{
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
 
  Wire.begin();
  Serial.begin(9600);
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(0,35,8,5,10,4,18);
 
  LightSensor.begin();
  /*
Set the address for this sensor
you can use 2 different address
Device_Address_H "0x5C"
Device_Address_L "0x23"
you must connect Addr pin to A3 .
*/
  LightSensor.SetAddress(Device_Address_H);//Address 0x5C
// To adjust the slave on other address , uncomment this line
// lightMeter.SetAddress(Device_Address_L); //Address 0x5C
//-----------------------------------------------
  /*
   set the Working Mode for this sensor
   Select the following Mode:
    Continuous_H_resolution_Mode
    Continuous_H_resolution_Mode2
    Continuous_L_resolution_Mode
    OneTime_H_resolution_Mode
    OneTime_H_resolution_Mode2
    OneTime_L_resolution_Mode
  
    The data sheet recommanded To use Continuous_H_resolution_Mode
  */

  LightSensor.SetMode(Continuous_H_resolution_Mode);

  //Serial.println("Running...");
 
}


void setDS3231time(byte second, byte minute, byte hour, byte dayOfWeek, byte
dayOfMonth, byte month, byte year)
{
  // sets time and date data to DS3231
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set next input to start at the seconds register
  Wire.write(decToBcd(second)); // set seconds
  Wire.write(decToBcd(minute)); // set minutes
  Wire.write(decToBcd(hour)); // set hours
  Wire.write(decToBcd(dayOfWeek)); // set day of week (1=Sunday, 7=Saturday)
  Wire.write(decToBcd(dayOfMonth)); // set date (1 to 31)
  Wire.write(decToBcd(month)); // set month
  Wire.write(decToBcd(year)); // set year (0 to 99)
  Wire.endTransmission();
}


void readDS3231time(byte *second,
byte *minute,
byte *hour,
byte *dayOfWeek,
byte *dayOfMonth,
byte *month,
byte *year)
{
  Wire.beginTransmission(DS3231_I2C_ADDRESS);
  Wire.write(0); // set DS3231 register pointer to 00h
  Wire.endTransmission();
  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);
  // request seven bytes of data from DS3231 starting from register 00h
  *second = bcdToDec(Wire.read() & 0x7f);
  *minute = bcdToDec(Wire.read());
  *hour = bcdToDec(Wire.read() & 0x3f);
  *dayOfWeek = bcdToDec(Wire.read());
  *dayOfMonth = bcdToDec(Wire.read());
  *month = bcdToDec(Wire.read());
  *year = bcdToDec(Wire.read());
}



void displayTime()
{
 
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
 
  lcd.setCursor(0,0);
  // send it to the serial monitor
  lcd.print(hour, DEC);
  // convert the byte variable to a decimal number when displayed
  lcd.print(":");
  if (minute<10)
  {
    lcd.print("0");
  }
  lcd.print(minute, DEC);
  lcd.print(":");
  if (second<10)
  {
    lcd.print("0");
  }
  lcd.print(second, DEC);
    
}



void loop()
{
  displayTime();
  delay(1000);
   
  lux = LightSensor.GetLightIntensity();// Get Lux value
 
  adcteg = analogRead(A0);
  tegangan = adcteg * (5.0 / 1023.0) * 4.8;
 
  adcarus = analogRead(A1);
    v = adcarus * (5.0 / 1023.0);
  arus = (v - 2.5)/0.1;
 
  adcsuhu = analogRead(A2);
  suhu = adcsuhu * (5.0 / 1023.0) * 100;
 
  if(arus < 0){
  arus = 0;
  }
  if(tegangan < 0){
  tegangan = 0;
  }
 
  lcd.setCursor(9,0);
  lcd.print("L:");
  lcd.print(lux);

 
  lcd.setCursor(0,1);
  lcd.print(tegangan);
  lcd.print("/");
  lcd.print(arus);
  lcd.print("/");
  lcd.print(suhu,1);
  lcd.print("     ");
 
 
  cacah++;
 
  if(cacah >= 60){
  lcd.clear();
  simpan();
  cacah = 0;
  lcd.clear();
  }
 
}



 void simpan(){

while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  Serial.print("Initializing SD card...");
  // On the Ethernet Shield, CS is pin 4. It's set as an output by default.
  // Note that even if it's not used as the CS pin, the hardware SS pin
  // (10 on most Arduino boards, 53 on the Mega) must be left as an output
  // or the SD library functions will not work.
  pinMode(10, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");

  // open the file. note that only one file can be open at a time,
  // so you have to close this one before opening another.
  myFile = SD.open("test.txt", FILE_WRITE);

  // if the file opened okay, write to it:
  if (myFile) {
    
    myFile.print("Tanggal:");
    myFile.print(dayOfMonth);
    myFile.print("/");
    myFile.print(month);
    myFile.print("/");
    myFile.println(year);
   
    myFile.print("Jam:");
    myFile.print(hour);
    myFile.print(":");
    myFile.print(minute);
    myFile.print(":");   
    myFile.println(second);
   
    myFile.print("V= ");
    myFile.println(tegangan);
    myFile.print("I= ");
    myFile.println(arus);
    myFile.print("P= ");
    myFile.println(tegangan*arus);
    myFile.print("T= ");
    myFile.println(suhu);
    myFile.print("Lux= ");
    myFile.println(lux);
   
    // close the file:
    myFile.close();
    Serial.println("done.");
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

  // re-open the file for reading:
  myFile = SD.open("test.txt");
  if (myFile) {
    Serial.println("test.txt:");

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      Serial.write(myFile.read());
    }
    // close the file:
    myFile.close();
  } else {
    // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }

}




  
i. VIDEO HASILNYA

 








Pet Feeder Otomatis Menggunakan Arduino dengan setting waktu via Android dan SMS Gateway

Pet Feeder Otomatis Menggunakan Arduino dengan setting waktu via Android dan SMS Gateway


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat alat yang bisa digunakan untuk memberikan makanan kepada hewan peliharaan seperti ikan atau kucing dll. secara otomatis dengan set waktu menggunakan handphone android dan sms, kemudian terdapat motor servo yang digunakan untuk buka-tutup pintu atau katub. alat ini juga dilengkapi dengan sensor jarak yang bisa mendeteksi kondisi pakan ketika masih full atau sudah mau habis. untuk lebih jelasnya berikut adalah skema dan programnya.   



a.Arduino Uno




b. Motor Servo




c.Bluetooth HC-05




d. Modul SMS SIM900A




e. LCD 16x2 I2C




f. RTC DS1302






g. Program Android







h. Program Arduino Pet Feeder

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#include <DS1302.h>
#include <Servo.h>
#define trigPin 3
#define echoPin 4

LiquidCrystal_I2C lcd(0x3F, 16, 2);

DS1302 rtc(7, 6, 5);
long duration, distance;
int mark;
String dataku;
int jampagi;
int jamsore;

Servo myservo1;
Servo myservo2;
Time t;

 int sen1;
 int sen2;
 int sen3;


void setup()
{
  pinMode(A0,INPUT);
  pinMode(A1,INPUT);
  pinMode(A2,INPUT);
 
  myservo1.attach(9);
  myservo2.attach(10);
 
  myservo1.write(100);
  myservo2.write(100);
 
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
 
  rtc.halt(false);
  rtc.writeProtect(false);
 
  Serial.begin(9600);
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
 
  //rtc.setTime(18, 02, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(9, 26, 2018);   // Set the date to August 6th, 2010
}


void loop()
{
 
  sen1 = digitalRead(A0);
  sen2 = digitalRead(A1);
  sen3 = digitalRead(A2);
 
  t = rtc.getTime();
 
  digitalWrite(trigPin, LOW);  // Added this line
  delayMicroseconds(2); // Added this line
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;

  lcd.setCursor(0, 0);
  lcd.print(rtc.getTimeStr());
  lcd.print(" | ");
  lcd.print(distance);
  lcd.print("           ");
 
  delay (1000);
 
  if((sen1 == 0)&&(sen2 == 0)&&(sen3 == 0)){
  lcd.setCursor(13, 1);
  lcd.print("OFF"); 
  }
 
  if((sen1 == 1)&&(sen2 == 0)&&(sen3 == 0)){
  lcd.setCursor(0, 1);
  lcd.print("7 | 17 MODE SMS              ");
  jampagi = 7;
  jamsore = 17;
  }
 
  if((sen1 == 0)&&(sen2 == 1)&&(sen3 == 0)){
  lcd.setCursor(0, 1);
  lcd.print("8 | 16 MODE SMS              ");
  jampagi = 8;
  jamsore = 16;
  }
 
  if((sen1 ==  0)&&(sen2 == 0)&&(sen3 == 1)){
  lcd.setCursor(0, 1);
  lcd.print("9 | 15 MODE SMS              ");
  jampagi = 9;
  jamsore = 15;
  }
 
 
  if((t.min == jampagi)&&(mark == 0)){
    myservo1.write(150);
    myservo2.write(150);
    delay(3000);
    myservo1.write(100);
    myservo2.write(100);
    mark = 1;
   }
  
    if((t.min == jamsore)&&(mark == 1)){
    myservo1.write(150);
    myservo2.write(150);
    delay(3000);
    myservo1.write(100);
    myservo2.write(100);
    mark = 0;
   }
 
  if ((Serial.available() > 0)&&(sen1 == 0)&&(sen2 == 0)&&(sen3 == 0))
{

  dataku = Serial.readString();

if(dataku.startsWith("x"))
{
   dataku.replace("x", "");
   jampagi = dataku.toInt();
}

else if(dataku.startsWith("y"))
{
   dataku.replace("y", "");
   jamsore = dataku.toInt();
}

  lcd.setCursor(0, 1);
  lcd.print(jampagi);
  lcd.print(" | ");
  lcd.print(jamsore);
  lcd.print("           ");

}

if((t.min == jampagi)&&(mark == 0)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 1;
}

if((t.min == jamsore)&&(mark == 1)){
myservo1.write(150);
myservo2.write(150);
delay(3000);
myservo1.write(100);
myservo2.write(100);
mark = 0;
}
 
}




i. Program Arduino SMS

#include "SIM900.h"
#include "sms.h"
#include "SoftwareSerial.h"
#include "sms.h"

SMSGSM sms;
boolean started=false;
char smsbuffer[160];
char n[20];



void setup(){
  pinMode(A0,OUTPUT);
  pinMode(A1,OUTPUT);
  pinMode(A2,OUTPUT);
   
  digitalWrite(A0,LOW);
  digitalWrite(A1,LOW);
  digitalWrite(A2,LOW);
 
  if(gsm.begin(9600)){
    started=true;
  
  }

  if(started){
   delsms();
  }
  delay(1000);
  sms.SendSMS("085726496643","SIAP EKSEKUSI");
}



void loop(){

 if(gsm.begin(9600)){
  started=true;
 }
 int pos=0;
 if(started){
  pos=sms.IsSMSPresent(SMS_ALL);
  if(pos){
    sms.GetSMS(pos,n,smsbuffer,100);
  
    if(!strcmp(smsbuffer,"off")){
    
        digitalWrite(A0,LOW);
        digitalWrite(A1,LOW);
        digitalWrite(A2,LOW);
      sms.SendSMS(n,"mode off");
    }
   
    if(!strcmp(smsbuffer,"mode1")){
    
        digitalWrite(A0,HIGH);
        digitalWrite(A1,LOW);
        digitalWrite(A2,LOW);
      sms.SendSMS(n,"mode satu");
    }
   
     if(!strcmp(smsbuffer,"mode2")){
    
        digitalWrite(A0,LOW);
        digitalWrite(A1,HIGH);
        digitalWrite(A2,LOW);
      sms.SendSMS(n,"mode dua");
    }
   
    if(!strcmp(smsbuffer,"mode3")){
    
        digitalWrite(A0,LOW);
        digitalWrite(A1,LOW);
        digitalWrite(A2,HIGH);
      sms.SendSMS(n,"mode tiga");
    }
 
    delsms();
  }
 }
  delay(100);
}

void delsms()
{
  for (int i=0; i<10; i++)
  {
      int pos=sms.IsSMSPresent(SMS_ALL);
      if (pos!=0)
      {
        if (sms.DeleteSMS(pos)==1){}else{}
      }
  }
}





j. VIDEO HASILNYA