Translate

Membuat Alat Ukur dan Monitor Kadar Gula Darah Dalam Tubuh Secara NON INVASIVE Menggunakan Arduino

Membuat Alat Ukur dan Monitor Kadar Gula Darah Dalam Tubuh Secara NON INVASIVE Menggunakan Arduino


        Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk mengukur kadar gula darah dalam tubuh dengan menggunakan Arduino dan sensor yang dipakai adalah photodioda. alat ini menggunakan LCD TFT sebagai interfacenya. dan juga terdapat sebuah tombol untuk memulai pengukurannya. untuk lebih jelasnya berikut adalah daftar komponen dan programnya. 




a. Arduino Uno




b. LCD TFT




c. Sensor Photodioda dan Led Merah

     R3 = 100 Kohm
     R2 = 220 Ohm






d. Program Arduino IDE

#include <Adafruit_GFX.h>    // Core graphics library
#include <MCUFRIEND_kbv.h>   // Hardware-specific library
MCUFRIEND_kbv tft;

#include <Fonts/FreeSans9pt7b.h>
#include <Fonts/FreeSans12pt7b.h>
#include <Fonts/FreeSerif12pt7b.h>

#include <FreeDefaultFonts.h>

#define BLACK   0x0000
#define RED     0xF800
#define GREEN   0x07E0
#define WHITE   0xFFFF
#define GREY    0x8410

int adcsensor;
int buzzer = 11;
int btok = 10;
float fix;
int datafix;
int cacah;
float kalibrasi;

void setup()
{
    uint16_t ID = tft.readID();
    if (ID == 0xD3D3) ID = 0x9481; //force ID if write-only display
    tft.begin(ID);
    tft.setRotation(0);
    tft.fillScreen(BLACK);
    tft.setTextColor(GREEN, BLACK);
    tft.setTextSize(2);
    pinMode(buzzer,OUTPUT);
    pinMode(btok,INPUT_PULLUP);
    
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);

}

void loop()
{

    int x = digitalRead(btok);
    
    tft.setTextColor(GREEN, BLACK);
    tft.setCursor(15, 60);
    tft.print("TEKAN TOMBOL       ");
    tft.setCursor(15, 80);
    tft.print("UNTUK MULAI        ");
   

if(x == 0){
    tft.setTextColor(GREEN, BLACK);
    tft.setCursor(15, 60);
    tft.print(" TUNGGU SEBENTAR   ");
    tft.setCursor(15, 80);
    tft.print(" SEDANG PROSES     ");

    tft.setTextColor(GREEN, BLACK);
    tft.setCursor(15, 110);
    tft.print("                  ");
    tft.setCursor(15, 130);
    tft.print("                  ");
    tft.setCursor(15, 150);
    tft.print("                  ");
    tft.setTextColor(RED, BLACK);
    tft.print("                  ");
    tft.setCursor(15, 190);
    tft.print("                  ");
    
    delay(5000);
    cacah = 0;
    datafix = 0;
    fix = 0;
  proses();
  }
   
    delay(200);
}


void proses(){
  
    adcsensor = analogRead(A3);

    tft.setTextColor(GREEN, BLACK);
    tft.setCursor(15, 60);
    tft.print("Monitor Gula Darah ");
    tft.setCursor(15, 80);
    tft.print("ADC= ");
    tft.setTextColor(RED, BLACK);
    tft.print(adcsensor);
    tft.print("      ");

cacah++;

datafix = adcsensor + datafix;

delay(10);

if(cacah > 20){
  fix = datafix / 20.0;
  kalibrasi = (fix - 1022.1) / 0.0967;

  if(kalibrasi > 200){
    digitalWrite(buzzer,HIGH);
    }
  if(kalibrasi < 200){
    digitalWrite(buzzer,LOW);
    }
    
    tft.setTextColor(GREEN, BLACK);
    tft.setCursor(15, 110);
    tft.print("KADAR Gula Darah");
    tft.setCursor(15, 130);
    tft.print("mg/dl= ");
    tft.setTextColor(RED, BLACK);
    tft.print(kalibrasi);
    tft.setTextColor(GREEN, BLACK);
    tft.setCursor(15, 150);
    tft.print("ADC= ");
    tft.setTextColor(RED, BLACK);
    tft.print(fix);
    tft.print("      ");

  if(kalibrasi < 60){
    tft.setTextColor(GREEN, BLACK);
    tft.setCursor(15, 190);
    tft.print("KADAR RENDAH    ");    
    }

  if((kalibrasi >= 60)&&(kalibrasi <= 90)){
    tft.setTextColor(WHITE, BLACK);
    tft.setCursor(15, 190);
    tft.print("KADAR NORMAL    ");    
    } 

  if(kalibrasi > 90){
    tft.setTextColor(RED, BLACK);
    tft.setCursor(15, 190);
    tft.print("KADAR TINGGI    ");    
    }   
    
  return;  
  }
  
  
proses();  
  }





