Translate

Membuat Alat Input Data Menggunakan ARDUINO KEYPAD Matrix 4x4 dan Datalogger SD Card SPIROMETER

Membuat Alat Input Data Menggunakan ARDUINO KEYPAD Matrix 4x4 dan Datalogger SD Card SPIROMETER


            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat dengan menggunakan arduino untuk menginputkan data diri seperti data umur, jenis kelamin, tinggi badan dan data sensor. alat ini dilengkapi dengan datalogger berupa SD Card dengan input data menggunakan keypad matrix 4x4. untuk lebih jelasnya berikut adalah skema dan programnya. 



a. Arduino Uno




b. Keypad Matrix 4x4




c. Lcd 20x4 + I2C




d. SD Card Module






e. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#include <Keypad.h>

LiquidCrystal_I2C lcd(0x3F,20,4);

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

long xx;
int adcsensor;
File myFile;

int x;
int y;
int ket;

int fix;

float rasio1;
float rasio2;

long umurx;
long umur;
long beratx;
long berat;
long tinggix;
long tinggi;
int klm;
int dataadc;
int dataadc2;

float tegangan;
float p;
float v;
float akar;
float q;

float tegangan2;
float p2;
float v2;
float akar2;
float q2;

float hasilku;
float hasilku2;

float fvc;
float fvcx;
float fev1;
float fev1x;
unsigned long simpan[10];
int zz;


char customKey;
const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {2,3,10,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6,7,8,9}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);



void setup() {
  Serial.begin(9600);
  lcd.begin();
  lcd.noCursor();
  lcd.clear();
    
}

void loop() {
 
  lcd.setCursor(0,0);
  lcd.print("Jenis Kelamin= ");
 
     if(klm == 1){
     lcd.print("L");
     }
    
     if(klm == 2){
     lcd.print("P");
     }
    
  lcd.setCursor(0,1);
  lcd.print("Umur= ");
  lcd.print(umur);
  lcd.setCursor(0,2);
  lcd.print("Tinggi= ");
  lcd.print(tinggi);

 customKey = customKeypad.getKey();
   
     if(customKey == 'D'){
      lcd.clear();
      delay(1000);
      setting1();
      setting2();
      setting4();
    }
   
    if(customKey == 'C'){
      lcd.clear();
      delay(1000);
      sensing1();
      berhenti();
      sensing2();
      berhenti();    
      lcd.clear();
      delay(1000);
      hasil();
      savesd();
    }
     
}

void berhenti(){
 customKey = customKeypad.getKey();
      if(customKey == '*'){
      lcd.clear();
      delay(1000);
      return; 
     }
 berhenti();   
}

void sensing1(){
     
    dataadc = analogRead(0);
   
    tegangan = dataadc * (5.0 / 1023.0);
    p = (tegangan-0.4)/0.225;
    v = ((2*p/1.2)/0.625);
   
    akar = sqrt(v);
    q = (0.0005*akar);
    fvc = q;
   
lcd.setCursor(0,0);
lcd.print("FVC=");
lcd.print(fvc);  
lcd.print("       ");

delay(1000);

simpan[zz] = fvc;

zz++;

if(zz > 5){
hasilku = simpan[1] + simpan[2] + simpan[3] + simpan[4] + simpan[5];
zz = 0;
return;
}

    
sensing1();
}


void sensing2(){
   
    dataadc2 = analogRead(0);
   
    tegangan2 = dataadc2 * (5.0 / 1023.0);
    p2 = (tegangan2-0.4)/0.225;
    v2 = ((2*p2/1.2)/0.625);
   
    akar2 = sqrt(v2);
    q2 = (0.0005*akar2);
    fev1 = q2;
   
lcd.setCursor(0,0);
lcd.print("FEV=");
lcd.print(fev1);  
lcd.print("       ");

delay(1000);

hasilku2 = fev1;

return;
}