e. VIDEO HASILNYA








Membuat Robot Line Tracer atau Robot Line Follower Menggunakan ARDUINO

Membuat Robot Line Tracer atau Robot Line Follower Menggunakan ARDUINO


           Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah robot dengan menggunakan Arduino sebagai kontrollernya. robot ini menggunakan sensor photodioda dan driver motor yang digunakan adalah modul drver L298. untuk lebih jelasnya berikut adalah daftar komponen dan programnya.




a. Arduino Uno




b. Driver Motor L298




c. Sensor Photodioda dan LED 




d. Motor DC dan Roda






e. Program Arduino IDE

#include <Wire.h>

int a,b,c,d,e,f,g,h ;
int aa = A3;
int bb = A4;
int cc = A5;

int a1 = 950;
int b1 = 850;
int c1 = 850;
int d1 = 900;
int e1 = 860;
int f1 = 850;
int g1 = 860;
int h1 = 750;

int kecepatan = 155;

void setup(){
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(aa,OUTPUT);
pinMode(bb,OUTPUT);
pinMode(cc,OUTPUT);
pinMode(11,OUTPUT);
digitalWrite(11,LOW);
Serial.begin (9600);
}


void loop(){
digitalWrite(aa,LOW);
digitalWrite(bb,LOW);
digitalWrite(cc,LOW);
a = analogRead(A0);

digitalWrite(aa,LOW);
digitalWrite(bb,LOW);
digitalWrite(cc,HIGH);
b = analogRead(A0);

digitalWrite(aa,LOW);
digitalWrite(bb,HIGH);
digitalWrite(cc,LOW);
c = analogRead(A0);

digitalWrite(aa,LOW);
digitalWrite(bb,HIGH);
digitalWrite(cc,HIGH);
d = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,LOW);
digitalWrite(cc,LOW);
e = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,LOW);
digitalWrite(cc,HIGH);
f = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,HIGH);
digitalWrite(cc,LOW);
g = analogRead(A0);

digitalWrite(aa,HIGH);
digitalWrite(bb,HIGH);
digitalWrite(cc,HIGH);
h = analogRead(A0);

Serial.print (a);
Serial.print (" ");
Serial.print (" ");
Serial.print (b);
Serial.print (" ");
Serial.print (" ");
Serial.print (c);
Serial.print (" ");
Serial.print (" ");
Serial.print (d);
Serial.print (" ");
Serial.print (" ");
Serial.print (e);
Serial.print (" ");
Serial.print (" ");
Serial.print (f);
Serial.print (" ");
Serial.print (" ");
Serial.print (g);
Serial.print (" ");
Serial.print (" ");
Serial.println (h);


if ((a > a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}

if ((a < a1)&&(b > b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}

if ((a < a1)&&(b < b1)&&(c > c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}

if ((a < a1)&&(b < b1)&&(c < c1)&&(d > d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan); 
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e > e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f > f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g > g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h > h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan); 
}
if ((a > a1)&&(b > b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b > b1)&&(c > c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c > c1)&&(d > d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d > d1)&&(e > e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e > e1)&&(f > f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f > f1)&& (g > g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g > g1)&&(h > h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a > a1)&&(b < b1)&&(c < c1)&&(d > d1)&&(e > e1)&&(f > f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, LOW);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a < a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f < f1)&& (g < g1)&&(h < h1)) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
analogWrite(10,kecepatan);
}
if ((a > a1)&&(b > b1)&&(c > c1)&&(d > d1)&&(e > e1)&&(f > f1)&& (g > g1)&&(h > h1)) {
  digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
analogWrite(10,kecepatan);
}
if ((a > a1)&&(b < b1)&&(c < c1)&&(d < d1)&&(e < e1)&&(f > f1)&& (g > g1)&&(h > h1)) {
  digitalWrite(2, HIGH);
digitalWrite(3, LOW);
analogWrite(9,kecepatan);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
analogWrite(10,kecepatan);
delay(5000);
}
}





f. VIDEO HASILNYA









Membuat Alat Monitor Arus dan Tegangan AC Daya KWH Meter Menggunakan Arduino dan sensor ZMPT101b dan ACS 712 Topup saldo via Bluetooth Android

Membuat Alat Monitor Arus dan Tegangan AC Daya KWH Meter Menggunakan Arduino dan sensor ZMPT101b dan ACS 712 Topup Saldo via Bluetooth Android


          Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat digunakan untuk monitoring arus dan tegangan dan menghitung daya terpakai seperti KWH meter. alat ini menggunakan arduino sebagai mikrokontrollernya dan RTC sebagai pewaktunya. alat ini bisa d topup saldo untuk isi ulangnya dengan menggunakan handphone android atau tab android via bluetooth. untuk lebih jelasnya berikut adalah program dan daftar komponennya.




a. Arduino Mega




b. Sensor Tegangan AC ZMPT101B




c. Sensor Arus ACS712




d. Module Relay 1 channel




e. Module RTC




f. LCD 16x2 + I2C






g. Program Arduino IDE

#include <Wire.h>  // i2C Conection Library
#include <LiquidCrystal_I2C.h>  //i2C LCD Library
#define DS3231_I2C_ADDRESS 0x68

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

char string[160];
int numdata;
boolean started=false;
char smsbuffer[160];
char n[20];
char strsms[5];
  byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
int menit;
float total;

unsigned long start_times[300];
unsigned long stop_times[300];
unsigned long values[300];

// Define various ADC prescaler
const unsigned char PS_16 = (1 << ADPS2);
const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0);
const unsigned char PS_64 = (1 << ADPS2) | (1 << ADPS1);
const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0);

int a = 0;
int zero = 1;
int vin = 0;
int iin = 0;
String dataku;
int isi;
int relay = 2;
int buzzer = 48;
float sisa;
unsigned int i;
unsigned int z;

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

  pinMode(relay,OUTPUT);
  digitalWrite(relay,HIGH);

  pinMode(buzzer,OUTPUT);
  digitalWrite(buzzer,LOW);

  Serial1.begin(9600);
  Serial1.setTimeout(5);

  lcd.begin();
  lcd.clear();
  lcd.noCursor();

  // set up the ADC
  ADCSRA &= ~PS_128;  // remove bits set by Arduino library

  // you can choose a prescaler from above.
  // PS_16, PS_32, PS_64 or PS_128
  ADCSRA |= PS_128;    // set our own prescaler to 64

 Wire.begin();
  Serial.begin(9600);
  // set the initial time here:
  // DS3231 seconds, minutes, hours, day, date, month, year
  // setDS3231time(0,30,7,6,24,7,15);

}


void loop() {


 if (Serial1.available()>0)
  {
    dataku = Serial1.readString();
    isi = dataku.toInt();
    sisa = isi;
  }


displayTime();

  z = 0;
 
  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A0);           

  if (values[i] >= z) {
  z = values[i];
  }
    stop_times[i] = micros();
  }

   int vin = z ;

  z = 0;

  //================================
  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A1);           

  if (values[i] >= z) {
  z = values[i];
  }
    stop_times[i] = micros();
  }
     float v1 = z * (5.0/1023.0);
     float iin = (v1-2.5)/0.1 ;

z = 0;

  // capture the values to memory
  for(i=0;i<300;i++) {
    start_times[i] = micros();
    values[i] = analogRead(A1);           

  if (values[i] >= z) {
  z = values[i];
  }
    stop_times[i] = micros();
  }
     float v1x = z * (5.0/1023.0);
     float iinx = (v1x-2.5)/0.1 ;

float iintot = (iin + iinx) / 2;

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

 z = 0;

float vrms = (vin - 530.9) / 0.413 ;

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

float p = vrms * iin;

if((menit != minute)&&(isi > 0)){
total = (p / 1000.0) + total;
menit = minute;
}

if((total >= isi)&&(isi > 0)){
digitalWrite(relay,HIGH);
}