void setting1(){

  while( 1 )
  {
 customKey = customKeypad.getKey();

 lcd.setCursor(0,0);
 lcd.print("-> Jenis Kelamin= ");

     if(customKey == 'A'){
       lcd.print("L");
       klm = 1;
     }
    
     if(customKey == 'B'){
       lcd.print("P");
       klm = 2;
     }
    
      if(customKey == 'D'){
       lcd.clear();
       delay(1000);
       return;
     }
     
   lcd.setCursor(0,1);
   lcd.print("Umur= ");
   lcd.print(umur);
   lcd.setCursor(0,2);
   lcd.print("Tinggi= ");
   lcd.print(tinggi); 
        
  }


setting1();
}



void setting2(){

  while( 1 )
  {
     lcd.setCursor(0,0);
     lcd.print("Jenis Kelamin= ");
    
     if(klm == 1){
     lcd.print("L");
     }
    
     if(klm == 2){
     lcd.print("P");
     }
   
 customKey = customKeypad.getKey();
 lcd.setCursor(0,1);
 lcd.print("-> Umur= ");
    if(customKey >= '0' && customKey <= '9')
    {
      umurx = umurx * 10 + (customKey - '0');
      lcd.print(umurx);
    }
   
     if(customKey == 'D'){
       lcd.clear();
       delay(1000);
       umur = umurx;
       return;
     }
   
   lcd.setCursor(0,2);
   lcd.print("Tinggi= ");
   lcd.print(tinggi); 
        
  }


setting2();
}



void setting4(){

  while( 1 )
  {
     lcd.setCursor(0,0);
     lcd.print("Jenis Kelamin= ");
    
     if(klm == 1){
     lcd.print("L");
     }
    
     if(klm == 2){
     lcd.print("P");
     }
    
   lcd.setCursor(0,1);
   lcd.print("Umur= ");
   lcd.print(umur);
    
 customKey = customKeypad.getKey();
 lcd.setCursor(0,2);
 lcd.print("-> Tinggi= ");
    if(customKey >= '0' && customKey <= '9')
    {
      tinggix = tinggix * 10 + (customKey - '0');
      lcd.print(tinggix);
    }
            
       if(customKey == 'D'){
       lcd.clear();
       delay(1000);
       tinggi = tinggix;
       return;
     }     
        
  }


setting4();
}


void hasil(){

  if(klm == 1){
   fvcx = -5.44018 + 0.06114 * umur + 0.04849 * tinggi + 1.62398 * 1 - 0.07768 * umur;
   fev1x = -4.10074 + 0.04864 * umur + 0.03947 * tinggi + 1.4969 * 1 - 0.07433 * umur;
   rasio1 = fev1 / fvc;
   rasio2 = 96.63286 - 0.36507 * umur;  
  
  lcd.setCursor(0,0);
  lcd.print("FVC=");
  lcd.print(fvc);
  lcd.print(" / ");
  lcd.print(fvcx);

  lcd.setCursor(0,1);
  lcd.print("FEV1=");
  lcd.print(fev1); 
  lcd.print(" / ");
  lcd.print(fev1x); 
 
  lcd.setCursor(0,2);
  lcd.print("Rasio=");
  lcd.print(rasio1); 
  lcd.print(" / ");
  lcd.print(rasio2); 

if((rasio1 >= 0.75 * rasio2) && (fvc >= 0.8 * fvcx)){
//normal
  lcd.setCursor(0,3);
  lcd.print("NORMAL        ");
  ket = 1;
}

if((rasio1 >= 0.75 * rasio2) && (fvc < 0.8 * fvcx)){
//restriktif
  lcd.setCursor(0,3);
  lcd.print("RESTRIKTIF    ");
  ket = 2;
}

if((rasio1 < 0.75 * rasio2) && (fvc > 0.8 * fvcx) && (fev1 < 0.95 * fev1x)){
//gangguan obstrukstif
  lcd.setCursor(0,3);
  lcd.print("OBSTRUKTIF    ");
  ket = 3;

 
  }
 
 
 
  if(klm == 2){
   fvcx = -3.37068 + 0.02824 * umur + 0.03583 * tinggi + 1.00051 * 1 - 0.04546 * umur;
   fev1x = -2.39380 + 0.01684 * umur + 0.02935 * tinggi + 0.85319 * 1 - 0.03894 * umur;
   rasio1 = fev1 / fvc;
   rasio2 = 97.89444 - 0.31804 * umur;  
 
  lcd.setCursor(0,0);
  lcd.print("FVC=");
  lcd.print(fvc);
  lcd.print(" / ");
  lcd.print(fvcx);

  lcd.setCursor(0,1);
  lcd.print("FEV1=");
  lcd.print(fev1); 
  lcd.print(" / ");
  lcd.print(fev1x); 

  lcd.setCursor(0,2);
  lcd.print("Rasio=");
  lcd.print(rasio1); 
  lcd.print(" / ");
  lcd.print(rasio2);
   
if((rasio1 >= 0.75 * rasio2) && (fvc >= 0.8 * fvcx)){
//normal
  lcd.setCursor(0,3);
  lcd.print("NORMAL        ");
  ket = 1;
}

if((rasio1 >= 0.75 * rasio2) && (fvc < 0.8 * fvcx)){
//restriktif
  lcd.setCursor(0,3);
  lcd.print("RESTRIKTIF    ");
  ket = 2;
}

if((rasio1 < 0.75 * rasio2) && (fvc > 0.8 * fvcx) && (fev1 < 0.95 * fev1x)){
//gangguan obstrukstif
  lcd.setCursor(0,3);
  lcd.print("OBSTRUKTIF    ");
  ket = 3;
}

}


customKey = customKeypad.getKey();
   
     if(customKey == '*'){
      lcd.clear();
      delay(1000);
      return;
     }

hasil();
}




void savesd(){
 
lcd.clear();
lcd.setCursor(0,0);
lcd.print("saving.....");
delay(3000);


  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  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("Jenis Kelamin= ");
   
     if(klm == 1){
     myFile.println("L");
     }
    
     if(klm == 2){
     myFile.println("P");
     }
    
    myFile.print("Umur= ");
    myFile.println(umur);
    myFile.print("Tinggi= ");
    myFile.println(tinggi);
    myFile.print("Kondisi= ");
   
    if(ket == 1){
    myFile.println("NORMAL");   
    }
   
    if(ket == 2){
    myFile.println("RESTRIKTIF");   
    }
   
    if(ket == 3){
    myFile.println("OBSTRUKTIF");   
    }
   
    myFile.println("     ");
   
    // 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");
  }

lcd.setCursor(0,0);
lcd.print("DONE..");
delay(1000);
lcd.clear();

}





f. VIDEO HASILNYA







Membuat Alat Monitor Jarak HC-SRF04 dan Lokasi GPS NEO UBLOX 6MV2 via HANDPHONE ANDROID ARDUINO

Membuat Alat Monitor Jarak HC-SRF04 dan Lokasi GPS NEO UBLOX 6MV2 via HANDPHONE ANDROID ARDUINO


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membat sebuah alat yang dapat memonitor jarak dan lokasi menggunakan arduino dan ditampilkan ke handphone android secara realtime. alat ini menggunakan media bluetooth sebagai media pengiriman datanya sehingga jaraknya tidak bisa jauh. untuk lebih jelasnya berikut adalah skema dan programnya.




a. Arduino Uno




b. LCD + I2C




c. Bluetooth HC-05




d. Sensor Jarak HC-SRF04




e. GPS NEO UBLOX 6MV2




f. Program Android







g. Program Arduino IDE

 //vcc pada GPS modul adalah 3,3 volt
/*********************
 *10 to GPS Module TX*
 *09 to GPS Module RX*
 *********************/

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library

#include <SoftwareSerial.h>
#include <TinyGPS.h>
#define trigPin 9
#define echoPin 8