if((total < isi)&&(isi > 0)){
digitalWrite(relay,LOW);
}

if((total >= sisa - 1)&&(isi > 0)){
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(500);
}

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

  lcd.setCursor(0, 0);
  lcd.print(vrms,1);

  lcd.print("/");
  lcd.print(iintot);
  lcd.print(" ");

  lcd.setCursor(9, 1);
  lcd.print(total);
  lcd.print("     ");

delay(200);
}



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);
  // send it to the serial monitor
  lcd.setCursor(0, 1);
  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);

}





h. Program Android







i. VIDEO HASILNYA










Membuat Alat Kendali Konveyor Deteksi Lubang dan Ketinggian Benda ARDUINO SENSOR LDR dan Jarak HC-SRF04

Membuat Alat Kendali Konveyor Deteksi Lubang dan Ketinggian Benda ARDUINO SENSOR LDR dan Jarak HC-SRF04



            Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat mendeteksi lubang dan ketinggian benda dengan menggunakan sensor LDR dan sensor HC-SRF04. alat ini dilengkapi dengan konveyor yang berfungsi untuk menjalankan benda dari posisi awal ke posisi akhir. jika terdeteksi ada lubang pada benda maka motor pada konveyor akan bernhenti dan buzzer menyala. begitupula jika terdeteksi ketinggian benda yang melebihi normal maka buzzer juga akan menyala. untuk lebih jelasnya berikut adalah program dan daftar komponenya. 




a. Arduino Mega




b. Sensor Cahaaya / LDR




c. Sensor HC-SRF04




d. Modul Driver Motor L298




e. LCD OLED






f. Program Arduino IDE

#include <EEPROM.h>
#include <Wire.h>
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NO_ACK);  

#define trigPin 15
#define echoPin 14

char tmp_string1[8];
char tmp_string2[8];
char tmp_string3[8];
char tmp_string4[8];
char tmp_string5[8];

int buzzer = 11;
int ledhijau = A6;
int ledmerah = A7;

int counter;

int batas1 = 50;
int batas2 = 50;

int motor1 = 2;
int motor2 = 3;
int pwmena = 9;
int ok;

int bton = 6;
int btoff = 7;
int resetku = 5;


int btonx = 0;
int btoffx = 0;
int resetkux = 0;
int cacah = 0;

int dataadc1, dataadc2;
long duration, distance;

int addr;

void draw(){

 itoa(distance, tmp_string1, 8);
 itoa(dataadc1, tmp_string2, 8);
 itoa(dataadc2, tmp_string3, 8);
 itoa(ok, tmp_string4, 8);
 itoa(counter, tmp_string5, 8);

  u8g.setFont(u8g_font_unifont);
  u8g.drawStr(0, 22, "J= "); 
  u8g.drawStr(40, 22, tmp_string1);
  u8g.drawStr(80, 22, tmp_string5);
  u8g.drawStr(0, 40, "A= "); 
  u8g.drawStr(20, 40, tmp_string2);
  u8g.drawStr(50, 40, "/");
  u8g.drawStr(60, 40, tmp_string3);
  u8g.drawStr(0, 60, "OK= "); 
  u8g.drawStr(40, 60, tmp_string4);
  
}

void setup() {
  
  Serial.begin (9600);

  pinMode(ledhijau, OUTPUT);  
  pinMode(ledmerah, OUTPUT);  

  pinMode(trigPin, OUTPUT);  
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);

  pinMode(bton, INPUT_PULLUP);
  pinMode(btoff, INPUT_PULLUP);
  pinMode(resetku, INPUT_PULLUP);

  pinMode(9,OUTPUT);
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);

  digitalWrite(ledhijau,LOW);
  digitalWrite(ledmerah,LOW);
  digitalWrite(buzzer,LOW);

  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
    u8g.setColorIndex(255);     // white
  }
  else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
    u8g.setColorIndex(3);         // max intensity
  }
  else if ( u8g.getMode() == U8G_MODE_BW ) {
    u8g.setColorIndex(1);         // pixel on
  }
  else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
    u8g.setHiColorByRGB(255,255,255);
  }
  
  ok = EEPROM.read(addr);

 }

 void loop() {
  
 btonx = digitalRead(bton);  
 btoffx = digitalRead(btoff);  
 resetkux = digitalRead(resetku);  
   
 u8g.firstPage();
  do {
    draw();

  } while( u8g.nextPage() );   

   
 dataadc1 = analogRead(A0);   
 dataadc2 = analogRead(A1);   

if(btonx == 0){   
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
analogWrite(9,100);
digitalWrite(ledhijau,LOW);
digitalWrite(ledmerah,HIGH);
}

if(btoffx == 0){   
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(buzzer,LOW);
analogWrite(9,0);
}


if((dataadc1 < batas1)&&(dataadc2 < batas2)){
counter = 0;
proses();
}


if(resetkux == 0){   
ok = 0;
}

  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;

delay(200);
}