SoftwareSerial mySerial(10, 11);
TinyGPS gps;

LiquidCrystal_I2C lcd(0x27, 16, 2);

void gpsdump(TinyGPS &gps);
void printFloat(double f, int digits = 2);
long duration, distance;

void setup()
{
   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);
   lcd.begin();
   lcd.clear();
   lcd.noCursor();
 
  // Oploen serial communications and wait for port to open:
  Serial.begin(9600);
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  delay(1000);
  //Serial.println("uBlox Neo 6M");
  //Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version());
  //Serial.println("by Mikal Hart");
  //Serial.println();
  //Serial.print("Sizeof(gpsobject) = ");
  //Serial.println(sizeof(TinyGPS));
  //Serial.println();
}

void loop() // run over and over
{
 
  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(13,0);
  lcd.print(distance);
  lcd.print("      ");
 
  bool newdata = false;
  unsigned long start = millis();
  // Every 5 seconds we print an update
  while (millis() - start < 5000)
  {
    if (mySerial.available())
  
    {
      char c = mySerial.read();
      //Serial.print(c);  // uncomment to see raw GPS data
      if (gps.encode(c))
      {
        newdata = true;
        break;  // uncomment to print new data immediately!
      }
    }
  }

  if (newdata)
  {
    //Serial.println("Acquired Data");
    //Serial.println("-------------");
    gpsdump(gps);
    //Serial.println("-------------");
    //Serial.println();
  }

}

void gpsdump(TinyGPS &gps)
{
  long lat, lon;
  float flat, flon;
  unsigned long age, date, time, chars;
  int year;
  byte month, day, hour, minute, second, hundredths;
  unsigned short sentences, failed;

  gps.get_position(&lat, &lon, &age);
  //Serial.print("Lat/Long(10^-5 deg): "); Serial.print(lat); Serial.print(", "); Serial.print(lon);
  //Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  gps.f_get_position(&flat, &flon, &age);
  //Serial.print("Lat/Long(float): "); printFloat(flat, 5); Serial.print(", "); printFloat(flon, 5);
    //Serial.print(" Fix age: "); Serial.print(age); Serial.println("ms.");

  lcd.setCursor(0,0);
  lcd.print("LAT:");
  lcd.print(flat, 5);
 
  lcd.setCursor(0,1);
  lcd.print("LONG:");
  lcd.print(flon, 5);

  Serial.print("jarak= ");
  Serial.print(distance);
  Serial.println(" cm");
  Serial.print("long= ");
  Serial.println(flat, 5);
  Serial.print("lat= ");
  Serial.println(flon, 5);
    
}

void printFloat(double number, int digits)
{
  // Handle negative numbers
  if (number < 0.0)
  {
     //Serial.print('-');
     number = -number;
  }

  // Round correctly so that print(1.999, 2) prints as "2.00"
  double rounding = 0.5;
  for (uint8_t i=0; i<digits; ++i)
    rounding /= 10.0;

  number += rounding;

  // Extract the integer part of the number and print it
  unsigned long int_part = (unsigned long)number;
  double remainder = number - (double)int_part;
  //Serial.print(int_part);

  // Print the decimal point, but only if there are digits beyond
  if (digits > 0)
   // Serial.print(".");

  // Extract digits from the remainder one at a time
  while (digits-- > 0)
  {
    remainder *= 10.0;
    int toPrint = int(remainder);
    //Serial.print(toPrint);
    remainder -= toPrint;
  }
}





h. VIDEO HASILNYA









Membuat Alat Monitoring Suhu dan Kelembaban DHT22 SMS Gateway SIM900A RTC DS3231 ARDUINO

Membuat Alat Monitoring Suhu dan Kelembaban DHT22 SMS Gateway SIM900A RTC DS3231 ARDUINO


         Pada kesempaan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang bisa digunakan untuk monitoring suhu dan kelembaban dengan indikator berupa SMS. alat ini terdapat fitur RTC yang digunakan untuk menampilkan jam dan waktu kemudian SIM900A digunakan untuk mengirimkan sms tiap jam tertentu sesuai pada program.



a. Arduino Uno




b. Sensor DHT22




c. LCD + I2C




d. RTC Modul






e. Program arduino IDE

#include "Wire.h"
#include <LiquidCrystal.h>
#include "DHT.h"
#include "SIM900.h"
#include <SoftwareSerial.h>

#include "sms.h"
SMSGSM sms;

#define DHTPIN 8     // what digital pin we're connected to
#define DHTTYPE DHT22   // DHT 22
#define DS3231_I2C_ADDRESS 0x68

DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal lcd(9, 10, 4, 5, 6, 7);
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;

int relaykipas1 = A0;
int relaykipas2 = A1;
int relaypompa = A2;
int relayheater = A3;

// 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) );
}


int mark = 0;
char string[160];

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

int tanda = 0;
int tanda2 = 0;

void setup() {

pinMode(relaykipas1,OUTPUT);
pinMode(relaykipas2,OUTPUT);
pinMode(relaypompa,OUTPUT);
pinMode(relayheater,OUTPUT);
 
digitalWrite(relaykipas1,HIGH); 
digitalWrite(relaykipas2,HIGH); 
digitalWrite(relaypompa,HIGH); 
digitalWrite(relayheater,HIGH); 
 
  lcd.begin(16, 2);
  lcd.clear();
  lcd.noCursor();
 
   lcd.setCursor(0,0);
   lcd.print("LOADING......");
  
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");

     if(started) {
         //if (sms.SendSMS("089691234567", "Alat Ready"))
         // Serial.println("\nSMS sent OK");
     }

  dht.begin();
  Serial.begin(9600);
   while (!Serial) {
  }
 
  lcd.clear();
 
    Wire.begin();
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
   setDS3231time(0,59,5,6,23,11,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()
{
  lcd.setCursor(0,1);
  // retrieve data from DS3231
  readDS3231time(&second, &minute, &hour, &dayOfWeek, &dayOfMonth, &month,
  &year);
  // 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);
  lcd.print(" ");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print(" Day of week: ");
  switch(dayOfWeek){
  case 1:
    Serial.println("Sunday");
    break;
  case 2:
    Serial.println("Monday");
    break;
  case 3:
    Serial.println("Tuesday");
    break;
  case 4:
    Serial.println("Wednesday");
    break;
  case 5:
    Serial.println("Thursday");
    break;
  case 6:
    Serial.println("Friday");
    break;
  case 7:
    Serial.println("Saturday");
    break;
  }
}

void loop(){
 displayTime();
 int h = dht.readHumidity();
 int t = dht.readTemperature();
 int f = dht.readTemperature(true);

 sprintf(string,"suhu = %d dan kelembaban = %d ", t , h);
 
 int hum = h ;
 int suhu = t;

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);
 
   lcd.setCursor(0,0);
   lcd.print("s/h=");
   lcd.print(suhu);
   lcd.print("/");
   lcd.print(hum);
   lcd.print("        ");



 if((suhu > 25)&&(suhu < 32)){
 digitalWrite(relaykipas1,HIGH);
 digitalWrite(relaykipas2,HIGH);
 digitalWrite(relayheater,HIGH); 
 }


 if(suhu < 25){
 digitalWrite(relayheater,LOW);
 }
 if(suhu >= 32){
 digitalWrite(relayheater,HIGH);
 digitalWrite(relaykipas1,LOW);
 digitalWrite(relaykipas2,LOW);
 }



 if(hum < 60){
 digitalWrite(relaypompa,LOW);
 }
 if(hum > 60){
 digitalWrite(relaypompa,HIGH);
 }

 if(hum >= 70){
 digitalWrite(relayheater,LOW);
 }

 if(hum < 70){
 digitalWrite(relayheater,HIGH);
 }


 if((suhu > 32)&&(tanda == 0)){
    if (sms.SendSMS("089691234567", "suhu ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda = 1;
 }

 if((suhu >= 25)&&(suhu <= 32)){
  tanda = 0;
 }

 if((suhu < 25)&&(tanda == 0)){
    if (sms.SendSMS("089691234567", "suhu ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda = 1;
 }


 if((hum > 70)&&(tanda2 == 0)){
    if (sms.SendSMS("089691234567", "kelembaban ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda2 = 1;
 }

 if((hum < 60)&&(tanda2 == 0)){
    if (sms.SendSMS("089691234567", "kelembaban ekstrim"))
    Serial.println("\nSMS sent OK");
    tanda2 = 1;   
 }

 if((hum >= 60)&&(hum <= 70)){
    tanda2 = 0;
 }



   if((hour == 6)&&(mark == 0)){  
   if (sms.SendSMS("089691234567", string));
   mark = 1;
   }  

   if((hour == 9)&&(mark == 1)){  
   if (sms.SendSMS("089691234567", string));
   mark = 2;
   }
 
   if((hour == 12)&&(mark == 2)){  
   if (sms.SendSMS("089691234567", string));
   mark = 3;
   } 
  
   if((hour == 15)&&(mark == 3)){  
   if (sms.SendSMS("089691234567", string));
   mark = 4;
   }
  
   if((hour == 18)&&(mark == 4)){  
   if (sms.SendSMS("089691234567", string));
   mark = 0;
   }
 
   delay(1000);
  

 

 


f. VIDEO HASILNYA










Membuat Alat Monitoring Suhu dan kelembaban (Temperature - Humidity) Sensor DHT11 dan SMS GATEWAY SIM900A

Membuat Alat Monitoring Suhu dan kelembaban (Temperature - Humidity) Sensor DHT11 dan SMS GATEWAY SIM900A


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat untuk monitor suhu dan kelembaban dengan notifikasi SMS sebagai alarm atau tanda peringatannya. Alat ini menggunakan Arduino Uno dan sensor DHT11, modul sms yang digunakan adalah SIM900A. jika kelembaban telah mencapai batas tertentu maka alat akan sms ke nomer yang dituju. untuk lebih jelasnya berikut adalah skema dan programnya.



a. Arduino Uno




b. Sensor DHT11




c. Modul SMS SIM900A




d. LCD I2C






e. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h> 
#include "DHT.h"
#include "SIM900.h"
#include <SoftwareSerial.h>

#include "sms.h"
SMSGSM sms;

#define DHTPIN 8     // what digital pin we're connected to
#define DHTTYPE DHT11   // DHT 11

DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal_I2C lcd(0x3F, 16, 2);

int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];

int mark = 0;

void setup() {
  lcd.begin();
  lcd.clear();
  lcd.noCursor();
 
   lcd.setCursor(0,0);
   lcd.print("LOADING......");
  
     //Serial connection.
     Serial.begin(9600);
     Serial.println("GSM Shield testing.");
     //Start configuration of shield with baudrate.
     //For http uses is raccomanded to use 4800 or slower.
     if (gsm.begin(2400)) {
          Serial.println("\nstatus=READY");
          started=true;
     } else Serial.println("\nstatus=IDLE");

     if(started) {
        
     }

  dht.begin();
  Serial.begin(9600);
   while (!Serial) {
  }
 
  lcd.clear();


void loop(){

 float h = dht.readHumidity();
 float t = dht.readTemperature();
 float f = dht.readTemperature(true);

 int hum = h ;
 int suhu = t;

  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  float hif = dht.computeHeatIndex(f, h);
  float hic = dht.computeHeatIndex(t, h, false);
 
   lcd.setCursor(0,0);
   lcd.print("suhu= ");
   lcd.print(suhu);
   lcd.print("            ");
   lcd.setCursor(0,1);
   lcd.print("hum= ");
   lcd.print(hum);
   lcd.print("            ");

   if((hum >= 73)&&(mark == 0)){
   lcd.noBacklight();  
/*
   if (sms.SendSMS("085726234567", "Bahaya"))
   Serial.println("\nSMS sent OK");
 
   mark = 1;
   }
  
   if((hum < 41)&&(mark == 1)){
   lcd.backlight();
   mark = 0;
   }
  
   if((hum < 41)&&(mark == 0)){
   lcd.backlight();
   mark = 0;
   }

   delay(1000);
  

  




f. VIDEO HASILNYA








Membuat Alat Monitor Intensitas Cahaya (LUXMETER) sensor BH1750 dan setting waktu pemakaian RTC DS1307 ARDUINO

Membuat Alat Monitor Intensitas Cahaya (LUXMETER) sensor BH1750 dan setting waktu pemakaian RTC DS1307 ARDUINO


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mengukur intensitas cahaya atau luxmeter dengan menggunakan Arduino dan sensor BH1750, selain itu juga terdapat setting waktu pemakaian sehingga bisa terlihat berapa waktu yang telah dipakai oleh alat. setting waktu menggunakan 4 buah tombol. untuk lebih jelasnya berikut adalah skema dan programnya.  



a. Arduino Uno




b. LCD + I2C




c. Sensor Intensitas Cahaya (LUX) bh1750




d. RTC DS1307






e. Program Arduino IDE

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

LiquidCrystal_I2C lcd(0x3F,16,2);

int btup = 3;
int btdown = 4;
int btok = 5;
int btset = 6;

int savejam;
int jam;

int btupx = 0;
int btdownx = 0;
int btokx = 0;
int btsetx = 0;

int buzzer = 2;

BH1750FVI LightSensor;
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() {
  Serial.begin(9600);
 
  lcd.begin();
  lcd.clear();
  lcd.noCursor();

  pinMode(btup,INPUT_PULLUP);
  pinMode(btdown,INPUT_PULLUP);
  pinMode(btok,INPUT_PULLUP);
  pinMode(btset,INPUT_PULLUP);
  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,HIGH);
 
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(0,0,0,5,10,4,18);
 
  LightSensor.begin();
  LightSensor.SetAddress(Device_Address_H);
  LightSensor.SetMode(Continuous_H_resolution_Mode);
}


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() {

  lux = LightSensor.GetLightIntensity();// Get Lux value
 
  lcd.setCursor(0,0);
  lcd.print("TEKAN TOMBOL");
 
  lcd.setCursor(0,1);
  lcd.print("L:");
  lcd.print(lux);
  lcd.print("      ");

btsetx = digitalRead(btset);
btokx = digitalRead(btok);
btupx = digitalRead(btup);
btdownx = digitalRead(btdown);

if(btsetx == 0){
delay(200);
lcd.clear();
setting();
delay(1000);
lcd.clear();
setDS3231time(0,0,0,5,10,4,18);
mulai();
}

}

void setting(){
 
  lcd.setCursor(0,0);
  lcd.print("SET JAM");
  lcd.setCursor(0,1); 
  lcd.print(jam);
  lcd.print("      ");

btupx = digitalRead(btup);
btdownx = digitalRead(btdown);
btokx = digitalRead(btok);
btsetx = digitalRead(btset);

if(btupx == 0){
delay(200);
jam++;


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

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


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

if(btokx == 0){
delay(2000);
savejam = jam;
lcd.clear();
return;
}

setting();
}

void mulai(){

  displayTime();
  delay(1000);

  lux = LightSensor.GetLightIntensity();// Get Lux value
 
  lcd.setCursor(0,1);
  lcd.print("L:");
  lcd.print(lux);
  lcd.print("  ");
  lcd.print("Jam:");
  lcd.print(savejam);
  lcd.print("         ");

if(savejam == hour){
digitalWrite(buzzer,LOW);
}

mulai();
}






f. VIDEO HASILNYA









Membuat Alat Pagar Buka Tutup Otomatis Menggunakan Arduino Driver Motor IBT-2 Sensor Jarak HC-SRF04 RFID RC-522

Membuat Alat Pagar Buka Tutup Otomatis Menggunakan Arduino Driver Motor IBT-2 Sensor Jarak HC-SRF04 RFID RC-522


         Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat menggunakan Arduino untuk buka tutup pagar otomatis menggunakan RFID, alat ini dilengkapi dengan sensor jarak HC-SRF04 yang difungsikan jika ada orang yang masuk ketika pagar sedang menuju ke mode tutup maka pagar akan berhenti sampai orang atau benda tersebut masuk dan tidak terdeteksi lagi, buka tutup pagar menggunakan kartu RFID dengan tipe RC-522. untuk lebih detailnya berikut adalah skema dan programnya. 




a. Arduino Uno




b. RFID RC-522




c. Driver Motor IBT-2




d. Sensor Jarak HC-SRF04






e. Program Arduino IDE

#include <SPI.h> //library serial parallel interface
#include <Wire.h> //library untuk wire i2c
#include <RFID.h> //library RFID

#define sda 10 //Pin Serialdata (SDA)
#define rst 9 //pin Reset
#define trigPin 2
#define echoPin 3

int sw1 = 7;
int sw2 = 6;
int sw1x = 0;
int sw2x = 0;

int pwm1 = 4;
int pwm2 = 5;

RFID rfid(sda,rst);
long duration, distance;

void setup(){
    Serial.begin(9600); //baud komunikasi serial monitor
    SPI.begin(); //Prosedur antarmuka SPI
    rfid.init(); //Memulai inialisasi module RFID
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
   
    pinMode(sw1, INPUT_PULLUP);
    pinMode(sw2, INPUT_PULLUP);
    pinMode(pwm1, OUTPUT);
    pinMode(pwm2, OUTPUT);
    
}


void loop(){

if(rfid.isCard()){
if(rfid.readCardSerial()){
  
   Serial.print(rfid.serNum[0]); //serial no.1
   Serial.print(" ");
  
   Serial.print(rfid.serNum[1]); //serial no.2
   Serial.print(" ");
  
   Serial.print(rfid.serNum[2]); //serial no.3
   Serial.print(" ");
   
   Serial.print(rfid.serNum[3]); //serial no.4
   Serial.print(" ");
  
   Serial.print(rfid.serNum[4]); //serial no.5
   Serial.println("");

 if((rfid.serNum[0] == 11) && (rfid.serNum[1] == 197) && (rfid.serNum[2] == 157) && (rfid.serNum[3] == 35) && (rfid.serNum[4] == 112)){
   Serial.println("BENAR");
  //buka
  analogWrite(pwm1,0);
  analogWrite(pwm2,100);
  buka();
  //tutup
  analogWrite(pwm1,150);
  analogWrite(pwm2,0);
  tutup();  
 }


   delay(1000);

   }  }  
     
 }

void buka(){
  Serial.println("BUKA");
  sw1x = digitalRead(sw1);
  
  if(sw1x == LOW){
  analogWrite(pwm1,0);
  analogWrite(pwm2,0);
  delay(10000);  //delay saat pagar buka dan mau nutup
  return;
  }

 buka();
}


void tutup(){
  Serial.println("TUTUP");
  sw2x = digitalRead(sw2);
 
  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;
  Serial.print(distance);
  Serial.println(" cm");
  delay(1000);

  if((distance < 100)&&(sw2x == HIGH)){
  //tutup
  analogWrite(pwm1,0);
  analogWrite(pwm2,0);
  }

  if((distance > 100)&&(sw2x == HIGH)){
  analogWrite(pwm1,150);
  analogWrite(pwm2,0);
  }
 
  if((distance > 100)&&(sw2x == LOW)){
  analogWrite(pwm1,0);
  analogWrite(pwm2,0);
  return;
  }
 
 tutup();
}






f. VIDEO HASILNYA









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