void proses(){

 EEPROM.write(addr, ok);

 btonx = digitalRead(bton);  
 btoffx = digitalRead(btoff);  
 resetkux = digitalRead(resetku);  

if(btonx == 0){   
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
analogWrite(9,100);
digitalWrite(ledhijau,LOW);
digitalWrite(ledmerah,HIGH);
}

if(btoffx == 0){   
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(buzzer,LOW);
analogWrite(9,0);
}

if(resetkux == 0){   
ok = 0;
}
   
 u8g.firstPage();
  do {
    draw();

  } while( u8g.nextPage() );   

dataadc1 = analogRead(A0);   
dataadc2 = analogRead(A1);   

counter++;

if(counter >= 5){
counter = 0;  
ok++;
}

if(dataadc1 >= batas1){
digitalWrite(ledhijau,HIGH);
digitalWrite(ledmerah,LOW);
digitalWrite(buzzer,HIGH);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
analogWrite(9,0);
berhenti();
return;
}

if(dataadc2 >= batas2){
digitalWrite(ledhijau,HIGH);
digitalWrite(ledmerah,LOW);
digitalWrite(buzzer,HIGH);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
analogWrite(9,0);
berhenti();
return;
}

  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;

if(distance < 6){
digitalWrite(ledhijau,HIGH);
digitalWrite(ledmerah,LOW);
digitalWrite(buzzer,HIGH);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
analogWrite(9,0);
berhenti();
return;
}

delay(50);
proses();
}

void berhenti(){

 btonx = digitalRead(bton);  
 btoffx = digitalRead(btoff);  
 resetkux = digitalRead(resetku);  

if(btonx == 0){   
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
analogWrite(9,100);
digitalWrite(ledhijau,LOW);
digitalWrite(ledmerah,HIGH);
return;
}

if(btoffx == 0){   
digitalWrite(2,LOW);
digitalWrite(3,LOW);
digitalWrite(buzzer,LOW);
analogWrite(9,0);
}

berhenti();
}






g. VIDEO HASILNYA





   
        



Arduino Monitor Ketinggian / Level Menggunakan Sensor Potensiometer

Arduino Monitor Ketinggian / Level Menggunakan Sensor Potensiometer


      Pada kesempatan kali ini saya akan menjelaskan mengenai bagaimana cara membuat sebuah alat yang dapat memonitor ketinggian atau level suatu kondisi dengan menggunakan sensor potensiometer, sensor ini menggunakan putaran agar didapat perubahan tegangan, dari nilai tegangan tersebut didapatlah suatu level yang bisa dimonitor. untuk lebiih jelasnya berikut adalah program dan daftar komponennya.



a. Arduino Uno




b. Modul Relay 1 channel




c. Sensor Potensio




d. Lcd 16x2 + I2C






e. Program Arduino IDE

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2);

int relay = 7;
int dataadc;

int maxValue = 1023;
int minValue = 0;
int friendlymaxValue = 100;
int friendlyminValue = 0;

int jarak;

void setup(){
pinMode(relay,OUTPUT);
digitalWrite(relay,HIGH);
lcd.begin();
lcd.noCursor();
lcd.clear();

}

void loop(){

  dataadc = analogRead(A0);
  jarak = map(dataadc, maxValue, minValue, friendlymaxValue, friendlyminValue);
  
  lcd.setCursor(0,0);
  lcd.print("T= ");
  lcd.print(jarak);
  lcd.print(" cm      ");
  
  if(jarak < 20){
  digitalWrite(relay,LOW);
  }
  
  if(jarak >= 20){
  digitalWrite(relay,HIGH);
  }
  
  
delay(200);  
}





f. VIDEO HASILNYA