diff --git a/ESP32_test_thinger.io/ESP32_test_thinger.io.ino b/ESP32_test_thinger.io/ESP32_test_thinger.io.ino new file mode 100644 index 0000000..37689a2 --- /dev/null +++ b/ESP32_test_thinger.io/ESP32_test_thinger.io.ino @@ -0,0 +1,32 @@ +#include +#include + +#define USERNAME "atmduino" +#define DEVICE_ID "Esp32_trial" +#define DEVICE_CREDENTIAL "GruAmtNTKkzd" + +#define SSID "Pkm_asia" +#define SSID_PASSWORD "sistemkomputer" + +// define your board pin here +#define LED_PIN 15 + +ThingerESP32 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); + +void setup() { + pinMode(LED_PIN, OUTPUT); + + thing.add_wifi(SSID, SSID_PASSWORD); + + // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) + thing["led"] << digitalPin(LED_PIN); + + // resource output example (i.e. reading a sensor value) + thing["millis"] >> outputValue(millis()); + + // more details at http://docs.thinger.io/arduino/ +} + +void loop() { + thing.handle(); +} diff --git a/IoT_Tranning/IoT_Tranning.ino b/IoT_Tranning/IoT_Tranning.ino new file mode 100644 index 0000000..d9b7268 --- /dev/null +++ b/IoT_Tranning/IoT_Tranning.ino @@ -0,0 +1,50 @@ +#include "DHT.h" // including the library of DHT11 temperature and humidity sensor +#define DHTTYPE DHT11 // DHT 11 + +#define dht_dpin D5 +DHT dht(dht_dpin, DHTTYPE); + +#include +#include + +#define USERNAME "atmduino" +#define DEVICE_ID "IoT_Tranning" +#define DEVICE_CREDENTIAL "zi5pTaWVGoeH" + +#define SSID "Pkm_asia" +#define SSID_PASSWORD "sistemkomputer" + +// thinger.io config +ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); + +void setup() { + dht.begin(); + pinMode(D4, OUTPUT); + pinMode(D5, INPUT) ; + pinMode(D6, OUTPUT); + pinMode(D7, OUTPUT); + + thing.add_wifi(SSID, SSID_PASSWORD); + + + + // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) + thing["Stop Kontak"] << digitalPin(D6); + thing["Lampu"] << digitalPin(D7); + // resource output example (i.e. reading a sensor value) + //thing["millis"] >> outputValue(millis()); + //pembacaan sensor dht11 + thing["dht11"] >>[](pson & out){ + out["humidity"] = dht.readHumidity(); + out["celsius"] = dht.readTemperature(); + out["fahrenheit"] = dht.readTemperature(true); + + }; + + // more details at http://docs.thinger.io/arduino/ +} + +void loop() { + thing.handle(); + digitalWrite(D4, HIGH); +} diff --git a/IoT_firebase_nodemcu/IoT_firebase_nodemcu.ino b/IoT_firebase_nodemcu/IoT_firebase_nodemcu.ino new file mode 100644 index 0000000..bf5c421 --- /dev/null +++ b/IoT_firebase_nodemcu/IoT_firebase_nodemcu.ino @@ -0,0 +1,56 @@ +#include "FirebaseESP8266.h" +#include "DHT.h" +#include + +#define FIREBASE_HOST "smarthomeasia1.firebaseio.com" +#define FIREBASE_AUTH "HYv6JMXLZP2PSKZTZFvcyiQssQw2d6SZ8gxKESjK" +#define WIFI_SSID "ggwp" // Change the name of your WIFI +#define WIFI_PASSWORD "sksaturasa" // Change the password of your WIFI +FirebaseData firebaseData; +#define DHTPIN D5 // Data Pin of DHT 11 , for NodeMCU D5 GPIO no. is 14 +#define lamp D6 +#define kipa D7 +#define DHTTYPE DHT11 // DHT 11 +DHT dht(DHTPIN, DHTTYPE); +int kip,lam; + +void setup() { + Serial.begin(9600); + pinMode(D4,OUTPUT); + pinMode(lamp,OUTPUT); + pinMode(DHTPIN,INPUT); + pinMode(kipa,OUTPUT); + WiFi.begin (WIFI_SSID, WIFI_PASSWORD); + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + dht.begin(); + Serial.println (""); + Serial.println ("WiFi Connected!"); + Firebase.begin(FIREBASE_HOST,FIREBASE_AUTH); + +} + +void loop() { + +kip=Firebase.getInt(firebaseData,"lampu22"); +lam=Firebase.getInt(firebaseData,"lampu12"); +if(kip==1){ + digitalWrite(kipa,HIGH); + digitalWrite(D4,HIGH); + Firebase.setInt(firebaseData,"k",3); +} +if(kip==0){ + digitalWrite(D4,LOW); + digitalWrite(kipa,LOW); + Firebase.setInt(firebaseData,"k",2); +} +if(lam==1){ + digitalWrite(lamp,HIGH); +} +if(lam==0){ + digitalWrite(lamp,LOW); +} + +} diff --git a/LF/LF.ino b/LF/LF.ino new file mode 100644 index 0000000..c1b5ede --- /dev/null +++ b/LF/LF.ino @@ -0,0 +1,145 @@ +/************************** + light follower robot + www.muhilham.com + 30/07/2018 +***********************/ + +//Motor Kiri +#define DIR_KI1 4 // IN4 +#define DIR_KI2 5 // IN3 +#define PWM_KI 3 // ENB +//Motor Kanan +#define DIR_KA1 7 // IN2 +#define DIR_KA2 8 // IN1 +#define PWM_KA 9 // ENA + +const int pinSensor[3] = {A0, A1, A2}; +int level = 150; +int threshold_SenKiri, threshold_SenTengah, threshold_SenKanan; +int baca[3]; + +int Kec_Min = -170; +int Kec_Max = 200; // Max = 255 + +void setup() { + //Serial.begin(9600); + pinMode(13, OUTPUT); + digitalWrite(13, LOW); + for (int i = 4; i <= 9; i++) { // Set pin digital 4 - 9 sebagai output (direction motor) + pinMode(i, OUTPUT); + } + for (int i = 0; i <= 2; i++) { // Kalibrasi batas ambang nilai sensor + pinMode(pinSensor[i], INPUT); + baca[i] = analogRead(pinSensor[i]); + } + threshold_SenKiri = baca[0] + level; + threshold_SenTengah = baca[1] + level; + threshold_SenKanan = baca[2] + level; +} + +void loop() { + for (int i = 0; i <= 2; i++) { + baca[i] = analogRead(pinSensor[i]); + } + Serial.print(threshold_SenKiri); + Serial.print("|"); + Serial.print(threshold_SenTengah); + Serial.print("|"); + Serial.print(threshold_SenKanan); + Serial.print("\t"); + Serial.print(baca[0]); + Serial.print("|"); + Serial.print(baca[1]); + Serial.print("|"); + Serial.print(baca[2]); + Serial.print("\t"); + followLight(); +} + +void followLight() { + int sensor = BacaSensor(); + if (sensor != 0b000) { + switch (sensor) { + case 0b001 : driveMotor(Kec_Max / 2, Kec_Max); break; + case 0b011 : driveMotor(Kec_Max / 3, Kec_Max / 2); break; + case 0b010 : driveMotor(Kec_Max, Kec_Max); break; + case 0b111 : driveMotor(Kec_Max, Kec_Max); break; + case 0b110 : driveMotor(Kec_Max / 2, Kec_Max / 3); break; + case 0b100 : driveMotor(Kec_Max, Kec_Max / 2); break; + } + } + else { + driveMotor(0, 0); + } +} + +void driveMotor(int KEC_KI, int KEC_KA) { + /** Motor Kiri **/ + if (KEC_KI < 0) { + digitalWrite(DIR_KI1, LOW); + digitalWrite(DIR_KI2, HIGH); + } + else if (KEC_KI > 0) { + digitalWrite(DIR_KI1, HIGH); + digitalWrite(DIR_KI2, LOW); + } + else { + digitalWrite(DIR_KI1, HIGH); + digitalWrite(DIR_KI2, HIGH); + } + + /** Motor Kanan **/ + if (KEC_KA < 0) { + digitalWrite(DIR_KA1, LOW); + digitalWrite(DIR_KA2, HIGH); + } + else if (KEC_KA > 0) { + digitalWrite(DIR_KA1, HIGH); + digitalWrite(DIR_KA2, LOW); + } + else { + digitalWrite(DIR_KA1, HIGH); + digitalWrite(DIR_KA2, HIGH); + } + + analogWrite(PWM_KI, abs(KEC_KI)); // Kirim PWM Kiri + analogWrite(PWM_KA, abs(KEC_KA)); // Kirim PWM Kanan + + /*** Pembatasan kecepatan ***/ + if (KEC_KI > Kec_Max)KEC_KI = Kec_Max; + if (KEC_KI < Kec_Min)KEC_KI = Kec_Min; + if (KEC_KA > Kec_Max)KEC_KA = Kec_Max; + if (KEC_KA < Kec_Min)KEC_KA = Kec_Min; + + Serial.print("PWM Kiri : "); + Serial.print(KEC_KI); + Serial.print(" | "); + Serial.print("PWM Kanan : "); + Serial.print(KEC_KA); + Serial.print(" | "); + Serial.print(" "); +} + +int BacaSensor() { + int SenKiri, SenTengah, SenKanan; + int Sensor = 0; + + if (baca[0] > threshold_SenKiri) SenKiri = 1; + else SenKiri = 0; + if (baca[1] > threshold_SenTengah) SenTengah = 1; + else SenTengah = 0; + if (baca[2] > threshold_SenKanan) SenKanan = 1; + else SenKanan = 0; + + int Sen[3] = {SenKiri, SenTengah, SenKanan}; + for (int i = 0; i <= 2; i++) { + if (Sen[i] == 1) { + Sensor = Sensor | (0b100 >> i); + } + Serial.print("|"); + Serial.print(Sen[i]); + Serial.print("|"); + if (i == 2) Serial.println(" "); + } + return Sensor; +} diff --git a/Line_Follower_PID/Line_Follower_PID.ino b/Line_Follower_PID/Line_Follower_PID.ino new file mode 100644 index 0000000..d0c9910 --- /dev/null +++ b/Line_Follower_PID/Line_Follower_PID.ino @@ -0,0 +1,452 @@ +#include +#include +#include + +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + + +#define selA A0 +#define selB A1 +#define selC A2 +#define sensLeft A4 +#define sensRight A3 +#define tombol1 2 +#define tombol2 4 +#define tombol3 0 +#define tombol4 1 +#define pwmKanan 10 +#define pwmKiri 9 +#define dirLA 8 +#define dirLB 7 +#define dirRA 5 +#define dirRB 6 +#define buzzer 3 + +int minSementara[13],maxSementara[13],minSensor[13],maxSensor[13]; +int ulang,eAverage[13]; +unsigned char valueLine[13],tombol[4]; +char lcdBuff[16]; +unsigned char Kp = 20; +unsigned char Kd = 35; +unsigned char max_pwm_ref=180; +int rate_error, error, last_error, MV,pid_l,pid_r; +int binerLine[12],hexaSensor,turnKe; +int intersectionKe=1; +int tandaT,tandaL,mirrorIntersection,gantiBackground,countBlackWhite,jmlIntersection,cekPoinKe[10],tambahCekPoin; +int Max_MV; +byte cZero[8]= +{ + B00000, + B00000, + B00000, + B00000, + B00000, + B00000, + B11111, + B11111, +}; +byte cOne[8]= +{ + B11111, + B11111, + B11111, + B11111, + B11111, + B11111, + B11111, + B11111, +}; +void setup() { + // put your setup code here, to run once: + lcd.begin(16,2); + lcd.createChar (0, cZero); + lcd.createChar (1, cOne); + lcd.home(); + for(int out=5; out<=10; out++) + { + pinMode(out, OUTPUT); + } + pinMode(tombol1, INPUT_PULLUP); + pinMode(tombol2, INPUT_PULLUP); + pinMode(tombol3, INPUT_PULLUP); + pinMode(tombol4, INPUT_PULLUP); + pinMode(selA, OUTPUT); + pinMode(selB, OUTPUT); + pinMode(selC, OUTPUT); + +} + + +void loop(){ + + awal: + actifMux(); + lcd.setCursor(0,0); + lcd.print(" < ^ v > "); + lcd.setCursor(0,1); + lcd.print("Set Run Sens PID"); + if(digitalRead(tombol1)==0) + { + delay(150); tune();lcd.clear();goto setKp; + } + if(digitalRead(tombol2)==0) + { + delay(150); tune();lcd.clear();goto setSens; + } + if(digitalRead(tombol3)==0) + { + delay(150); tune();lcd.clear();goto freeRunning; + } + if(digitalRead(tombol4)==0) + { + delay(150); tune();lcd.clear(); goto freeRunning; + } + goto awal; +setKp: + actifMux(); + Kp=EEPROM.read(51); + if(digitalRead(tombol2)==0){Kp++;delay(10);lcd.clear();} + if(digitalRead(tombol3)==0){Kp--;delay(10);lcd.clear();} + lcd.setCursor(0,0); + lcd.print("Bismillah..."); + lcd.setCursor(0,1); + sprintf(lcdBuff,"Nilai KP:%i",Kp); + lcd.print(lcdBuff); + EEPROM.write(51, Kp); + delay(100); + if(digitalRead(tombol1)==0) + { + delay(150);tune();lcd.clear();goto setKd; + } + if(digitalRead(tombol4)==0) + { + delay(150);tune();lcd.clear();goto awal; + } + goto setKp; +setKd: + actifMux(); + Kd=EEPROM.read(52); + if(digitalRead(tombol2)==0){Kd++;delay(10);lcd.clear();} + if(digitalRead(tombol3)==0){Kd--;delay(10);lcd.clear();} + lcd.setCursor(0,0); + lcd.print("Bismillah..."); + lcd.setCursor(0,1); + sprintf(lcdBuff,"Nilai KD:%i",Kd); + lcd.print(lcdBuff); + EEPROM.write(52, Kd); + delay(100); + if(digitalRead(tombol1)==0) + { + delay(150);tune();lcd.clear();goto pwmReff; + } + if(digitalRead(tombol4)==0) + { + delay(150);tune();lcd.clear();goto setKp; + } + goto setKd; +pwmReff: + actifMux(); + max_pwm_ref=EEPROM.read(53); + if(digitalRead(tombol2)==0){max_pwm_ref++;delay(10);lcd.clear();} + if(digitalRead(tombol3)==0){max_pwm_ref--;delay(10);lcd.clear();} + lcd.setCursor(0,0); + lcd.print("Bismillah..."); + lcd.setCursor(0,1); + sprintf(lcdBuff,"Pwm Reff:%i",max_pwm_ref); + lcd.print(lcdBuff); + EEPROM.write(53, max_pwm_ref); + delay(100); + if(digitalRead(tombol1)==0) + { + delay(150);tune();lcd.clear();goto awal; + } + if(digitalRead(tombol4)==0) + { + delay(150);tune();lcd.clear();goto setKd; + } + goto pwmReff; +setSens: + actifMux(); + lcd.setCursor(2,0); + lcd.print("< ^ v >"); + lcd.setCursor(2,1); + lcd.print("R 01 Rec L"); + if(digitalRead(tombol1)==0) + { + delay(150); lcd.clear();tune(); + lcd.setCursor(0,0); + lcd.print("Read Left Sens"); + delay(1000); + lcd.clear(); + while(1) + { + readLeftSensor(); + } + } + if(digitalRead(tombol2)==0) + { + delay(150); lcd.clear();tune(); + lcd.setCursor(0,0); + lcd.print("Record Data"); + delay(1000); + lcd.clear(); + actifMux(); + recordBack();recordLine(); + averageLine(); + } + if(digitalRead(tombol3)==0) + { + delay(150); lcd.clear();tune(); + lcd.setCursor(0,0); + lcd.print("Convert Logic"); + delay(1000); + lcd.clear(); + while(1) + { + convertLogic(); + } + } + if(digitalRead(tombol4)==0) + { + delay(150); lcd.clear();tune(); + lcd.setCursor(0,0); + lcd.print("Read Right Sens"); + delay(1000); + lcd.clear(); + while(1) + { + readRightSensor(); + } + } + goto setSens; + //eeprom untuk path planning mulai di 56 + +freeRunning: + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("Free Running"); + delay(2000); + lcd.clear(); + while(1) + { + RUN(); + } + goto freeRunning; + +} +void TurnR(int pwmL, int pwmR) +{ + digitalWrite(dirLA, 1);digitalWrite(dirLB, 0);analogWrite(pwmKiri, pwmL); + digitalWrite(dirRA, 1);digitalWrite(dirRB, 0);analogWrite(pwmKanan, pwmR); +} +void forward(int pwmL, int pwmR) +{ + digitalWrite(dirLA, 0);digitalWrite(dirLB, 1);analogWrite(pwmKiri, pwmL); + digitalWrite(dirRA, 1);digitalWrite(dirRB, 0);analogWrite(pwmKanan, pwmR); +} +void TurnL(int pwmL, int pwmR) +{ + digitalWrite(dirLA, 0);digitalWrite(dirLB, 1);analogWrite(pwmKiri, pwmL); + digitalWrite(dirRA, 0);digitalWrite(dirRB, 1);analogWrite(pwmKanan, pwmR); +} +void stopRun() +{ + digitalWrite(dirLA, 1);digitalWrite(dirLB, 1);analogWrite(pwmKiri, 255); + digitalWrite(dirRA, 1);digitalWrite(dirRB, 1);analogWrite(pwmKanan, 255); +} +void switchMUX(int a, int b, int c) +{ + digitalWrite(selA, a); + digitalWrite(selB, b); + digitalWrite(selC, c); +} +void actifMux() +{ + switchMUX(0,0,0); + valueLine[2] = analogRead(4); + tombol[1] = analogRead(3); + switchMUX(0,0,1); + valueLine[4] = analogRead(4); + tombol[0] = analogRead(3); + switchMUX(0,1,0); + valueLine[0] = analogRead(4); + tombol[3] = analogRead(3); + switchMUX(0,1,1); + valueLine[5] = analogRead(4); + tombol[2] = analogRead(3); + switchMUX(1,0,0); + valueLine[1] = analogRead(4); + valueLine[10] = analogRead(3); + switchMUX(1,0,1); + valueLine[7] = analogRead(4); + valueLine[8] = analogRead(3); + switchMUX(1,1,0); + valueLine[3] = analogRead(4); + valueLine[11] = analogRead(3); + switchMUX(1,1,1); + valueLine[6] = analogRead(4); + valueLine[9] = analogRead(3); +} + +void tune() +{ + analogWrite(buzzer, 100); + delay(150); + analogWrite(buzzer, 0); +} + +void recordBack() +{ + lcd.setCursor(0,0); + lcd.print("Record Back"); + for(int i=0; i<=11; i++) + { + lcd.setCursor(0,1); + sprintf(lcdBuff, "ke: %i-->%3d",i,valueLine[i]); + lcd.print(lcdBuff); + EEPROM.write(i, valueLine[i]);//valueLine[i] --> baca postingan 16 channel sensor garis + delay(250); + } +} +void recordLine() +{ + lcd.setCursor(0,0); + lcd.print("Record Line"); + for(int i=0; i<=11; i++) + { + lcd.setCursor(0,1); + sprintf(lcdBuff, "ke: %i-->%3d",i,valueLine[i]); + lcd.print(lcdBuff); + EEPROM.write(i+12, valueLine[i]);//valueLine[i] --> baca postingan 16 channel sensor garis + delay(250); + } +} + +void averageLine() +{ + for(int i=0; i<=11; i++) + { + lcd.setCursor(0,0); + lcd.print(i); + maxSensor[i] = EEPROM.read(i); + minSensor[i] = EEPROM.read(i+12); + eAverage[i]=(maxSensor[i]+minSensor[i])/2; + EEPROM.write(i+24,eAverage[i]); + } +} +void readLeftSensor() +{ + actifMux(); + lcd.setCursor(0,0); + sprintf(lcdBuff, "%3d %3d %3d %3d", valueLine[8],valueLine[9],valueLine[10],valueLine[11]); + lcd.print(lcdBuff); + lcd.setCursor(0,1); + sprintf(lcdBuff, "%3d %3d %3d %3d", tombol[0],tombol[1],tombol[2],tombol[3]); + lcd.print(lcdBuff); +} +void readRightSensor() +{ + actifMux(); + lcd.setCursor(0,0); + sprintf(lcdBuff, "%3d %3d %3d %3d", valueLine[0],valueLine[1],valueLine[2],valueLine[3]); + lcd.print(lcdBuff); + lcd.setCursor(0,1); + sprintf(lcdBuff, "%3d %3d %3d %3d", valueLine[4],valueLine[5], valueLine[6],valueLine[7]); + lcd.print(lcdBuff); +} +void convertLogic() +{ + for(int i=0; i<=11; i++) + { + actifMux(); + if(valueLine[i]sensor sebelah kiri + case 0b0000000011: error = 8;break; + case 0b0000000010: error = 7;break; + case 0b0000000110: error = 6;break; + case 0b0000000100: error = 5;break; + case 0b0000001100: error = 4;break; + case 0b0000001000: error = 3;break; + case 0b0000011000: error = 2;break; + case 0b0000010000: error = 1;break; + case 0b0000110000: error = 0;break; + case 0b0000100000: error = -1;break; + case 0b0001100000: error = -2;break; + case 0b0001000000: error = -3;break; + case 0b0011000000: error = -4;break; + case 0b0010000000: error = -5;break; + case 0b0110000000: error = -6;break; + case 0b0100000000: error = -7;break; + case 0b1100000000: error = -8;break; + case 0b1000000000: error = -9;break;//---->sensor sebelah kanan + case 0b0000000000: + if(error>=8) + { + error = 9; + } + if(error<=-8) + { + error = -9; + } + break; + + } + Max_MV = Kp*9; + rate_error = error - last_error; + MV = (Kp*error) + (Kd*rate_error); + last_error = error; + if(MV>=-Max_MV && MV<=Max_MV) + { + pid_l = max_pwm_ref - MV; + pid_r = max_pwm_ref + MV; + + if (pid_l < 0) pid_l = 0; + if (pid_l > 255) pid_l = 255; + if (pid_r < 0) pid_r = 0; + if (pid_r > 255) pid_r = 255; + forward(pid_r,pid_l); + } + else if(MV<-Max_MV) + { + TurnR(200,100); + } + else if(MV>Max_MV) + { + TurnL(100,200); + } + else + { + forward(pid_r,pid_l); + } + lcd.setCursor(0,0); + sprintf(lcdBuff, "%3d %3d %2d %2d",pid_l,pid_r,intersectionKe,error); + lcd.print(lcdBuff); +} diff --git a/Line_Follower_nano_PID/Line_Follower_nano_PID.ino b/Line_Follower_nano_PID/Line_Follower_nano_PID.ino new file mode 100644 index 0000000..f4f5e3a --- /dev/null +++ b/Line_Follower_nano_PID/Line_Follower_nano_PID.ino @@ -0,0 +1,208 @@ +#include +#include +#include + +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +#define eepromKp 0 +#define eepromSpeed 1 +#define eepromKd 2 + +#define button1 13 +#define button2 12 +#define button3 1 +#define button4 0 +#define echo 10 +#define trigger 11 +#define pwmOne 5 +#define inAOne 4 +#define inBOne 9 +#define pwmTwo 6 +#define inATwo 8 +#define inBTwo 7 +int sensorVal[6]; + +void setup() { + // put your setup code here, to run once: + pinMode(button1, INPUT_PULLUP); + pinMode(button2, INPUT_PULLUP); + pinMode(button3, INPUT_PULLUP); + pinMode(button4, INPUT_PULLUP); + pinMode(pwmOne, OUTPUT); + pinMode(inAOne, OUTPUT); + pinMode(inBOne, OUTPUT); + pinMode(pwmTwo, OUTPUT); + pinMode(inATwo, OUTPUT); + pinMode(inBTwo, OUTPUT); + Serial.begin(9600); + delay(1000); + pinMode(A0, INPUT); + pinMode(A1, INPUT); + pinMode(A2, INPUT); + pinMode(A3, INPUT); + pinMode(A4, INPUT); + pinMode(A5, INPUT); + lcd.begin(16,2); + + lcd.setCursor(0,0); + lcd.print("Automaton"); + lcd.setCursor(0,1); + lcd.print("Stmik Asia Ready"); + delay(2000); + lcd.clear(); +} +unsigned char Kp = 25; +unsigned char Kd = 9; +unsigned char Ts = 1; +unsigned char max_pwm_ref=125; +int error, last_error, MV,pid_l,pid_r,D,D1,D2,D3,P,Pd, bitSensor; +int Max_MV; +char lcdBuff[16]; +void loop() { + Kp = EEPROM.read(eepromKp); + //max_pwm_ref = EEPROM.read(eepromSpeed); + Kd = EEPROM.read(eepromKd); + + lcd.setCursor(0,0); + lcd.print("Kp Speed Kd"); + lcd.setCursor(0,1); + sprintf(lcdBuff,"%3d %3d %3d",Kp, max_pwm_ref,Kd); + lcd.print(lcdBuff); + if(digitalRead(button3) == LOW) + { + + delay(150); + Kp++; + EEPROM.write(eepromKp, Kp); + } + if(digitalRead(button2) == LOW) + { + + delay(150); + Kd++; + EEPROM.write(eepromKd, Kd); + } + + if(digitalRead(button4) == LOW) + { + while(1) + { + robotRun(); + } + } +} +void readSens() +{ + sensorVal[0] = digitalRead(A0); sensorVal[1] = digitalRead(A1); sensorVal[2] = digitalRead(A2); + sensorVal[3] = digitalRead(A3); sensorVal[4] = digitalRead(A5); sensorVal[5] = digitalRead(A4); +} +void robotRun() +{ + readSens(); + bitSensor = ((sensorVal[0]*1)+(sensorVal[1]*2)+(sensorVal[2]*4)+(sensorVal[3]*8)+(sensorVal[4]*16)+(sensorVal[5]*32)); + switch(bitSensor) + { + case 0b011111: error = -5; break; + case 0b001111: error = -4; break; + case 0b101111: error = -3; break; + case 0b100111: error = -2; break; + case 0b110111: error = -1; break; + case 0b110011: error = 0; break; + case 0b111011: error = 1; break; + case 0b111001: error = 2; break; + case 0b111101: error = 3; break; + case 0b111100: error = 4; break; + case 0b111110: error = 5; break; + case 0b111111: if(error > 3) {error=6;} + if(error <- 3){error=-6;} break; + } + + Max_MV = Kp*5; //pembatasan nilai output dari hasil PID +//### rumus PID digital + P = Kp * error; + + D1 = Kd*8; + D2 = D1 / Ts; + D3 = error - last_error; + D = D2 * D3; + + last_error = error; + + MV = P + D; +//=======================================// + if(MV>=-Max_MV && MV<=Max_MV) //jika output PID tidak melebihi nilai pembatasan output PID maka robot akan berjalan + { //maju dengan pengaturan PWM kanan dan kiri + pid_l = max_pwm_ref - MV; + pid_r = max_pwm_ref + MV; + + if (pid_l < 0) pid_l = 0; + if (pid_l > 255) pid_l = 255; + if (pid_r < 0) pid_r = 0; + if (pid_r > 255) pid_r = 255; + forward(pid_r,pid_l); + } + else if(MV<-Max_MV) //jika output PID lebih kecil dari nilai batasan output PID maka robot akan putar KANAN + { + turnLeft(200,100); + } + else if(MV>Max_MV) //jika output PID lebih besar dari nilai batasan output PID maka robot akan putar KIRI + { + turnRight(100,200); + } + else + { + forward(pid_r,pid_l); + } + lcd.setCursor(0,0); + sprintf(lcdBuff,"%i%i%i%i%i%i", sensorVal[0],sensorVal[1],sensorVal[2],sensorVal[3],sensorVal[4],sensorVal[5]); + lcd.print(lcdBuff); + lcd.setCursor(0,1); + sprintf(lcdBuff, "%2d %3d %3d", error, pid_l, pid_r); + lcd.print(lcdBuff); +} +void forward(int valLeft, int valRight) +{ + digitalWrite(inAOne, LOW); + digitalWrite(inBOne, HIGH); + analogWrite(pwmOne, valLeft); + digitalWrite(inATwo, HIGH); + digitalWrite(inBTwo, LOW); + analogWrite(pwmTwo, valRight); +} +void backward(int valLeft, int valRight) +{ + digitalWrite(inAOne, HIGH); + digitalWrite(inBOne, LOW); + analogWrite(pwmOne, valLeft); + digitalWrite(inATwo, LOW); + digitalWrite(inBTwo, HIGH); + analogWrite(pwmTwo, valRight); +} +void turnRight(int valLeft, int valRight) +{ + digitalWrite(inAOne, LOW); + digitalWrite(inBOne, HIGH); + analogWrite(pwmOne, valLeft); + digitalWrite(inATwo, LOW); + digitalWrite(inBTwo, HIGH); + analogWrite(pwmTwo, valRight); +} +void turnLeft(int valLeft, int valRight) +{ + digitalWrite(inAOne, HIGH); + digitalWrite(inBOne, LOW); + analogWrite(pwmOne, valLeft); + digitalWrite(inATwo, HIGH); + digitalWrite(inBTwo, LOW); + analogWrite(pwmTwo, valRight); +} +void stopRun() +{ + digitalWrite(inAOne, HIGH); + digitalWrite(inBOne, HIGH); + analogWrite(pwmOne, 0); + digitalWrite(inATwo, HIGH); + digitalWrite(inBTwo, HIGH); + analogWrite(pwmTwo, 0); +} + diff --git a/Line_Follower_simple/Line_Follower_simple.ino b/Line_Follower_simple/Line_Follower_simple.ino new file mode 100644 index 0000000..10a5983 --- /dev/null +++ b/Line_Follower_simple/Line_Follower_simple.ino @@ -0,0 +1,103 @@ +#include + +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +int kiriA = 9; +int kiriB = 6; +int kananA = 5; +int kananB = 3; + +void setup() +{ + lcd.begin(16,2); + Serial.begin(9600); + pinMode(kiriA,OUTPUT); + pinMode(kiriB,OUTPUT); + pinMode(kananA,OUTPUT); + pinMode(kananB,OUTPUT); + pinMode(A0,INPUT); + pinMode(A1,INPUT); + pinMode(A2,INPUT); + +} + +void loop() +{ + int kiri = digitalRead(A0); + int kanan = digitalRead(A1); + int kanan = digitalRead(A2); + + //HIGH=hitam, LOW=putih + + if ((kiri==HIGH)&&(kanan==LOW)) + { + digitalWrite(kiriA,HIGH); + digitalWrite(kiriB,LOW); + digitalWrite(kananA,LOW); + digitalWrite(kananB,HIGH); + + //LCD Program + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("i=hitam a=putih"); + lcd.setCursor(0,1); + lcd.print("BELOK KIRI"); + + //Serial Program + Serial.println("Sensor Kiri Hitam & Sensor Kanan Putih"); + Serial.println("BELOK KIRI"); + } + else if ((kiri==LOW)&&(kanan==HIGH)) + { + digitalWrite(kiriA,LOW); + digitalWrite(kiriB,HIGH); + digitalWrite(kananA,HIGH); + digitalWrite(kananB,LOW); + //LCD Program + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("i=putih a=hitam"); + lcd.setCursor(0,1); + lcd.print("BELOK KANAN"); + + //Serial Program + Serial.println("Sensor Kiri Putih & Sensor Kanan Hitam"); + Serial.println("BELOK KANAN"); + } + else if ((kiri==HIGH)&&(kanan==HIGH)) + { + digitalWrite(kiriA,HIGH); + digitalWrite(kiriB,LOW); + digitalWrite(kananA,HIGH); + digitalWrite(kananB,LOW); + //LCD Program + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("i=hitam a=hitam"); + lcd.setCursor(0,1); + lcd.print("MUNDUR"); + + //Serial Program + Serial.println("Sensor Kiri Hitam & Sensor Kanan Hitam"); + Serial.println("MUNDUR"); + } + + else + { + digitalWrite(kiriA,LOW); + digitalWrite(kiriB,HIGH); + digitalWrite(kananA,LOW); + digitalWrite(kananB,HIGH); + //LCD Program + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("i=putih a=putih"); + lcd.setCursor(0,1); + lcd.print("MAJU"); + + //Serial Program + Serial.println("Sensor Kiri Putih & Sensor Kanan Putih"); + Serial.println("MAJU"); + } + +} diff --git a/Sensor_air/Sensor_air.ino b/Sensor_air/Sensor_air.ino new file mode 100644 index 0000000..1da4af8 --- /dev/null +++ b/Sensor_air/Sensor_air.ino @@ -0,0 +1,35 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +#define sensor 8 +#define relay 9 + +void setup() { + pinMode(sensor, INPUT_PULLUP); + pinMode(relay, OUTPUT); + lcd.begin (16,2); + lcd.setCursor(0,0); + lcd.print("Smart Bak Mandi"); + delay(2000); + lcd.setCursor(4,1); + lcd.print("Ready...!"); + delay(1000); + lcd.clear(); +} + +void loop() { + while(digitalRead(sensor) == HIGH){ + digitalWrite(relay, HIGH); + lcd.setCursor(0,0); + lcd.print("Air Penuh Gan!"); + lcd.setCursor(0,1); + lcd.print("Keran OFF"); + + } + digitalWrite(relay, LOW); + lcd.setCursor(0,0); + lcd.print("Air Kosong Gan!"); + lcd.setCursor(0,1); + lcd.print("Keran ON "); + +} diff --git a/UAS_driver_motor/UAS_driver_motor.ino b/UAS_driver_motor/UAS_driver_motor.ino new file mode 100644 index 0000000..37d752b --- /dev/null +++ b/UAS_driver_motor/UAS_driver_motor.ino @@ -0,0 +1,53 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +#define pb3 7 // off +#define pb1 6 // arah motor cw +#define pb2 5 // arah motor cww + +int kondisi1 = 0; +int kondisi2 = 0; +int kondisi3 = 1; + +void setup() { + // put your setup code here, to run once: +lcd.begin(16,2); +// motor dc +pinMode(8,OUTPUT); +pinMode(9,OUTPUT); +// input button +pinMode(pb1,INPUT_PULLUP); +pinMode(pb2,INPUT_PULLUP); +pinMode(pb3,INPUT_PULLUP); +} + +void loop() { + // put your main code here, to run repeatedly: + + kondisi1 = digitalRead(pb1);// arah kanan + kondisi2 = digitalRead(pb2);// arah kiri + kondisi3 = digitalRead(pb3);// off + +if(kondisi1 == 1) + { + digitalWrite(9,HIGH); + lcd.setCursor(0,0); + lcd.print("arah motor kanan"); + } + + if(kondisi2 == 1) + { + digitalWrite(8,HIGH); + lcd.setCursor(0,0); + lcd.print("arah motor kiri"); + } + + if(kondisi1 == HIGH && kondisi2 == HIGH && kondisi3 == LOW) + { + digitalWrite(8,LOW); + digitalWrite(9,LOW); + lcd.setCursor(0,0); + lcd.print("Stop "); + } +} + diff --git a/Uas_motor_Counter/Uas_motor_Counter.ino b/Uas_motor_Counter/Uas_motor_Counter.ino new file mode 100644 index 0000000..48951da --- /dev/null +++ b/Uas_motor_Counter/Uas_motor_Counter.ino @@ -0,0 +1,116 @@ +#include +LiquidCrystal_I2C lcd(0x3F ,2,1,0,4,5,6,7,3, POSITIVE); + + +int motorKanan = 8; +int motorKiri = 9; + +int switchUpPin = 13; +int switchDownPin = 12; +int counter = 0; +int buttonUpState = 0; +int lastButtonUpState = 0; +int buttonDownState = 0; +int lastButtonDownState = 0; + +void setup() { + // put your setup code here, to run once: + lcd.begin (16,2); + + pinMode(motorKanan, OUTPUT); + pinMode(motorKiri, OUTPUT); + +} + +void loop() { + // put your main code here, to run repeatedly: + lcd.setCursor(0,0); + lcd.print("Arah Motor :"); + + buttonUpState = digitalRead(switchUpPin); + buttonDownState = digitalRead(switchDownPin); + + if (buttonUpState != lastButtonUpState) + { + if (buttonUpState == HIGH) + { + if (counter == 100) + { + counter = -1; + } + counter++; + Serial.println(counter); + changeNumber(counter); + delay(300); + } + else + { + Serial.println("OFF"); + } + delay(50); + } + + + if (buttonDownState != lastButtonDownState) + { + if (buttonDownState == HIGH) + { + if (counter == 0) + { + counter = 100; + } + counter--; + Serial.println(counter); + changeNumber(counter); + delay(300); + } + else + { + Serial.println("OFF"); + } + delay(50); + } + changeNumber(counter); +} + + +void changeNumber(int buttonPress) +{ + switch (buttonPress) + { + //start + case 0: + digitalWrite(motorKanan, LOW); + digitalWrite(motorKiri, LOW); + lcd.setCursor(0,1); + lcd.print("Ready "); + break; + //arah motor ke kanan + case 1: + digitalWrite(motorKanan, HIGH); + digitalWrite(motorKiri, LOW); + lcd.setCursor(0,1); + lcd.print("Kanan "); + break; + //arah motor ke kiri + case 2: + digitalWrite(motorKanan, LOW); + digitalWrite(motorKiri, HIGH); + lcd.setCursor(0,1); + lcd.print("Kiri "); + break; + //motor Stop + case 3: + digitalWrite(motorKanan, LOW); + digitalWrite(motorKiri, LOW); + lcd.setCursor(0,1); + lcd.print("Stop "); + break; + //berakhir + case 4: + digitalWrite(motorKanan, LOW); + digitalWrite(motorKiri, LOW); + lcd.setCursor(0,1); + lcd.print("Ojok tekan Lagi"); + } +} diff --git a/_7segment/_7segment.ino b/_7segment/_7segment.ino new file mode 100644 index 0000000..ee4339c --- /dev/null +++ b/_7segment/_7segment.ino @@ -0,0 +1,269 @@ +#define segA 2//connecting segment A to PIN2 + +#define segB 3// connecting segment B to PIN3 + +#define segC 4// connecting segment C to PIN4 + +#define segD 5// connecting segment D to PIN5 + +#define segE 6// connecting segment E to PIN6 + +#define segF 7// connecting segment F to PIN7 + +#define segG 8// connecting segment G to PIN8 + + + + int COUNT=0;//count integer for 0-9 increment + +void setup() + +{ + + for (int i=2;i<9;i++) + + { + + pinMode(i, OUTPUT);// taking all pins from 2-8 as output + + } + +} + + + +void loop() + +{ + +switch (COUNT) + + { + + + + case 0://when count value is zero show”0” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, HIGH); + + digitalWrite(segE, HIGH); + + digitalWrite(segF, HIGH); + + digitalWrite(segG, LOW); + + break; + + + + case 1:// when count value is 1 show”1” on disp + + digitalWrite(segA, LOW); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, LOW); + + digitalWrite(segE, LOW); + + digitalWrite(segF, LOW); + + digitalWrite(segG, LOW); + + break; + + + + case 2:// when count value is 2 show”2” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, LOW); + + digitalWrite(segD, HIGH); + + digitalWrite(segE, HIGH); + + digitalWrite(segF, LOW); + + digitalWrite(segG, HIGH); + + break; + + + + case 3:// when count value is 3 show”3” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, HIGH); + + digitalWrite(segE, LOW); + + digitalWrite(segF, LOW); + + digitalWrite(segG, HIGH); + + break; + + + + case 4:// when count value is 4 show”4” on disp + + digitalWrite(segA, LOW); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, LOW); + + digitalWrite(segE, LOW); + + digitalWrite(segF, HIGH); + + digitalWrite(segG, HIGH); + + break; + + + + case 5:// when count value is 5 show”5” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, LOW); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, HIGH); + + digitalWrite(segE, LOW); + + digitalWrite(segF, HIGH); + + digitalWrite(segG, HIGH); + + break; + + + + case 6:// when count value is 6 show”6” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, LOW); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, HIGH); + + digitalWrite(segE, HIGH); + + digitalWrite(segF, HIGH); + + digitalWrite(segG, HIGH); + + break; + + + + case 7:// when count value is 7 show”7” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, LOW); + + digitalWrite(segE, LOW); + + digitalWrite(segF, LOW); + + digitalWrite(segG, LOW); + + break; + + + + case 8:// when count value is 8 show”8” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, HIGH); + + digitalWrite(segE, HIGH); + + digitalWrite(segF, HIGH); + + digitalWrite(segG, HIGH); + + break; + + + + case 9:// when count value is 9 show”9” on disp + + digitalWrite(segA, HIGH); + + digitalWrite(segB, HIGH); + + digitalWrite(segC, HIGH); + + digitalWrite(segD, HIGH); + + digitalWrite(segE, LOW); + + digitalWrite(segF, HIGH); + + digitalWrite(segG, HIGH); + + break; + + + + break; + + } + + if (COUNT<10) + + { + + COUNT++; + + delay(1000);///increment count integer for every second + + } + + if (COUNT==10) + + { + + COUNT=0;// if count integer value is equal to 10, reset it to zero. + + delay(1000); + + } + +} diff --git a/bluetooth/bluetooth.ino b/bluetooth/bluetooth.ino new file mode 100644 index 0000000..83e3251 --- /dev/null +++ b/bluetooth/bluetooth.ino @@ -0,0 +1,82 @@ +/************************************************************* + Blynk is a platform with iOS and Android apps to control + Arduino, Raspberry Pi and the likes over the Internet. + You can easily build graphic interfaces for all your + projects by simply dragging and dropping widgets. + + Downloads, docs, tutorials: http://www.blynk.cc + Sketch generator: http://examples.blynk.cc + Blynk community: http://community.blynk.cc + Social networks: http://www.fb.com/blynkapp + http://twitter.com/blynk_app + + Blynk library is licensed under MIT license + This example code is in public domain. + + ************************************************************* + This example shows how to use Arduino with HC-06/HC-05 + Bluetooth 2.0 Serial Port Profile (SPP) module + to connect your project to Blynk. + + Note: This only works on Android! iOS does not support SPP :( + You may need to pair the module with your smartphone + via Bluetooth settings. Default pairing password is 1234 + + Feel free to apply it to any other example. It's simple! + + NOTE: Bluetooth support is in beta! + + *************************************************************/ + +#define BLYNK_USE_DIRECT_CONNECT + +// You could use a spare Hardware Serial on boards that have it (like Mega) +#include +SoftwareSerial DebugSerial(0, 1); // RX, TX + +#define BLYNK_PRINT DebugSerial +#include + +int relay = 5; +int led = 7; +int button = 6; + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +char auth[] = "6f0ab9c206aa4dc2ab16232d83ca5672"; + +void setup() +{ + // Debug console + DebugSerial.begin(38400); + + DebugSerial.println("Waiting for connections..."); + + // Blynk will work through Serial + // 9600 is for HC-06. For HC-05 default speed is 38400 + // Do not read or write this serial manually in your sketch + Serial.begin(38400); + Blynk.begin(Serial, auth); + + pinMode(relay, OUTPUT); + pinMode(led, OUTPUT); + pinMode(button, INPUT_PULLUP); +} + +void loop() +{ + Blynk.run(); + + if (digitalRead (button)) + { + digitalWrite(relay, HIGH); + digitalWrite(led, HIGH); + } + + else + { + digitalWrite(relay, LOW); + digitalWrite(led, LOW); + } +} + diff --git a/blynk_nodemcu/blynk_nodemcu.ino b/blynk_nodemcu/blynk_nodemcu.ino new file mode 100644 index 0000000..9a208ff --- /dev/null +++ b/blynk_nodemcu/blynk_nodemcu.ino @@ -0,0 +1,115 @@ +#define BLYNK_PRINT Serial + + +#include +#include +#include + +#define relay D0 +//#define button2 D7 + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +char auth[] = "6f0ab9c206aa4dc2ab16232d83ca5672"; + +// Your WiFi credentials. +// Set password to "" for open networks. +char ssid[] = "IoT_smartHome"; +char pass[] = "robotics"; + +#define DHTPIN D2 // What digital pin we're connected to + +// Uncomment whatever type you're using! +#define DHTTYPE DHT11 // DHT 11 +//#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321 +//#define DHTTYPE DHT21 // DHT 21, AM2301 + +DHT dht(DHTPIN, DHTTYPE); +BlynkTimer timer; + +// This function sends Arduino's up time every second to Virtual Pin (5). +// In the app, Widget's reading frequency should be set to PUSH. This means +// that you define how often to send data to Blynk App. +void sendSensor() +{ + //pembacaan sensor membutuhkan waktu 250ms + + //Pembacaan untuk data kelembaban + float humidity_1 = dht.readHumidity(); + //Pembacaan dalam format celcius (c) + float celcius_1 = dht.readTemperature(); + //pembacaan dalam format Fahrenheit + float fahrenheit_1 = dht.readTemperature(true); + + //mengecek pembacaan apakah terjadi kegagalan atau tidak + if (isnan(humidity_1) || isnan(celcius_1) || isnan(fahrenheit_1)) { + Serial.println("Pembacaan data dari module sensor gagal!"); + return; + } + + float htof = dht.computeHeatIndex(fahrenheit_1, humidity_1); + //Prosedur pembacaaan data indeks panas dalam bentuk fahreheit + float htoc = dht.computeHeatIndex(celcius_1, humidity_1, false); + //Prosedur pembacaaan data indeks panas dalam bentuk celcius + // You can send any value at any time. + // Please don't send more that 10 values per second. + Blynk.virtualWrite(V5, humidity_1); + Blynk.virtualWrite(V6, celcius_1); + Blynk.virtualWrite(V7, fahrenheit_1); + Blynk.virtualWrite(V8, htof); + + Blynk.virtualWrite(V2, HIGH); + + //pembacaan nilai pembacaan data kelembaban + Serial.print("Kelembaban: "); + Serial.print(humidity_1); + Serial.print(" %\t"); + + //pembacaan nilai pembacaan data suhu + Serial.print("Suhu : "); + Serial.print(celcius_1); //format derajat celcius + Serial.print(" 'C "); + Serial.print(fahrenheit_1); //format derajat fahrenheit + Serial.print(" 'F\t"); + + Serial.print("Indeks Panas: "); + Serial.print(htof); + Serial.println(" *F"); +} + +void setup() +{ + // Debug console + Serial.begin(9600); + + Blynk.begin(auth, ssid, pass); + // You can also specify server: + //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80); + //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080); + + pinMode(relay,OUTPUT); + //pinMode(button2, INPUT_PULLUP); + dht.begin(); + + // Setup a function to be called every second + timer.setInterval(1000L, sendSensor); +} + +void loop() +{ + Blynk.run(); + timer.run(); + + float humidity_1 = dht.readHumidity(); + + if (humidity_1 >=70){ + digitalWrite(relay, HIGH); + delay(4000); + } else { + digitalWrite(relay, LOW); + delay(4000); + } + +} + + diff --git a/contoh_counter_PB/contoh_counter_PB.ino b/contoh_counter_PB/contoh_counter_PB.ino new file mode 100644 index 0000000..1f99f80 --- /dev/null +++ b/contoh_counter_PB/contoh_counter_PB.ino @@ -0,0 +1,134 @@ +/* +*Simulasi Penghitung Jumlah Kendaraan Parkir di Mall +*Created by Muhamad Andi Prasetyo +*30 Juni 2015 +*Email : muhandi.prasetyo@gmail.com +*www.boarduino.blogspot.com +*/ + +#include +LiquidCrystal lcd(12, 11, 5, 4, 3, 2); +const int buttonMasuk = 6; +const int buttonKeluar = 7; +const int buttonReset = 8; +int Penghitung = 0; +int statusMasuk = 0; +int statusKeluar = 0; +int statusReset = 0; +int statusTerakhir = 0; +int led = 13; +int maksimal = 20; + +void setup() { + pinMode(buttonMasuk, INPUT); + pinMode(buttonKeluar, INPUT); + pinMode(buttonReset, INPUT); + pinMode(led, OUTPUT); + lcd.begin(16,2); + lcd.setCursor(1,0); + lcd.print("Selamat Datang"); + lcd.setCursor(2,1); + lcd.print("Di Boarduino"); + delay(5000); + lcd.clear(); + lcd.setCursor(1,0); + lcd.print("Total :"); + lcd.setCursor(9,0); + lcd.print("KOSONG"); + lcd.setCursor(1,1); + lcd.print("Sisa : "); + lcd.setCursor(9,1); + lcd.print(maksimal); +} + +void loop() { + statusReset = digitalRead(buttonReset); + if (statusReset == HIGH) { + Penghitung = 0; + maksimal = 20; + lcd.clear(); + delay(50); + lcd.setCursor(1,0); + lcd.print("Total :"); + lcd.setCursor(1,1); + lcd.print("Sisa : "); + lcd.setCursor(9,0); + lcd.print("KOSONG"); + lcd.setCursor(9,1); + lcd.print(maksimal); + digitalWrite(led, HIGH); + delay(100); + digitalWrite(led, LOW); + } + statusMasuk = digitalRead(buttonMasuk); + if (statusMasuk != statusTerakhir) { + if (statusMasuk == HIGH) + { + Penghitung++; + maksimal--; + digitalWrite(led, HIGH); + delay(100); + digitalWrite(led, LOW); + lcd.setCursor(9,0); + lcd.print(Penghitung); + lcd.setCursor(9,1); + lcd.print(maksimal); + } + delay(50); + + } + statusTerakhir = statusMasuk; + statusKeluar = digitalRead(buttonKeluar); + if (statusKeluar != statusTerakhir) { + if (statusKeluar == HIGH) + { + Penghitung-=1; + maksimal++; + digitalWrite(led, HIGH); + delay(100); + digitalWrite(led, LOW); + lcd.setCursor(9,0); + lcd.print(Penghitung); + } + delay(50); + if (Penghitung > 0) + { + lcd.clear(); + delay(3); + lcd.setCursor(1,0); + lcd.print("Total :"); + lcd.setCursor(1,1); + lcd.print("Sisa : "); + lcd.setCursor(9,0); + lcd.print(Penghitung); + lcd.setCursor(9,1); + lcd.print(maksimal); + } + + if (Penghitung <= 0) + { + Penghitung = 0; + maksimal = 20; + lcd.setCursor(1,1); + lcd.print("Sisa : "); + lcd.setCursor(9,1); + lcd.print(maksimal); + lcd.setCursor(9,0); + lcd.print("KOSONG"); + } + if (Penghitung >= maksimal) + { + Penghitung = 20; + maksimal = 0; + lcd.setCursor(9,0); + lcd.print(Penghitung); + lcd.setCursor(9,1); + lcd.print("KOSONG"); + digitalWrite(led, HIGH); + delay(5000); + digitalWrite(led, LOW); + delay(1000); + } + } + statusTerakhir = statusKeluar; +} diff --git a/control_with_telegram/control_with_telegram.ino b/control_with_telegram/control_with_telegram.ino new file mode 100644 index 0000000..5533861 --- /dev/null +++ b/control_with_telegram/control_with_telegram.ino @@ -0,0 +1,109 @@ +//esp32 +#include "WiFi.h" +#include "WiFiClientSecure.h" +#include "UniversalTelegramBot.h" +//esp8266 +//#include // memsaukan Library ESP8266 +//#include +//#include // memasukan Library TelegramBot + +char ssid[] = "Pkm_asia"; +char password[] = "sistemkomputer"; +#define BOTtoken "872146786:AAFqUC58J3mU5eNv271lfjYEozV_dj_qdzQ" + +WiFiClientSecure client; +UniversalTelegramBot bot(BOTtoken, client); + +int Bot_mtbs = 1000; +long Bot_lasttime; +bool Start = false; + +const int ledPin = 15; // menggunakan LED bawaan Wemos / Nodemcu, bisa diganti dengan pin lain, misal const int ledPin = 13; +int ledStatus; + +void handleNewMessages(int numNewMessages) { + Serial.println("Pesan Baru Masuk"); + Serial.println(String(numNewMessages)); + + for (int i=0; i Bot_lasttime + Bot_mtbs) + { + int numNewMessages = bot.getUpdates(bot.last_message_received + 1); + + while(numNewMessages) + { + Serial.println("Memeriksa Respon"); + handleNewMessages(numNewMessages); + numNewMessages = bot.getUpdates(bot.last_message_received + 1); + } + + Bot_lasttime = millis(); + } + } diff --git a/counter_7segment/counter_7segment.ino b/counter_7segment/counter_7segment.ino new file mode 100644 index 0000000..aafa657 --- /dev/null +++ b/counter_7segment/counter_7segment.ino @@ -0,0 +1,201 @@ +int A = 2; +int B = 3; +int C = 4; +int D = 6; +int DP = 5; +int E = 7; +int F = 8; +int G = 9; + +int switchUpPin = 13; +int switchDownPin = 12; +int counter = 0; +int buttonUpState = 0; +int lastButtonUpState = 0; +int buttonDownState = 0; +int lastButtonDownState = 0; + +void setup() +{ + Serial.begin(9600); + + pinMode(A, OUTPUT); + pinMode(B, OUTPUT); + pinMode(C, OUTPUT); + pinMode(D, OUTPUT); + pinMode(E, OUTPUT); + pinMode(F, OUTPUT); + pinMode(G, OUTPUT); + pinMode(DP, OUTPUT); + pinMode(switchUpPin,INPUT_PULLUP); + pinMode(switchDownPin,INPUT_PULLUP); + + + digitalWrite(DP , HIGH); +} + +void loop() +{ + buttonUpState = digitalRead(switchUpPin); + buttonDownState = digitalRead(switchDownPin); + + if (buttonUpState != lastButtonUpState) + { + if (buttonUpState == HIGH) + { + if (counter == 100) + { + counter = -1; + } + counter++; + Serial.println(counter); + changeNumber(counter); + delay(300); + } + else + { + Serial.println("OFF"); + } + delay(50); + } + + + if (buttonDownState != lastButtonDownState) + { + if (buttonDownState == HIGH) + { + if (counter == 0) + { + counter = 100; + } + counter--; + Serial.println(counter); + changeNumber(counter); + delay(300); + } + else + { + Serial.println("OFF"); + } + delay(50); + } + changeNumber(counter); +} + +void changeNumber(int buttonPress) +{ + switch (buttonPress) + { + //number 0 + case 0: + digitalWrite(A, LOW); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, LOW); + digitalWrite(E, LOW); + digitalWrite(F, LOW); + digitalWrite(G, HIGH); + break; + //number 1 + case 1: + digitalWrite(A, HIGH); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, HIGH); + digitalWrite(E, HIGH); + digitalWrite(F, HIGH); + digitalWrite(G, HIGH); + break; + //number 2 + case 2: + digitalWrite(A, LOW); + digitalWrite(B, LOW); + digitalWrite(C, HIGH); + digitalWrite(D, LOW); + digitalWrite(E, LOW); + digitalWrite(F, HIGH); + digitalWrite(G, LOW); + break; + //number 3 + case 3: + digitalWrite(A, LOW); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, LOW); + digitalWrite(E, HIGH); + digitalWrite(F, HIGH); + digitalWrite(G, LOW); + break; + //number 4 + case 4: + digitalWrite(A, HIGH); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, HIGH); + digitalWrite(E, HIGH); + digitalWrite(F, LOW); + digitalWrite(G, LOW); + break; + //number 5 + case 5: + digitalWrite(A, LOW); + digitalWrite(B, HIGH); + digitalWrite(C, LOW); + digitalWrite(D, LOW); + digitalWrite(E, HIGH); + digitalWrite(F, LOW); + digitalWrite(G, LOW); + break; + //number 6 + case 6: + digitalWrite(A, LOW); + digitalWrite(B, HIGH); + digitalWrite(C, LOW); + digitalWrite(D, LOW); + digitalWrite(E, LOW); + digitalWrite(F, LOW); + digitalWrite(G, LOW); + break; + //number 7 + case 7: + digitalWrite(A, LOW); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, HIGH); + digitalWrite(E, HIGH); + digitalWrite(F, HIGH); + digitalWrite(G, HIGH); + break; + //number 8 + case 8: + digitalWrite(A, LOW); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, LOW); + digitalWrite(E, LOW); + digitalWrite(F, LOW); + digitalWrite(G, LOW); + break; + //number 9 + case 9: + digitalWrite(A, LOW); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, LOW); + digitalWrite(E, HIGH); + digitalWrite(F, LOW); + digitalWrite(G, LOW); + break; + + case 10: + digitalWrite(A, LOW); + digitalWrite(B, LOW); + digitalWrite(C, LOW); + digitalWrite(D, LOW); + digitalWrite(E, HIGH); + digitalWrite(F, LOW); + digitalWrite(G, LOW); + break; + } + +} diff --git a/dht11/dht11.ino b/dht11/dht11.ino new file mode 100644 index 0000000..1b31856 --- /dev/null +++ b/dht11/dht11.ino @@ -0,0 +1,120 @@ +// +// FILE: dht11_test1.pde +// PURPOSE: DHT11 library test sketch for Arduino +// + +//Celsius to Fahrenheit conversion +double Fahrenheit(double celsius) +{ + return 1.8 * celsius + 32; +} + +// fast integer version with rounding +//int Celcius2Fahrenheit(int celcius) +//{ +// return (celsius * 18 + 5)/10 + 32; +//} + + +//Celsius to Kelvin conversion +double Kelvin(double celsius) +{ + return celsius + 273.15; +} + +// dewPoint function NOAA +// reference (1) : http://wahiduddin.net/calc/density_algorithms.htm +// reference (2) : http://www.colorado.edu/geography/weather_station/Geog_site/about.htm +// +double dewPoint(double celsius, double humidity) +{ + // (1) Saturation Vapor Pressure = ESGG(T) + double RATIO = 373.15 / (273.15 + celsius); + double RHS = -7.90298 * (RATIO - 1); + RHS += 5.02808 * log10(RATIO); + RHS += -1.3816e-7 * (pow(10, (11.344 * (1 - 1/RATIO ))) - 1) ; + RHS += 8.1328e-3 * (pow(10, (-3.49149 * (RATIO - 1))) - 1) ; + RHS += log10(1013.246); + + // factor -3 is to adjust units - Vapor Pressure SVP * humidity + double VP = pow(10, RHS - 3) * humidity; + + // (2) DEWPOINT = F(Vapor Pressure) + double T = log(VP/0.61078); // temp var + return (241.88 * T) / (17.558 - T); +} + +// delta max = 0.6544 wrt dewPoint() +// 6.9 x faster than dewPoint() +// reference: http://en.wikipedia.org/wiki/Dew_point +double dewPointFast(double celsius, double humidity) +{ + double a = 17.271; + double b = 237.7; + double temp = (a * celsius) / (b + celsius) + log(humidity*0.01); + double Td = (b * temp) / (a - temp); + return Td; +} + + +#include + +dht11 DHT11; + +#define DHT11PIN A2 + +void setup() +{ + Serial.begin(115200); + Serial.println("DHT11 TEST PROGRAM "); + Serial.print("LIBRARY VERSION: "); + Serial.println(DHT11LIB_VERSION); + Serial.println(); +} + +void loop() +{ + Serial.println("\n"); + + int chk = DHT11.read(DHT11PIN); + + Serial.print("Read sensor: "); + switch (chk) + { + case DHTLIB_OK: + Serial.println("OK"); + break; + case DHTLIB_ERROR_CHECKSUM: + Serial.println("Checksum error"); + break; + case DHTLIB_ERROR_TIMEOUT: + Serial.println("Time out error"); + break; + default: + Serial.println("Unknown error"); + break; + } + + Serial.print("Humidity (%): "); + Serial.println((float)DHT11.humidity, 2); + + Serial.print("Temperature (°C): "); + Serial.println((float)DHT11.temperature, 2); + + Serial.print("Temperature (°F): "); + Serial.println(Fahrenheit(DHT11.temperature), 2); + + Serial.print("Temperature (°K): "); + Serial.println(Kelvin(DHT11.temperature), 2); + + Serial.print("Dew Point (°C): "); + Serial.println(dewPoint(DHT11.temperature, DHT11.humidity)); + + Serial.print("Dew PointFast (°C): "); + Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity)); + + delay(2000); +} +// +// END OF FILE +// diff --git a/doube_double_driver__Hbridge/doube_double_driver__Hbridge.ino b/doube_double_driver__Hbridge/doube_double_driver__Hbridge.ino new file mode 100644 index 0000000..e8abf26 --- /dev/null +++ b/doube_double_driver__Hbridge/doube_double_driver__Hbridge.ino @@ -0,0 +1,57 @@ +int i; +void setup() { + // put your setup code here, to run once: +pinMode(2,OUTPUT); +pinMode(3,OUTPUT); +pinMode(4,OUTPUT); +pinMode(5,OUTPUT); +pinMode(6,OUTPUT); +pinMode(7,OUTPUT); +pinMode(8,OUTPUT); +pinMode(9,OUTPUT); + +pinMode(10,INPUT_PULLUP); +pinMode(11,INPUT_PULLUP); +pinMode(12,INPUT_PULLUP); +} + +void loop() { + // put your main code here, to run repeatedly: + + if (digitalRead(10)==LOW){ + +//motor1 + digitalWrite(2,LOW); + digitalWrite(3,HIGH); +//motor2 + digitalWrite(4,LOW); + digitalWrite(5,HIGH); +//motor3 + digitalWrite(7,LOW); + digitalWrite(6,HIGH); +//motor4 + digitalWrite(8,LOW); + digitalWrite(9,HIGH); + } + if (digitalRead(11)==LOW){ + +//motor1 + digitalWrite(2,LOW); + digitalWrite(3,LOW); +//motor2 + digitalWrite(4,LOW); + digitalWrite(5,LOW); +//motor3 + digitalWrite(7,LOW); + digitalWrite(6,LOW); +//motor4 + digitalWrite(8,LOW); + digitalWrite(9,LOW); + } + if (digitalRead(12)==LOW){ + analogWrite(3,100); + analogWrite(5,100); + analogWrite(6,100); + analogWrite(9,100); + } +} diff --git a/driver_motor/driver_motor.ino b/driver_motor/driver_motor.ino new file mode 100644 index 0000000..4429444 --- /dev/null +++ b/driver_motor/driver_motor.ino @@ -0,0 +1,31 @@ +void setup() { + // put your setup code here, to run once: +pinMode(13,OUTPUT); +pinMode(12,OUTPUT); +Serial.begin(9600); +} + +void loop() { + // put your main code here, to run repeatedly: +if(Serial.available()){ + int inByte = Serial.read(); + if(inByte == 'a') + {digitalWrite(13,HIGH); + digitalWrite(12,LOW); + Serial.println("arah motor kanan"); + } + + if(inByte == 'b') + {digitalWrite(12,HIGH); + digitalWrite(13,LOW); + Serial.println("arah motor kiri"); +} + + if(inByte == 'c') + {digitalWrite(12,LOW); + digitalWrite(13,LOW); + Serial.println("Stop"); +} + } +} + diff --git a/driver_motor_mosfet/driver_motor_mosfet.ino b/driver_motor_mosfet/driver_motor_mosfet.ino new file mode 100644 index 0000000..6a933c8 --- /dev/null +++ b/driver_motor_mosfet/driver_motor_mosfet.ino @@ -0,0 +1,54 @@ +const int bt = 5; +const int bt2 = 6; +int st = 0; + +void setup() { + // put your setup code here, to run once: + pinMode(bt, INPUT_PULLUP); + pinMode(bt2, INPUT_PULLUP); + pinMode(8, OUTPUT); + pinMode(9, OUTPUT); + int bt = 0; + int bt2 = 0; + Serial.begin(9600); +} + +void loop() { + // put your main code here, to run repeatedly: + if(digitalRead(bt)==0 && st == 0){ + // lcd.clear(); + digitalWrite(8, HIGH); + digitalWrite(9, LOW); + delay(500); + + st =1; + + } + if(digitalRead(bt)==0 && st == 1){ + // lcd.clear(); + delay(500); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + st =0; + + } + + if(digitalRead(bt2)==0 && st == 0){ + // lcd.clear(); + delay(500); + digitalWrite(8, LOW); + digitalWrite(9, HIGH); + + st =1; + + } + + if(digitalRead(bt2)==0 && st == 1){ + // lcd.clear(); + delay(500); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + st =0; + + } + } diff --git a/esr_meter_atmduino/esr_meter_atmduino.ino b/esr_meter_atmduino/esr_meter_atmduino.ino new file mode 100644 index 0000000..7f633f2 --- /dev/null +++ b/esr_meter_atmduino/esr_meter_atmduino.ino @@ -0,0 +1,4850 @@ +/* + + ___ ___ _____ ___ ___ ___ ___ ___ + / /\ / /\ / /::\ /__/\ ___ / /\ / /\ ___ / /\ / /\ + / /::\ / /::\ / /:/\:\ \ \:\ / /\ / /:/_ / /:/_ / /\ / /:/_ / /::\ + / /:/\:\ / /:/\:\ / /:/ \:\ \ \:\ / /:/ / /:/ /\ / /:/ /\ / /:/ / /:/ /\ / /:/\:\ + / /:/~/::\ / /:/~/:/ /__/:/ \__\:| ___ \ \:\ / /:/ / /:/ /:/_ / /:/ /::\ / /:/ / /:/ /:/_ / /:/~/:/ + /__/:/ /:/\:\ /__/:/ /:/___ \ \:\ / /:/ /__/\ \__\:\ / /::\ /__/:/ /:/ /\ /__/:/ /:/\:\ / /::\ /__/:/ /:/ /\ /__/:/ /:/___ + \ \:\/:/__\/ \ \:\/:::::/ \ \:\ /:/ \ \:\ / /:/ /__/:/\:\ \ \:\/:/ /:/ \ \:\/:/~/:/ /__/:/\:\ \ \:\/:/ /:/ \ \:\/:::::/ + \ \::/ \ \::/~~~~ \ \:\/:/ \ \:\ /:/ \__\/ \:\ \ \::/ /:/ \ \::/ /:/ \__\/ \:\ \ \::/ /:/ \ \::/~~~~ + \ \:\ \ \:\ \ \::/ \ \:\/:/ \ \:\ \ \:\/:/ \__\/ /:/ \ \:\ \ \:\/:/ \ \:\ + \ \:\ \ \:\ \__\/ \ \::/ \__\/ \ \::/ /__/:/ \__\/ \ \::/ \ \:\ + \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ \__\/ + + + + + ARDUTESTER v0.X 25/04/2013 + + Original Source from: http://www.mikrocontroller.net/articles/AVR-Transistortester + Original Software: by Karl-Heinz Kuebbeler (kh_kuebbeler@web.de) + The Ardutester software is based on porting by Markus Reschke (madires@theca-tabellaria.de) + + Schematic & Home Page: http://www.pighixxx.com/lavori/ardutester/ + + Arduino version: PighiXXX (info@pighixxx.com) + PaoloP (http://www.arduino.cc/forum/index.php?action=profile;u=58300) + + - ONLY TTL COMPONENTS! + + TODO: + - Detailed Component Analysis + + CHANGELOG: + - 01/05/2013 v06e - Waitus Function, String to Flash Functions, Killed 3 Goto :-), Code Cleanup - PighiXXX + - 01/05/2013 v06f - Killed all Goto (Thanks to PaoloP), Implemented Button + - 01/05/2013 v06g - Code Cleanup + - 02/05/2013 v06h - Code Cleanup, SERIAL-LCD Flag, I2C LCD Functions + - 02/05/2013 v06i - Button Flag, Button Function + - 02/05/2013 v06j - PowerSave Function, Code Cleanup, Flag only when more info + - 02/05/2013 v06k - Some fix (By PaoloP) + - 03/05/2013 v06l - Disabled digital input on analog pins (By PaoloP), Minor fixes + - 04/05/2013 v06m - ShowFET() fixed, Code Cleanup, Short Circuit Ok + - 05/05/2013 v06n - CheckResistor Function Ok + - 06/05/2013 v06o - SelfTest Function (v0.3), SelfAdjust, Minor fixes + - 21/05/2013 v06p - Add LCD no I2C, Removed Leonardo support: this sketch work only on ATmega328. (By PaoloP) + - 07/06/2013 v06q - ArduTester Software Client Functions (By PighiXXX) + - 08/07/2013 v07a - SmallResistor() fixes, Inductance Measurement, Leakage Current Measurement, BJT functions fixed, Minor fixes (By PighiXXX) + TODO ReCheck Print Functions & LCD Functions - This is an alpha version! Lightless version! + - 17/07/2013 v07b - MOSFETs function fixed, Minor fixes, Show Functions revisited, I2C LCD Deprecated, Deep debug :-) + Button Function revisited, PWM Tool, Serial Menu, AutoAdjust, EEProm functions (By PighiXXX) + - 21/07/2013 v07c Some fix (By PaoloP), LCD Functions revisited (By PighiXXX) + - 22/07/2013 v07d LCDMenu, Some fix (By PighiXXX) + - 23/07/2013 v07e SetDefault function, Some fix, selFreq optimized, TestKey improvements, Client support (By PighiXXX) + TWI, SPI, TIMER2 disabled (By PaoloP) + - 25/07/2013 v07f ReadU function revisited (By PaoloP), Some fix (By PaoloP & PighiXXX) + +*/ + +//WorkAround for IDE ifndef bug +char foo; + + //ARDUTESTER FEATURES + +//Remember LCD_PRINT or DEBUG_PRINT +#define BUTTON_INST //Button Installed +#define LCD_PRINT //Print on LCD +//Remember DEBUG_PRINT or ATSW +//#define ATSW //ArduTester Software Client Enabled +//#define DEBUG_PRINT //Print on Serial Port +#define DET_COMP_ANALYSIS //Detailed Component Analysis (Soon) +#define TIMEOUT_BL 600 //LCD Backlight Timeout +#define LONG_PRESS 30 //Button Long Press era26 py2ohh +#define USER_WAIT 3000 //Nexpage Timeout + +//Check features +#if not defined(__AVR_ATmega328P__) + #error Sorry, this program works only on Arduino Uno +#endif +#if defined(LCD_PRINT) && defined(DEBUG_PRINT) + #error Invalid Parameters: Use LCD_PRINT or DEBUG_PRINT +#endif + +#if defined(DEBUG_PRINT) && defined(ATSW) + #error Invalid Parameters: Use DEBUG_PRINT or ATSW +#endif + +//Includes +#include +#include +#include +#include + +//LCD Output +#ifdef LCD_PRINT +//#include +#include + +// initialize the library with the numbers of the interface pins +//LiquidCrystal_I2C lcd(0x27, 16,2); +LiquidCrystal lcd(7,6,5,4,3,2); +#endif + +//UINT32_MAX +#define UINT32_MAX ((uint32_t)-1) + +//Test probes - Must be an ADC port :-) +#define ADC_PORT PORTC //ADC port data register +#define ADC_DDR DDRC //ADC port data direction register +#define ADC_PIN PINC //Port input pins register +#define TP1 0 //Test pin 1 (=0) +#define TP2 1 //Test pin 2 (=1) +#define TP3 2 //Test pin 3 (=2) +/* + Probe resistors: + The resistors must be connected to the lower 6 pins of the port in + following sequence: + - pin 0: Rl1 680R (test pin 1)3w`12a + - pin 1: Rh1 470k (test pin 1) + - pin 2: Rl2 680R (test pin 2) + - pin 3: Rh2 470k (test pin 2) + - pin 4: Rl3 680R (test pin 3) + - pin 5: Rh3 470k (test pin 3) +*/ +#define R_PORT PORTB //Port data register +#define R_DDR DDRB //Port data direction register + +//Push button +#define TEST_BUTTON A3 //Test/start push button (low active) + +//Button Delay +#define CYCLE_DELAY 3000 + + //ARDUESTER PARAMETERS + +//Maximum number of measurements without any components found. +#define CYCLE_MAX 5 +//ADC voltage reference based on Vcc (in mV). +#define UREF_VCC 5001 +/* + Offset for the internal bandgap voltage reference (in mV): -100 up to 100 + - To compensate any difference between real value and measured value. + - The ADC has a resolution of about 4.88mV for V_ref = 5V (Vcc) and + 1.07mV for V_ref = 1.1V (bandgap). + - Will be added to measured voltage of bandgap reference. +*/ +#define UREF_OFFSET 0 +/* + Exact values of probe resistors. + - Standard value for Rl is 680 Ohms. + - Standard value for Rh is 470k Ohms. +*/ +//Rl in Ohms +#define R_LOW 672 +//Rh in Ohms +#define R_HIGH 462000 +//Offset for systematic error of resistor measurement with Rh (470k) in Ohms.Valor 700 +#define RH_OFFSET 700 +/* + Resistance of probe leads (in 0.01 Ohms). + - Resistance of two probe leads in series. + - Assuming all probe leads got same/similar resistance. +*/ +#define R_ZERO 20 +/* + Capacitance of the wires between PCB and terminals (in pF). + Examples: + - 2pF for wires 10cm long ...valor 15 +*/ +#define CAP_WIRES 5 +/* + Capacitance of the probe leads connected to the tester (in pF). + Examples: + capacity length of probe leads + ------------------------------- + 3pF about 10cm + 9pF about 30cm + 15pF about 50cm +*/ +#define CAP_PROBELEADS 3 +//Maximum voltage at which we consider a capacitor being discharged (in mV)valor 2 +#define CAP_DISCHARGED 5 +/* + Number of ADC samples to perform for each mesurement. + - Valid values are in the range of 1 - 255. valor 25 +*/ +#define ADC_SAMPLES 25 +//Estimated internal resistance of port to GND (in 0.1 Ohms) +#define R_MCU_LOW 200 //Default: 209 +//Estimated internal resistance of port to VCC (in 0.1 Ohms) +#define R_MCU_HIGH 220 //Default: 235 +//Voltage offset of �Cs analog comparator (in mV): -50 up to 50 +#define COMPARATOR_OFFSET 15 +//Capacitance of the probe tracks of the PCB and the �C (in pF) valor = 42 +#define CAP_PCB 15 +//Total default capacitance (in pF): max. 255 +#define C_ZERO CAP_PCB + CAP_WIRES + CAP_PROBELEADS +//ATMEGA328, 16Mhz Related +#define ADC_CLOCK_DIV (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0) +#define CPU_FREQ F_CPU +#define OSC_STARTUP 16384 + +//Components ID's +#define COMP_NONE 0 +#define COMP_ERROR 1 +#define COMP_MENU 2 +#define COMP_RESISTOR 10 +#define COMP_CAPACITOR 11 +#define COMP_INDUCTOR 12 +#define COMP_DIODE 20 +#define COMP_BJT 21 +#define COMP_FET 22 +#define COMP_IGBT 23 +#define COMP_TRIAC 24 +#define COMP_THYRISTOR 25 + +//Chars +#define LCD_CHAR_UNSET 0 //Just a place holder +#define LCD_CHAR_DIODE1 1 //Diode icon '>|' +#define LCD_CHAR_DIODE2 2 //Diode icon '|<' +#define LCD_CHAR_CAP 3 //Capacitor icon '||' +#define LCD_CHAR_FLAG 4 //Flag Icon +#define LCD_CHAR_RESIS1 6 //Resistor left icon '[' +#define LCD_CHAR_RESIS2 7 //Resistor right icon ']' +#ifdef DEBUG_PRINT + #define LCD_CHAR_OMEGA 79 + #define LCD_CHAR_MICRO '\u00B5' //Code for Arduino Serial Monitor +#else + #define LCD_CHAR_OMEGA 244 //Default: 244 + #define LCD_CHAR_MICRO 228 +#endif + +//Error type IDs +#define TYPE_DISCHARGE 1 //Discharge error + +//FET type bit masks (also used for IGBTs) +#define TYPE_N_CHANNEL 0b00000001 //n channel +#define TYPE_P_CHANNEL 0b00000010 //p channel +#define TYPE_ENHANCEMENT 0b00000100 //Enhancement mode +#define TYPE_DEPLETION 0b00001000 //Depletion mode +#define TYPE_MOSFET 0b00010000 //MOSFET +#define TYPE_JFET 0b00100000 //JFET +#define TYPE_IGBT 0b01000000 //IGBT (no FET) + +//Mode bitmask +#define MODE_LOW_CURRENT 0b00000001 //Low test current +#define MODE_HIGH_CURRENT 0b00000010 //High test current +#define MODE_DELAYED_START 0b00000100 //Delayed start + +//BJT (bipolar junction transistor) type IDs +#define TYPE_NPN 1 //NPN +#define TYPE_PNP 2 //PNP + +//Tester operation modes +#define MODE_CONTINOUS 0 //Continous +#define MODE_AUTOHOLD 1 //Auto hold + +//Multiplicator tables +#define TABLE_SMALL_CAP 1 +#define TABLE_LARGE_CAP 2 +#define TABLE_INDUCTOR 3 + +//Bit flags for PullProbe() +#define FLAG_PULLDOWN 0b00000000 +#define FLAG_PULLUP 0b00000001 +#define FLAG_1MS 0b00001000 +#define FLAG_10MS 0b00010000 + +//Tester modes, offsets and values +typedef struct +{ + byte TesterMode; //Tester operation mode + byte SleepMode; //MCU sleep mode + byte Samples; //Number of ADC samples + byte AutoScale; //Flag to disable/enable ADC auto scaling + byte RefFlag; //Internal control flag for ADC + unsigned int U_Bandgap; //Voltage of internal bandgap reference (mV) + unsigned int RiL; //Internal pin resistance of �C in low mode (0.1 Ohms) + unsigned int RiH; //Internal pin resistance of �C in high mode (0.1 Ohms) + unsigned int RZero; //Resistance of probe leads (2 in series) (0.01 Ohms) + byte CapZero; //Capacity zero offset (input + leads) (pF) + signed char RefOffset; //Voltage offset of bandgap reference (mV) + signed char CompOffset; //Voltage offset of analog comparator (mV) +} Config_Type; + +//Probes +typedef struct +{ + //Probe pins + byte Pin_1; //Probe-1 + byte Pin_2; //Probe-2 + byte Pin_3; //Probe-3 + //Bit masks for switching probes and test resistors + byte Rl_1; //Rl mask for probe-1 + byte Rh_1; //Rh mask for probe-1 + byte Rl_2; //Rl mask for probe-2 + byte Rh_2; //Rh mask for probe-2 + byte Rl_3; //Rl mask for probe-3 + byte Rh_3; //Rh mask for probe-3 + byte ADC_1; //ADC mask for probe-1 + byte ADC_2; //ADC mask for probe-2 +} Probe_Type; + +//Checking/probing +typedef struct +{ + byte Done; //Flag for transistor detection done + byte Found; //Component type which was found + byte Type; //Component specific subtype + byte Resistors; //Number of resistors found + byte Diodes; //Number of diodes found + byte Probe; //Error: probe pin + unsigned int U; //Error: voltage left in mV +} Check_Type; + +//Resistor +typedef struct +{ + byte A; //Probe pin #1 + byte B; //Probe pin #2 + byte Scale; //Exponent of factor (value * 10^x) + unsigned long Value; //Resistance +} Resistor_Type; + +//Capacitor +typedef struct +{ + byte A; //Probe pin #1 + byte B; //Probe pin #2 + signed char Scale; //Exponent of factor (value * 10^x) + unsigned long Value; //Capacitance incl. zero offset + unsigned long Raw; //Capacitance excl. zero offset +} Capacitor_Type; + +//Inductor +typedef struct +{ + signed char Scale; //Exponent of factor (value * 10^x) + unsigned long Value; //Inductance +} Inductor_Type; + +//Diode +typedef struct +{ + byte A; //Probe pin connected to anode + byte C; //Probe pin connected to cathode + unsigned int V_f; //Forward voltage in mV (high current) + unsigned int V_f2; //Forward voltage in mV (low current) +} Diode_Type; + +//Bipolar junction transistor +typedef struct +{ + byte B; //Probe pin connected to base + byte C; //Probe pin connected to collector + byte E; //Probe pin connected to emitter + unsigned long hFE; //Current amplification factor + //U_BE voltage + unsigned int I_CE0; //Leakage current (in �A) +} BJT_Type; + +//FET +typedef struct +{ + byte G; //Test pin connected to gate + byte D; //Test pin connected to drain + byte S; //Test pin connected to source + unsigned int V_th; //Threshold voltage of gate in mV +} FET_Type; + +//Error (failed discharge) - Deprecated +typedef struct +{ + +} Error_Type; + +//Output buffers +char OutBuffer[12]; +char PRGBuffer[32]; + +//Configuration +Config_Type Config; //Tester modes, offsets and values + +//Probing +Probe_Type Probes; //Test probes +Check_Type Check; //Checking/testing + +//Components +Resistor_Type Resistors[3]; //Resistors (3 combinations) +Capacitor_Type Caps[3]; //Capacitors (3 combinations) +Diode_Type Diodes[6]; //Diodes (3 combinations in 2 directions) +BJT_Type BJT; //Bipolar junction transistor +FET_Type FET; //FET +Inductor_Type Inductor; //Inductor + +//Store String to Flash Functions :-) +class __FlashStringHelper; +#define X(str) (strcpy_P(PRGBuffer, PSTR(str)), PRGBuffer) + +//Strings +const unsigned char Mode_str[] PROGMEM = "Mode:"; +const unsigned char Continous_str[] PROGMEM = "Continous"; +const unsigned char AutoHold_str[] PROGMEM = "Auto Hold"; +const unsigned char Running_str[] PROGMEM = "Mengukur..."; +const unsigned char Weak_str[] PROGMEM = "weak"; +const unsigned char Low_str[] PROGMEM = "low"; +const unsigned char Failed1_str[] PROGMEM = "No component"; +const unsigned char Failed2_str[] PROGMEM = "found!"; +const unsigned char Thyristor_str[] PROGMEM = "SCR"; +const unsigned char Triac_str[] PROGMEM = "Triac"; +const unsigned char GAK_str[] PROGMEM = "GAC="; +const unsigned char Done_str[] PROGMEM = "selesai!"; +const unsigned char Select_str[] PROGMEM = "pilih"; +const unsigned char Selftest_str[] PROGMEM = "Selftest"; +const unsigned char Adjustment_str[] PROGMEM = "Adjustment"; +const unsigned char Default_str[] PROGMEM = "Default Values"; +const unsigned char Save_str[] PROGMEM = "Save"; +const unsigned char Show_str[] PROGMEM = "Show Values"; +const unsigned char Remove_str[] PROGMEM = "Remove"; +const unsigned char Create_str[] PROGMEM = "Create"; +const unsigned char ShortCircuit_str[] PROGMEM = "Short Circuit!"; +const unsigned char DischargeFailed_str[] PROGMEM = ""; +const unsigned char Error_str[] PROGMEM = "Error!"; +const unsigned char Battery_str[] PROGMEM = "Bat."; +const unsigned char OK_str[] PROGMEM = "ok"; +const unsigned char MOS_str[] PROGMEM = "MOS"; +const unsigned char FET_str[] PROGMEM = "FET"; +const unsigned char Channel_str[] PROGMEM = "-ch"; +const unsigned char Enhancement_str[] PROGMEM = "enh."; +const unsigned char Depletion_str[] PROGMEM = "dep."; +const unsigned char IGBT_str[] PROGMEM = "IGBT"; +const unsigned char GateCap_str[] PROGMEM = "Cgs="; +const unsigned char GDS_str[] PROGMEM = "GDS="; +const unsigned char GCE_str[] PROGMEM = "GCE="; +const unsigned char NPN_str[] PROGMEM = "NPN"; +const unsigned char PNP_str[] PROGMEM = "PNP"; +const unsigned char EBC_str[] PROGMEM = "EBC="; +const unsigned char hFE_str[] PROGMEM ="h_FE="; +const unsigned char V_BE_str[] PROGMEM ="V_BE="; +const unsigned char I_CEO_str[] PROGMEM = "I_CEO="; +const unsigned char Vf_str[] PROGMEM = "Vf="; +const unsigned char DiodeCap_str[] PROGMEM = "C="; +const unsigned char Vth_str[] PROGMEM = "Vth="; +const unsigned char I_R_str[] PROGMEM = "I_R="; +const unsigned char URef_str[] PROGMEM = "Vref"; +const unsigned char RhLow_str[] PROGMEM = "Rh-"; +const unsigned char RhHigh_str[] PROGMEM = "Rh+"; +const unsigned char RiLow_str[] PROGMEM = "Ri-"; +const unsigned char RiHigh_str[] PROGMEM = "Ri+"; +const unsigned char Rl_str[] PROGMEM = "+Rl-"; +const unsigned char Rh_str[] PROGMEM = "+Rh-"; +const unsigned char ProbeComb_str[] PROGMEM = "12 13 23"; +const unsigned char CapOffset_str[] PROGMEM = "C0"; +const unsigned char ROffset_str[] PROGMEM = "R0"; +const unsigned char CompOffset_str[] PROGMEM = "AComp"; +const unsigned char PWM_str[] PROGMEM = "PWM"; +const unsigned char Hertz_str[] PROGMEM = "Hz"; +const unsigned char Splash_str[] PROGMEM = "ESR METER "; +const unsigned char Version_str[] PROGMEM = "atmduino product"; + +#ifdef DEBUG_PRINT + const unsigned char Cap_str[] PROGMEM = {'-','|','|', '-',0}; + const unsigned char Diode_AC_str[] PROGMEM = {'-', '>', '-', 0}; + const unsigned char Diode_CA_str[] PROGMEM = {'-', '<', '-', 0}; + const unsigned char Diodes_str[] PROGMEM = {'*', '>', ' ', ' ', 0}; + const unsigned char Resistor_str[] PROGMEM = {'-', '[', ']', '-', 0}; +#else + const unsigned char Cap_str[] PROGMEM = {'-',LCD_CHAR_CAP, '-',0}; + const unsigned char Diode_AC_str[] PROGMEM = {'-', LCD_CHAR_DIODE1, '-', 0}; + const unsigned char Diode_CA_str[] PROGMEM = {'-', LCD_CHAR_DIODE2, '-', 0}; + const unsigned char Diodes_str[] PROGMEM = {'*', LCD_CHAR_DIODE1, ' ', ' ', 0}; + const unsigned char Resistor_str[] PROGMEM = {'-', LCD_CHAR_RESIS1, LCD_CHAR_RESIS2, '-', 0}; +#endif + +//Diode icon with anode at left side +byte DiodeIcon1[8] = {0x11, 0x19, 0x1d, 0x1f, 0x1d, 0x19, 0x11, 0x00}; +//Diode icon with anode at right side +byte DiodeIcon2[8] = {0x11, 0x13, 0x17, 0x1f, 0x17, 0x13, 0x11, 0x00}; +//Capacitor icon +byte CapIcon[8] = {0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x00}; +//Resistor icon #1 (left part) +byte ResIcon1[8] = {0x00, 0x0f, 0x08, 0x18, 0x08, 0x0f, 0x00, 0x00}; +//Resistor icon #2 (right part) +byte ResIcon2[8] = {0x00, 0x1e, 0x02, 0x03, 0x02, 0x1e, 0x00, 0x00}; +//Flag Icon +byte FlagIcon[8] = {0x1f, 0x11, 0x0e, 0x04, 0x0a, 0x15, 0x1f, 0x00}; + +//Prefix Table +const unsigned char Prefix_table[] = {'p', 'n', LCD_CHAR_MICRO, 'm', 0, 'k', 'M'}; +//PWM menu: frequencies +const unsigned int PWM_Freq_table[] = {100, 250, 500, 1000, 2500, 5000, 10000, 25000}; +//Voltage based factors for large caps (using Rl) +const unsigned int LargeCap_table[] = {23022, 21195, 19629, 18272, 17084, 16036, 15104, 14271, 13520, 12841, 12224, 11660, 11143, 10668, 10229, 9822, 9445, 9093, 8765, 8458, 8170, 7900, 7645, 7405, 7178, 6963, 6760, 6567, 6384, 6209, 6043, 5885, 5733, 5589, 5450, 5318, 5191, 5069, 4952, 4839, 4731, 4627, 4526, 4430, 4336}; +//Voltage based factors for small caps (using Rh) +const unsigned int SmallCap_table[] = {954, 903, 856, 814, 775, 740, 707, 676, 648}; +//Ratio based factors for inductors +const unsigned int Inductor_table[] = {4481, 3923, 3476, 3110, 2804, 2544, 2321, 2128, 1958, 1807, 1673, 1552, 1443, 1343, 1252, 1169, 1091, 1020, 953, 890, 831, 775, 721, 670, 621, 574, 527, 481, 434, 386, 334, 271}; + +//Bitmasks for Rl probe resistors based on probe ID +const unsigned char Rl_table[] = {(1 << (TP1 * 2)), (1 << (TP2 * 2)), (1 << (TP3 * 2))}; +//Bitmasks for ADC pins based on probe ID +const unsigned char ADC_table[] = {(1 << TP1), (1 << TP2), (1 << TP3)}; + +//Function prototype +byte SmallCap(Capacitor_Type *Cap); +byte LargeCap(Capacitor_Type *Cap); +byte MeasureInductor(Resistor_Type *Resistor); +void ShowDiode_Uf(Diode_Type *Diode); +void ShowDiode_C(Diode_Type *Diode); + +//Program control +byte RunsPassed; //Counter for successful measurements +byte RunsMissed; //Counter for failed/missed measurements +byte ErrFnd; //An Error is occured + +//Setup function +void setup() +{ + byte Test; //Test value + //Disable power on spi, twi, timer2 + //power_spi_disable(); + //power_twi_disable(); + //power_timer2_disable(); + + #ifdef LCD_PRINT + //lcd.init(); + //lcd.backlight(); + lcd.begin(16,2); + delay(5); + //Symbols for components + lcd.createChar(LCD_CHAR_DIODE1,DiodeIcon1); //Diode symbol |<| + lcd.createChar(LCD_CHAR_DIODE2,DiodeIcon2); //Diode symbol |<| + lcd.createChar(LCD_CHAR_CAP,CapIcon); //Capacitor symbol || + lcd.createChar(LCD_CHAR_RESIS1,ResIcon1); //Resistor symbol [ + lcd.createChar(LCD_CHAR_RESIS2,ResIcon2); //Resistor symbol ] + lcd.createChar(LCD_CHAR_FLAG,FlagIcon); //Flag symbol + lcd.home(); + lcd.setCursor(3,0); + lcd_fixed_string(Splash_str); + lcd.setCursor(0,1); + lcd_fixed_string(Version_str); + + #endif + #ifdef ATSW //Client Begin + Serial.begin(19200); + #endif + #ifdef DEBUG_PRINT + Serial.begin(9600); //Serial Output + #endif + //Setup �C + ADCSRA = (1 << ADEN) | ADC_CLOCK_DIV; //Enable ADC and set clock divider + MCUSR &= ~(1 << WDRF); //Reset watchdog flag + DIDR0 = 0b00110111; + wdt_disable(); //Disable watchdog + //Default offsets and values + Config.Samples = ADC_SAMPLES; //Number of ADC samples + Config.AutoScale = 1; //Enable ADC auto scaling + Config.RefFlag = 1; //No ADC reference set yet + delay(100); + //Reset variables + RunsMissed = 0; + RunsPassed = 0; + Config.TesterMode = MODE_CONTINOUS; //Set default mode: continous + #ifdef BUTTON_INST + pinMode(TEST_BUTTON, INPUT_PULLUP); //Initialize the pushbutton pin as an input + #endif + //Init + LoadAdjust(); //Load adjustment values + #ifdef DEBUG_PRINT + lcd.print(X("A R D U T E S T E R ")); + lcd_fixed_string(Version_str); //Print Ardutester Version + Serial.println(); + Serial.println(X(" By PighiXXX & PaoloP")); + Serial.println(X("original version by Markus Reschke")); + Serial.println(); + #ifdef BUTTON_INST + Serial.print(X("Press Button to Probe")); + Serial.println(X(", long press enter Menu")); + #endif + #endif + delay(100); +} + +//Main loop +void loop() +{ + byte Test; + #ifdef BUTTON_INST + Test = TestKey(0, 0); //Wait user + #else + delay(3000); //No button installed, Wait 3 seconds + Test=1; //No button, no menu :-) + #endif + #ifdef WDT_enabled + wdt_enable(WDTO_2S); //Enable watchdog (timeout 2s) + #endif + //Reset variables + Check.Found = COMP_NONE; + Check.Type = 0; + Check.Done = 0; + Check.Diodes = 0; + Check.Resistors = 0; + BJT.hFE = 0; + BJT.I_CE0 = 0; + //Reset hardware + SetADCHiz(); //Set all pins of ADC port as input + lcd_clear(); //Clear LCD + #ifdef LCD_PRINT + lcd.setCursor(3,0); //proses pembacaan komponen + lcd_fixed_string(Splash_str); + //lcd_fixed_string(Version_str); + #endif + //Internal bandgap reference + Config.U_Bandgap = ReadU(0x0e); //Dummy read for bandgap stabilization + Config.Samples = 200; //Do a lot of samples for high accuracy + Config.U_Bandgap = ReadU(0x0e); //Get voltage of bandgap reference + Config.Samples = ADC_SAMPLES; //Set samples back to default + Config.U_Bandgap += Config.RefOffset; //Add voltage offset + if (Test==2) //Long Press + { + wdt_disable(); //Disable watchdog + MainMenu(); //Main Menu + } + else + { + if (AllProbesShorted() == 3) //All probes Shorted! + { + #ifdef DEBUG_PRINT + Serial.println(); + #endif + lcd_fixed_string(Remove_str); //Display: Remove/Create + lcd_line(1); + lcd_fixed_string(ShortCircuit_str); //Display: short circuit! + } + else + { + //Display start of probing + lcd_line(1); //Move to line #2 + lcd_fixed_string(Running_str); //Display: probing... + DischargeProbes(); + if (Check.Found == COMP_ERROR) //Discharge failed + { //Only for Standalone Version! + lcd.setCursor(3,0); + lcd_fixed_string(DischargeFailed_str); //Display: Battery? + //Display probe number and remaining voltage + lcd_line(1); + lcd.setCursor(0,1); + lcd.print("pin "); + lcd.setCursor(4,1); + lcd_testpin(Check.Probe); + lcd.setCursor(5,1); + lcd.print("(+)"); + lcd_data(':'); + lcd_space(); + lcd.setCursor(10,1); + DisplayValue(Check.U, -3, 'V'); + } + else //Skip all other checks + { + //Check all 6 combinations of the 3 probes + CheckProbes(TP1, TP2, TP3); + CheckProbes(TP2, TP1, TP3); + CheckProbes(TP1, TP3, TP2); + CheckProbes(TP3, TP1, TP2); + CheckProbes(TP2, TP3, TP1); + CheckProbes(TP3, TP2, TP1); + //If component might be a capacitor + if ((Check.Found == COMP_NONE) || + (Check.Found == COMP_RESISTOR)) + { + #ifdef DEBUG_PRINT + Serial.println(); + Serial.println(X("Wait a moment...")); + #else + //Tell user to be patient with large caps + lcd_clear_line(1); + lcd_fixed_string(Running_str); + lcd_data('.'); + #endif + //Check all possible combinations + MeasureCap(TP3, TP1, 0); + #ifdef LCD_PRINT + lcd_data('.'); + #endif + MeasureCap(TP3, TP2, 1); + #ifdef LCD_PRINT + lcd_data('.'); + #endif + MeasureCap(TP2, TP1, 2); + } + //Clear LCD + lcd_clear(); + #ifdef BUTTON_INST + pinMode(TEST_BUTTON, INPUT_PULLUP); //Reinitialize the pushbutton pin as an input + #endif + //Call output function based on component type + #ifdef DEBUG_PRINT + Serial.print("Found: "); + //Components ID's + switch (Check.Found) + { + case COMP_ERROR: + Serial.println(X("Component Error!")); + break; + case COMP_NONE: + Serial.println(X("No Component!")); + break; + case COMP_RESISTOR: + Serial.println(X("Resistor")); + break; + case COMP_CAPACITOR: + Serial.println(X("Capacitor")); + break; + case COMP_INDUCTOR: + Serial.println(X("Inductor")); + break; + case COMP_DIODE: + Serial.println(X("Diode")); + break; + case COMP_BJT: + Serial.println(X("BJT")); + break; + case COMP_FET: + Serial.println(X("FET")); + break; + case COMP_IGBT: + Serial.println(X("IGBT")); + break; + case COMP_TRIAC: + Serial.println(X("TRIAC")); + break; + case COMP_THYRISTOR: + Serial.println(X("Thyristor")); + break; + } + #endif + switch (Check.Found) + { + case COMP_ERROR: + ShowError(); + break; + case COMP_DIODE: + ShowDiode(); + break; + case COMP_BJT: + ShowBJT(); + break; + case COMP_FET: + ShowFET(); + break; + case COMP_IGBT: + ShowIGBT(); + break; + case COMP_THYRISTOR: + ShowSpecial(); + break; + case COMP_TRIAC: + ShowSpecial(); + break; + case COMP_RESISTOR: + ShowResistor(); + break; + case COMP_CAPACITOR: + ShowCapacitor(); + break; + default: //No component found + ShowFail(); + } + #ifdef ATSW //Client output + Serial.println("@>"); + Serial.println(Check.Found); + Serial.println("|"); + Serial.println(Check.Type); + Serial.println("|"); + Serial.println(Check.Done); + Serial.println("|"); + Serial.println("@<"); + //Component spedific output + #endif + //Component was found + RunsMissed = 0; //Reset counter + RunsPassed++; //Increase counter + } + } + } + delay(1000); //Let the user read the text + wdt_disable(); //Disable watchdog +} + +//Set ADC port to HiZ mode +void SetADCHiz(void) +{ + ADC_DDR &= ~(1< UREF_VCC/2 - 30) && (U1 < UREF_VCC/2 + 30)) + { + if ((U2 > UREF_VCC/2 - 30) && (U2 < UREF_VCC/2 + 30)) + { + Flag = 1; + } + } + //Reset port + R_DDR = 0; + return Flag; +} + + //Check for a short circuit between all probes + byte AllProbesShorted(void) +{ + byte Flag = 0; //Return value + //Check all possible combinations + Flag = ShortedProbes(TP1, TP2); + Flag += ShortedProbes(TP1, TP3); + Flag += ShortedProbes(TP2, TP3); + return Flag; +} + +//Try to discharge any connected components, e.g. capacitors +void DischargeProbes(void) +{ + byte Counter; //Loop control + byte Limit = 40; //Sliding timeout (2s) + byte ID; //Test pin + byte DischargeMask; //Bitmask + unsigned int U_c; //Current voltage + unsigned int U_old[3]; //Old voltages + //Set probes to a save discharge mode (pull-down via Rh), Set ADC port to HiZ input + SetADCHiz(); + SetADCLow(); + //All probe pins: Rh and Rl pull-down + R_PORT = 0; + R_DDR = (2 << (TP1 * 2)) | (2 << (TP2 * 2)) | (2 << (TP3 * 2)); + R_DDR |= (1 << (TP1 * 2)) | (1 << (TP2 * 2)) | (1 << (TP3 * 2)); + //Get current voltages + U_old[0] = ReadU(TP1); + U_old[1] = ReadU(TP2); + U_old[2] = ReadU(TP3); + /* + Try to discharge probes + - We check if the voltage decreases over time. + - A slow discharge rate will increase the timeout to support + large caps. + - A very large cap will discharge too slowly and an external voltage + maybe never :-) + */ + Counter = 1; + ID = 2; + DischargeMask = 0; + while (Counter > 0) + { + ID++; //Next probe + if (ID > 2) ID = 0; //Start with probe #1 again + if (DischargeMask & (1 << ID)) //Skip discharged probe + continue; + U_c = ReadU(ID); //Get voltage of probe + if (U_c < U_old[ID]) //Voltage decreased + { + U_old[ID] = U_c; //Update old value + //Adapt timeout based on discharge rate + if ((Limit - Counter) < 20) + { + //Increase timeout while preventing overflow + if (Limit < (255 - 20)) Limit += 20; + } + Counter = 1; //Reset no-changes counter + } + else //Voltage not decreased + { + //Increase limit if we start at a low voltage + if ((U_c < 10) && (Limit <= 40)) Limit = 80; + Counter++; //Increase no-changes counter + } + if (U_c <= CAP_DISCHARGED) //Seems to be discharged + { + DischargeMask |= (1 << ID); //Set flag + } + else if (U_c < 800) //Extra pull-down + { + //It's save now to pull-down probe pin directly + ADC_DDR |= ADC_table[ID]; + } + if (DischargeMask == 0b00000111) //All probes discharged + { + Counter = 0; //End loop + } + else if (Counter > Limit) //No decrease for some time + { + //Might be a battery or a super cap + Check.Found = COMP_ERROR; //Report error + Check.Type = TYPE_DISCHARGE; //Discharge problem + Check.Probe = ID; //Save probe + Check.U = U_c; //Save voltage + Counter = 0; //End loop + } + else //Go for another round + { + wdt_reset(); //Reset watchdog + delay(50); //Wait for 50ms + } + } + //Reset probes + R_DDR = 0; //Set resistor port to input mode + SetADCHiz(); //Set ADC port to input mode +} + +//Pull probe up/down via probe resistor for 1 or 10 ms +void PullProbe(byte Mask, byte Mode) +{ + //Set pull mode + if (Mode & FLAG_PULLUP) R_PORT |= Mask; //Pull-up + else R_PORT &= ~Mask; //Pull-down + R_DDR |= Mask; //Enable pulling + if (Mode & FLAG_1MS) delay(1); //Wait 1ms + else delay(10); //Wait 10ms + //Reset pulling + R_DDR &= ~Mask; //Set to HiZ mode + R_PORT &= ~Mask; //Set 0 +} + +//Rescale value +unsigned long RescaleValue(unsigned long Value, signed char Scale, signed char NewScale) +{ + unsigned long NewValue; + NewValue = Value; //Take old value + while (Scale != NewScale) //Processing loop + { + if (NewScale > Scale) //Upscale + { + NewValue /= 10; + Scale++; + } + else //Downscale + { + NewValue *= 10; + Scale--; + } + } + return NewValue; +} + +//Lokup a voltage/ratio based factor in a table and interpolate it's value +unsigned int GetFactor(unsigned int U_in, byte ID) +{ + unsigned int Factor; //Return value + unsigned int U_Diff; //Voltage difference to table start + unsigned int Fact1, Fact2; //Table entries + unsigned int TabStart; //Table start voltage + unsigned int TabStep; //Table step voltage + unsigned int TabIndex; //Table entries (-2) + unsigned int *Table; + byte Index; //Table index + byte Diff; //Difference to next entry + //Setup table specific stuff + if (ID == TABLE_SMALL_CAP) + { + TabStart = 1000; //Table starts at 1000mV + TabStep = 50; //50mV steps between entries + TabIndex = 7; //Entries in table - 2 + Table = (unsigned int *)&SmallCap_table[0]; //Pointer to table start + } + else if (ID == TABLE_LARGE_CAP) + { + TabStart = 300; //Table starts at 1000mV + TabStep = 25; //25mV steps between entries + TabIndex = 42; //Entries in table - 2 + Table = (unsigned int *)&LargeCap_table[0]; //Pointer to table start + } + else if (ID == TABLE_INDUCTOR) + { + TabStart = 200; //Table starts at 200 + TabStep = 25; //Steps between entries + TabIndex = 30; //Entries in table - 2 + Table = (unsigned int *)&Inductor_table[0]; //Pointer to table start + } + else + { + return 0; + } + //We interpolate the table values corresponding to the given voltage/ratio, difference to start of table + if (U_in >= TabStart) U_Diff = U_in - TabStart; + else U_Diff = 0; + //Calculate table index + Index = U_Diff / TabStep; //Index (position in table) + Diff = U_Diff % TabStep; //Difference to index + Diff = TabStep - Diff; //Difference to next entry + //Prevent index overflow + if (Index > TabIndex) Index = TabIndex; + //Get values for index and next entry + Table += Index; //Advance to index + Fact1 = *(Table); + Table++; //Next entry + Fact2 = *(Table); + //Interpolate values based on the difference + Factor = Fact1 - Fact2; + Factor *= Diff; + Factor += TabStep / 2; + Factor /= TabStep; + Factor += Fact2; + return Factor; +} + +//Identify component +void CheckProbes(byte Probe1, byte Probe2, byte Probe3) +{ + byte Flag; //Temporary value + unsigned int U_Rl; //Voltage across Rl (load) + unsigned int U_1; //Voltage #1 + //Init + if (Check.Found == COMP_ERROR) return; //Skip check on any error + wdt_reset(); //Reset watchdog + UpdateProbes(Probe1, Probe2, Probe3); //Update bitmasks + /* + We measure the current from probe 2 to ground with probe 1 pulled up + to 5V and probe 3 in HiZ mode to determine if we got a self-conducting + part, i.e. diode, resistor or depletion-mode FET. Rl is used as current + shunt. + + In case of a FET we have to take care about the gate charge based on + the channel type. + */ + //Set probes: Gnd -- Rl -- probe-2 / probe-1 -- Vcc + R_PORT = 0; //Set resistor port to Gnd + R_DDR = Probes.Rl_2; //Pull down probe-2 via Rl + ADC_DDR = Probes.ADC_1; //Set probe-1 to output + ADC_PORT = Probes.ADC_1; //Pull-up probe-1 directly + /* + For a possible n channel FET we pull down the gate for a few ms, + assuming: probe-1 = D / probe-2 = S / probe-3 = G + */ + //Discharge gate via Rl + PullProbe(Probes.Rl_3, FLAG_10MS | FLAG_PULLDOWN); + U_Rl = ReadU_5ms(Probes.Pin_2); //Get voltage at Rl + /* + If we got conduction we could have a p channel FET. For any + other part U_Rl will be the same. + */ + if (U_Rl >= 977) // > 1.4mA + { + /* + For a possible p channel FET we pull up the gate for a few ms, + assuming: probe-1 = S / probe-2 = D / probe-3 = G + */ + //Discharge gate via Rl + PullProbe(Probes.Rl_3, FLAG_10MS | FLAG_PULLUP); + U_Rl = ReadU_5ms(Probes.Pin_2); //Get voltage at Rl + } + /* + If there's some current we could have a depletion-mode FET + (self-conducting). To skip germanium BJTs with a high leakage current + we check for a current larger then the usual V_CEO. + + Other possibilities: + - diode or resistor + */ + if (U_Rl > 490) // > 700�A (was 92mV/130�A) + { + CheckDepletionModeFET(U_Rl); + } + /* + If there's nearly no conduction (just a small leakage current) between + probe-1 and probe-2 we might have a semiconductor: + - BJT + - enhancement mode FET + - Thyristor or Triac + or a large resistor + */ + if (U_Rl < 977) //Load current < 1.4mA + { + /* + check for: + - PNP BJT (common emitter circuit) + - p-channel MOSFET (low side switching circuit) + */ + if (Check.Done == 0) //Not sure yet + { + //We assume: probe-1 = E / probe-2 = C / probe-3 = B, set probes: Gnd -- Rl - probe-2 / probe-1 -- Vcc + R_DDR = Probes.Rl_2; //Enable Rl for probe-2 + R_PORT = 0; //Pull down collector via Rl + ADC_DDR = Probes.ADC_1; //Set probe 1 to output + ADC_PORT = Probes.ADC_1; //Pull up emitter directly + delay(5); + R_DDR = Probes.Rl_2 | Probes.Rl_3; //Pull down base via Rl + U_1 = ReadU_5ms(Probe2); //Get voltage at collector + //If DUT is conducting we might have a PNP BJT or p-channel FET. + if (U_1 > 3422) //Detected current > 4.8mA + { + //Distinguish PNP BJT from p-channel MOSFET + CheckBJTorEnhModeMOSFET(TYPE_PNP, U_Rl); + } + } + /* + Check for + - NPN BJT (common emitter circuit) + - Thyristor and Triac + - n-channel MOSFET (high side switching circuit) + */ + if (Check.Done == 0) //Not sure yet + { + //We assume: probe-1 = C / probe-2 = E / probe-3 = B, set probes: Gnd -- probe-2 / probe-1 -- Rl -- Vcc + ADC_DDR = Probes.ADC_2; //Set probe-2 to output mode + SetADCLow(); //Pull down probe-2 directly + R_DDR = Probes.Rl_1 | Probes.Rl_3; //Select Rl for probe-1 & Rl for probe-3 + R_PORT = Probes.Rl_1 | Probes.Rl_3; //Pull up collector & base via Rl + U_1 = ReadU_5ms(Probe1); //Get voltage at collector + //If DUT is conducting we might have a NPN BJT, something similar or a n-channel MOSFET. + if (U_1 < 1600) //Detected current > 4.8mA + { + //First check for thyristor and triac + Flag = CheckThyristorTriac(); + if (Flag == 0) //No thyristor or triac + { + //We might got a NPN BJT or a n-channel MOSFET. + CheckBJTorEnhModeMOSFET(TYPE_NPN, U_Rl); + } + } + } + } + /* + If there's conduction between probe-1 and probe-2 we might have a + - diode (conducting) + - small resistor (checked later on) + */ + else //Load current > 1.4mA + { + //We check for a diode even if we already found a component to get Vf, since there could be a body/protection diode of a transistor. + CheckDiode(); + } + //Check for a resistor. + if ((Check.Found == COMP_NONE) || + (Check.Found == COMP_RESISTOR)) + { + CheckResistor(); + } + //Otherwise run some final checks. + else + { + //Verify a MOSFET + if ((Check.Found == COMP_FET) && (Check.Type & TYPE_MOSFET)) + VerifyMOSFET(); + } + //Clean up + SetADCHiz(); //Set ADC port to HiZ mode + SetADCLow(); //Set ADC port low + R_DDR = 0; //Set resistor port to HiZ mode + R_PORT = 0; //Set resistor port low +} + +//Read ADC and return voltage in mV +unsigned int ReadU(byte Probe) +{ + unsigned int U; //Return value (mV) + byte Counter; //Loop counter + unsigned long Value; //ADC value + boolean cycle; + Probe |= (1 << REFS0); //Use internal reference anyway + do { + cycle = false; + ADMUX = Probe; //Set input channel and U reference + //If voltage reference has changed run a dummy conversion (recommended by datasheet) + Counter = Probe & (1 << REFS1); //Get REFS1 bit flag + if (Counter != Config.RefFlag) + { + waitus(100); //Time for voltage stabilization + ADCSRA |= (1 << ADSC); //Start conversion + while (ADCSRA & (1 << ADSC)); //Wait until conversion is done + Config.RefFlag = Counter; //Update flag + } + //Sample ADC readings + Value = 0UL; //Reset sampling variable + Counter = 0; //Reset counter + while (Counter < Config.Samples) //Take samples + { + ADCSRA |= (1 << ADSC); //Start conversion + while (ADCSRA & (1 << ADSC)); //Wait until conversion is done + Value += ADCW; //Add ADC reading + //Auto-switch voltage reference for low readings + if (Counter == 4) + { + if (((unsigned int)Value < 1024) && !(Probe & (1 << REFS1)) && (Config.AutoScale == 1)) + { + Probe |= (1 << REFS1); //Select internal bandgap reference + cycle = true; //Re-run sampling + break; + } + } + Counter++; //One less to do + } + } while (cycle); + //Convert ADC reading to voltage - single sample: U = ADC reading * U_ref / 1024 + //Get voltage of reference used + if (Probe & (1 << REFS1)) U = Config.U_Bandgap;//Bandgap reference + else U = UREF_VCC; //Vcc reference + //Convert to voltage; + Value *= U; //ADC readings * U_ref + Value /= 1024; // / 1024 for 10bit ADC + //De-sample to get average voltage + Value /= Config.Samples; + U = (unsigned int)Value; + return U; +} + +//Wait 5ms and then read ADC +unsigned int ReadU_5ms(byte Probe) +{ + delay(5); //Wait 5ms + return (ReadU(Probe)); +} + +//Wait 20ms and then read ADC +unsigned int ReadU_20ms(byte Probe) +{ + delay(20); //Wait 20ms + return (ReadU(Probe)); +} + +//Wait Functions +void waitus(byte microsec) { + delayMicroseconds(microsec); +} + +//Measure hFE of BJT in common collector circuit (emitter follower) +unsigned long Get_hFE_C(byte Type) +{ + unsigned long hFE; //Return value + unsigned int U_R_e; //Voltage across emitter resistor + unsigned int U_R_b; //Voltage across base resistor + unsigned int Ri; //Internal resistance of �C + /* + Measure hFE for a BJT in common collector circuit + (emitter follower): + - hFE = (I_e - I_b) / I_b + - measure the voltages across the resistors and calculate the currents + (resistor values are well known) + - hFE = ((U_R_e / R_e) - (U_R_b / R_b)) / (U_R_b / R_b) + */ + //Setup probes and get voltages + if (Type == TYPE_NPN) //NPN + { + //We assume: probe-1 = C / probe-2 = E / probe-3 = B, set probes: Gnd -- Rl -- probe-2 / probe-1 -- Vcc + ADC_DDR = Probes.ADC_1; //Set probe 1 to output + ADC_PORT = Probes.ADC_1; //Pull up collector directly + R_DDR = Probes.Rl_2 | Probes.Rl_3; //Select Rl for probe-2 & Rl for probe-3 + R_PORT = Probes.Rl_3; //Pull up base via Rl + U_R_e = ReadU_5ms(Probes.Pin_2); //U_R_e = U_e + U_R_b = UREF_VCC - ReadU(Probes.Pin_3); //U_R_b = Vcc - U_b + } + else //PNP + { + //We assume: probe-1 = E / probe-2 = C / probe-3 = B, set probes: Gnd -- probe-2 / probe-1 -- Rl -- Vcc + SetADCLow(); //Set ADC port low + ADC_DDR = Probes.ADC_2; //Pull down collector directly + R_PORT = Probes.Rl_1; //Pull up emitter via Rl + R_DDR = Probes.Rl_1 | Probes.Rl_3; //Pull down base via Rl + U_R_e = UREF_VCC - ReadU_5ms(Probes.Pin_1); //U_R_e = Vcc - U_e + U_R_b = ReadU(Probes.Pin_3); //U_R_b = U_b + } + if (U_R_b < 10) //I_b < 14�A -> Darlington + { + //Change base resistor from Rl to Rh and measure again + if (Type == TYPE_NPN) //NPN + { + R_DDR = Probes.Rl_2 | Probes.Rh_3; //Select Rl for probe-2 & Rh for probe-3 + R_PORT = Probes.Rh_3; //Pull up base via Rh + U_R_e = ReadU_5ms(Probes.Pin_2); //U_R_e = U_e + U_R_b = UREF_VCC - ReadU(Probes.Pin_3); //U_R_b = Vcc - U_b + Ri = Config.RiL; //Get internal resistor + } + else //PNP + { + R_DDR = Probes.Rl_1 | Probes.Rh_3; //Pull down base via Rh + U_R_e = UREF_VCC - ReadU_5ms(Probes.Pin_1);//U_R_e = Vcc - U_e + U_R_b = ReadU(Probes.Pin_3); //U_R_b = U_b + Ri = Config.RiH; //Get internal resistor + } + /* + Since I_b is so small vs. I_e we'll neglect it and use + hFE = I_e / I_b + = (U_R_e / R_e) / (U_R_b / R_b) + = (U_R_e * R_b) / (U_R_b * R_e) + */ + if (U_R_b < 1) U_R_b = 1; //Prevent division by zero + hFE = U_R_e * R_HIGH; //U_R_e * R_b + hFE /= U_R_b; // / U_R_b + hFE *= 10; //Upscale to 0.1 + hFE /= (R_LOW * 10) + Ri; // / R_e in 0.1 Ohm + } + else //I_b > 14�A -> standard + { + /* + Both resistors are the same (R_e = R_b): + - hFE = ((U_R_e / R_e) - (U_R_b / R_b)) / (U_R_b / R_b) + - = (U_R_e - U_R_b) / U_R_b + */ + hFE = (unsigned long)((U_R_e - U_R_b) / U_R_b); + } + return hFE; +} + +//Measure the gate threshold voltage of a depletion-mode MOSFET +void GetGateThreshold(byte Type) +{ + unsigned long Uth = 0; //Gate threshold voltage + byte Drain_Rl; //Rl bitmask for drain + byte Drain_ADC; //ADC bitmask for drain + byte PullMode; + byte Counter; //Loop counter + //Init variables + if (Type & TYPE_N_CHANNEL) //n-channel + { + /* + We assume: probe-1 = D / probe-2 = S / probe-3 = G + probe-2 is still pulled down directly + probe-1 is still pulled up via Rl + */ + Drain_Rl = Probes.Rl_1; + Drain_ADC = Probes.ADC_1; + PullMode = FLAG_10MS | FLAG_PULLDOWN; + } + else //p-channel + { + /* + We assume: probe-1 = S / probe-2 = D / probe-3 = G + probe-2 is still pulled down via Rl + probe-1 is still pulled up directly + */ + Drain_Rl = Probes.Rl_2; + Drain_ADC = Probes.ADC_2; + PullMode = FLAG_10MS | FLAG_PULLUP; + } + //For low reaction times we use the ADC directly. + //Sanitize bit mask for drain to prevent a never-ending loop + Drain_ADC &= 0b00000111; //drain + ADMUX = Probes.Pin_3 | (1 << REFS0); //Select probe-3 for ADC input + //Sample 10 times + for (Counter = 0; Counter < 10; Counter++) + { + wdt_reset(); //Reset watchdog + //Discharge gate via Rl for 10 ms + PullProbe(Probes.Rl_3, PullMode); + //Pull up/down gate via Rh to slowly charge gate + R_DDR = Drain_Rl | Probes.Rh_3; + //Wait until FET conducts + if (Type & TYPE_N_CHANNEL) //n-channel + { + //FET conducts when the voltage at drain reaches low level + while (ADC_PIN & Drain_ADC); + } + else //p-channel + { + //FET conducts when the voltage at drain reaches high level + while (!(ADC_PIN & Drain_ADC)); + } + R_DDR = Drain_Rl; //Set probe-3 to HiZ mode + //Get voltage of gate + ADCSRA |= (1 << ADSC); //Start ADC conversion + while (ADCSRA & (1 << ADSC)); //Wait until conversion is done + //Add ADC reading + if (Type & TYPE_N_CHANNEL) //n-channel + { + Uth += ADCW; //U_g = U_measued + } + else //p-channel + { + Uth += (1023 - ADCW); //U_g = Vcc - U_measured + } + } + //Calculate V_th + Uth /= 10; //Average of 10 samples + Uth *= UREF_VCC; //Convert to voltage + Uth /= 1024; //Using 10 bit resolution + //Save data + FET.V_th = (unsigned int)Uth; +} + +//Measure leakage current +unsigned int GetLeakageCurrent(void) +{ + unsigned int I_leak = 0; //Return value + unsigned int U_Rl; //Voltage at Rl + unsigned int R_Shunt; //Shunt resistor + uint32_t Value; + /* + Setup probes: + - use Rl as current shunt + - probe-1 = pos / probe-2 = neg / probe-3 = HiZ + Diode: probe-1 = cathode / probe-2 = anode + NPN BJT: probe-1 = collector / probe-2 = emitter + PNP BJT: probe-1 = emitter / probe-2 = collector + */ + R_PORT = 0; //Set resistor port to Gnd + R_DDR = Probes.Rl_2; //Pull down probe-2 via Rl + ADC_DDR = Probes.ADC_1; //Set probe-1 to output + ADC_PORT = Probes.ADC_1; //Pull-up probe-1 directly + U_Rl = ReadU_5ms(Probes.Pin_2); //Get voltage at Rl + //Calculate current + R_Shunt = Config.RiL + (R_LOW * 10); //Consider internal resistance of MCU (0.1 Ohms) + R_Shunt += 5; //For rounding + R_Shunt /= 10; //Scale to Ohms + Value = U_Rl * 100000; //Scale to 10nV + Value /= R_Shunt; //in 10nA + Value += 55; //For rounding + Value /= 100; //Scale to �A + I_leak = Value; + //Clean up + SetADCHiz(); //Set ADC port to HiZ mode + SetADCLow(); //Set ADC port low + R_DDR = 0; //Set resistor port to HiZ mode + R_PORT = 0; //Set resistor port low + return I_leak; +} + +//Check for diode +void CheckDiode(void) +{ + Diode_Type *Diode; //Pointer to diode + unsigned int U1_Rl; //Vf #1 with Rl pull-up + unsigned int U1_Rh; //Vf #1 with Rh pull-up + unsigned int U1_Zero; //Vf #1 zero + unsigned int U2_Rl; //Vf #2 with Rl pull-up + unsigned int U2_Rh; //Vf #2 with Rh pull-up + unsigned int U2_Zero; //Vf #2 zero + wdt_reset(); //Reset watchdog + DischargeProbes(); //Try to discharge probes + if (Check.Found == COMP_ERROR) return; //Skip on error + /* + DUT could be: + - simple diode + - protection diode of a MOSFET or another device + - intrinsic diode junction of a BJT + - small resistor (< 3k) + - capacitor (> around 22�F) + + Solution: + - Vf of a diode rises with the current within some limits (about twice + for Si and Schottky). Ge, Z-diodes and LEDs are hard to determine. + So it might be better to filter out other components. + - For a MOSFET pretection diode we have to make sure that the MOSFET + in not conducting, to be able to get Vf of the protection diode. + So we discharge the gate and run the measurements twice for p and n + channel FETs. + - Take care about the internal voltage drop of the �C at the cathode + for high test currents (Rl). + - Filter out resistors by the used voltage divider: + k = Rl + Ri_H + Ri_L + U_Rh = U_Rl / (k - (k - 1) U_Rl / 5V) + U_Rl = k U_Rh / (1 + (k - 1) U_Rh / 5V) + - Filter out caps by checking the voltage before and after measurement + with Rh. In 15ms a 22�F cap would be charged from 0 to 7mV, a larger + cap would have a lower voltage. We have to consider that caps also + might be charged by EMI. + + Hints: + - Rl drives a current of about 7mA. That's not the best current for + measuring Vf. The current for Rh is about 10.6�A. + Most DMMs use 1mA. + + Vf #1, supporting a possible p-channel MOSFET + */ + //We assume: probe-1 = A / probe2 = C, set probes: Gnd -- probe-2 / probe-1 -- Rl or Rh -- Vcc + SetADCLow(); + ADC_DDR = Probes.ADC_2; //Pull down cathode directly + //R_DDR is set to HiZ by DischargeProbes(); + U1_Zero = ReadU(Probes.Pin_1); //Get voltage at anode + //Measure voltage across DUT (Vf) with Rh + R_DDR = Probes.Rh_1; //Enable Rh for probe-1 + R_PORT = Probes.Rh_1; //Pull up anode via Rh + //Discharge gate + PullProbe(Probes.Rl_3, FLAG_10MS | FLAG_PULLUP); + U1_Rh = ReadU_5ms(Probes.Pin_1); //Get voltage at anode, neglect voltage at cathode + //Measure voltage across DUT (Vf) with Rl + R_DDR = Probes.Rl_1; //Enable Rl for probe-1 + R_PORT = Probes.Rl_1; //Pull up anode via Rl + //Discharge gate + PullProbe(Probes.Rl_3, FLAG_10MS | FLAG_PULLUP); + U1_Rl = ReadU_5ms(Probes.Pin_1); //Get voltage at anode + U1_Rl -= ReadU(Probes.Pin_2); //Substract voltage at cathode + DischargeProbes(); //Try to discharge probes + if (Check.Found == COMP_ERROR) return; //Skip on error + //Vf #2, supporting a possible n-channel MOSFET + //We assume: probe-1 = A / probe2 = C, set probes: Gnd -- probe-2 / probe-1 -- Rl or Rh -- Vcc + SetADCLow(); + ADC_DDR = Probes.ADC_2; //Pull down cathode directly + U2_Zero = ReadU(Probes.Pin_1); //Get voltage at anode + //Measure voltage across DUT (Vf) with Rh + R_DDR = Probes.Rh_1; //Enable Rh for probe-1 + R_PORT = Probes.Rh_1; //Pull up anode via Rh + //Discharge gate + PullProbe(Probes.Rl_3, FLAG_10MS | FLAG_PULLDOWN); + U2_Rh = ReadU_5ms(Probes.Pin_1); //Get voltage at anode, neglect voltage at cathode + //Measure voltage across DUT (Vf) with Rl + R_DDR = Probes.Rl_1; //Enable Rl for probe-1 + R_PORT = Probes.Rl_1; //Pull up anode via Rl + //Discharge gate + PullProbe(Probes.Rl_3, FLAG_10MS | FLAG_PULLDOWN); + U2_Rl = ReadU_5ms(Probes.Pin_1); //Get voltage at anode + U2_Rl -= ReadU(Probes.Pin_2); //Substract voltage at cathode + R_PORT = 0; //Stop pulling up + //Process results, choose between measurements of p and n channel setup + if (U1_Rl > U2_Rl) //The higher voltage wins + { + U2_Rl = U1_Rl; + U2_Rh = U1_Rh; + U2_Zero = U1_Zero; + } + /* + U_Rh < 10mV for + - resistor < 1k Ohm + - very large cap + */ + if (U2_Rh <= 10) return; //Small resistor or very large cap + /* + U_Zero <= 2 for resistor or diode + U_Zero > 2 for cap or diode + if U_Zero > 2 then U_Rh - U_Zero < 100 for cap + + Hints: + If U_Zero > 10 and U_Rh is about U_Zero it's a large cap. + As larger the cap as lower U_Rl (charging time 15ms). + */ + U1_Zero = U2_Rh - U2_Zero; //Voltage difference + if ((U2_Zero > 2) && (U1_Zero < 100)) return; //Capacitor + /* + The voltages for a resistor will follow the equation: + k = Rl + Ri_H + Ri_L + Ul = k U_Rh / (1 + (k - 1) U_Rh / 5V) + Allow a tolerance of 3%. + For U_Rh > 40mV we don't need to check for a resistor. + + Hint: + Actually we could change the thresshold above from 10 t0 40 and + remove this test completely. The lowest U_Rh measured for a diode was + 56mV for a AA118. + */ + if (U2_Rh < 40) //Resistor (< 3k) + { + uint32_t a, b; + //Calculate expected U_Rl based on measured U_Rh in mV, k factor + b = (R_HIGH * 10) / ((R_LOW * 10) + Config.RiH + Config.RiL); + a = b - 1; //k - 1 + a /= 5; // / 5V + a *= U2_Rh; // *U_Rh + a += 1000; // +1 (1000 for mV) + b *= 1000; //For mV + b *= U2_Rh; // *U_Rh + b /= a; //U_Rl in mV + //Check if calculated U_Rl is within some % of measured value + U1_Zero = (unsigned int)b; + U1_Rl = U1_Zero; + U1_Rh = U1_Zero; + U1_Zero /= 50; //2% + U1_Rh += U1_Zero; //102% + U1_Zero = (unsigned int)b; + U1_Zero /= 33; //3% + U1_Rl -= U1_Zero; //97% (for resistors near 1k) + //Resistor + if ((U2_Rl >= U1_Rl) && (U2_Rl <= U1_Rh)) return; + } + //If U_Rl (Vf) is between 0.15V and 4.64V it's a diode + if ((U2_Rl > 150) && (U2_Rl < 4640)) + { + //If we haven't found any other component yet + if ((Check.Found == COMP_NONE) || + (Check.Found == COMP_RESISTOR)) + { + Check.Found = COMP_DIODE; + } + //Save data + Diode = &Diodes[Check.Diodes]; + Diode->A = Probes.Pin_1; + Diode->C = Probes.Pin_2; + Diode->V_f = U2_Rl; //Vf for high measurement current + Diode->V_f2 = U2_Rh; //Vf for low measurement current + Check.Diodes++; + } +} + +//Verify MOSFET by checking the body diode +void VerifyMOSFET(void) +{ + byte Flag = 0; + byte n = 0; + byte Anode; + byte Cathode; + Diode_Type *Diode; //Pointer to diode + //Set expected body diode + if (Check.Type & TYPE_N_CHANNEL) //n-channel + { + Anode = FET.S; + Cathode = FET.D; + } + else //p-channel + { + Anode = FET.D; + Cathode = FET.S; + } + Diode = &Diodes[0]; //First diode + //Check all known diodes for reversed one + while (n < Check.Diodes) + { + if ((Diode->A == Cathode) && (Diode->C == Anode)) + { + Flag = 1; //Signal match + n = 10; //End loop + } + n++; //Next diode + Diode++; + } + if (Flag == 1) //Found reversed diode + { + //This can't be a MOSFET, so let's reset + Check.Found = COMP_NONE; + Check.Type = 0; + Check.Done = 0; + } +} + +//Check for BJT or enhancement-mode MOSFET +void CheckBJTorEnhModeMOSFET(byte BJT_Type, unsigned int U_Rl) +{ + byte FET_Type; //MOSFET type + unsigned int U_R_c; //Voltage across collector resistor + unsigned int U_R_b; //Voltage across base resistor + unsigned int BJT_Level; //Voltage threshold for BJT + unsigned int FET_Level; //Voltage threshold for FET + unsigned int I_CE0; //Leakage current + unsigned long hFE_C; //hFE (common collector) + unsigned long hFE_E; //hFE (common emitter) + //Init, set probes and measure + if (BJT_Type == TYPE_NPN) //NPN / n-channel + { + BJT_Level = 2557; //Voltage across base resistor (5.44�A) + FET_Level = 3400; //Voltage across drain resistor (4.8mA) + FET_Type = TYPE_N_CHANNEL; + /* + We assume + - BJT: probe-1 = C / probe-2 = E / probe-3 = B + - FET: probe-1 = D / probe-2 = S / probe-3 = G + probes already set to: Gnd -- probe-2 / probe-1 -- Rl -- Vcc + drive base/gate via Rh instead of Rl + */ + R_DDR = Probes.Rl_1 | Probes.Rh_3; //Enable Rl for probe-1 & Rh for probe-3 + R_PORT = Probes.Rl_1 | Probes.Rh_3; //Pull up collector via Rl and base via Rh + delay(50); //Wait to skip gate charging of a FET + U_R_c = UREF_VCC - ReadU(Probes.Pin_1); //U_R_c = Vcc - U_c + U_R_b = UREF_VCC - ReadU(Probes.Pin_3); //U_R_b = Vcc - U_b + } + else //PNP / p-channel + { + BJT_Level = 977; //Voltage across base resistor (2.1�A) + FET_Level = 2000; //Voltage across drain resistor (2.8mA) + FET_Type = TYPE_P_CHANNEL; + /* + We assume + - BJT: probe-1 = E / probe-2 = C / probe-3 = B + - FET: probe-1 = S / probe-2 = D / probe-3 = G + probes already set to: Gnd -- Rl - probe-2 / probe-1 -- Vcc + drive base/gate via Rh instead of Rl + */ + R_DDR = Probes.Rl_2 | Probes.Rh_3; //Pull down base via Rh + U_R_c = ReadU_5ms(Probes.Pin_2); //U_R_c = U_c + U_R_b = ReadU(Probes.Pin_3); //U_R_b = U_b + } + //Distinguish BJT from depletion-mode MOSFET + if (U_R_b > BJT_Level) //U_R_b exceeds minimum level of BJT + { + /* + A voltage drop across the base resistor Rh means that a current + is flowing constantly. So this can't be a FET. + + Problem: + A reversed collector and emitter also passes the tests, but with + a low hFE. So we need to run two tests to be sure and select the + test results with the higher hFE. + */ + //Two test runs needed at maximium to get right hFE & pins + if (Check.Found == COMP_BJT) Check.Done = 1; + Check.Found = COMP_BJT; + Check.Type = BJT_Type; + //Leakage current + I_CE0 = GetLeakageCurrent(); //Get leakage current (in �A) + /* + Calculate hFE via voltages and known resistors: + - hFE = I_c / I_b + = (U_R_c / R_c) / (U_R_b / R_b) + = (U_R_c * R_b) / (U_R_b * R_c) + - consider leakage current: + I_c = I_c_conducting - I_c_leak + = (U_R_c_conducting / R_c) - (U_R_c_leak / R_c) + = (U_R_c_conducting - U_R_c_leak) / R_c + -> U_R_c = U_R_c_conducting - U_R_c_leak + = U_R_c_conducting - U_Rl + */ + if (U_R_c > U_Rl) U_R_c -= U_Rl; // - U_Rl (leakage) + hFE_E = U_R_c * R_HIGH; //U_R_c * R_b + hFE_E /= U_R_b; // / U_R_b + hFE_E *= 10; //Upscale to 0.1 + if (BJT_Type == TYPE_NPN) //NPN + hFE_E /= (R_LOW * 10) + Config.RiH; // / R_c in 0.1 Ohm + else //PNP + hFE_E /= (R_LOW * 10) + Config.RiL; // / R_c in 0.1 Ohm + //Get hFE for common collector circuit + hFE_C = Get_hFE_C(BJT_Type); + //Keep largest hFE + if (hFE_C > hFE_E) hFE_E = hFE_C; + //Only update data if hFE is larger than old one + if (hFE_E > BJT.hFE) + { + //Save data + BJT.hFE = hFE_E; + BJT.I_CE0 = I_CE0; + BJT.B = Probes.Pin_3; + if (BJT_Type == TYPE_NPN) //NPN + { + BJT.C = Probes.Pin_1; + BJT.E = Probes.Pin_2; + } + else //PNP + { + BJT.C = Probes.Pin_2; + BJT.E = Probes.Pin_1; + } + } +#if 0 + /* + Check for proper emitter and collector: + - I_c is much lower for reversed emitter and collector. + - So we reverse the probes and measure I_c (= U_R_c / R_c) again. + - Since R_c is constant we may simply compare U_R_c. + + This is an alternative solution instead of running the check two times. + */ + SetADCHiz(); //Set ADC port to HiZ mode + R_DDR = 0; //Set resistor port to HiZ mode + if (BJT_Type == TYPE_NPN) //NPN + { + //We assume: probe-1 = E / probe-2 = C / probe-3 = B, set probes: Gnd -- probe-1 / probe-2 -- Rl -- Vcc + SetADCLow(); + ADC_DDR = Probes.ADC_1; //Pull-down emitter directly + R_PORT = Probes.Rl_2 | Probes.Rh_3; //Pull-up base via Rh + R_DDR = Probes.Rl_2 | Probes.Rh_3; //Enable probe resistors + U_R_b = UREF_VCC - ReadU_5ms(Probes.Pin_2);//U_R_c = Vcc - U_c + } + else //PNP + { + //We assume: probe-1 = C / probe-2 = E / probe-3 = B, set probes: Gnd -- Rl - probe-1 / probe-2 -- Vcc + R_PORT = 0; + R_DDR = Probes.Rl_1 | Probes.Rh_3; //Pull down base via Rh + ADC_DDR = Probes.ADC_2; + ADC_PORT = Probes.ADC_2; //Pull-up emitter directly + U_R_b = ReadU_5ms(Probes.Pin_1); //U_R_c = U_c + } + //If not reversed, BJT is identified + if (U_R_c > U_R_b) //I_c > I_c_reversed + { + //Move other stuff here: save data & Comp= + Check.Done = 1; + } +#endif + } + else if ((U_Rl < 97) && (U_R_c > FET_Level)) //No BJT + { + /* + If there's + - just a small leakage current (< 0.1mA) in non-conducting mode + - a large U_R_c (= large current) when conducting + - a low U_R_b (= very low gate current) + we got a FET or an IGBT. + The drain source channel of a MOSFET is modeled as a resistor + while an IGBT acts more like a diode. So we measure the voltage drop + across the conducting path. A MOSFET got a low voltage drop based on + it's R_DS_on and the current. An IGBT got a much higher voltage drop. + */ + I_CE0= ReadU(Probes.Pin_1) - ReadU(Probes.Pin_2); + if (I_CE0 < 250) //MOSFET + { + Check.Found = COMP_FET; + Check.Type = FET_Type | TYPE_ENHANCEMENT | TYPE_MOSFET; + } + else //IGBT + { + Check.Found = COMP_IGBT; + Check.Type = FET_Type | TYPE_ENHANCEMENT; + } + Check.Done = 1; //Transistor found + //Measure gate threshold voltage + GetGateThreshold(FET_Type); + //Save data + FET.G = Probes.Pin_3; + if (FET_Type == TYPE_N_CHANNEL) //n-channel + { + FET.D = Probes.Pin_1; + FET.S = Probes.Pin_2; + } + else //p-channel + { + FET.D = Probes.Pin_2; + FET.S = Probes.Pin_1; + } + } +} + +//Check for a depletion mode FET (self conducting) +void CheckDepletionModeFET(unsigned int U_Rl_L) +{ + unsigned int U_1; //Voltage #1 + unsigned int U_2; //Voltage #2 + /* + Required probe setup (by calling function): + - Gnd -- Rl -- probe-2 / probe-1 -- Vcc + + Check if we got a n-channel JFET or depletion-mode MOSFET + - JFETs are depletion-mode only + */ + if (Check.Done == 0) //No transistor found yet + { + //We assume: probe-1 = D / probe-2 = S / probe-3 = G, probes already set to: Gnd -- Rl -- probe-2 / probe-1 -- Vcc + R_DDR = Probes.Rl_2 | Probes.Rh_3; //Pull down gate via Rh + U_1 = ReadU_20ms(Probes.Pin_2); //Voltage at source + R_PORT = Probes.Rh_3; //Pull up gate via Rh + U_2 = ReadU_20ms(Probes.Pin_2); //Voltage at source + /* + If the source voltage is higher when the gate is driven by a positive + voltage vs. connected to ground we got a depletion-mode n-channel FET. + The source resistor creates a voltage offset based on the current + causing V_GS to become negative with the gate pulled down. + */ + if (U_2 > (U_1 + 488)) + { + //Compare gate voltages to distinguish JFET from MOSFET + //Set probes: Gnd -- probe-2 / probe-1 -- Rl -- Vcc + SetADCLow(); //Set ADC port to low + ADC_DDR = Probes.ADC_2; //Pull down source directly + R_DDR = Probes.Rl_1 | Probes.Rh_3; //Enable Rl for probe-1 & Rh for probe-3 + R_PORT = Probes.Rl_1 | Probes.Rh_3; //Pull up drain via Rl / pull up gate via Rh + U_2 = ReadU_20ms(Probes.Pin_3); //Get voltage at gate + if (U_2 > 3911) //MOSFET + { + //n channel depletion-mode MOSFET + Check.Type = TYPE_N_CHANNEL | TYPE_DEPLETION | TYPE_MOSFET; + } + else //JFET + { + //n channel JFET (depletion-mode only) + Check.Type = TYPE_N_CHANNEL | TYPE_JFET; + } + //Save data + Check.Found = COMP_FET; + Check.Done = 1; + FET.G = Probes.Pin_3; + FET.D = Probes.Pin_1; + FET.S = Probes.Pin_2; + } + } + //Check if we got a p-channel JFET or depletion-mode MOSFET - JFETs are depletion-mode only + if (Check.Done == 0) //No transistor found yet + { + //We assume: probe-1 = S / probe-2 = D / probe-3 = G, set probes: Gnd -- probe-2 / probe-1 -- Rl -- Vcc + SetADCLow(); //Set ADC port to Gnd + ADC_DDR = Probes.ADC_2; //Pull down drain directly + R_DDR = Probes.Rl_1 | Probes.Rh_3; //Enable Rl for probe-1 & Rh for probe-3 + R_PORT = Probes.Rl_1 | Probes.Rh_3; //Pull up source via Rl / pull up gate via Rh + U_1 = ReadU_20ms(Probes.Pin_1); //Get voltage at source + R_PORT = Probes.Rl_1; //Pull down gate via Rh + U_2 = ReadU_20ms(Probes.Pin_1); //Get voltage at source + /* + If the source voltage is higher when the gate is driven by a positive + voltage vs. connected to ground we got a depletion-mode p-channel FET. + The source resistor creates a voltage offset based on the current + causing V_GS to become positive with the gate pulled up. + */ + if (U_1 > (U_2 + 488)) + { + //Compare gate voltages to distinguish JFET from MOSFET + //Set probes: probe-2 = HiZ / probe-1 -- Vcc + ADC_PORT = Probes.ADC_1; //Pull up source directly + ADC_DDR = Probes.ADC_1; //Enable pull up for source + //Gate is still pulled down via Rh + U_2 = ReadU_20ms(Probes.Pin_3); //Get voltage at gate + if (U_2 < 977) //MOSFET + { + //p channel depletion-mode MOSFET + Check.Type = TYPE_P_CHANNEL | TYPE_DEPLETION | TYPE_MOSFET; + } + else //JFET + { + //p channel JFET (depletion-mode only) + Check.Type = TYPE_P_CHANNEL | TYPE_DEPLETION | TYPE_JFET; + } + //Save data + Check.Found = COMP_FET; + Check.Done = 1; + FET.G = Probes.Pin_3; + FET.D = Probes.Pin_2; + FET.S = Probes.Pin_1; + } + } +} + +//Special devices +byte CheckThyristorTriac(void) +{ + byte Flag = 0; //Return value + unsigned int U_1; //Voltage #1 + unsigned int U_2; //Voltage #2 + /* + Check for a thyristor (SCR) or triac + - A thyristor conducts also after the gate is discharged as long + as the load current stays alive and doesn't reverse polarity. + - A triac is a pair of anti-parallel thyristors. + - It's possible that the tester doesn't deliver enough current, so + it can't detect all types. + + probes need to be set already to: + Gnd -- probe-2 / probe-1 -- Rl -- Vcc + */ + //We assume: probe-1 = A / probe-2 = C / probe-3 = G, discharge gate + PullProbe(Probes.Rl_3, FLAG_10MS | FLAG_PULLDOWN); + U_1 = ReadU_5ms(Probes.Pin_1); //Get voltage at anode + R_PORT = 0; //Pull down anode + delay(5); + R_PORT = Probes.Rl_1; //And pull up anode again + U_2 = ReadU_5ms(Probes.Pin_1); //Get voltage at anode (below Rl) + //Voltages match behaviour of thyristor or triac + if ((U_1 < 1600) && (U_2 > 4400)) + { + Check.Found = COMP_THYRISTOR; //If not detected as a triac below + Check.Done = 1; + /* + Check if we got a triac + - reverse A and C (A = MT2 / C = MT1) + - check if behaviour is the same + */ + //We assume: probe-1 = MT2 / probe-2 = MT1 / probe-3 = G + R_DDR = 0; //Disable all probe resistors + R_PORT = 0; + ADC_PORT = Probes.ADC_2; //Pull up MT1 directly + delay(5); + R_DDR = Probes.Rl_1; //Pull down MT2 via Rl + //Probe-3/gate is in HiZ mode, triac shouldn't conduct without a triggered gate + U_1 = ReadU_5ms(Probes.Pin_1); //Get voltage at MT2 + //Voltage of MT2 is low (no current) + if (U_1 <= 244) + { + //Trigger gate for reverse direction + R_DDR = Probes.Rl_1 | Probes.Rl_3; //And pull down gate via Rl + U_1 = ReadU_5ms(Probes.Pin_3); //Get voltage at gate + U_2 = ReadU(Probes.Pin_1); //Get voltage at MT2 + //Voltage at gate is ok and voltage at MT2 is high (current = triac is conducting) + if ((U_1 >= 977) && (U_2 >= 733)) + { + //Check if triac still conducts without triggered gate + R_DDR = Probes.Rl_1; //Set probe3 to HiZ mode + U_1 = ReadU_5ms(Probes.Pin_1); //Get voltage at MT2 + //Voltage at MT2 is still high (current = triac is conducting) + if (U_1 >= 733) + { + //Check if triac stops conducting when load current drops to zero + R_PORT = Probes.Rl_1; //Pull up MT2 via Rl + delay(5); + R_PORT = 0; //And pull down MT2 via Rl + U_1 = ReadU_5ms(Probes.Pin_1); //Get voltage at MT2 + //Voltage at MT2 is low (no current = triac is not conducting) + if (U_1 <= 244) + { + //Now we are pretty sure that the DUT is a triac + Check.Found = COMP_TRIAC; + } + } + } + } + //Save data (we misuse BJT) + BJT.B = Probes.Pin_3; + BJT.C = Probes.Pin_1; + BJT.E = Probes.Pin_2; + Flag = 1; //Signal that we found a component + } + return Flag; +} + +//Measure a resistor with low resistance (< 100 Ohms) +unsigned int SmallResistor(byte ZeroFlag) +{ + unsigned int R = 0; //Return value + byte Probe; //Probe ID + byte Mode; //Measurement mode + byte Counter; //Sample counter + unsigned long Value; //ADC sample value + unsigned long Value1 = 0; //U_Rl temp. value + unsigned long Value2 = 0; //U_R_i_L temp. value + DischargeProbes(); //Try to discharge probes + if (Check.Found == COMP_ERROR) return R; //Skip on error + /* + Measurement method: + - use Rl as current shunt + - create a pulse and measure voltage at high side of DUT for 1000 times + - repeat that for the low side of the DUT + */ + //Pulse on: GND -- probe 2 / probe 1 -- Rl -- 5V, pulse off: GND -- probe 2 / probe 1 -- Rl -- GND + SetADCLow(); //Set ADC port to low + ADC_DDR = Probes.ADC_2; //Pull-down probe 2 directly + R_PORT = 0; //Low by default + R_DDR = Probes.Rl_1; //Enable resistor + #define MODE_HIGH 0b00000001 + #define MODE_LOW 0b00000010 + //Measurement loop + Mode = MODE_HIGH; + while (Mode > 0) + { + //Setup measurement + if (Mode & MODE_HIGH) Probe = Probes.Pin_1; + else Probe = Probes.Pin_2; + wdt_reset(); //Reset watchdog + Counter = 0; //Reset loop counter + Value = 0; //Reset sample value + //Set ADC to use bandgap reference and run a dummy conversion + Probe |= (1 << REFS0) | (1 << REFS1); + ADMUX = Probe; //Set input channel and U reference + waitus(100); //Time for voltage stabilization + ADCSRA |= (1 << ADSC); //Start conversion + while (ADCSRA & (1 << ADSC)); //Wait until conversion is done + //Measurement loop (about 1ms per cycle) + while (Counter < 100) + { + //Create short pulse + ADC_DDR = Probes.ADC_2; //Pull-down probe-2 directly + R_PORT = Probes.Rl_1; + //Start ADC conversion, ADC performs S&H after 1.5 ADC cycles (12�s) + ADCSRA |= (1 << ADSC); //Start conversion + //Wait 20�s to allow the ADC to do it's job + waitus(20); + //Stop pulse + R_PORT = 0; + ADC_DDR = Probes.ADC_2 | Probes.ADC_1; + //Get ADC reading (about 100�s) + while (ADCSRA & (1 << ADSC)); //Wait until conversion is done + Value += ADCW; //Add ADC reading + //Wait + waitus(900); + Counter++; //Next round + } + //Convert ADC reading to voltage + Value *= Config.U_Bandgap; + Value /= 1024; // / 1024 for 10bit ADC + Value /= 10; //De-sample to 0.1mV + //Loop control + if (Mode & MODE_HIGH) //Probe #1 / Rl + { + Mode = MODE_LOW; //Switch to low side + Value1 = Value; //Save measured value + } + else //Probe #2 / R_i_L + { + Mode = 0; //End loop + Value2 = Value; //Save measured value + } + } + //Process measurement + if (Value1 > Value2) //Sanity check + { + //I = U/R = (5V - U_Rl)/(Rl + R_i_H) + Value = 10UL * UREF_VCC; //in 0.1 mV + Value -= Value1; + Value *= 1000; //Scale to �A + Value /= ((R_LOW * 10) + Config.RiH); //in 0.1 Ohms + Value1 -= Value2; //in 0.1 mV + Value1 *= 10000; //Scale to 0.01 �V + //R = U/I (including R of probe leads) + Value1 /= Value; //in 0.01 Ohms + R = (unsigned int)Value1; //Copy result + if (ZeroFlag == 1) //Auto-zero + { + if (R > Config.RZero) R -= Config.RZero; + else R = 0; + } + } +#undef MODE_LOW +#undef MODE_HIGH + //Update Uref flag for next ADC run + Config.RefFlag = (1 << REFS1); //Set REFS1 bit flag + return R; +} + +//Check for resistor +void CheckResistor(void) +{ + Resistor_Type *Resistor; //Pointer to resistor + unsigned long Value1; //Resistance of measurement #1 + unsigned long Value2; //Resistance of measurement #2 + unsigned long Value; //Resistance value + unsigned long Temp; //Temp. value + signed char Scale; //Resistance scale + signed char Scale2; //Resistance scale + byte n; //Counter + //Voltages + unsigned int U_Rl_H; //Voltage #1 + unsigned int U_Ri_L; //Voltage #2 + unsigned int U_Rl_L; //Voltage #3 + unsigned int U_Ri_H; //Voltage #4 + unsigned int U_Rh_H; //Voltage #5 + unsigned int U_Rh_L; //Voltage #6 + wdt_reset(); //Reset watchdog + /* + Resistor measurement + - Set up a voltage divider with well known probe resistors and + measure the voltage at the DUT. + - For low resistance consider the internal resistors of the �C + for pulling up/down. + - Calculate resistance via the total current and the voltage + at the DUT. + - We could also use the voltage divider rule: + (Ra / Rb) = (Ua / Ub) -> Ra = Rb * (Ua / Ub) + + check if we got a resistor + - A resistor has the same resistance in both directions. + - We measure both directions with both probe resistors. + */ + //We assume: resistor between probe-1 and probe-2, set probes: Gnd -- probe-2 / probe-1 -- Rl -- Vcc + SetADCLow(); //Set ADC port low low + ADC_DDR = Probes.ADC_2; //Pull down probe-2 directly + R_DDR = Probes.Rl_1; //Enable Rl for probe-1 + R_PORT = Probes.Rl_1; //Pull up probe-1 via Rl + U_Ri_L = ReadU_5ms(Probes.Pin_2); //Get voltage at internal R of �C + U_Rl_H = ReadU(Probes.Pin_1); //Get voltage at Rl pulled up + /* + Check for a capacitor + - A capacitor would need some time to discharge. + - So we pull down probe-1 via Rh and measure the voltage. + - The voltage will drop immediately for a resistor. + */ + //Set probes: Gnd -- probe-2 / Gnd -- Rh -- probe-1 + R_PORT = 0; //Set resistor port low + R_DDR = Probes.Rh_1; //Pull down probe-1 via Rh + U_Rh_L = ReadU_5ms(Probes.Pin_1); //Get voltage at probe 1 + //We got a resistor if the voltage is near Gnd + if (U_Rh_L <= 20) + { + //Set probes: Gnd -- probe-2 / probe-1 -- Rh -- Vcc + R_PORT = Probes.Rh_1; //Pull up probe-1 via Rh + U_Rh_H = ReadU_5ms(Probes.Pin_1); //Get voltage at Rh pulled up + //Set probes: Gnd -- Rl -- probe-2 / probe-1 -- Vcc + ADC_DDR = Probes.ADC_1; //Set probe-1 to output + ADC_PORT = Probes.ADC_1; //Pull up probe-1 directly + R_PORT = 0; //Set resistor port to low + R_DDR = Probes.Rl_2; //Pull down probe-2 via Rl + U_Ri_H = ReadU_5ms(Probes.Pin_1); //Get voltage at internal R of �C + U_Rl_L = ReadU(Probes.Pin_2); //Get voltage at Rl pulled down + //Set probes: Gnd -- Rh -- probe-2 / probe-1 -- Vcc + R_DDR = Probes.Rh_2; //Pull down probe-2 via Rh + U_Rh_L = ReadU_5ms(Probes.Pin_2); //Get voltage at Rh pulled down + //If voltage breakdown is sufficient + if ((U_Rl_H >= 4400) || (U_Rh_H <= 97)) //R >= 5.1k / R < 9.3k + { + if (U_Rh_H < 4972) //R < 83.4M & prevent division by zero + { + //Voltage breaks down with low test current and it is not nearly shorted => resistor + Value = 0; //Reset value of resistor + if (U_Rl_L < 169) //R > 19.5k + { + //Use measurements done with Rh, resistor is less 60MOhm + if (U_Rh_L >= 38) //R < 61.4M & prevent division by zero + { + /* + Rh pulled up (above DUT): + I = U_Rh / Rh = (Vcc - U_Rh_H) / Rh + R = U_R / I = U_Rh_H / ((Vcc - U_Rh_H) / Rh) + = Rh * U_Rh_H / (Vcc - U_Rh_H) + + Or via voltage divider: + R = Rh * (U_dut / U_Rh) + = Rh * (U_Rh_H / (Vcc - U_Rh_H)) + */ + Value1 = R_HIGH * U_Rh_H; + Value1 /= (UREF_VCC - U_Rh_H); + /* + Rh pulled down (below DUT): + I = U_Rh_L / Rh + R = U_R / I = (Vcc - U_Rh_L) / (U_Rh_L / Rh) + = Rh * (Vcc - U_Rh_L) / U_Rh_L + + Or via voltage divider: + R = Rh * (U_R / U_Rh) + = Rh * ((Vcc - U_Rh_L) / U_Rh_L) + */ + Value2 = R_HIGH * (UREF_VCC - U_Rh_L); + Value2 /= U_Rh_L; + /* + Calculate weighted average of both measurements + - Voltages below the bandgap reference got a higher resolution + (1.1mV instead of 4.9mV). + */ + if (U_Rh_H < 990) //Below bandgap reference + { + //Weighted average for U_Rh_H mig + Value = (Value1 * 0); //era4 py2ohh + Value += Value2; + Value /= 1; //era5 py2ohh + } + else if (U_Rh_L < 990) //Below bandgap reference + { + //Weighted average for U_Rh_L + Value = (Value2 * 0); //era4 py2ohh + Value += Value1; + Value /= 1; //era5 py2ohh + } + else //Higher than bandgap reference + { + //Classic average + Value = (Value1 + Value2) / 2; + } + Value += RH_OFFSET; //Add offset value for Rh + Value *= 10; //Upscale to 0.1 Ohms + } + } + else //U_Rl_L: R <= 19.5k + { + //Use measurements done with Rl + //Voltages below and above DUT match voltage divider + //Voltage below DUT can't be higher than above DUT + if ((U_Rl_H >= U_Ri_L) && (U_Ri_H >= U_Rl_L)) + { + /* + Rl pulled up (above DUT): + I = U_Rl_RiH / (Rl + RiH) = (Vcc - U_Rl_H) / (Rl + RiH) + R = U_Dut / I + = (U_Rl_H - U_Ri_L) / ((Vcc - U_Rl_H) / (Rl + RiH)) + = (Rl + RiH) * (U_Rl_H - U_Ri_L) / (Vcc - U_Rl_H) + + Or via voltage divider: + R = (Rl + RiH) * (U_R_RiL / U_Rl_RiH) - RiL + = (Rl + RiH) * (U_R_RiL / (Vcc - U_dut_RiL)) - RiL + */ + //Prevent division by zero + if (U_Rl_H == UREF_VCC) U_Rl_H = UREF_VCC - 1; + Value1 = (R_LOW * 10) + Config.RiH; //Rl + RiH in 0.1 Ohm + Value1 *= (U_Rl_H - U_Ri_L); + Value1 /= (UREF_VCC - U_Rl_H); + /* + Rl pulled down (below DUT): + I = U_Rl_RiL / (Rl + RiL) + R = U_R / I + = (U_Ri_H - U_Rl_L) / (U_Rl_RiL / (Rl + RiL)) + = (Rl + RiL) * (U_Ri_H - U_Rl_L) / U_Rl_RiL + + Or via voltage divider: + R = (Rl + RiL) * (U_R_RiH / U_Rl_RiL) - RiH + = (Rl + RiL) * ((Vcc - U_Rl_RiL) / U_Rl_RiL) - RiH + */ + Value2 = (R_LOW * 10) + Config.RiL; //Rl + RiL in 0.1 Ohms + Value2 *= (U_Ri_H - U_Rl_L); + Value2 /= U_Rl_L; + /* + Calculate weighted average of both measurements + - Voltages below the bandgap reference got a higher resolution + (1.1mV instead of 4.9mV). + */ + if (U_Rl_H < 990) //Below bandgap reference + { + //Weighted average for U_Rh_H + Value = (Value1 * 0); //era4 py2ohh + Value += Value2; + Value /= 1; //era5 py2ohh + } + else if (U_Rl_L < 990) //Below bandgap reference + { + //Weighted average for U_Rh_L + Value = (Value2 * 0); //era 4 py2ohh + Value += Value1; + Value /= 1; //era 5 py2ohh + } + else //Higher than bandgap reference + { + //Classic average + Value = (Value1 + Value2) / 2; + } + } + else //May happen for very low resistances + { + if (U_Rl_L > 4750) Value = 1; //U_Rl_L: R < 15 Ohms + //This will trigger the low resistance measurement below + } + } + //Process results of the resistance measurement + if (Value > 0) //Valid resistor + { + Scale = -1; //0.1 Ohm by default + //Meassure small resistor <10 Ohm with special method + if (Value < 100UL) + { + //Run low resistance measurement + Value2 = (unsigned long)SmallResistor(1); + Scale2 = -2; //0.01 Ohm + //Check for valid result + Value1 = Value * 2; //Allow 100% tolerance + Value1 *= 10; //Re-scale to 0.01 Ohms + if (Value1 > Value2) //Got expected value + { + Value = Value2; //Update data + Scale = Scale2; + } + } + //Check for measurement in reversed direction + n = 0; + while (n < Check.Resistors) //Loop through resistors + { + Resistor = &Resistors[n]; //Pointer to element + if ((Resistor->A == Probes.Pin_1) && (Resistor->B == Probes.Pin_2)) + { + //Check if the reversed measurement is within a specific tolerance + //Set lower and upper tolerance limits + //< 2 Ohm + if (CmpValue(Value, Scale, 2, 0) == -1) + { + Temp = Value / 2; //50% + } + else //>= 2 Ohm + { + Temp = Value / 20; //5% + } + Value1 = Value - Temp; //95% or 50% + Value2 = Value + Temp; //105% or 150% + //Special case for very low resistance + //< 0.1 Ohm + if (CmpValue(Value, Scale, 1, -1) == -1) + { + Value1 = 0; //0 + Value2 = Value * 5; //500% + if (Value2 == 0) Value2 = 5; //Special case + } + //Check if value matches given tolerance + if ((CmpValue(Resistor->Value, Resistor->Scale, Value1, Scale) >= 0) && + (CmpValue(Resistor->Value, Resistor->Scale, Value2, Scale) <= 0)) + { + Check.Found = COMP_RESISTOR; + n = 100; //End loop and signal match + } + else //No match + { + n = 200; //End loop and signal mis-match + } + } + else //No match + { + n++; //Next one + } + } + //We got a new resistor + if (n != 100) //Not a known resistor + { + if (Check.Resistors < 3) //Prevent array overflow + { + //Save data + //Unused dataset + Resistor = &Resistors[Check.Resistors]; + Resistor->A = Probes.Pin_2; + Resistor->B = Probes.Pin_1; + Resistor->Value = Value; + Resistor->Scale = Scale; + Check.Resistors++; //Another one found + } + } + } + } + } + } +} + +//Compare two scaled values +signed char CmpValue(unsigned long Value1, signed char Scale1, unsigned long Value2, signed char Scale2) +{ + signed char Flag; //Return value + signed char Len1, Len2; //Length + //Determine virtual length + Len1 = NumberOfDigits(Value1) + Scale1; + Len2 = NumberOfDigits(Value2) + Scale2; + if ((Value1 == 0) || (Value2 == 0)) //Special case + { + Flag = 10; //Perform direct comparison + } + else if (Len1 > Len2) //More digits -> larger + { + Flag = 1; + } + else if (Len1 == Len2) //Same length + { + //Re-scale to longer value + Len1 -= Scale1; + Len2 -= Scale2; + while (Len1 > Len2) //Up-scale Value #2 + { + Value2 *= 10; + Len2++; + } + while (Len2 > Len1) //Up-scale Value #1 + { + Value1 *= 10; + Len1++; + } + Flag = 10; //Perform direct comparison + } + else //Less digits -> smaller + { + Flag = -1; + } + + if (Flag == 10) //Perform direct comparison + { + if (Value1 > Value2) Flag = 1; + else if (Value1 < Value2) Flag = -1; + else Flag = 0; + } + return Flag; +} + +//Get number of digits of a value +byte NumberOfDigits(unsigned long Value) +{ + byte Counter = 1; + while (Value >= 10) + { + Value /= 10; + Counter++; + } + return Counter; +} + +//Measure cap >4.7�F between two probe pins +byte LargeCap(Capacitor_Type *Cap) +{ + byte Flag = 3; //Return value + byte TempByte; //Temp. value + byte Mode; //Measurement mode + signed char Scale; //Capacitance scale + unsigned int TempInt; //Temp. value + unsigned int Pulses; //Number of charging pulses + unsigned int U_Zero; //Voltage before charging + unsigned int U_Cap; //Voltage of DUT + unsigned int U_Drop = 0; //Voltage drop + unsigned long Raw; //Raw capacitance value + unsigned long Value; //Corrected capacitance value + boolean rerun; + //Setup mode + Mode = FLAG_10MS | FLAG_PULLUP; //Start with large caps + do { + rerun = false; //One-Time + /* + We charge the DUT with up to 500 pulses each 10ms long until the + DUT reaches 300mV. The charging is done via Rl. This method is + suitable for large capacitances from 47uF up to 100mF. If we find a + lower capacitance we'll switch to 1ms charging pulses and try again + (4.7�F up to 47�F). + + Problem: + ReadADC() needs about 5ms (44 runs). We charge the DUT for 10ms and + measure for 5ms. During that time the voltage will drop due to + resistive losses of the DUT and the measurement itself. So the DUT + seems to need more time to reach 300mV causing a higher capacitance + be calculated. + + Remark: + The Analog Input Resistance of the ADC is 100MOhm typically. + */ + //Prepare probes + DischargeProbes(); //Try to discharge probes + if (Check.Found == COMP_ERROR) return 0; //Skip on error + //Setup probes: Gnd -- probe 1 / probe 2 -- Rl -- Vcc + SetADCLow(); //Set ADC port to low + ADC_DDR = Probes.ADC_2; //Pull-down probe 2 directly + R_PORT = 0; //Set resistor port to low + R_DDR = 0; //Set resistor port to HiZ + U_Zero = ReadU(Probes.Pin_1); //Get zero voltage (noise) + //Charge DUT with up to 500 pulses until it reaches 300mV + Pulses = 0; + TempByte = 1; + while (TempByte) + { + Pulses++; + PullProbe(Probes.Rl_1, Mode); //Charging pulse + U_Cap = ReadU(Probes.Pin_1); //Get voltage + U_Cap -= U_Zero; //Zero offset + //End loop if charging is too slow + if ((Pulses == 126) && (U_Cap < 75)) TempByte = 0; + //End loop if 300mV are reached + if (U_Cap >= 300) TempByte = 0; + //End loop if maximum pulses are reached + if (Pulses == 500) TempByte = 0; + wdt_reset(); //Reset watchdog + } + //If 300mV are not reached DUT isn't a cap or much too large (>100mF) we can ignore that for mid-sized caps + if (U_Cap < 300) + { + Flag = 1; + } + //If 1300mV are reached with one pulse we got a small cap + if ((Pulses == 1) && (U_Cap > 1300)) + { + if (Mode & FLAG_10MS) //<47�F + { + Mode = FLAG_1MS | FLAG_PULLUP; //Set mode (1ms charging pulses) + rerun = true; //And re-run + } + else //<4.7�F + { + Flag = 2; + } + } + } while (rerun); + /* + Check if DUT sustains the charge and get the voltage drop + - run the same time as before minus the 10ms charging time + - this gives us the approximation of the self-discharging + */ + if (Flag == 3) + { + //Check self-discharging + TempInt = Pulses; + while (TempInt > 0) + { + TempInt--; //Descrease timeout + U_Drop = ReadU(Probes.Pin_1); //Get voltage + U_Drop -= U_Zero; //Zero offset + wdt_reset(); //Reset watchdog + } + //Calculate voltage drop + if (U_Cap > U_Drop) U_Drop = U_Cap - U_Drop; + else U_Drop = 0; + //If voltage drop is too large consider DUT not to be a cap + if (U_Drop > 100) Flag = 0; + } + /* + Calculate capacitance + - use factor from pre-calculated LargeCap_table + - ignore Config.CapZero since it's in the pF range + */ + if (Flag == 3) + { + Scale = -9; //Factor is scaled to nF + //Get interpolated factor from table + Raw = GetFactor(U_Cap + U_Drop, TABLE_LARGE_CAP); + Raw *= Pulses; //C = pulses * factor + if (Mode & FLAG_10MS) Raw *= 10; // *10 for 10ms charging pulses + if (Raw > UINT32_MAX / 1000) //Scale down if C >4.3mF + { + Raw /= 1000; //Scale down by 10^3 + Scale += 3; //Add 3 to the exponent + } + Value = Raw; //Copy raw value + //It seems that we got a systematic error + Value *= 100; + if (Mode & FLAG_10MS) Value /= 109; //-9% for large cap + else Value /= 104; //-4% for mid cap + //Copy data + Cap->A = Probes.Pin_2; //Pull-down probe pin + Cap->B = Probes.Pin_1; //Pull-up probe pin + Cap->Scale = Scale; //-9 or -6 + Cap->Raw = Raw; + Cap->Value = Value; //Max. 4.3*10^6nF or 100*10^3�F + } + return Flag; +} + +//Measure cap <4.7�F between two probe pins +byte SmallCap(Capacitor_Type *Cap) +{ + byte Flag = 3; //Return value + byte TempByte; //Temp. value + signed char Scale; //Capacitance scale + unsigned int Ticks; //Timer counter + unsigned int Ticks2; //Timer overflow counter + unsigned int U_c; //Voltage of capacitor + unsigned long Raw; //Raw capacitance value + unsigned long Value; //Corrected capacitance value + /* + Measurement method used for small caps < 50uF: + We need a much better resolution for the time measurement. Therefore we + use the �Cs internal 16-bit counter and analog comparator. The counter + inceases until the comparator detects that the voltage of the DUT is as + high as the internal bandgap reference. To support the higher time + resolution we use the Rh probe resistor for charging. + + Remark: + The analog comparator has an Input Leakage Current of -50nA up to 50nA + at Vcc/2. The Input Offset is <10mV at Vcc/2. + */ + Ticks2 = 0; //Reset timer overflow counter + //Init hardware, prepare probes + DischargeProbes(); //Try to discharge probes + if (Check.Found == COMP_ERROR) return 0; //Skip on error + //Set probes: Gnd -- all probes / Gnd -- Rh -- probe-1 + R_PORT = 0; //Set resistor port to low + //Set ADC probe pins to output mode + ADC_DDR = (1 << TP1) | (1 << TP2) | (1 << TP3); + SetADCLow(); //Set ADC port to low + R_DDR = Probes.Rh_1; //Pull-down probe-1 via Rh + //Setup analog comparator + ADCSRB = (1 << ACME); //Use ADC multiplexer as negative input + ACSR = (1 << ACBG) | (1 << ACIC); //Use bandgap as positive input, trigger timer1 + ADMUX = (1 << REFS0) | Probes.Pin_1; //Switch ADC multiplexer to probe 1 and set AREF to Vcc + ADCSRA = ADC_CLOCK_DIV; //Disable ADC, but keep clock dividers + waitus(200); + //Setup timer + TCCR1A = 0; //Set default mode + TCCR1B = 0; //Set more timer modes + //Timer stopped, falling edge detection, noise canceler disabled + TCNT1 = 0; //Set Counter1 to 0 + //Clear all flags (input capture, compare A & B, overflow + TIFR1 = (1 << ICF1) | (1 << OCF1B) | (1 << OCF1A) | (1 << TOV1); + R_PORT = Probes.Rh_1; //Pull-up probe-1 via Rh + //Enable timer + if (Check.Found == COMP_FET) + { + //Keep all probe pins pulled down but probe-1 + TempByte = (((1 << TP1) | (1 << TP2) | (1 << TP3)) & ~(1 << Probes.Pin_1)); + } + else + { + TempByte = Probes.ADC_2; //Keep just probe-1 pulled down + } + //Start timer by setting clock prescaler (1/1 clock divider) + TCCR1B = (1 << CS10); + ADC_DDR = TempByte; //Start charging DUT + //Timer loop - run until voltage is reached - detect timer overflows + while (1) + { + TempByte = TIFR1; //Get timer1 flags + //End loop if input capture flag is set (= same voltage) + if (TempByte & (1 << ICF1)) break; + //Detect timer overflow by checking the overflow flag + if (TempByte & (1 << TOV1)) + { + //Happens at 65.536ms for 1MHz or 8.192ms for 8MHz + TIFR1 = (1 << TOV1); //Reset flag + wdt_reset(); //Reset watchdog + Ticks2++; //Increase overflow counter + //End loop if charging takes too long (13.1s) + if (Ticks2 == (CPU_FREQ / 5000)) break; + } + } + //Stop counter + TCCR1B = 0; //Stop timer + TIFR1 = (1 << ICF1); //Reset Input Capture flag + Ticks = ICR1; //Get counter value + //Disable charging + R_DDR = 0; //Set resistor port to HiZ mode + //Catch missed timer overflow + if ((TCNT1 > Ticks) && (TempByte & (1 << TOV1))) + { + TIFR1 = (1 << TOV1); //Reset overflow flag + Ticks2++; //Increase overflow counter + } + //Enable ADC again + ADCSRA = (1 << ADEN) | (1 << ADIF) | ADC_CLOCK_DIV; + //Get voltage of DUT + U_c = ReadU(Probes.Pin_1); //Get voltage of cap + //Start discharging DUT + R_PORT = 0; //Pull down probe-2 via Rh + R_DDR = Probes.Rh_1; //Enable Rh for probe-1 again + //Skip measurement if charging took too long + if (Ticks2 >= (CPU_FREQ / 5000)) Flag = 1; + //Calculate capacitance (<50uF) - use factor from pre-calculated SmallCap_table + if (Flag == 3) + { + //Combine both counter values + Raw = (unsigned long)Ticks; //Set lower 16 bits + Raw |= (unsigned long)Ticks2 << 16; //Set upper 16 bits + if (Raw > 2) Raw -= 2; //Subtract processing time overhead + Scale = -12; //Default factor is for pF scale + if (Raw > (UINT32_MAX / 1000)) //Prevent overflow (4.3*10^6) + { + Raw /= 1000; //Scale down by 10^3 + Scale += 3; //Add 3 to the exponent (nF) + } + //Multiply with factor from table + Raw *= GetFactor(Config.U_Bandgap + Config.CompOffset, TABLE_SMALL_CAP); + //Divide by CPU frequency to get the time and multiply with table scale + Raw /= (CPU_FREQ / 10000); + Value = Raw; //Take raw value + //Take care about zero offset if feasable + if (Scale == -12) //pF scale + { + if (Value >= Config.CapZero) //If value is larger than offset + { + Value -= Config.CapZero; //Substract offset + } + else //If value is smaller than offset + { + //We have to prevent a negative value + Value = 0; //Set value to 0 + } + } + //Copy data + Cap->A = Probes.Pin_2; //Pull-down probe pin + Cap->B = Probes.Pin_1; //Pull-up probe pin + Cap->Scale = Scale; //-12 or -9 + Cap->Raw = Raw; + Cap->Value = Value; //Max. 5.1*10^6pF or 125*10^3nF + /* + Self-adjust the voltage offset of the analog comparator and internal + bandgap reference if C is 100nF up to 20�F. The minimum of 100nF + should keep the voltage stable long enough for the measurements. + Changed offsets will be used in next test run. + */ + if (((Scale == -12) && (Value >= 100000)) || + ((Scale == -9) && (Value <= 20000))) + { + signed int Offset; + signed long TempLong; + /* + * We can self-adjust the offset of the internal bandgap reference + by measuring a voltage lower than the bandgap reference, one time + with the bandgap as reference and a second time with Vcc as + reference. The common voltage source is the cap we just measured. + */ + while (ReadU(Probes.Pin_1) > 980) + { + //Keep discharging + } + R_DDR = 0; //Stop discharging + Config.AutoScale = 0; //Disable auto scaling + Ticks = ReadU(Probes.Pin_1); //U_c with Vcc reference + Config.AutoScale = 1; //Enable auto scaling again + Ticks2 = ReadU(Probes.Pin_1); //U_c with bandgap reference + R_DDR = Probes.Rh_1; //Resume discharging + Offset = Ticks - Ticks2; + //Allow some offset caused by the different voltage resolutions (4.88 vs. 1.07) + if ((Offset < -4) || (Offset > 4)) //Offset too large + { + /* + Calculate total offset: + - first get offset per mV: Offset / U_c + - total offset for U_ref: (Offset / U_c) * U_ref + */ + TempLong = Offset; + TempLong *= Config.U_Bandgap; // * U_ref + TempLong /= Ticks2; // / U_c + Config.RefOffset = (signed char)TempLong; + } + /* + In the cap measurement above the analog comparator compared + the voltages of the cap and the bandgap reference. Since the �C + has an internal voltage drop for the bandgap reference the + �C used actually U_bandgap - U_offset. We get that offset by + comparing the bandgap reference with the voltage of the cap: + U_c = U_bandgap - U_offset -> U_offset = U_c - U_bandgap + */ + Offset = U_c - Config.U_Bandgap; + //Limit offset to a valid range of -50mV - 50mV + if ((Offset > -50) && (Offset < 50)) Config.CompOffset = Offset; + } + } + return Flag; +} + +//Measure capacitance between two probe pins +void MeasureCap(byte Probe1, byte Probe2, byte ID) +{ + byte TempByte; //Temp. value + Capacitor_Type *Cap; //Pointer to cap data structure + Diode_Type *Diode; //Pointer to diode data structure + Resistor_Type *Resistor; //Pointer to resistor data structure + //Init - Reset cap data + Cap = &Caps[ID]; + Cap->A = 0; + Cap->B = 0; + Cap->Scale = -12; //pF by default + Cap->Raw = 0; + Cap->Value = 0; + if (Check.Found == COMP_ERROR) return; //Skip check on any error + //Skip resistors - But check for a resistor < 10 Ohm. Might be a large cap. + if (Check.Found == COMP_RESISTOR) + { + Resistor = &Resistors[0]; //Pointer to first resistor + TempByte = 0; + while (TempByte < Check.Resistors) + { + //Got matching pins + if (((Resistor->A == Probe1) && (Resistor->B == Probe2)) || + ((Resistor->A == Probe2) && (Resistor->B == Probe1))) + { + //Check for low value + if (CmpValue(Resistor->Value, Resistor->Scale, 10UL, 0) == -1) + TempByte = 99; //Signal low resistance and end loop + } + TempByte++; //Next one + Resistor++; //Next one + } + //We got a valid resistor + if (TempByte != 100) return; //Skip this one + } + /* + Skip measurement for "dangerous" diodes + - when Vf collides with the voltage of the capacitance measurement + */ + Diode = &Diodes[0]; //Pointer to first diode + for (TempByte = 0; TempByte < Check.Diodes; TempByte++) + { + //Got matching pins and low threshold voltage + if ((Diode->C == Probe2) && + (Diode->A == Probe1) && + (Diode->V_f < 1500)) + { + return; + } + Diode++; //Next one + } + //Run measurements + UpdateProbes(Probe1, Probe2, 0); //Update bitmasks and probes + //First run measurement for large caps + TempByte = LargeCap(Cap); + //If cap is too small run measurement for small caps + if (TempByte == 2) + { + TempByte = SmallCap(Cap); + } + //Check for plausibility + //If there aren't any diodes in reverse direction which could be detected as capacitors by mistake + if (Check.Diodes == 0) + { + //Low resistance might be a large cap + if (Check.Found == COMP_RESISTOR) + { + //Report capacitor for large C (> 4.3�F) + if (Cap->Scale >= -6) Check.Found = COMP_CAPACITOR; + } + //We consider values below 5pF being just ghosts + else if ((Cap->Scale > -12) || (Cap->Value >= 5UL)) + { + Check.Found = COMP_CAPACITOR; //Report capacitor + } + } + //Clean up + DischargeProbes(); //Discharge DUT + //Reset all ports and pins + SetADCHiz(); //Set ADC port to input + SetADCLow(); //Set ADC port low + R_DDR = 0; //Set resistor port to input + R_PORT = 0; //Set resistor port low +} + +//Measure inductance between two probe pins +byte MeasureInductance(uint32_t *Time, byte Mode) +{ + byte Flag = 3; //Return value + byte Test; //Test flag + signed char Offset; //Counter offet + unsigned int Ticks_L; //Timer counter + unsigned int Ticks_H; //Timer overflow counter + unsigned long Counter; //Counter + //Sanity check + if (Time == NULL) return 0; + DischargeProbes(); //Try to discharge probes + if (Check.Found == COMP_ERROR) return 0; + /* + Measurement modes: + - low current: Gnd -- Rl -- probe-2 / probe-1 -- Vcc + - high current: Gnd -- probe-2 / probe-1 -- Vcc + + init hardware + */ + //Set probes: Gnd -- probe-1 / Gnd -- Rl -- probe-2 + R_PORT = 0; //Set resistor port to low + SetADCLow(); //Set ADC port to low + if (Mode & MODE_LOW_CURRENT) //Low current + { + R_DDR = Probes.Rl_2; //Pull down probe-2 via Rl + ADC_DDR = Probes.ADC_1; //Pull down probe-1 directly + } + else //High current + { + R_DDR = 0; //Disable probe resistors + //Pull down probe-1 and probe-2 directly + ADC_DDR = Probes.ADC_1 | Probes.ADC_2; + } + //Setup analog comparator + ADCSRB = (1 << ACME); //Use ADC multiplexer as negative input + ACSR = (1 << ACBG) | (1 << ACIC); //Use bandgap as positive input, trigger timer1 + ADMUX = (1 << REFS0) | Probes.Pin_2; //Switch ADC multiplexer to probe-2 and set AREF to Vcc + ADCSRA = ADC_CLOCK_DIV; //Disable ADC, but keep clock dividers + waitus(200); //Allow bandgap reference to settle + //Setup timer + Ticks_H = 0; //Reset timer overflow counter + TCCR1A = 0; //Set default mode + TCCR1B = 0; //Set more timer modes + //Timer stopped, falling edge detection, noise canceler disabled + TCNT1 = 0; //Set Counter1 to 0 + //Clear all flags (input capture, compare A & B, overflow + TIFR1 = (1 << ICF1) | (1 << OCF1B) | (1 << OCF1A) | (1 << TOV1); + if (Mode & MODE_DELAYED_START) //Delayed start + { + Test = (CPU_FREQ / 1000000); //Cycles per �s + //Change probes: Gnd -- Rl -- probe-2 / probe-1 -- Vcc + ADC_PORT = Probes.ADC_1; //Pull up probe-1 directly + /* + Delay timer by about 3-4�s to skip capacitive effects of large inductors + - a single loop needs 4 cycles, the last loop run just 3 + - cycles burnt: * 4 - 1 + */ + while (Test > 0) + { + Test--; + asm volatile("nop\n\t"::); + } + TCCR1B |= (1 << CS10); //Start timer (1/1 clock divider) + } + else //Immediate start + { + TCCR1B |= (1 << CS10); //Start timer (1/1 clock divider) + //Change probes: Gnd -- Rl -- probe-2 / probe-1 -- Vcc + ADC_PORT = Probes.ADC_1; //Pull up probe-1 directly + } + //Timer loop - run until voltage threshold is reached - detect timer overflows + while (1) + { + Test = TIFR1; //Get timer1 flags + //End loop if input capture flag is set (= same voltage) + if (Test & (1 << ICF1)) break; + //Detect timer overflow by checking the overflow flag + if (Test & (1 << TOV1)) + { + //Happens at 65.536ms for 1MHz or 8.192ms for 8MHz + TIFR1 = (1 << TOV1); //Reset flag + wdt_reset(); //Reset watchdog + Ticks_H++; //Increase overflow counter + //If it takes too long (0.26s) + if (Ticks_H == (CPU_FREQ / 250000)) + { + Flag = 0; //Signal timeout + break; //End loop + } + } + } + //Stop counter + TCCR1B = 0; //Stop timer + TIFR1 = (1 << ICF1); //Reset Input Capture flag + Ticks_L = ICR1; //Get counter value + //Prepare cut off: Gnd -- Rl -- probe-2 / probe-1 -- Rl -- Gnd + R_DDR = Probes.Rl_2 | Probes.Rl_1; + //Stop current flow + SetADCHiz(); + //Catch missed timer overflow + if ((TCNT1 > Ticks_L) && (Test & (1 << TOV1))) + { + TIFR1 = (1 << TOV1); //Reset overflow flag + Ticks_H++; //Increase overflow counter + } + //Enable ADC again + ADCSRA = (1 << ADEN) | (1 << ADIF) | ADC_CLOCK_DIV; + //Process counters, combine both counter values + Counter = (unsigned long)Ticks_L; //Lower 16 bits + Counter |= (unsigned long)Ticks_H << 16; //Upper 16 bits + Offset = -4; //Subtract processing overhead + if (Mode & MODE_DELAYED_START) //Delayed start + { + //Add MCU cycles for delayed start + Offset += ((CPU_FREQ / 1000000) * 4) - 1; + } + else //Immediate start + { + Offset -= 1; //Timer started one cycle too early + } + if (Offset >= 0) //Positive offet + { + Counter += Offset; + } + else //Negative offset + { + Offset *= -1; //Make it positive + if (Counter < Offset) Counter = 0; //Prevent underflow + else Counter -= Offset; //Subtract offset + } + //Convert counter (MCU cycles) to time (in �s) + if (Counter > 0) + { + Counter += (CPU_FREQ / 2000000); //Add half of cycles for rounding + Counter /= (CPU_FREQ / 1000000); //Divide by frequeny and scale to �s + } + if (Counter <= 1) Flag = 2; //Signal inductance too low + *Time = Counter; //Save time + return Flag; +} + +//Measure inductance between two probe pins of a resistor +byte MeasureInductor(Resistor_Type *Resistor) +{ + byte Test = 0; //Return value / measurement result + byte Mode; //Measurement mode + byte Scale; //Scale of value + unsigned int R_total; //Total resistance + unsigned int Factor; //Factor + unsigned long Value; //Value + unsigned long Time1; //Time #1 + unsigned long Time2; //Time #2 + //Reset data + Inductor.Scale = 0; + Inductor.Value = 0; + //Sanity check + if (Resistor == NULL) return Test; + //Limit resistor to 2k (feasibilty & prevent variable overflow) + if (CmpValue(Resistor->Value, Resistor->Scale, 2000, 0) >= 0) return Test; + /* + Manage measurements: + - run in immediate and delayed mode to deal with capacitive effects + of large inductors and keep smaller time + - in case of a small inductance run in high current mode (implies + immediate mode only) + */ + UpdateProbes(Resistor->A, Resistor->B, 0); //Update probes + Mode = MODE_LOW_CURRENT; + Test = MeasureInductance(&Time1, Mode); + if (Test == 2) //Inductance too low + { + //If resistance < 40 Ohms we may run the high current test + if (CmpValue(Resistor->Value, Resistor->Scale, 40, 0) < 0) + { + Mode = MODE_HIGH_CURRENT; + Test = MeasureInductance(&Time1, Mode); + } + } + else if (Test == 3) //Valid time + { + //Let's run the delayed mode + Mode = MODE_LOW_CURRENT | MODE_DELAYED_START; + Test = MeasureInductance(&Time2, Mode); + if (Time1 > Time2) Time1 = Time2; //Lower value wins + } + if (Test != 3) Test = 0; //Measurements faile + //Calculate inductance + if (Test == 3) + { + //Resistances - Total resistance (in 0.1 Ohms) - R_L + R_total = RescaleValue(Resistor->Value, Resistor->Scale, -1); + R_total += Config.RiH + Config.RiL; + //Shunt resistance (in 0.1 Ohms) + Factor = Config.RiL; + if (Mode & MODE_LOW_CURRENT) //Low current measurement mode + { + //Add R_l + R_total += (R_LOW * 10); + Factor += (R_LOW * 10); + } + /* + Ratio and factor + - ratio = ((U_ref * R_total) / (5V * R_shunt)) * 10^3 + */ + Value = Config.U_Bandgap + Config.CompOffset; + Value *= R_total; // * R_total (in 0.1 Ohms) + Value /= Factor; // / R_shunt (in 0.1 Ohms) + Value /= 5; // / 5000mV, * 10^3 + //Get ratio based factor + Factor = GetFactor((unsigned int)Value, TABLE_INDUCTOR); + /* + calculate inductance + L = t_stop * R_total * factor + */ + Scale = -6; //�H by default + Value = Time1; //t_stop + Value *= Factor; // * factor (�s * 10^-3) + while (Value > 100000) //Re-scale to prevent overflow + { + Value /= 10; + Scale++; + } + Value *= R_total; // * R_total (in 0.1 Ohms) + Value /= 10000; + //Update data + Inductor.Scale = Scale; + Inductor.Value = Value; + Test = 1; //Signal success + } + return Test; +} + + //DISPLAY FUNCTIONS + +//Clear the display +void lcd_clear(void) +{ + #ifdef LCD_PRINT + lcd.clear(); + delay(2); //LCD needs some time for processing + #endif + #ifdef DEBUG_PRINT + Serial.println(); + #endif +} + +//Move cursor to the first position of a specified line +void lcd_line(unsigned char Line) +{ + #ifdef LCD_PRINT + lcd.setCursor(0,Line); + #endif + #ifdef DEBUG_PRINT + Serial.println(); + #endif +} + + //Clear single line of display + void lcd_clear_line(unsigned char Line) +{ + unsigned char Pos; + #ifdef LCD_PRINT + lcd_line(Line); //Go to beginning of line + for (Pos = 0; Pos < 20; Pos++) //For 20 times + { + lcd_data(' '); //Send space + } + lcd_line(Line); //Go back to beginning of line + #endif + #ifdef DEBUG_PRINT + Serial.println(); + #endif +} + +//Write probe pin number to the LCD +void lcd_testpin(unsigned char Probe) +{ + //Since TP1 is 0 we simply add the value to '1' + lcd_data('1' + Probe); //Send data +} + +//Display a space +void lcd_space(void) +{ + lcd_data(' '); +} + +//Display a string +void lcd_string(char *String) +{ + while (*String) //Loop until trailing 0 is reached + { + lcd_data(*String); //Send character + String++; //Next one + } +} + +//Display a fixed string stored in PROGMEM +void lcd_fixed_string(const unsigned char *String) +{ + while (pgm_read_byte(String) != 0x00) + lcd_data(pgm_read_byte(String++)); //Send character +} + +//Send data to the LCD +void lcd_data(unsigned char Data) +{ + #ifdef LCD_PRINT + lcd.write(Data); //Send data to LCD + #endif + #ifdef DEBUG_PRINT + Serial.write(Data); //Send data to Serial + #endif +} + + //USER FUNCTIONS + +//Display value and unit +void DisplayValue(unsigned long Value, signed char Exponent, unsigned char Unit) +{ + unsigned char Prefix = 0; //Prefix character + byte Offset = 0; //Exponent offset to next 10^3 step + byte Index; //Index ID + byte Length; //String length + //Scale value down to 4 digits + while (Value >= 10000) + { + Value += 5; //For automagic rounding + Value = Value / 10; //Scale down by 10^1 + Exponent++; //Increase exponent by 1 + } + //Determine prefix and offset (= number of digits right of dot) + if (Exponent >= -12) //Prevent index underflow + { + Exponent += 12; //Shift exponent to be >= 0 + Index = Exponent / 3; //Number of 10^3 steps + Offset = Exponent % 3; //Offset to lower 10^3 step + if (Offset > 0) //Dot required + { + Index++; //Upscale prefix + Offset = 3 - Offset; //Reverse value (1 or 2) + } + //Look up prefix in table (also prevent array overflow) + if (Index <= 6) Prefix = *(&Prefix_table[Index]); + } + //Display value, convert value into string + utoa((unsigned int)Value, OutBuffer, 10); + Length = strlen(OutBuffer); + //We misuse Exponent for the dot position + Exponent = Length - Offset; //Calculate position + if (Exponent <= 0) //We have to prepend "0." + { + //0: factor 10 / -1: factor 100 + lcd_data('0'); + lcd_data('.'); + if (Exponent < 0) lcd_data('0'); //Extra 0 for factor 100 + } + if (Offset == 0) Exponent = -1; //Disable dot if not needed + //Adjust position to match array or disable dot if set to 0 + Exponent--; + //Display value and add dot if requested + Index = 0; + while (Index < Length) //Loop through string + { + lcd_data(OutBuffer[Index]); //Display char + if (Index == Exponent) lcd_data('.'); //Display dot + Index++; //Next one + } + //Display prefix and unit + if (Prefix) lcd_data(Prefix); + if (Unit) lcd_data(Unit); +} + +//Display signed value and unit +void DisplaySignedValue(signed long Value, signed char Exponent, unsigned char Unit) +{ + //Take care about sign + if (Value < 0) //Negative value + { + lcd_data('-'); //Display: "-" + Value = -Value; //Make value positive + } + //And display unsigned value + DisplayValue((signed long)Value, Exponent, Unit); +} + +//Tell user to create or remove short-circuit of all three probes +void ShortCircuit(byte Mode) +{ + byte Run = 0; //Loop control + byte Test; //Test feedback + unsigned char *String = NULL; //Display string pointer + Test = AllProbesShorted(); //Get current status + if (Mode == 0) //Remove short + { + //Some shorted + if (Test != 0) String = (unsigned char *)Remove_str; + } + else //Create short + { + //Some unshorted + if (Test != 3) String = (unsigned char *)Create_str; + } + //If required tell user what to do + if (String) + { + lcd_clear(); + lcd_fixed_string(String); //Display: Remove/Create + lcd_line(1); + lcd_fixed_string(ShortCircuit_str); //Display: short circuit! + Run = 1; //Enter loop + } + //Wait until all probes are dis/connected + while (Run == 1) + { + Test = AllProbesShorted(); //Check for short circuits + if (Mode == 0) //Remove short + { + if (Test == 0) Run = 0; //End loop if all removed + } + else //Create short + { + if (Test == 3) Run = 0; //End loop if all shorted + } + if (Run == 1) //If not done yet + delay(50); //Wait a little bit + else //If done + delay(200); //Time to debounce + } +} + +//Detect keypress of test push button +byte TestKey(unsigned int Timeout, byte Mode) +{ + byte Flag = 0; //Return value + byte Run = 1; //Loop control + byte Counter = 0; //Time counter + byte ButtonStatus=0; //Button Status + //Init + if (Mode > 10) //Consider operation mode + { + if (Config.TesterMode == MODE_AUTOHOLD) //Auto hold mode + { + Timeout = 0; //Disable timeout + Mode -= 10; //Set cursor mode + } + else //Continous mode + { + Mode = 0; //Disable cursor + } + } + if (Mode > 0) //Cursor enabled + { + //Set position: char 16 in line 2 + #ifdef LCD_PRINT + lcd.setCursor(15, 2); + //Enable cursor + lcd.cursor(); + #endif + } + //Wait for key press or timeout + while (Run) + { + //Take care about timeout + if (Timeout > 0) //Timeout enabled + { + //Set position: char 16 in line 2 + #ifdef LCD_PRINT + lcd.setCursor(15, 2); + //Show flag, more info + lcd_data(LCD_CHAR_FLAG); + #endif + if (Timeout > 5) Timeout -= 5; //Decrease timeout by 5ms + else Run = 0; //End loop on timeout + } + //Check for key press, Test push button is low active + if (!(digitalRead(TEST_BUTTON))) //If key is pressed + { + Counter = 0; //Reset counter + delay(30); //Time to debounce + while (Run) //Detect how long key is pressed + { + if (!(digitalRead(TEST_BUTTON))) //Key still pressed + { + Counter++; //Increase counter + if (Counter > LONG_PRESS) Run = 0; //End loop if LONG_PRESS are reached + else delay(10); //Otherweise wait 10ms + } + else //Key released + { + Run = 0; //End loop + } + } + //Determine key press type + if (Counter > LONG_PRESS) Flag = 2; //Long (>= LONG_PRESS) + else Flag = 1; //Short (< LONG_PRESS) + } + else //No key press + { + delay(5); //Wait a little bit more (5ms) + //Simulate blinking cursor, The LCDs built in cursor blinking is ugly and slow + if (Mode == 2) //Blinking cursor + { + Counter++; //Increase counter + if (Counter == 100) //Every 500ms (2Hz) + { + Counter = 0; //Reset counter + //We misuse Run as toggle switch + if (Run == 1) //Turn off + { + //Disable cursor + #ifdef LCD_PRINT + lcd.noCursor(); + #endif + Run = 2; //Toggle flag + } + else //Turn on + { + //Enable cursor + #ifdef LCD_PRINT + lcd.cursor(); + #endif + Run = 1; //Toggle flag + } + } + } + } + } + //Clean up + if (Mode > 0) //Cursor enabled + { + //Disable cursor + #ifdef LCD_PRINT + lcd.noCursor(); + #endif + } + return Flag; +} + +//Show failed test +void ShowFail(void) +{ + //Display info + lcd_fixed_string(Failed1_str); //Display: No component + lcd_line(1); //Move to line #2 + lcd_fixed_string(Failed2_str); //Display: found! + //Display numbers of diodes found + if (Check.Diodes > 0) //Diodes found + { + lcd_space(); //Display space + lcd_data(Check.Diodes + '0'); //Display number of diodes found + lcd_fixed_string(Diode_AC_str); //Display: -|>|- + } + RunsMissed++; //Increase counter + RunsPassed = 0; //Reset counter +} + +//Show Error //Only for Standalone Version! +void ShowError() +{ + if (Check.Type == TYPE_DISCHARGE) //Discharge failed + { + lcd_fixed_string(DischargeFailed_str); //Display: Battery? + //Display probe number and remaining voltage + lcd_line(1); + lcd_testpin(Check.Probe); + lcd_data(':'); + lcd_space(); + DisplayValue(Check.U, -3, 'V'); + } +} + +//Display Uf of a diode +void ShowDiode_Uf(Diode_Type *Diode) +{ + //Sanity check + if (Diode == NULL) return; + //Display Vf + DisplayValue(Diode->V_f, -3, 'V'); +} + +//Display capacitance of a diode +void ShowDiode_C(Diode_Type *Diode) +{ + //Sanity check + if (Diode == NULL) return; + //Get capacitance (opposite of flow direction) + MeasureCap(Diode->C, Diode->A, 0); + //And show capacitance + DisplayValue(Caps[0].Value, Caps[0].Scale, 'F'); +} + +//Show diode +void ShowDiode(void) +{ + Diode_Type *D1; //Pointer to diode #1 + Diode_Type *D2 = NULL; //Pointer to diode #2 + byte SkipFlag = 0; //Flag for anti-parallel diodes + byte A = 5; //ID of common anode + byte C = 5; //ID of common cothode + unsigned int I_leak; //Leakage current + D1 = &Diodes[0]; //Pointer to first diode + //Figure out which diodes to display + if (Check.Diodes == 1) //Single diode + { + C = D1->C; //Make anode first pin + } + else if (Check.Diodes == 2) //Two diodes + { + D2 = D1; + D2++; //Pointer to second diode + if (D1->A == D2->A) //Common anode + { + A = D1->A; //Save common anode + } + else if (D1->C == D2->C) //Common cathode + { + C = D1->C; //Save common cathode + } + //Anti-parallel + else if ((D1->A == D2->C) && (D1->C == D2->A)) + { + A = D1->A; //Anode and cathode + C = A; //Are the same + SkipFlag = 1; //Signal anti-parallel diodes + } + } + else if (Check.Diodes == 3) //Three diodes + { + byte n; + byte m; + /* + Two diodes in series are additionally detected as third big diode: + - Check for any possible way of 2 diodes be connected in series. + - Only once the cathode of diode #1 matches the anode of diode #2. + */ + for (n = 0; n <= 2; n++) //Loop for first diode + { + D1 = &Diodes[n]; //Get pointer of first diode + for (m = 0; m <= 2; m++) //Loop for second diode + { + D2 = &Diodes[m]; //Get pointer of second diode + if (n != m) //Don't check same diode :-) + { + if (D1->C == D2->A) //Got match + { + n = 5; //End loops + m = 5; + } + } + } + } + if (n < 5) D2 = NULL; //No match found + C = D1->C; //Cathode of first diode + A = 3; //In series mode + } + else //To much diodes + { + D1 = NULL; //Don't display any diode + ShowFail(); //And tell user + return; + } + //Display pins, first Diode + if (A < 3) lcd_testpin(D1->C); //Common anode + else lcd_testpin(D1->A); //Common cathode + if (A < 3) lcd_fixed_string(Diode_CA_str); //Common anode + else lcd_fixed_string(Diode_AC_str); //Common cathode + if (A < 3) lcd_testpin(A); //Common anode + else lcd_testpin(C); //Common cathode + if (D2) //Second diode + { + if (A <= 3) lcd_fixed_string(Diode_AC_str); //Common anode or in series + else lcd_fixed_string(Diode_CA_str); //Common cathode + if (A == C) lcd_testpin(D2->A); //Anti parallel + else if (A <= 3) lcd_testpin(D2->C); //Common anode or in series + else lcd_testpin(D2->A); //Common cathode + } + /* + display: + - Uf (forward voltage) + - reverse leakage current (for single diodes) + - capacitance (not for anti-parallel diodes) + */ + //Uf + lcd_line(1); //Go to line #2 + lcd_fixed_string(Vf_str); //Display: Vf= + ShowDiode_Uf(D1); //First diode + lcd_space(); + if (D2 == NULL) //Single diode + { + //Display low current Uf if it's quite low (Ge/Schottky diode) + if (D1->V_f2 < 250) + { + lcd_data('('); + DisplayValue(D1->V_f2, 0, 0); + lcd_data(')'); + } + //Reverse leakage current + UpdateProbes(D1->C, D1->A, 0); //Reverse diode + I_leak = GetLeakageCurrent(); //Get current (in �A) + if (I_leak > 0) //Show if not zero + { + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Next page + #else + delay(3000); + #endif + lcd_clear_line(2); //Only change line #2 + lcd_fixed_string(I_R_str); //Display: I_R= + DisplayValue(I_leak, -6, 'A'); //Display current + } + } + else + { + ShowDiode_Uf(D2); //Second diode (optional) + } + //Capacitance + if (SkipFlag == 0) + { + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Next page + #else + delay(3000); + #endif + lcd_clear_line(2); //Only change line #2 + lcd_fixed_string(DiodeCap_str); //Display: C= + ShowDiode_C(D1); //First diode + lcd_space(); + ShowDiode_C(D2); //Second diode (optional) + } +} + +//Show BJT +void ShowBJT(void) +{ + Diode_Type *Diode; //Pointer to diode + unsigned char *String; //Display string pointer + byte Counter; //Counter + byte A_Pin; //Pin acting as anode + byte C_Pin; //Pin acting as cathode + unsigned int V_BE; //V_BE + signed int Slope; //Slope of forward voltage + //Display type + if (Check.Type == TYPE_NPN) //NPN + String = (unsigned char *)NPN_str; + else //PNP + String = (unsigned char *)PNP_str; + lcd_fixed_string(String); //Display: NPN / PNP + //Protections diodes + if (Check.Diodes > 2) //Transistor is a set of two diodes :-) + { + lcd_space(); + if (Check.Type == TYPE_NPN) //NPN + String = (unsigned char *)Diode_AC_str; + else //PNP + String = (unsigned char *)Diode_CA_str; + lcd_fixed_string(String); //Display: -|>|- / -|<|- + } + //Display pins + lcd_space(); + lcd_fixed_string(EBC_str); //Display: EBC= + lcd_testpin(BJT.E); //Display emitter pin + lcd_testpin(BJT.B); //Display base pin + lcd_testpin(BJT.C); //Display collector pin + //Display hFE + lcd_line(1); //Move to line #2 + lcd_fixed_string(hFE_str); //Display: h_FE= + DisplayValue(BJT.hFE, 0, 0); + //Display V_BE (taken from diode forward voltage) + Diode = &Diodes[0]; //Get pointer of first diode + Counter = 0; + while (Counter < Check.Diodes) //Check all diodes + { + //Set pins based on BJT type + if (Check.Type == TYPE_NPN) //NPN + { + //Diode B -> E + A_Pin = BJT.B; + C_Pin = BJT.E; + } + else //PNP + { + //Diode E -> B + A_Pin = BJT.E; + C_Pin = BJT.B; + } + //If the diode matches the transistor + if ((Diode->A == A_Pin) && (Diode->C == C_Pin)) + { + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Next page + #else + delay(3000); + #endif + lcd_clear_line(2); //Update line #2 + lcd_fixed_string(V_BE_str); //Display: V_BE= + /* + Vf is quite linear for a logarithmicly scaled I_b. + So we may interpolate the Vf values of low and high test current + measurements for a virtual test current. Low test current is 10�A + and high test current is 7mA. That's a logarithmic scale of + 3 decades. + */ + //Calculate slope for one decade + Slope = Diode->V_f - Diode->V_f2; + Slope /= 3; + //Select V_BE based on hFE + if (BJT.hFE < 100) //Low hFE + { + /* + BJTs with low hFE are power transistors and need a large I_b + to drive the load. So we simply take Vf of the high test current + measurement (7mA). + */ + V_BE = Diode->V_f; + } + else if (BJT.hFE < 250) //Mid-range hFE + { + /* + BJTs with a mid-range hFE are signal transistors and need + a small I_b to drive the load. So we interpolate Vf for + a virtual test current of about 1mA. + */ + V_BE = Diode->V_f - Slope; + } + else //High hFE + { + /* + BJTs with a high hFE are small signal transistors and need + only a very small I_b to drive the load. So we interpolate Vf + for a virtual test current of about 0.1mA. + */ + V_BE = Diode->V_f2 + Slope; + } + DisplayValue(V_BE, -3, 'V'); + //I_CEO: collector emitter cutoff current (leakage) + if (BJT.I_CE0 > 0) //Show if not zero + { + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Next page + #else + delay(3000); + #endif + lcd_clear_line(2); //Only change line #2 + lcd_fixed_string(I_CEO_str); //Display: I_CE0= + DisplayValue(BJT.I_CE0, -6, 'A'); //Display current + } + Counter = Check.Diodes; //End loop + } + else + { + Counter++; //Increase counter + Diode++; //Next one + } + } +} + +//Show MOSFET/IGBT extras +void Show_FET_IGBT_Extras(byte Symbol) +{ + //Instrinsic diode + if (Check.Diodes > 0) + { + lcd_space(); //Display space + lcd_data(Symbol); //Display diode symbol + } + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Next page + #else + delay(3000); + #endif + lcd_clear(); + //Gate threshold voltage + lcd_fixed_string(Vth_str); //Display: Vth + DisplayValue(FET.V_th, -3, 'V'); //Display V_th in mV + lcd_line(1); + //Display gate capacitance + lcd_fixed_string(GateCap_str); //Display: Cgs= + MeasureCap(FET.G, FET.S, 0); //Measure capacitance + //Display value and unit + DisplayValue(Caps[0].Value, Caps[0].Scale, 'F'); +} + +//Show FET +void ShowFET(void) +{ + byte Data; //Temp. data + byte Symbol; //Intrinsic diode + //Set variables based on channel mode + if (Check.Type & TYPE_N_CHANNEL) //n-channel + { + Data = 'N'; + Symbol = LCD_CHAR_DIODE2; // '|<|' cathode pointing to drain + } + else //p-channel + { + Data = 'P'; + Symbol = LCD_CHAR_DIODE1; // '|>|' cathode pointing to source + } + //Display type + if (Check.Type & TYPE_MOSFET) //MOSFET + lcd_fixed_string(MOS_str); //Display: MOS + else //JFET + lcd_data('J'); //Display: J + lcd_fixed_string(FET_str); //Display: FET + //Display channel type + lcd_space(); + lcd_data(Data); //Display: N / P + lcd_fixed_string(Channel_str); //Display: -ch + //Display mode + if (Check.Type & TYPE_MOSFET) //MOSFET + { + lcd_space(); + if (Check.Type & TYPE_ENHANCEMENT) //Enhancement mode + lcd_fixed_string(Enhancement_str); + else //Depletion mode + lcd_fixed_string(Depletion_str); + } + //Pins + lcd_line(1); //Move to line #2 + lcd_fixed_string(GDS_str); //Display: GDS= + lcd_testpin(FET.G); //Display gate pin + if (Check.Type & TYPE_JFET) + { + //D & S can't be detected for a JFET + lcd_data('?'); + lcd_data('?'); + } + else + { + lcd_testpin(FET.D); //Display drain pin + lcd_testpin(FET.S); //Display source pin + } + //Extra data for MOSFET in enhancement mode + if (Check.Type & (TYPE_ENHANCEMENT | TYPE_MOSFET)) + { + //Show diode, V_th and Cgs + Show_FET_IGBT_Extras(Symbol); + } +} + +//Show IGBT +void ShowIGBT(void) +{ + byte Data; //Temp. data + byte Symbol; //Intrinsic diode + //Set variables based on channel mode + if (Check.Type & TYPE_N_CHANNEL) //n-channel + { + Data = 'N'; + Symbol = LCD_CHAR_DIODE2; // '|<|' cathode pointing to drain + } + else //p-channel + { + Data = 'P'; + Symbol = LCD_CHAR_DIODE1; // '|>|' cathode pointing to source + } + lcd_fixed_string(IGBT_str); //Display: IGBT + //Display channel type + lcd_space(); + lcd_data(Data); //Display: N / P + lcd_fixed_string(Channel_str); //Display: -ch + //Display mode + lcd_space(); + if (Check.Type & TYPE_ENHANCEMENT) //Enhancement mode + lcd_fixed_string(Enhancement_str); + else //Depletion mode + lcd_fixed_string(Depletion_str); + //Pins + lcd_line(1); //Move to line #2 + lcd_fixed_string(GCE_str); //Display: GCE= + lcd_testpin(FET.G); //Display gate pin + lcd_testpin(FET.D); //Display collector pin + lcd_testpin(FET.S); //Display emitter pin + //Show diode, V_th and C_CE + Show_FET_IGBT_Extras(Symbol); +} + +//Show special components like Thyristor and Triac +void ShowSpecial(void) +{ + //Display component type + if (Check.Found == COMP_THYRISTOR) + { + lcd_fixed_string(Thyristor_str); //Display: thyristor + } + else if (Check.Found == COMP_TRIAC) + { + lcd_fixed_string(Triac_str); //Display: triac + } + //Display pins + lcd_line(1); //Move to line #2 + lcd_fixed_string(GAK_str); //Display: GAK + lcd_testpin(BJT.B); //Display gate pin + lcd_testpin(BJT.C); //Display anode pin + lcd_testpin(BJT.E); //Display cathode pin +} + +//Show resistor +void ShowResistor(void) +{ + Resistor_Type *R1; //Pointer to resistor #1 + Resistor_Type *R2; //Pointer to resistor #2 + byte Pin; //ID of common pin + R1 = &Resistors[0]; //Pointer to first resistor + if (Check.Resistors == 1) //Single resistor + { + R2 = NULL; //Disable second resistor + Pin = R1->A; //Make B the first pin + } + else //Multiple resistors + { + R2 = R1; + R2++; //Pointer to second resistor + if (Check.Resistors == 3) //Three resistors + { + Resistor_Type *Rmax; //Pointer to largest resistor + /* + 3 resistors mean 2 single resistors and both resitors in series. + So we have to single out that series resistor by finding the + largest resistor. + */ + Rmax = R1; //Starting point + for (Pin = 1; Pin <= 2; Pin++) + { + if (CmpValue(R2->Value, R2->Scale, Rmax->Value, Rmax->Scale) == 1) + { + Rmax = R2; //Update largest one + } + R2++; //Next one + } + //Get the two smaller resistors + if (R1 == Rmax) R1++; + R2 = R1; + R2++; + if (R2 == Rmax) R2++; + } + //Find common pin of both resistors + if ((R1->A == R2->A) || (R1->A == R2->B)) Pin = R1->A; + else Pin = R1->B; + } + //Display the pins, first resistor + if (R1->A != Pin) lcd_testpin(R1->A); + else lcd_testpin(R1->B); + lcd_fixed_string(Resistor_str); + lcd_testpin(Pin); + if (R2) //Second resistor + { + lcd_fixed_string(Resistor_str); + if (R2->A != Pin) lcd_testpin(R2->A); + else lcd_testpin(R2->B); + } + //Display the values, first resistor + lcd_line(1); + DisplayValue(R1->Value, R1->Scale, LCD_CHAR_OMEGA); + if (R2) //Second resistor + { + lcd_space(); + DisplayValue(R2->Value, R2->Scale, LCD_CHAR_OMEGA); + } + else //Single resistor + { + //Get inductance and display if relevant + if (MeasureInductor(R1) == 1) + { + lcd_space(); + DisplayValue(Inductor.Value, Inductor.Scale, 'H'); + } + } +} + +//Show capacitor +void ShowCapacitor(void) +{ + Capacitor_Type *MaxCap; //Pointer to largest cap + Capacitor_Type *Cap; //Pointer to cap + byte Counter; //Loop counter + //Find largest cap + MaxCap = &Caps[0]; //Pointer to first cap + Cap = MaxCap; + for (Counter = 1; Counter <= 2; Counter++) + { + Cap++; //Next cap + if (CmpValue(Cap->Value, Cap->Scale, MaxCap->Value, MaxCap->Scale) == 1) + { + MaxCap = Cap; + } + } + //Display pinout + lcd_testpin(MaxCap->A); //Display pin #1 + lcd_fixed_string(Cap_str); //Display capacitor symbol + lcd_testpin(MaxCap->B); //Display pin #2 + lcd_line(1); //Move to line #2 + //And show capacitance + DisplayValue(MaxCap->Value, MaxCap->Scale, 'F'); +} + +//Load adjustment values +void LoadAdjust(void) +{ + if (EEPROM.read(10)==126) + { + //Read from EEPROM + ReadEEP(); + } + else + { + //Default Values + Config.RiL = R_MCU_LOW; + Config.RiH = R_MCU_HIGH; + Config.RZero = R_ZERO; + Config.CapZero = C_ZERO; + Config.RefOffset = UREF_OFFSET; + Config.CompOffset = COMPARATOR_OFFSET; + //Save to EEProm + SaveEEP(); + } +} + + //UTILITY FUNCTIONS + +//SelfTest +byte SelfTest(void) +{ + byte Flag = 0; //Return value + byte Test = 1; //Test counter + byte Counter; //Loop counter + byte DisplayFlag; //Display flag + unsigned int Val0; //Voltage/value + //Voltages/values + signed int Val1 = 0, Val2 = 0, Val3 = 0; + ShortCircuit(1); //Make sure all probes are shorted + //Loop through all tests + while (Test <= 6) + { + Counter = 1; + //Repeat each test 5 times + while (Counter <= 5) + { + //Display test number + lcd_clear(); + lcd_data('T'); //Display: T + lcd_data('0' + Test); //Display test number + lcd_space(); + DisplayFlag = 1; //Display values by default + //Tests + switch (Test) + { + case 1: //Reference voltage + Val0 = ReadU(0x0e); //Dummy read for bandgap stabilization + Val0 = ReadU(0x0e); //Read bandgap reference voltage + lcd_fixed_string(URef_str); //Display: Vref + lcd_line(1); + DisplayValue(Val0, -3, 'V'); //Display voltage in mV + DisplayFlag = 0; //Reset flag + break; + case 2: //Compare Rl resistors (probes still shorted) + lcd_fixed_string(Rl_str); //Display: +Rl- + lcd_space(); + lcd_fixed_string(ProbeComb_str); //Display: 12 13 23 + //Set up a voltage divider with the Rl's, substract theoretical voltage of voltage divider + //TP1: Gnd -- Rl -- probe-2 -- probe-1 -- Rl -- Vcc + R_PORT = 1 << (TP1 * 2); + R_DDR = (1 << (TP1 * 2)) | (1 << (TP2 * 2)); + Val1 = ReadU_20ms(TP3); + Val1 -= ((long)UREF_VCC * (R_MCU_LOW + R_LOW)) / (R_MCU_LOW + R_LOW + R_LOW + R_MCU_HIGH); + //TP1: Gnd -- Rl -- probe-3 -- probe-1 -- Rl -- Vcc + R_DDR = (1 << (TP1 * 2)) | (1 << (TP3 * 2)); + Val2 = ReadU_20ms(TP2); + Val2 -= ((long)UREF_VCC * (R_MCU_LOW + R_LOW)) / (R_MCU_LOW + R_LOW + R_LOW + R_MCU_HIGH); + //TP1: Gnd -- Rl -- probe-3 -- probe-2 -- Rl -- Vcc + R_PORT = 1 << (TP2 * 2); + R_DDR = (1 << (TP2 * 2)) | (1 << (TP3 * 2)); + Val3 = ReadU_20ms(TP2); + Val3 -= ((long)UREF_VCC * (R_MCU_LOW + R_LOW)) / (R_MCU_LOW + R_LOW + R_LOW + R_MCU_HIGH); + break; + case 3: //Compare Rh resistors (probes still shorted) + lcd_fixed_string(Rh_str); //Display: +Rh- + lcd_space(); + lcd_fixed_string(ProbeComb_str); //Display: 12 13 23 + //Set up a voltage divider with the Rh's + //TP1: Gnd -- Rh -- probe-2 -- probe-1 -- Rh -- Vcc + R_PORT = 2 << (TP1 * 2); + R_DDR = (2 << (TP1 * 2)) | (2 << (TP2 * 2)); + Val1 = ReadU_20ms(TP3); + Val1 -= (UREF_VCC / 2); + //TP1: Gnd -- Rh -- probe-3 -- probe-1 -- Rh -- Vcc + R_DDR = (2 << (TP1 * 2)) | (2 << (TP3 * 2)); + Val2 = ReadU_20ms(TP2); + Val2 -= (UREF_VCC / 2); + //TP1: Gnd -- Rh -- probe-3 -- probe-2 -- Rh -- Vcc + R_PORT = 2 << (TP2 * 2); + R_DDR = (2 << (TP2 * 2)) | (2 << (TP3 * 2)); + Val3 = ReadU_20ms(TP1); + Val3 -= (UREF_VCC / 2); + break; + case 4: //Un-short probes + ShortCircuit(0); //Make sure probes are not shorted + Counter = 100; //Skip test + DisplayFlag = 0; //Reset flag + break; + case 5: //Rh resistors pulled down + lcd_fixed_string(RhLow_str); //Display: Rh- + //TP1: Gnd -- Rh -- probe + R_PORT = 0; + R_DDR = 2 << (TP1 * 2); + Val1 = ReadU_20ms(TP1); + //TP1: Gnd -- Rh -- probe + R_DDR = 2 << (TP2 * 2); + Val2 = ReadU_20ms(TP2); + //TP1: Gnd -- Rh -- probe + R_DDR = 2 << (TP3 * 2); + Val3 = ReadU_20ms(TP3); + break; + case 6: //Rh resistors pulled up + lcd_fixed_string(RhHigh_str); //Display: Rh+ + //TP1: probe -- Rh -- Vcc + R_DDR = 2 << (TP1 * 2); + R_PORT = 2 << (TP1 * 2); + Val1 = ReadU_20ms(TP1); + //TP1: probe -- Rh -- Vcc + R_DDR = 2 << (TP2 * 2); + R_PORT = 2 << (TP2 * 2); + Val2 = ReadU_20ms(TP2); + //TP1: probe -- Rh -- Vcc + R_DDR = 2 << (TP3 * 2); + R_PORT = 2 << (TP3 * 2); + Val3 = ReadU_20ms(TP3); + break; + } + //Reset ports to defaults + R_DDR = 0; //Input mode + R_PORT = 0; //All pins low + //Display voltages/values of all probes + if (DisplayFlag) + { + lcd_line(1); //Move to line #2 + DisplaySignedValue(Val1, 0 , 0); //Display TP1 + lcd_space(); + DisplaySignedValue(Val2, 0 , 0); //Display TP2 + lcd_space(); + DisplaySignedValue(Val3, 0 , 0); //Display TP3 + } + //Wait and check test push button + if (Counter < 100) //When we don't skip this test + { + #ifdef BUTTON_INST + DisplayFlag = TestKey(1000, 0); //Catch key press or timeout + #else + delay(1000); + DisplayFlag=0; + #endif + //Short press -> next test / long press -> end selftest + if (DisplayFlag > 0) + { + Counter = 100; //Skip current test anyway + if (DisplayFlag == 2) Test = 100; //Also skip selftest + } + } + Counter++; //Next run + } + Test++; //Next one + } + Flag = 1; //Signal success + return Flag; +} + +//Self adjustment +byte SelfAdjust(void) +{ + byte Flag = 0; //Return value + byte Test = 1; //Test counter + byte Counter; //Loop counter + byte DisplayFlag; //Display flag + //Voltages + unsigned int Val1 = 0, Val2 = 0, Val3 = 0; + byte CapCounter = 0; //Number of C_Zero measurements + unsigned int CapSum = 0; //Sum of C_Zero values + byte RCounter = 0; //Number of R_Zero measurements + unsigned int RSum = 0; //Sum of R_Zero values + byte RiL_Counter = 0; //Number of U_RiL measurements + unsigned int U_RiL = 0; //Sum of U_RiL values + byte RiH_Counter = 0; //Number of U_RiH measurements + unsigned int U_RiH = 0; //Sum of U_RiL values + unsigned long Val0; //Temp. value + //Measurements + ShortCircuit(1); //Make sure all probes are shorted + while (Test <= 5) + { + Counter = 1; + //Repeat each measurement 5 times + while (Counter <= 5) + { + //Display test number + lcd_clear(); + lcd_data('A'); //Display: a + lcd_data('0' + Test); //Display number + lcd_space(); + DisplayFlag = 1; //Display values by default + //Tests + switch (Test) + { + case 1: //Resistance of probe leads (probes shorted) + lcd_fixed_string(ROffset_str); //Display: R0 + lcd_space(); + lcd_fixed_string(ProbeComb_str); //Display: 12 13 23 + //The resistance is for two probes in series and we expect it to be smaller than 1.00 Ohms, i.e. 0.50 Ohms for a single probe + UpdateProbes(TP2, TP1, 0); + Val1 = SmallResistor(0); + if (Val1 < 100) //Within limit + { + RSum += Val1; + RCounter++; + } + UpdateProbes(TP3, TP1, 0); + Val2 = SmallResistor(0); + if (Val2 < 100) //Whithin limit + { + RSum += Val2; + RCounter++; + } + UpdateProbes(TP3, TP2, 0); + Val3 = SmallResistor(0); + if (Val3 < 100) //Within limit + { + RSum += Val3; + RCounter++; + } + break; + case 2: //Un-short probes + ShortCircuit(0); //Make sure probes are not shorted + Counter = 100; //Skip test + DisplayFlag = 0; //Reset display flag + break; + case 3: //Internal resistance of �C in pull-down mode + lcd_fixed_string(RiLow_str); //Display: Ri- + //TP1: Gnd -- Ri -- probe -- Rl -- Ri -- Vcc + SetADCLow(); + ADC_DDR = 1 << TP1; + R_PORT = 1 << (TP1 * 2); + R_DDR = 1 << (TP1 * 2); + Val1 = ReadU_5ms(TP1); + U_RiL += Val1; + //TP2: Gnd -- Ri -- probe -- Rl -- Ri -- Vcc + ADC_DDR = 1 << TP2; + R_PORT = 1 << (TP2 * 2); + R_DDR = 1 << (TP2 * 2); + Val2 = ReadU_5ms(TP2); + U_RiL += Val2; + //TP3: Gnd -- Ri -- probe -- Rl -- Ri -- Vcc + ADC_DDR = 1 << TP3; + R_PORT = 1 << (TP3 * 2); + R_DDR = 1 << (TP3 * 2); + Val3 = ReadU_5ms(TP3); + U_RiL += Val3; + RiL_Counter += 3; + break; + case 4: //Internal resistance of �C in pull-up mode + lcd_fixed_string(RiHigh_str); //Display: Ri+ + //TP1: Gnd -- Ri -- Rl -- probe -- Ri -- Vcc + R_PORT = 0; + ADC_PORT = 1 << TP1; + ADC_DDR = 1 << TP1; + R_DDR = 1 << (TP1 * 2); + Val1 = UREF_VCC - ReadU_5ms(TP1); + U_RiH += Val1; + //TP2: Gnd -- Ri -- Rl -- probe -- Ri -- Vcc + ADC_PORT = 1 << TP2; + ADC_DDR = 1 << TP2; + R_DDR = 1 << (TP2 * 2); + Val2 = UREF_VCC - ReadU_5ms(TP2); + U_RiH += Val2; + //TP3: Gnd -- Ri -- Rl -- probe -- Ri -- Vcc + ADC_PORT = 1 << TP3; + ADC_DDR = 1 << TP3; + R_DDR = 1 << (TP3 * 2); + Val3 = UREF_VCC - ReadU_5ms(TP3); + U_RiH += Val3; + RiH_Counter += 3; + break; + case 5: //Capacitance offset (PCB and probe leads) + lcd_fixed_string(CapOffset_str); //Display: C0 + lcd_space(); + lcd_fixed_string(ProbeComb_str); //Display: 12 13 23 + //The capacitance is for two probes and we expect it to be less than 100pF. + MeasureCap(TP2, TP1, 0); + Val1 = (unsigned int)Caps[0].Raw; + //Limit offset to 100pF + if ((Caps[0].Scale == -12) && (Caps[0].Raw <= 100)) + { + CapSum += Val1; + CapCounter++; + } + MeasureCap(TP3, TP1, 1); + Val2 = (unsigned int)Caps[1].Raw; + //Limit offset to 100pF + if ((Caps[1].Scale == -12) && (Caps[1].Raw <= 100)) + { + CapSum += Val2; + CapCounter++; + } + MeasureCap(TP3, TP2, 2); + Val3 = (unsigned int)Caps[2].Raw; + //Limit offset to 100pF + if ((Caps[2].Scale == -12) && (Caps[2].Raw <= 100)) + { + CapSum += Val3; + CapCounter++; + } + break; + } + //Reset ports to defaults + SetADCHiz(); //Input mode + SetADCLow(); //All pins low + R_DDR = 0; //Input mode + R_PORT = 0; //All pins low + //Display values + if (DisplayFlag) + { + lcd_line(1); //Move to line #2 + DisplayValue(Val1, 0 , 0); //Display TP1 + lcd_space(); + DisplayValue(Val2, 0 , 0); //Display TP2 + lcd_space(); + DisplayValue(Val3, 0 , 0); //Display TP3 + } + //Wait and check test push button + if (Counter < 100) //When we don't skip this test + { + #ifdef BUTTON_INST + DisplayFlag = TestKey(1000, 0); //Catch key press or timeout + #else + delay(1000); + DisplayFlag=0; + #endif + //Short press -> next test / long press -> end selftest + if (DisplayFlag > 0) + { + Counter = 100; //Skip current test anyway + if (DisplayFlag == 2) Test = 100; //Also skip selftest + } + } + Counter++; //Next run + } + Test++; //Next one + } + //Calculate values and offsets + //Capacitance auto-zero: calculate average value for all probe pairs + if (CapCounter == 15) + { + //Calculate average offset (pF) + Config.CapZero = CapSum / CapCounter; + Flag++; + } + //Resistance auto-zero: calculate average value for all probes pairs + if (RCounter == 15) + { + //Calculate average offset (0.01 Ohms) + Config.RZero = RSum / RCounter; + Flag++; + } + //RiL & RiH + if ((RiL_Counter == 15) && (RiH_Counter == 15)) + { + /* + Calculate RiL and RiH using the voltage divider rule: + Ri = Rl * (U_Ri / U_Rl) + - scale up by 100, round up/down and scale down by 10 + */ + //Use values multiplied by 3 to increase accuracy + U_RiL /= 5; //Average sum of 3 U_RiL + U_RiH /= 5; //Average sum of 3 U_RiH + Val1 = (UREF_VCC * 3) - U_RiL - U_RiH; //U_Rl * 3 + //RiL, Rl * U_Ri / U_Rl in 0.01 Ohm + Val0 = ((unsigned long)R_LOW * 100 * U_RiL) / Val1; + Val0 += 5; //For automagic rounding + Val0 /= 10; //Scale down to 0.1 Ohm + if (Val0 < 250UL) // < 25 Ohms + { + Config.RiL = (unsigned int)Val0; + Flag++; + } + //RiH, Rl * U_Ri / U_Rl in 0.01 Ohm + Val0 = ((unsigned long)R_LOW * 100 * U_RiH) / Val1; + Val0 += 5; //For automagic rounding + Val0 /= 10; //Scale down to 0.1 Ohm + if (Val0 < 280UL) // < 29 Ohms + { + Config.RiH = (unsigned int)Val0; + Flag++; + } + } + //Show values and offsets + ShowAdjust(); + if (Flag == 4) Flag = 1; //All adjustments done -> success + else Flag = 0; //Signal error + return Flag; +} + +//Show adjustment values and offsets +void ShowAdjust(void) +{ + //Display RiL and RiH + lcd_clear(); + lcd_fixed_string(RiLow_str); //Display: Ri- + lcd_space(); + DisplayValue(Config.RiL, -1, LCD_CHAR_OMEGA); + lcd_line(1); + lcd_fixed_string(RiHigh_str); //Display: Ri+ + lcd_space(); + DisplayValue(Config.RiH, -1, LCD_CHAR_OMEGA); + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Let the user read + #else + delya(3000); + #endif + //Display C-Zero + lcd_clear(); + lcd_fixed_string(CapOffset_str); //Display: C0 + lcd_space(); + DisplayValue(Config.CapZero, -12, 'F'); //Display C0 offset + //Display R-Zero + lcd_line(1); + lcd_fixed_string(ROffset_str); //Display: R0 + lcd_space(); + DisplayValue(Config.RZero, -2, LCD_CHAR_OMEGA);//Display R0 + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Let the user read + #else + delay(3000); + #endif + //Display offset of bandgap reference + lcd_clear(); + lcd_fixed_string(URef_str); //Display: Vref + lcd_space(); + DisplaySignedValue(Config.RefOffset, -3, 'V'); + //Display offset of analog comparator + lcd_line(1); + lcd_fixed_string(CompOffset_str); //Display: AComp + lcd_space(); + DisplaySignedValue(Config.CompOffset, -3, 'V'); + #ifdef BUTTON_INST + TestKey(USER_WAIT, 11); //Let the user read + #else + delay(3000); + #endif +} + +//PWM tool +void PWM_Tool(unsigned int Frequency) +{ + //Use probe #2 (PB2, OC1B) as PWM output and probe #1 + probe #3 as ground - Freqency in Hz + byte Test = 1; //Loop control and user feedback + byte Ratio; //PWM ratio + byte Prescaler; //Timer prescaler + unsigned int Top; //Top value + unsigned int Toggle; //Counter value to toggle output + uint32_t Value; //Temporary value + /* + fast PWM: f = f_MCU / (prescaler * depth) + phase correct PWM: f = f_MCU / (2 * prescaler * depth) + available prescalers: 1, 8, 64, 256, 1024 + depth: 2^x (x is the bit depth) + */ + ShortCircuit(0); //Make sure probes are not shorted + lcd_clear(); + lcd_fixed_string(PWM_str); //Display: PWM + lcd_data(' '); + DisplayValue(Frequency, 0, 'H'); //Display frequency + lcd_data('z'); //Make it Hz :-) + R_PORT = 0; //Make probe #1 and #3 ground + //Set all probes to output mode + R_DDR = (1 << (TP1 * 2)) | (1 << (TP2 * 2)) | (1 << (TP3 * 2)); + //Calculate required prescaler and top value based on MCU clock, depth = f_MCU / (2 * prescaler * f_PWM) + Value = CPU_FREQ / 2; + Value /= Frequency; + if (Value > 2000000) //Low frequency + { + Value /= 256; + Prescaler = (1 << CS12); //256 + } + else if (Value > 16000) //Mid-range frequency + { + Value /= 64; + Prescaler = (1 << CS11) | (1 << CS10); //64 + } + else //High frequency + { + Prescaler = (1 << CS10); //1 + } + Top = (unsigned int)Value; + //Setup timer1 for PWM - PWM, phase correct, top value by OCR1A + Ratio = 50; //Default ratio is 50% + Toggle = (Top / 2) - 1; //Compare value for 50% + //Power save mode would disable timer1 + Config.SleepMode = SLEEP_MODE_IDLE; //Change sleep mode to Idle + TCCR1B = 0; //Disable timer + //Enable OC1B pin and set timer mode + TCCR1A = (1 << WGM11) | (1 << WGM10) | (1 << COM1B1); + TCCR1B = (1 << WGM13); + TCNT1 = 0; //Set counter to 0 + OCR1A = Top - 1; //Set top value (-1) + OCR1B = Toggle; //Set value to compare with + //Enable counter by setting clock prescaler + TCCR1B = (1 << WGM13) | Prescaler; + //Ratio control + while (Test > 0) + { + //Show current ratio + lcd_clear_line(2); + DisplayValue(Ratio, 0, '%'); //Show ratio in % + delay(500); //Smooth UI + //Short key press -> increase ratio, long key press -> decrease ratio, two short key presses -> exit PWM + #ifdef BUTTON_INST + Test = TestKey(0, 0); //Wait for user feedback + #else + delay(3000); + Test=1; + #endif + if (Test == 1) //Short key press + { + delay(50); //Debounce button a little bit longer + #ifdef BUTTON_INST + Prescaler = TestKey(200, 0); //Check for second key press + #else + delay(3000); + Prescaler=0; + #endif + if (Prescaler > 0) //Second key press + { + Test = 0; //End loop + } + else //Single key press + { + if (Ratio <= 95) Ratio += 5; // +5% and limit to 100% + } + } + else //Long key press + { + if (Ratio >= 5) Ratio -= 5; // -5% and limit to 0% + } + //Calculate toggle value: (depth * (ratio / 100)) - 1 + Value = (uint32_t)Top * Ratio; + Value /= 100; + Toggle = (unsigned int)Value; + Toggle--; + OCR1B = Toggle; //Update compare value + } + //Clean up + TCCR1B = 0; //Disable timer + TCCR1A = 0; //Reset flags (also frees PB2) + R_DDR = 0; //Set HiZ mode + Config.SleepMode = SLEEP_MODE_PWR_SAVE; //Reset sleep mode to default +} + + //EEPROM FUNCTIONS +//Update values stored in EEPROM +void SaveEEP(void) +{ + //Ri of �C in low mode + EEPROMWriteInt(1,Config.RiL); + //Ri of �C in low mode + EEPROMWriteInt(3,Config.RiH); + //Resistance of probe leads + EEPROMWriteInt(5,Config.RZero); + //Capacitance offset: PCB + wiring + probe leads + EEPROM.write(7,Config.CapZero); + delay(10); + //Voltage offset of bandgap reference + EEPROM.write(8,Config.RefOffset); + delay(10); + //Voltage offset of analog comparator + EEPROM.write(9,Config.CompOffset); + delay(10); + EEPROM.write(10,126); //Saved :-) + delay(10); +} + +//Read values stored in EEPROM +void ReadEEP(void) +{ + Config.RiL =EEPROMReadInt(1); + Config.RiH = EEPROMReadInt(3); + Config.RZero = EEPROMReadInt(5); + Config.CapZero = EEPROM.read(7); + Config.RefOffset = EEPROM.read(8); + Config.CompOffset = EEPROM.read(9); +} + +//Read a 2 byte integer from the eeprom +unsigned int EEPROMReadInt(int p_address) +{ + byte lowByte = EEPROM.read(p_address); + byte highByte = EEPROM.read(p_address + 1); + return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00); +} + +//Write a 2 byte integer to the eeprom +void EEPROMWriteInt(int p_address, int p_value) +{ + byte lowByte = ((p_value >> 0) & 0xFF); + byte highByte = ((p_value >> 8) & 0xFF); + EEPROM.write(p_address, lowByte); + delay(10); + EEPROM.write(p_address + 1, highByte); + delay(10); +} + + //MENU FUNCTIONS +//Main Menu +void MainMenu(void) +{ + #ifdef DEBUG_PRINT + //Menu via Serial + unsigned int Frequency; //Frequency for PWM Tool + boolean doexit=false; //Exit Menu Flag + do + { + boolean cmdexec=false; //CMD Exec Flag + //Show Menu + Serial.println(); + Serial.println(X("** MAIN MENU")); + Serial.println(); + Serial.println(X(" 1) PWM")); + Serial.println(X(" 2) SelfTest")); + Serial.println(X(" 3) Adjust")); + Serial.println(X(" 4) Save")); + Serial.println(X(" 5) Show")); + Serial.println(X(" 6) Default")); + Serial.print(X(" 0) Exit >")); + //Check for incoming serial data: + do + { + if (Serial.available() > 0) + { + //Read incoming serial data: + char inChar = Serial.read(); + //User Feedback + Serial.println(inChar); + switch((byte)inChar-48) + { + case 1: //Pwm Menu + Serial.println(); + Frequency=selFreq(); + Serial.println(); + Serial.println(X("Info:")); + Serial.println(X(" Short Press +")); + Serial.println(X(" Long Press -")); + Serial.println(X(" Double Press Exit")); + PWM_Tool(Frequency); + Serial.println(); + cmdexec=true; + break; + case 2: //Selftest + SelfTest(); + Serial.println(); + cmdexec=true; + break; + case 3: //Adjust + SelfAdjust(); + Serial.println(); + cmdexec=true; + break; + case 4: //Save + SaveEEP(); + Serial.println(); + cmdexec=true; + case 5: //Show + ShowAdjust(); + Serial.println(); + cmdexec=true; + break; + case 6: //Default Parameters + DefaultPar(); + Serial.println(); + cmdexec=true; + break; + case 0: //Exit + cmdexec=true; + doexit=true; + Serial.println(); + Serial.println(X("Done. Exit")); + return; + default: + //Redo + Serial.print(X(" >")); + cmdexec=false; + doexit=false; + } + } + } while (cmdexec==false); + } while (doexit==false); + #else + delay(800); + LcdMenu(); + #endif +} + +//Select Frequency +unsigned int selFreq(void) +{ + boolean cmdexec=false; //CMD Exec Flag + Serial.println(X("Select Frequency:")); + for(int f; f<8; f++) + { + Serial.print(X(" ")); + Serial.print(f+1); + Serial.print(X(") ")); + DisplayValue(PWM_Freq_table[f], 0, 0); + Serial.println(X("Hz")); + } + Serial.print(X(" >")); + do + { + if (Serial.available() > 0) + { + char inChar = Serial.read(); + byte selNum=(byte)inChar-48; + if (selNum>0 && selNum<9) + { + //User Feedback + Serial.println(inChar); + cmdexec=true; + return PWM_Freq_table[selNum-1]; + } + else + { + //Redo + Serial.println(X(" >")); + cmdexec=false; + } + } + } while (cmdexec==false); + return 100; +} + +//Lcd Menu +void LcdMenu(void) +{ + byte Flag = 1; //Control flag + byte Selected; //ID of selected item + byte ID; //ID of selected item + unsigned int Frequency; //PWM frequency + void *Menu[6]; + //Setup menu + Menu[0] = (void *)PWM_str; + Menu[1] = (void *)Selftest_str; + Menu[2] = (void *)Adjustment_str; + Menu[3] = (void *)Save_str; + Menu[4] = (void *)Show_str; + Menu[5] = (void *)Default_str; + //Run menu + lcd_clear(); + lcd_fixed_string(Select_str); + Selected = MenuTool(6, 1, Menu, NULL); + //Run selected item + switch (Selected) + { + case 0: //PWM tool + //Run PWM menu + lcd_clear(); + lcd_fixed_string(PWM_str); + ID = MenuTool(8, 2, (void **)PWM_Freq_table, (unsigned char *)Hertz_str); + //Get selected frequency + Frequency =PWM_Freq_table[ID]; + PWM_Tool(Frequency); //And run PWM tool + break; + case 1: //Self test + Flag = SelfTest(); + break; + case 2: //Self adjustment + Flag = SelfAdjust(); + break; + case 3: //Save self adjument values + SaveEEP(); + break; + case 4: //Show self adjument values + ShowAdjust(); + break; + } + //Display end of item + lcd_clear(); + if (Flag == 1) + lcd_fixed_string(Done_str); //Display: done! + else + lcd_fixed_string(Error_str); //Display: error! +} + +//Menu Tool +byte MenuTool(byte Items, byte Type, void *Menu[], unsigned char *Unit) +{ + byte Selected = 0; //Return value / ID of selected item + byte Run = 1; //Loop control flag + byte n; //Temp value + void *Address; //Address of menu element + unsigned int Value; //Temp. value + Items--; //To match array counter + lcd_data(':'); //Whatever: + while (Run) + { + //Display item + lcd_clear_line(2); + Address = &Menu[Selected]; //Get address of element + if (Type == 1) //Fixed string + { + lcd_fixed_string(*(unsigned char **)Address); + } + else + { + Value=PWM_Freq_table[Selected]; + DisplayValue(Value, 0, 0); + } + if (Unit) //Optional fixed string + { + lcd_fixed_string(Unit); + } + //Show navigation help + delay(100); //Smooth UI + //Set position: char 16 in line 2 + #ifdef LCD_PRINT + lcd.setCursor(15,2); + #endif + if (Selected < Items) n = 126; //Another item follows + else n = 127; //Last item + lcd_data(n); + //Process user feedback + n = TestKey(0, 0); //Wait for testkey + if (n == 1) //Short key press: moves to next item + { + Selected++; //Move to next item + if (Selected > Items) + { + Selected = 0; //Roll over to first one + } + } + else if (n == 2) //Long key press: select current item + { + Run = 0; + } + } + lcd_clear(); + delay(500); //Smooth UI + return Selected; +} + +//Reset Parameters +void DefaultPar(void) +{ + //Default Values + Config.RiL = R_MCU_LOW; + Config.RiH = R_MCU_HIGH; + Config.RZero = R_ZERO; + Config.CapZero = C_ZERO; + Config.RefOffset = UREF_OFFSET; + Config.CompOffset = COMPARATOR_OFFSET; + //Save to EEProm + SaveEEP(); +} + + + diff --git a/fuzzifikasi/fuzzifikasi.ino b/fuzzifikasi/fuzzifikasi.ino new file mode 100644 index 0000000..869ad22 --- /dev/null +++ b/fuzzifikasi/fuzzifikasi.ino @@ -0,0 +1,76 @@ +float suhu; +float dingin,hangat,panas; +float pwm; +float Lambat,Sedang,Cepat; +unsigned char suhuDingin(){ + if (suhu <= 30){dingin =1;} + else if (suhu >=30 && suhu <=45){dingin=(45-suhu)/15;} + else if (suhu >= 45){dingin =0;} + return dingin; +} +unsigned char suhuHangat(){ + if (suhu <= 30){hangat =0;} + else if (suhu >=30 && suhu <=45){hangat=(suhu-30)/15;} + else if (suhu >=45 && suhu <=60){hangat=(60-suhu)/15;} + else if (suhu >= 60){hangat =0;} + return hangat; +} +unsigned char suhuPanas (){ + if (suhu <=45 ){panas =0;} + else if (suhu >=45 && suhu <=60){panas=(suhu-45)/15;} + else if (suhu >= 60){panas =1;} + return panas; +} +unsigned char pwmLambat(){ + if (pwm <= 100){Lambat =1;} + else if (pwm >=100 && pwm <=150){Lambat=(150-pwm)/50;} + else if (pwm >= 150){Lambat =0;} + return Lambat; +} +unsigned char pwmSedang(){ + if (pwm <= 100){Sedang =0;} + else if (pwm >=100 && pwm <=150){Sedang=(pwm-100)/50;} + else if (pwm >=150 && pwm <=200){Sedang=(200-pwm)/50;} + else if (pwm >= 200){Sedang =0;} + return Sedang; +} +unsigned char pwmCepat (){ + if (pwm <= 100){Lambat =1;} + else if (pwm >=150 && pwm <=200){Cepat=(pwm-150)/50;} + else if (pwm >= 200){Cepat =0;} + return Cepat; +} +void fuzzifikasi(){ + suhuDingin(); + suhuHangat(); + suhuPanas(); + pwmLambat(); + pwmSedang(); + pwmCepat(); +} +void setup() { + // put your setup code here, to run once: +Serial.begin(9600); +suhu = 54; // contoh kita memasukan nilai suhu 54 derajat +pwm = 104; // contoh kita memasukan nilai pwm 104 +fuzzifikasi(); // memanggil fungsi fuzzifikasi untuk menghitung keanggotaan masing2 variable +Serial.print("dingin : "); +Serial.print(dingin); +Serial.print("t"); +Serial.print("hangat : "); +Serial.print(hangat); +Serial.print("t"); +Serial.print("panas : "); +Serial.println(panas); +Serial.print("lambat : "); +Serial.print(Lambat); +Serial.print("t"); +Serial.print("sedang : "); +Serial.print(Sedang); +Serial.print("t"); +Serial.print("cepat : "); +Serial.println(Cepat); +} +void loop() { + // put your main code here, to run repeatedly: +} diff --git a/gas_blynk/gas_blynk.ino b/gas_blynk/gas_blynk.ino new file mode 100644 index 0000000..b7ab592 --- /dev/null +++ b/gas_blynk/gas_blynk.ino @@ -0,0 +1,51 @@ +#define BLYNK_PRINT Serial +#include +#include +BlynkTimer timer; +char auth[] = "********************************"; +char ssid[] = "********************************"; +char pass[] = "********************************"; + +int n; + +void setup() +{ + + Serial.begin(9600); + + Blynk.begin(auth, ssid, pass); + // You can also specify server: + //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80); + //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080); + pinMode(16,OUTPUT); + pinMode(5,OUTPUT); + timer.setInterval(1000L, sendUptime); +} + + +void sendUptime() +{ + Blynk.virtualWrite(V1, n); +} + +void loop() +{ + Blynk.run(); + timer.run(); + + n=analogRead(A0); + Serial.println(n); + + if(n>190) + { + digitalWrite(16,LOW); + digitalWrite(5,HIGH); + } + + if(n<190) + { + digitalWrite(16,HIGH); + digitalWrite(5,LOW); + } + +} diff --git a/gate_otomatis_servo/gate_otomatis_servo.ino b/gate_otomatis_servo/gate_otomatis_servo.ino new file mode 100644 index 0000000..1acf237 --- /dev/null +++ b/gate_otomatis_servo/gate_otomatis_servo.ino @@ -0,0 +1,132 @@ +#include + +//#define Up 40 +//#define Down 0 + +#define trigPin 10 +#define echoPin 13 +#define Servo1 9 // Sinyal Servo1 +#define Bright 11 // Anoda 7Segment + +#define Kapasitas 9 // Jumlah Maks yang bisa di masuk +#define Light 10 // Pengaturan Terang 7 Segment (%) + +#define A 2 +#define B 3 +#define C 4 +#define D 5 // Pin Arduino To 7Segment ABCDEFG +#define E 6 +#define F 7 +#define G 8 + +long duration, distance; +int i=0; +int Tersedia=5; // Variabel Menentukan yang tersedia saat ini +int penuh; +const int buzzer = 12; + +byte segmen [10] = { // Array untuk urutan Tampilan angka 7Segment +// PGFEDCBA <--- Urutan 7segment + B00111111, // number 0 + B00000110, // number 1 + B01011011, // number 2 + B01001111, // number 3 + B01100110, // number 4 + B01101101, // number 5 + B01111101, // number 6 + B00000111, // number 7 + B01111111, // number 8 + B01101111 // number 9 +}; + +byte Full [] = { + B01110001 // Tampilan Kapasitas Penuh (F) +}; + +Servo servo1; + +void setup(){ + Serial.begin(9600); + servo1.attach(9); // turn on servo1 + servo1.write(0); // Set 0 servo1 + pinMode(trigPin, OUTPUT); + pinMode(echoPin, INPUT); + pinMode(A,OUTPUT); + pinMode(B,OUTPUT); + pinMode(C,OUTPUT); + pinMode(D,OUTPUT); + pinMode(E,OUTPUT); + pinMode(F,OUTPUT); + pinMode(G,OUTPUT); + pinMode(Bright,OUTPUT); + pinMode(buzzer, OUTPUT); + tone(buzzer, 2000); // Send 2KHz sound signal... + delay(1000); + noTone(buzzer); // Stop sound... + analogWrite(Bright,255*Light/100); + } + +void loop(){ + analogWrite(Bright,255*Light/100); + Display(Tersedia); + digitalWrite(trigPin, LOW); + delayMicroseconds(2); + digitalWrite(trigPin, HIGH); + delayMicroseconds(10); + digitalWrite(trigPin, LOW); + duration = pulseIn(echoPin, HIGH); + distance = (duration/2) / 29.1; + Serial.print("Jarak: "); + Serial.println(distance); + + if (distance < 16) + { + delay (500); + if(Tersedia == 0){ + if(distance < 16){ + analogWrite(Bright,255*Light/100); + Tampil(penuh); + tone(buzzer, 2000); // Send 2KHz sound signal... + delay(1500); + noTone(buzzer); // Stop sound... + //delay(1000); // ...for 1sec} + //delay(200); + analogWrite(Bright,255*Light/100); + Tampil(penuh);; + delay(1000);} + } + if (Tersedia != 0){ + Tersedia--; + for (i=0; i<=40; i++){ + servo1.write(i); + delay(15);} + delay(3000); + for (i=40; i>=0; i--){ + servo1.write(i); + delay(10);} + } + } +} + +void Display(int number){ + byte seg = ~segmen[number]; //"~" is used for commom anode. + digitalWrite(A, bitRead(seg, 0) ); + digitalWrite(B, bitRead(seg, 1) ); + digitalWrite(C, bitRead(seg, 2) ); + digitalWrite(D, bitRead(seg, 3) ); + digitalWrite(E, bitRead(seg, 4) ); + digitalWrite(F, bitRead(seg, 5) ); + digitalWrite(G, bitRead(seg, 6) ); + } + +void Tampil(int number){ + byte seg = ~Full[number]; //"~" is used for commom anode. + digitalWrite(A, bitRead(seg, 0) ); + digitalWrite(B, bitRead(seg, 1) ); + digitalWrite(C, bitRead(seg, 2) ); + digitalWrite(D, bitRead(seg, 3) ); + digitalWrite(E, bitRead(seg, 4) ); + digitalWrite(F, bitRead(seg, 5) ); + digitalWrite(G, bitRead(seg, 6) ); +} + diff --git a/hasil_output_nilai_sensor_ldr/hasil_output_nilai_sensor_ldr.ino b/hasil_output_nilai_sensor_ldr/hasil_output_nilai_sensor_ldr.ino new file mode 100644 index 0000000..8122033 --- /dev/null +++ b/hasil_output_nilai_sensor_ldr/hasil_output_nilai_sensor_ldr.ino @@ -0,0 +1,22 @@ + + +const int pin_ldr = A2; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + +} + +void loop() { + // put your main code here, to run repeatedly: + int nilai = analogRead (pin_ldr); // nilai analog dari sensor ldr + float tegangan_hasil = 5.0 * nilai / 1024; + //tampilan hasil output nilai analog + Serial.print ("Vout="); + Serial.print (tegangan_hasil); + Serial.print (" V"); + Serial.println(""); + + delay(1000); +} diff --git a/jam_digital/jam_digital.ino b/jam_digital/jam_digital.ino new file mode 100644 index 0000000..f507180 --- /dev/null +++ b/jam_digital/jam_digital.ino @@ -0,0 +1,286 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); +#include + +Time t; + +char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; +#define tahun now.year() +#define bulan now.month() +#define tanggal now.day() +#define hari daysOfTheWeek[now.dayOfTheWeek()] +#define jam now.hour() +#define menit now.minute() +#define detik now.second() +#define addrmenit 0 +#define addrjam 1 +#define addrtanggal 2 +#define addrbulan 3 +#define btnmenu 2 +#define btnup 3 +#define btndown 4 +#define pinBuzzer 13 +byte sel = 0, ajam, amenit, atanggal, abulan, bjam=0, bmenit=0; +boolean state; +char buff[10]; +void setup() +{ + // initialize the LCD + Serial.begin(9600); + lcd.begin(16,2); + pinMode (btnmenu, INPUT_PULLUP); + pinMode (btnup, INPUT_PULLUP); + pinMode (btndown, INPUT_PULLUP); + pinMode (13, OUTPUT); +} +unsigned long waktulama = 0; +int interval = 5000; +void loop() +{ +// t = rtc.now(); + if (digitalRead(btnmenu) == 0) { + while (digitalRead(btnmenu) == 0) {} + sel++; + switch (sel) { + case 0 : + break; + case 1 : + break; + case 2 : + EEPROM.write(addrjam, ajam); + break; + case 3 : + EEPROM.write(addrmenit, amenit); + sel = 0; + break; + // case 4 : + // EEPROM.write(addrtanggal, atanggal); + // break; + // case 5 : + // EEPROM.write(addrtanggal, abulan); + // sel = 0; + // break; + } + } + switch (sel) { + case 0 : + run_alarm(); + break; + case 1 : + lcd.clear (); + set_alarm_jam(); + break; + case 2 : + lcd.clear (); + set_alarm_menit(); + break; + // case 3 : + // lcd.clear (); + // set_alarm_tanggal(); + // break; + // case 4 : + // lcd.clear (); + // set_alarm_bulan(); + // break; + } + if (digitalRead(btnup) == 0) { + while (digitalRead(btnup) == 0) {} + switch (sel) { + case 1: + ajam++; + break; + case 2: + amenit++; + break; + case 3: + atanggal++; + break; + case 4: + abulan++; + break; + } + } + if (digitalRead(btndown) == 0) { + while (digitalRead(btndown) == 0) {} + switch (sel) { + case 1: + ajam--; + break; + case 2: + amenit--; + break; + } + } +} +void tampil_jam () { + t = rtc.now(); + if (jam < 10 && menit < 10) { + sprintf (buff, "0%d:0%d", jam, menit); + } + else if (jam < 10 && menit >= 10) { + sprintf (buff, "0%d:%d", jam, menit); + } + else if (jam >= 10 && menit < 10) { + sprintf (buff, "%d:0%d", jam, menit); + } + else if (jam >= 10 && menit >= 10) { + sprintf (buff, "%d:%d", jam, menit); + } + + + lcd.setCursor (5, 0); + lcd.print(buff); +} +void tampil_tanggal() { +// t = rtc.now(); + if (tanggal < 10 && bulan < 10) { + sprintf (buff, "0%d-0%d-%d", tanggal, bulan, tahun); + } + else if (tanggal < 10 && bulan >= 10) { + sprintf (buff, "0%d-%d-%d", tanggal, bulan, tahun); + } + else if (tanggal >= 10 && bulan < 10) { + sprintf (buff, "%d-0%d-%d", tanggal, bulan, tahun); + } + else if (tanggal >= 10 && bulan >= 10) { + sprintf (buff, "%d-%d-%d", tanggal, bulan, tahun); + } + lcd.setCursor(3, 1); + lcd.print(buff); +} +void set_alarm_jam() { + if (ajam < 10 && amenit < 10) { + sprintf (buff, "0%d:0%d", ajam, amenit); + } + else if (ajam < 10 && amenit >= 10) { + sprintf (buff, "0%d:%d", ajam, amenit); + } + else if (ajam >= 10 && amenit < 10) { + sprintf (buff, "%d:0%d", ajam, amenit); + } + else if (ajam >= 10 && amenit >= 10) { + sprintf (buff, "%d:%d", ajam, amenit); + } + if (ajam > 23) { + ajam = 0; + } + lcd.setCursor(1, 0); + lcd.print("Set nilai Jam"); + lcd.setCursor(5, 1); + lcd.print(buff); +} +void set_alarm_menit() { + if (ajam < 10 && amenit < 10) { + sprintf (buff, "0%d:0%d", ajam, amenit); + } + else if (ajam < 10 && amenit >= 10) { + sprintf (buff, "0%d:%d", ajam, amenit); + } + else if (ajam >= 10 && amenit < 10) { + sprintf (buff, "%d:0%d", ajam, amenit); + } + else if (ajam >= 10 && amenit >= 10) { + sprintf (buff, "%d:%d", ajam, amenit); + } + if (amenit > 59) { + amenit = 0; + } + lcd.setCursor(1, 0); + lcd.print("Set Nilai Menit"); + lcd.setCursor(5, 1); + lcd.print(buff); +} +//void set_alarm_tanggal() { +// DateTime now = rtc.now(); +// if (atanggal < 10 && abulan < 10) { +// sprintf (buff, "0%d-0%d-%d", atanggal, abulan, tahun); +// } +// else if (tanggal < 10 && bulan >= 10) { +// sprintf (buff, "0%d-%d-%d", atanggal, abulan, tahun); +// } +// else if (atanggal >= 10 && abulan < 10) { +// sprintf (buff, "%d-0%d-%d", atanggal, abulan, tahun); +// } +// else if (atanggal >= 10 && abulan >= 10) { +// sprintf (buff, "%d-%d-%d", atanggal, abulan, tahun); +// } +// +// lcd.setCursor(0, 0); +// lcd.print("Set Nilai Tnggl"); +// lcd.setCursor(3, 1); +// lcd.print(buff); +//} +//void set_alarm_bulan() { +// DateTime now = rtc.now(); +// if (atanggal < 10 && abulan < 10) { +// sprintf (buff, "0%d-0%d-%d", atanggal, abulan, tahun); +// } +// else if (tanggal < 10 && bulan >= 10) { +// sprintf (buff, "0%d-%d-%d", atanggal, abulan, tahun); +// } +// else if (atanggal >= 10 && abulan < 10) { +// sprintf (buff, "%d-0%d-%d", atanggal, abulan, tahun); +// } +// else if (atanggal >= 10 && abulan >= 10) { +// sprintf (buff, "%d-%d-%d", atanggal, abulan, tahun); +// } +// +// lcd.setCursor(0, 0); +// lcd.print("Set Nilai Bulan"); +// lcd.setCursor(3, 1); +// lcd.print(buff); +//} +void menu_utama() { + if (state == 1) { + tampil_jam(); + tampil_tanggal(); + } + else if (state == 0) { + tampil_alarm_now(); + } +} +void tampil_alarm_now() { + bjam = EEPROM.read(addrjam); + bmenit = EEPROM.read(addrmenit); + if (bjam < 10 && bmenit < 10) { + sprintf (buff, "0%d:0%d", bjam, bmenit); + } + else if (bjam < 10 && bmenit >= 10) { + sprintf (buff, "0%d:%d", bjam, bmenit); + } + else if (bjam >= 10 && bmenit < 10) { + sprintf (buff, "%d:0%d", bjam, bmenit); + } + else if (bjam >= 10 && bmenit >= 10) { + sprintf (buff, "%d:%d", bjam, bmenit); + } + lcd.setCursor(2, 0); + lcd.print("Alarm di Set"); + lcd.setCursor(5, 1); + lcd.print(buff); +} +void run_alarm() { + t//t = rtc.now(); + if (millis() - waktulama >= interval) { + lcd.clear (); + waktulama = millis(); + if (state == 0) { + state = 1; + } + else if (state == 1) { + state = 0; + } + menu_utama(); + Serial.print(bjam); + Serial.print(":"); + Serial.print(bmenit); + Serial.print("\t"); + Serial.print(bjam); + Serial.print(":"); + Serial.println(bmenit); + if ((jam == bjam) && (menit == bmenit)) { + Serial.println("Alarm"); + digitalWrite(pinBuzzer, state); + } + } +} diff --git a/jam_dtigital_menu/jam_dtigital_menu.ino b/jam_dtigital_menu/jam_dtigital_menu.ino new file mode 100644 index 0000000..5a886ac --- /dev/null +++ b/jam_dtigital_menu/jam_dtigital_menu.ino @@ -0,0 +1,326 @@ +#include +#include +#include +#include +#include "RTClib.h" +RTC_DS3231 rtc; +LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); + +char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; +#define tahun now.year() +#define bulan now.month() +#define tanggal now.day() +#define hari daysOfTheWeek[now.dayOfTheWeek()] +#define jam now.hour() +#define menit now.minute() +#define detik now.second() +#define addrmenit 0 +#define addrjam 1 +#define addrtanggal 2 +#define addrbulan 3 +#define btnmenu 11 +#define btnup 10 +#define btndown 9 +#define pinBuzzer 12 +#define indicator 8 +byte sel = 0, ajam, amenit, atanggal, abulan, bjam=0, bmenit=0; +boolean state; +char buff[10]; + +void setup() +{ + // initialize the LCD + Serial.begin(9600); + lcd.begin(16,2); + pinMode (btnmenu, INPUT_PULLUP); + pinMode (btnup, INPUT_PULLUP); + pinMode (btndown, INPUT_PULLUP); + pinMode (12, OUTPUT); + pinMode (indicator,OUTPUT); + + digitalWrite(12,HIGH); + delay(300); + digitalWrite(12,LOW); + delay(100); + digitalWrite(12,HIGH); + delay(300); + digitalWrite(12,LOW); + delay(100); +} +unsigned long waktulama = 0; +int interval = 5000; +void loop(){ + DateTime now = rtc.now(); + if (digitalRead(btnmenu) == 0) { + while (digitalRead(btnmenu) == 0) {} + sel++; + switch (sel) { + case 0 : + break; + case 1 : + break; + case 2 : + EEPROM.write(addrjam, ajam); + break; + case 3 : + EEPROM.write(addrmenit, amenit); + sel = 0; + break; + case 4 : + EEPROM.write(addrtanggal, atanggal); + break; + case 5 : + EEPROM.write(addrtanggal, abulan); + sel = 0; + break; + } + } + switch (sel) { + case 0 : + run_alarm(); + break; + case 1 : + //lcd.clear (); + set_alarm_jam(); + break; + case 2 : + //lcd.clear (); + set_alarm_menit(); + break; + case 3 : + //lcd.clear (); + set_alarm_tanggal(); + break; + case 4 : + // lcd.clear (); + set_alarm_bulan(); + break; + } + if (digitalRead(btnup) == 0) { + while (digitalRead(btnup) == 0) {} + switch (sel) { + case 1: + ajam++; + break; + case 2: + amenit++; + break; + case 3: + atanggal++; + break; + case 4: + abulan++; + break; + } + } + if (digitalRead(btndown) == 0) { + while (digitalRead(btndown) == 0) {} + switch (sel) { + case 1: + ajam--; + break; + case 2: + amenit--; + break; + } + } +} +void tampil_jam () { + DateTime now = rtc.now(); + if (jam < 10 && menit < 10) { + sprintf (buff, "0%d:0%d", jam, menit); + } + else if (jam < 10 && menit >= 10) { + sprintf (buff, "0%d:%d", jam, menit); + } + else if (jam >= 10 && menit < 10) { + sprintf (buff, "%d:0%d", jam, menit); + } + else if (jam >= 10 && menit >= 10) { + sprintf (buff, "%d:%d", jam, menit); + } + + + lcd.setCursor (5, 1); + lcd.print(buff); +} +void tampil_tanggal() { + DateTime now = rtc.now(); + if (tanggal < 10 && bulan < 10) { + sprintf (buff, "0%d-0%d-%d", tanggal, bulan, tahun); + } + else if (tanggal < 10 && bulan >= 10) { + sprintf (buff, "0%d-%d-%d", tanggal, bulan, tahun); + } + else if (tanggal >= 10 && bulan < 10) { + sprintf (buff, "%d-0%d-%d", tanggal, bulan, tahun); + } + else if (tanggal >= 10 && bulan >= 10) { + sprintf (buff, "%d-%d-%d", tanggal, bulan, tahun); + } + lcd.setCursor(3, 0); + lcd.print(buff); +} +void set_alarm_jam() { + if (ajam < 10 && amenit < 10) { + sprintf (buff, "0%d:0%d", ajam, amenit); + } + else if (ajam < 10 && amenit >= 10) { + sprintf (buff, "0%d:%d", ajam, amenit); + } + else if (ajam >= 10 && amenit < 10) { + sprintf (buff, "%d:0%d", ajam, amenit); + } + else if (ajam >= 10 && amenit >= 10) { + sprintf (buff, "%d:%d", ajam, amenit); + } + if (ajam > 23) { + ajam = 0; + } + lcd.setCursor(1, 0); + lcd.print("Set nilai Jam"); + lcd.setCursor(5, 1); + lcd.print(buff); +} +void set_alarm_menit() { + if (ajam < 10 && amenit < 10) { + sprintf (buff, "0%d:0%d", ajam, amenit); + } + else if (ajam < 10 && amenit >= 10) { + sprintf (buff, "0%d:%d", ajam, amenit); + } + else if (ajam >= 10 && amenit < 10) { + sprintf (buff, "%d:0%d", ajam, amenit); + } + else if (ajam >= 10 && amenit >= 10) { + sprintf (buff, "%d:%d", ajam, amenit); + } + if (amenit > 59) { + amenit = 0; + } + lcd.setCursor(1, 0); + lcd.print("Set Nilai Menit"); + lcd.setCursor(5, 1); + lcd.print(buff); +} +void set_alarm_tanggal() { + DateTime now = rtc.now(); + if (atanggal < 10 && abulan < 10) { + sprintf (buff, "0%d-0%d-%d", atanggal, abulan, tahun); + } + else if (tanggal < 10 && bulan >= 10) { + sprintf (buff, "0%d-%d-%d", atanggal, abulan, tahun); + } + else if (atanggal >= 10 && abulan < 10) { + sprintf (buff, "%d-0%d-%d", atanggal, abulan, tahun); + } + else if (atanggal >= 10 && abulan >= 10) { + sprintf (buff, "%d-%d-%d", atanggal, abulan, tahun); + } + + lcd.setCursor(0, 0); + lcd.print("Set Nilai Tnggl"); + lcd.setCursor(3, 1); + lcd.print(buff); +} +void set_alarm_bulan() { + DateTime now = rtc.now(); + if (atanggal < 10 && abulan < 10) { + sprintf (buff, "0%d-0%d-%d", atanggal, abulan, tahun); + } + else if (tanggal < 10 && bulan >= 10) { + sprintf (buff, "0%d-%d-%d", atanggal, abulan, tahun); + } + else if (atanggal >= 10 && abulan < 10) { + sprintf (buff, "%d-0%d-%d", atanggal, abulan, tahun); + } + else if (atanggal >= 10 && abulan >= 10) { + sprintf (buff, "%d-%d-%d", atanggal, abulan, tahun); + } + + lcd.setCursor(0, 0); + lcd.print("Set Nilai Bulan"); + lcd.setCursor(3, 1); + lcd.print(buff); +} +void menu_utama() { + if (state == 1) { + tampil_jam(); + tampil_tanggal(); + } + else if (state == 0) { + tampil_alarm_now(); + } +} +void tampil_alarm_now() { + bjam = EEPROM.read(addrjam); + bmenit = EEPROM.read(addrmenit); + if (bjam < 10 && bmenit < 10) { + sprintf (buff, "0%d:0%d", bjam, bmenit); + } + else if (bjam < 10 && bmenit >= 10) { + sprintf (buff, "0%d:%d", bjam, bmenit); + } + else if (bjam >= 10 && bmenit < 10) { + sprintf (buff, "%d:0%d", bjam, bmenit); + } + else if (bjam >= 10 && bmenit >= 10) { + sprintf (buff, "%d:%d", bjam, bmenit); + } + lcd.setCursor(2, 0); + lcd.print("Alarm di Set"); + lcd.setCursor(5, 1); + lcd.print(buff); + delay(3000); + lcd.clear(); + lcd.setCursor(2, 0); + lcd.print("Eunbi Line98"); + lcd.setCursor(2, 1); + lcd.print("Robotic Team"); +} +void run_alarm() { + DateTime now = rtc.now(); + if (millis() - waktulama >= interval) { + lcd.clear (); + waktulama = millis(); + if (state == 0) { + state = 1; + } + else if (state == 1) { + state = 0; + } + menu_utama(); + Serial.print(bjam); + Serial.print(":"); + Serial.print(bmenit); + Serial.print("\t"); + Serial.print(bjam); + Serial.print(":"); + Serial.println(bmenit); + if ((jam == bjam) && (menit == bmenit)) { + Serial.println("Alarm"); + digitalWrite(12,HIGH); + delay(50); + digitalWrite(12,LOW); + delay(50); + digitalWrite(12,HIGH); + delay(50); + digitalWrite(12,LOW); + delay(50); + digitalWrite(12,HIGH); + delay(50); + digitalWrite(12,LOW); + delay(50); + digitalWrite(12,HIGH); + delay(50); + digitalWrite(12,LOW); + delay(50); + + } + } + // led indicator + digitalWrite(indicator,HIGH); + delay (1000); + digitalWrite(indicator,LOW); + delay (1000); +} diff --git a/keamanan_rfid/keamanan_rfid.ino b/keamanan_rfid/keamanan_rfid.ino new file mode 100644 index 0000000..cb9e8b2 --- /dev/null +++ b/keamanan_rfid/keamanan_rfid.ino @@ -0,0 +1,97 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); +#include +#include + +#define SS_PIN 10 +#define RST_PIN 9 +#define kontak 3 // kontak sepeda motor +#define hijau 4 // lampu ok +#define merah 5 // lampu error + + +MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. + +void setup() +{ + Serial.begin(9600); + SPI.begin(); + lcd.begin(16,2); + mfrc522.PCD_Init(); + + pinMode(hijau, OUTPUT); + pinMode(merah, OUTPUT); + pinMode(kontak, OUTPUT); + + lcd.setCursor (0,0); + lcd.print(" Pengamanan "); + lcd.setCursor (0,1); + lcd.print(" Sepeda Motor"); + delay (4000); + lcd.clear(); + +} +void loop(){ + lcd.setCursor (0,0); + lcd.print("Please scan card"); + lcd.setCursor (0,1); + lcd.print(" ...<<< Here ");; + + // membaca ID card + if ( ! mfrc522.PICC_IsNewCardPresent()) + { + return; + } + // memilih salah satu card yang terdeteksi + if ( ! mfrc522.PICC_ReadCardSerial()) + { + return; + } + +// clear lcd + lcd.setCursor(0,0); + lcd.print(" "); + lcd.setCursor(0,1); + lcd.print(" "); + //tampilkan ID card di serial monitor + +Serial.print("UID tag :"); + String content= ""; + byte letter; + for (byte i = 0; i < mfrc522.uid.size; i++) + { + Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "); + Serial.print(mfrc522.uid.uidByte[i], HEX); + content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); + content.concat(String(mfrc522.uid.uidByte[i], HEX)); + } + Serial.println(); + Serial.print("Message : "); + content.toUpperCase(); + if (content.substring(1) == "2F 7D 68 68") //ganti dengan ID RFID tag kalian + { + lcd.setCursor(0,0); + lcd.print("Access Accepted"); + lcd.setCursor(0,1); + lcd.print("Start Engine "); + + delay(2000); + digitalWrite(kontak,HIGH); + digitalWrite(hijau,HIGH); + delay(1000); + digitalWrite(hijau,LOW); + + lcd.clear(); + } + + else + { + lcd.setCursor(0,0); + lcd.print(" Access Denied "); + digitalWrite(merah,HIGH); + delay(3000); + digitalWrite(merah,LOW); + digitalWrite(kontak,LOW); + lcd.clear(); + } +} diff --git a/keyboard_communication_led/keyboard_communication_led.ino b/keyboard_communication_led/keyboard_communication_led.ino new file mode 100644 index 0000000..33c8212 --- /dev/null +++ b/keyboard_communication_led/keyboard_communication_led.ino @@ -0,0 +1,84 @@ +int lamp1 = 12,lamp2 = 13,lamp3 = 10,databaca; + +void setup() { +Serial.begin(9600); +pinMode(lamp1, OUTPUT); +pinMode(lamp2, OUTPUT); +pinMode(lamp3, OUTPUT); +} + +void loop() +{ +if (Serial.available()) +{ +int bacadata = Serial.read(); +if (bacadata =='a') {databaca=1;} +if (bacadata =='b') {databaca=2;} +if (bacadata =='c') {databaca=3;} +if (bacadata =='d') {databaca=4;} + + +if(databaca==1) +runn: +{ +digitalWrite(lamp1, HIGH); +delay(100); +digitalWrite(lamp1, LOW); +delay(100); +digitalWrite(lamp2, HIGH); +delay(100); +digitalWrite(lamp2, LOW); +delay(100); +digitalWrite(lamp3, HIGH); +delay(100); +digitalWrite(lamp3, LOW); +delay(100); +Serial.println("LED mode running"); +loop(); +goto runn; +} + +if(databaca==2) +flipflop: +{ +digitalWrite(lamp1, LOW); +digitalWrite(lamp2, LOW); +digitalWrite(lamp3, LOW); +delay(500); +digitalWrite(lamp1, HIGH); +digitalWrite(lamp2, HIGH); +digitalWrite(lamp3, HIGH); +delay(500); +Serial.println("LED mode flip flop"); +loop(); +goto flipflop; +} + +if(databaca==3) +mix: +{ +digitalWrite(lamp1, HIGH); +digitalWrite(lamp2, LOW); +digitalWrite(lamp3, HIGH); +delay(500); +digitalWrite(lamp1, LOW); +digitalWrite(lamp2, HIGH); +digitalWrite(lamp3, LOW); +delay(500); +Serial.println("LED mode mix"); +loop(); +goto mix; +} + +if(databaca==4) +modeoff: +{ +digitalWrite(lamp1,LOW); +digitalWrite(lamp2,LOW); +digitalWrite(lamp3,LOW); +delay(1000); +Serial.println("LED mode off"); +loop(); +goto modeoff; } +} +} diff --git a/keypad/keypad.ino b/keypad/keypad.ino new file mode 100644 index 0000000..a8e9e96 --- /dev/null +++ b/keypad/keypad.ino @@ -0,0 +1,88 @@ +#include //include LCD library (standard library) +#include //include keypad library - first you must install library (library link in the video description) + +#define redLED 10 //define the LED pins +#define greenLED 11 + +char* password ="1234"; //create a password +int pozisyon = 0; //keypad position + +const byte rows = 4; //number of the keypad's rows and columns +const byte cols = 4; + +char keyMap [rows] [cols] = { //define the cymbols on the buttons of the keypad + + {'1', '2', '3', 'A'}, + {'4', '5', '6', 'B'}, + {'7', '8', '9', 'C'}, + {'*', '0', '#', 'D'} +}; + +byte rowPins [rows] = {1, 2, 3, 4}; //pins of the keypad +byte colPins [cols] = {5, 6, 7, 8}; + +Keypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, rows, cols); + +LiquidCrystal lcd (A0, A1, A2, A3, A4, A5); // pins of the LCD. (RS, E, D4, D5, D6, D7) + +void setup(){ + + lcd.begin(16, 2); + pinMode(redLED, OUTPUT); //set the LED as an output + pinMode(greenLED, OUTPUT); + setLocked (true); //state of the password +} + +void loop(){ + + char whichKey = myKeypad.getKey(); //define which key is pressed with getKey + + lcd.setCursor(0, 0); + lcd.print(" Welcome"); + lcd.setCursor(0, 1); + lcd.print(" Enter Password"); + + if(whichKey == '*' || whichKey == '#' || whichKey == 'A' || //define invalid keys + whichKey == 'B' || whichKey == 'C' || whichKey == 'D'){ + + pozisyon=0; + setLocked (true); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" Invalid Key!"); + delay(1000); + lcd.clear(); + } + if(whichKey == password [pozisyon]){ + + pozisyon ++; + } + if(pozisyon == 4){ + setLocked (false); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("*** Verified ***"); + delay(3000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" Mert Arduino"); + lcd.setCursor(0, 1); + lcd.print("Tutorial Project"); + delay(7000); + lcd.clear(); + } + delay(100); +} + +void setLocked(int locked){ + if(locked){ + digitalWrite(redLED, HIGH); + digitalWrite(greenLED, LOW); + } + else{ + digitalWrite(redLED, LOW); + digitalWrite(greenLED, HIGH); + } + } + + diff --git a/keypad_lcd/keypad_lcd.ino b/keypad_lcd/keypad_lcd.ino new file mode 100644 index 0000000..99413c3 --- /dev/null +++ b/keypad_lcd/keypad_lcd.ino @@ -0,0 +1,45 @@ +#include +#include +#include + +#define BINTANG 42 +#define PAGAR 35 +#define TOMBOL_A 65 +#define TOMBOL_B 66 +#define TOMBOL_C 67 +#define TOMBOL_D 68 + +const byte ROWS = 4; //four rows +const byte COLS = 4; //three columns +char keys[ROWS][COLS] = { + {1, 2, 3, 'A'}, + {4, 5, 6, 'B'}, + {7, 8, 9, 'C'}, + {'*','0', '#','D'} +}; +byte rowPins[ROWS] = {7, 6, 5, 4}; //connect to the row pinouts of the keypad +byte colPins[COLS] = {3, 2, 1, 0}; //connect to the column pinouts of the keypad +Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); +// Set the LCD address to 0x27 for a 16 chars and 2 line display +LiquidCrystal_I2C lcd(0x27, 16, 2); +long dtKey=0; +void setup(){ + //Serial.begin(9600); + lcd.begin(); + lcd.backlight(); +} +void loop(){ + char key = keypad.getKey(); + if (key){ + if(key == BINTANG ){ // clear data = tekan *; + lcd.clear(); + dtKey=0; key = 0; + lcd.print(dtKey); + } + + if ( key == 48 )key=0; // conversi variable '0' ke 0 + lcd.clear(); + dtKey = dtKey*10+key; + lcd.print(dtKey); + } +} diff --git a/lampu_control_suara/lampu_control_suara.ino b/lampu_control_suara/lampu_control_suara.ino new file mode 100644 index 0000000..6746aee --- /dev/null +++ b/lampu_control_suara/lampu_control_suara.ino @@ -0,0 +1,22 @@ +boolean lampON=false; +int inSensor = 8; +int lamp = 9; +void setup(){ +pinMode(inSensor, INPUT); +pinMode(lamp, OUTPUT); +digitalWrite(lamp, LOW); +} +void loop(){ +if (digitalRead(inSensor)==0){ +if(lampON==false){ +digitalWrite(lamp, HIGH); +lampON=true; +delay(2000); +} +else{ +digitalWrite(lamp, LOW); +lampON=false; +delay(2000); +} +} +} diff --git a/lampu_keypad_rtc/lampu_keypad_rtc.ino b/lampu_keypad_rtc/lampu_keypad_rtc.ino new file mode 100644 index 0000000..17c7eba --- /dev/null +++ b/lampu_keypad_rtc/lampu_keypad_rtc.ino @@ -0,0 +1,107 @@ +#include +int stop, led1 = 12, led2= 13,menu,menit=57; + +Time t; +DS3231 rtc (SDA,SCL); +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + rtc.begin(); + pinMode(led1,OUTPUT); + pinMode(led2,OUTPUT); + +} + +void loop() { + // put your main code here, to run repeatedly: + int kode = Serial.read(); + if (kode =='a') {menu=1;} + if (kode =='b') {menu=2;} + + if(menu==1){ +Serial.print(rtc.getDOWStr()); + Serial.print(" "); + + // Send date + Serial.print(rtc.getDateStr()); + Serial.print(" -- "); + + // Send time + Serial.println(rtc.getTimeStr()); + + // Wait one second before repeating :) + delay (1000); + + t = rtc.getTime(); + + if (t.hour == 23 & t.min == menit & t.sec == 0){ + + while(t.sec<33){ + + if(t.sec<30) + { + digitalWrite(led1,HIGH); + digitalWrite(led2,LOW); + Serial.println("LED mode on"); + delay(1000); + } + else + { + digitalWrite(led1,LOW); + digitalWrite(led2,HIGH); + delay(1000); + digitalWrite(led2,LOW); + delay(1000); + Serial.println("LED mode blink"); + delay(1000); + } + + t.sec ++; + + } + + menit=menit+1; + + } + + else{ + + digitalWrite(led1,LOW); + digitalWrite(led2,LOW); + Serial.println("LED mode off"); + } + + if(menu==2){ + while(t.sec<33){ + + if(t.sec<30) + { + digitalWrite(led1,HIGH); + digitalWrite(led2,LOW); + Serial.println("LED mode on"); + delay(1000); + } + else + { + digitalWrite(led1,LOW); + digitalWrite(led2,HIGH); + delay(1000); + digitalWrite(led2,LOW); + delay(1000); + Serial.println("LED mode blink"); + delay(1000); + } + + t.sec ++; + + } + + menit=menit+1; + + } + } +} + + + + diff --git a/lcd_default/lcd_default.ino b/lcd_default/lcd_default.ino new file mode 100644 index 0000000..d6bbf51 --- /dev/null +++ b/lcd_default/lcd_default.ino @@ -0,0 +1,18 @@ +#include //mengincludekan library LCD + +//untuk urutannya RS, E, 4, 5, 6, 7 +LiquidCrystal lcd(26, 28, 30, 32, 34, 36); //pin yang disambungkan antara arduino dengan LCD + +void setup() +{ +//prosedur pemanggilan fungsi LCD +lcd.begin(16, 2);//16 = Baris, 2 = kolom +} + +void loop() { +lcd.setCursor(2,0); //set pada baris 1 dan kolom 1 +lcd.print("Robo Arduino"); //menuliskan "nyebarilmu.com" +lcd.setCursor(0,1);//set pada baris 2 dan kolom 1 +lcd.print("--Siskom Asia--"); +delay(3000); //waktu tunda 3 detik +} diff --git a/lcd_menu_coba/lcd_menu_coba.ino b/lcd_menu_coba/lcd_menu_coba.ino new file mode 100644 index 0000000..973dcc9 --- /dev/null +++ b/lcd_menu_coba/lcd_menu_coba.ino @@ -0,0 +1,113 @@ +#include +LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); + +#define sw1 10 +#define sw2 11 +#define sw3 12 +#define led 13 +int ok = 0; +int next = 0; +int back = 0; +void setup() { + +pinMode(sw1, INPUT_PULLUP); +pinMode(sw2, INPUT_PULLUP); +pinMode(sw3, INPUT_PULLUP); +pinMode(led,OUTPUT); + +lcd.begin(16,2); +lcd.setCursor(5,1); +lcd.print("Welcome"); +delay(2000); +lcd.clear(); + +} + +void loop() +{ + +menu: +while(1) +{ +lcd.clear(); +lcd.setCursor(6,0); +lcd.print("Menu"); +lcd.setCursor(0,1); +lcd.print("Please Input!..."); +delay(200); + +ok = digitalRead(sw1); +next = digitalRead(sw2); +back = digitalRead(sw3); +if (ok == LOW) { delay(300); goto menu1; } +if (next == LOW) { } +if (back == LOW) { } +} + +menu1: +while(1) +{ +lcd.clear(); +lcd.setCursor(0,0); +lcd.print("Led"); +lcd.setCursor(0,1); +lcd.print("1.Next 2.Back"); +delay(200); + +digitalWrite(led,LOW); +ok = digitalRead(sw1); +next = digitalRead(sw2); +back = digitalRead(sw3); +if (ok == LOW) { delay(300); goto menu2; } +if (back == LOW) { delay(300); goto menu; } + +} +menu2: +while(1) +{ + +lcd.clear(); +lcd.setCursor(0,0); +lcd.print("1.Led Menyala"); +lcd.setCursor(0,1); +lcd.print("2.Led Mati "); + +digitalWrite(led,LOW); +ok = digitalRead(sw1); +next = digitalRead(sw2); +back = digitalRead(sw3); +if (back == LOW) { delay(300); goto menu4; } +if (next == LOW) { delay(300); goto menu3; } +if (ok == LOW) { } + + +menu3: +while(1) +{ + +lcd.setCursor(0,0); +lcd.print("1.Led Menyala"); +digitalWrite(led,HIGH); + +ok = digitalRead(sw1); +next = digitalRead(sw2); +back = digitalRead(sw3); +if (back == LOW) { delay(300); goto menu1; } + +} +menu4: +while(1) +{ + lcd.clear(); +lcd.setCursor(0,0); +lcd.print("1.Led Mati "); +digitalWrite(led,LOW); + +ok = digitalRead(sw1); +next = digitalRead(sw2); +back = digitalRead(sw3); +if (back == LOW) { delay(300); goto menu1; } + +} +} +} diff --git a/lcd_test/lcd_test.ino b/lcd_test/lcd_test.ino new file mode 100644 index 0000000..3ac1311 --- /dev/null +++ b/lcd_test/lcd_test.ino @@ -0,0 +1,11 @@ +#include +LiquidCrystal_I2C lcd(0x27, 16, 2); +void setup() { + //type lcd +} + +void loop() { + // put your main code here, to run repeatedly: + lcd.setCursor(0,0);// kordinat karakter + lcd.print("sistem komputer"); //tampilan lcd +} diff --git a/ldr_status/ldr_status.ino b/ldr_status/ldr_status.ino new file mode 100644 index 0000000..14ac4b4 --- /dev/null +++ b/ldr_status/ldr_status.ino @@ -0,0 +1,19 @@ +int sensorPin = A0; // select the input pin for LDR + +int sensorValue = 0; // variable to store the value coming from the sensor +void setup() { +Serial.begin(9600); //sets serial port for communication +} +void loop() { +sensorValue = analogRead(sensorPin); // read the value from the sensor +Serial.println(sensorValue); //prints the values coming from the sensor on the screen + +if (sensorValue >20){ + digitalWrite(13,HIGH); + Serial.print("on"); +} +else{ + digitalWrite(13,LOW); +} +delay(100); +} diff --git a/led_berkedip/led_berkedip.ino b/led_berkedip/led_berkedip.ino new file mode 100644 index 0000000..876ff66 --- /dev/null +++ b/led_berkedip/led_berkedip.ino @@ -0,0 +1,26 @@ + +//int ledpin = 2; //sesuai dengan port yg di arduino + +void setup() { + // put your setup code here, to run once: +pinMode(2,OUTPUT); +pinMode(3,OUTPUT); +pinMode(4,OUTPUT); +} + +void loop() { + // put your main code here, to run repeatedly: +digitalWrite(2,HIGH); +delay(100); +digitalWrite(2,LOW); +delay(100); +digitalWrite(3,HIGH); +delay(500); +digitalWrite(3,LOW); +delay(500); +digitalWrite(4,HIGH); +delay(300); +digitalWrite(4,LOW); +delay(300); +} + diff --git a/led_color_control/led_color_control.ino b/led_color_control/led_color_control.ino new file mode 100644 index 0000000..5c7df2d --- /dev/null +++ b/led_color_control/led_color_control.ino @@ -0,0 +1,88 @@ +/************************************************************* + Download latest Blynk library here: + https://github.com/blynkkk/blynk-library/releases/latest + + Blynk is a platform with iOS and Android apps to control + Arduino, Raspberry Pi and the likes over the Internet. + You can easily build graphic interfaces for all your + projects by simply dragging and dropping widgets. + + Downloads, docs, tutorials: http://www.blynk.cc + Sketch generator: http://examples.blynk.cc + Blynk community: http://community.blynk.cc + Follow us: http://www.fb.com/blynkapp + http://twitter.com/blynk_app + + Blynk library is licensed under MIT license + This example code is in public domain. + + ************************************************************* + + Blynk using a LED widget on your phone! + + App project setup: + LED widget on V1 + *************************************************************/ + +/* Comment this out to disable prints and save space */ +#define BLYNK_PRINT Serial + + +#include +#include + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +char auth[] = "YourAuthToken"; + +// Your WiFi credentials. +// Set password to "" for open networks. +char ssid[] = "YourNetworkName"; +char pass[] = "YourPassword"; + +WidgetLED led1(V1); + +BlynkTimer timer; +bool ledStatus = false; + +#define BLYNK_GREEN "#23C48E" +#define BLYNK_BLUE "#04C0F8" +#define BLYNK_YELLOW "#ED9D00" +#define BLYNK_RED "#D3435C" +#define BLYNK_DARK_BLUE "#5F7CD8" + +// V1 LED Widget is blinking +void blinkLedWidget() +{ + if (ledStatus) { + led1.setColor(BLYNK_RED); + Serial.println("LED on V1: red"); + ledStatus = false; + } else { + led1.setColor(BLYNK_GREEN); + Serial.println("LED on V1: green"); + ledStatus = true; + } +} + +void setup() +{ + // Debug console + Serial.begin(9600); + + Blynk.begin(auth, ssid, pass); + // You can also specify server: + //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80); + //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080); + + // Turn LED on, so colors are visible + led1.on(); + // Setup periodic color change + timer.setInterval(1000L, blinkLedWidget); +} + +void loop() +{ + Blynk.run(); + timer.run(); +} diff --git a/led_control/led_control.ino b/led_control/led_control.ino new file mode 100644 index 0000000..017ca0e --- /dev/null +++ b/led_control/led_control.ino @@ -0,0 +1,21 @@ + + +#define BLYNK_PRINT Serial // Comment this out to disable prints and save space +#include +#include + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +char auth[] = "Enter you Auth Token"; + +void setup() +{ + Serial.begin(9600); + Blynk.begin(auth, "wifi router name ", "wifi router pass"); +} + +void loop() +{ + Blynk.run(); +} + diff --git a/led_kelip/led_kelip.ino b/led_kelip/led_kelip.ino new file mode 100644 index 0000000..6454bfb --- /dev/null +++ b/led_kelip/led_kelip.ino @@ -0,0 +1,22 @@ +#define led1 7 +#define led2 9 +void setup() { + // put your setup code here, to run once: + pinMode(led1,OUTPUT); + pinMode(led2,OUTPUT); + +} + +void loop() { + // put your main code here, to run repeatedly: + + digitalWrite(led1,HIGH); + delay(2000); + digitalWrite(led1,LOW); + delay(2000); + + digitalWrite(led2,HIGH); + delay(2000); + digitalWrite(led2,LOW); + delay(2000); +} diff --git a/led_pushbutton/led_pushbutton.ino b/led_pushbutton/led_pushbutton.ino new file mode 100644 index 0000000..427a8e0 --- /dev/null +++ b/led_pushbutton/led_pushbutton.ino @@ -0,0 +1,89 @@ +int led1 = 2 ; +int led2 = 3 ; +int led3 = 4 ; + +int button1 = 6 ; +int button2 = 7 ; +int button3 = 8 ; + +void setup() { + // put your setup code here, to run once: +pinMode (led1, OUTPUT); +pinMode (led2, OUTPUT); +pinMode (led3, OUTPUT); +pinMode (button1, INPUT); +pinMode (button2, INPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + if (digitalRead(button1) == LOW) { + + digitalWrite(led1, HIGH); + digitalWrite(led2, LOW); + digitalWrite(led3, LOW); + +delay(200); + + digitalWrite(led1, LOW); + digitalWrite(led2, HIGH); + digitalWrite(led3, LOW); + +delay(200); + + digitalWrite(led1, LOW); + digitalWrite(led2, LOW); + digitalWrite(led3, HIGH); + +delay(200); + } + + else if (digitalRead(button2) == LOW) { + + digitalWrite(led1,LOW); + digitalWrite(led2, LOW); + digitalWrite(led3, HIGH); + +delay(200); + + digitalWrite(led1, LOW); + digitalWrite(led2, HIGH); + digitalWrite(led3, LOW); + +delay(200); + + digitalWrite(led1, HIGH); + digitalWrite(led2, LOW); + digitalWrite(led3, LOW); + +delay(200); + } + + else if (digitalRead(button3) == LOW) { + + digitalWrite(led1,HIGH); + digitalWrite(led2, LOW); + digitalWrite(led3, HIGH); + +delay(200); + + digitalWrite(led1, LOW); + digitalWrite(led2, HIGH); + digitalWrite(led3, LOW); + +delay(150); + + digitalWrite(led1, HIGH); + digitalWrite(led2, LOW); + digitalWrite(led3, HIGH); + +delay(200); + } + + else { + // turn LED off: + digitalWrite(led1, LOW); + digitalWrite(led2, LOW); + digitalWrite(led3, LOW); + } + } diff --git a/line_follower_arduino_nano/line_follower_arduino_nano.ino b/line_follower_arduino_nano/line_follower_arduino_nano.ino new file mode 100644 index 0000000..b48e09a --- /dev/null +++ b/line_follower_arduino_nano/line_follower_arduino_nano.ino @@ -0,0 +1,175 @@ +#include +#include +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +#define kendaliLed1 12 +#define kendaliLed2 13 +#define kendaliTombol 2 +unsigned int sensor[8], nilaiMin[8], nilaiMax[8], nilaiRef[8]; +int i, x=0; +boolean biner[8]; +void KendaliSelector(int c, int b, int a){ + digitalWrite (A1, a); + digitalWrite (A2, b); + digitalWrite (A3, c); +} +void KendaliBacasensor (){ + KendaliSelector (0,0,0); + sensor[0] = analogRead (A0)/4; + KendaliSelector (0,0,1); + sensor[1] = analogRead (A0)/4; + KendaliSelector (0,1,0); + sensor[2] = analogRead (A0)/4; + KendaliSelector (0,1,1); + sensor[3] = analogRead (A0)/4; + KendaliSelector (1,0,0); + sensor[4] = analogRead (A0)/4; + KendaliSelector (1,0,1); + sensor[5] = analogRead (A0)/4; + KendaliSelector (1,1,0); + sensor[6] = analogRead (A0)/4; + KendaliSelector (1,1,1); + sensor[7] = analogRead (A0)/4; +} +void KendaliTampilsensor (){ + bacaSensorbiner(); + lcd.clear(); + lcd.setCursor(0,0); + lcd.print(biner[0]); + lcd.setCursor(1,0); + lcd.print(biner[1]); + lcd.setCursor(2,0); + lcd.print(biner[2]); + lcd.setCursor(3,0); + lcd.print(biner[3]); + lcd.setCursor(4,0); + lcd.print(biner[4]); + lcd.setCursor(5,0); + lcd.print(biner[5]); + lcd.setCursor(6,0); + lcd.print(biner[6]); + lcd.setCursor(7,0); + lcd.print(biner[7]); + lcd.setCursor (1,1); + lcd.print ("Sensor Biner"); +} +void setup() { +pinMode (A1, OUTPUT); +pinMode (A2, OUTPUT); +pinMode (A3, OUTPUT); +pinMode (kendaliLed1, OUTPUT); +pinMode (kendaliLed2, OUTPUT); +pinMode (kendaliTombol, INPUT); +digitalWrite(kendaliTombol, HIGH); +Serial.begin(9600); +lcd.begin(16,2); +dataSensor(); +} +void loop() { +tampilDatasensor(); +if (digitalRead(kendaliTombol)==LOW){ + while (digitalRead(kendaliTombol)==LOW){ + } + kalibrasi(); +} + + KendaliTampilsensor (); +} +void kalibrasi (){ + lcd.clear(); + lcd.print ("kalibrasi on !"); + Serial.println ("kalibrasi on !"); + for (i=0; i<8; i++){ + nilaiMin[i] = 1023; + nilaiMax[i] = 0; + } + delay(100); + while (digitalRead(kendaliTombol) == HIGH){ + digitalWrite (12, HIGH); + digitalWrite (13, LOW); + delay(100); + KendaliBacasensor(); + for(i=0;i<8;i++){ + if(sensor[i] > nilaiMax[i]) nilaiMax[i] = sensor[i]; + if(sensor[i] < nilaiMin[i]) nilaiMin[i] = sensor[i]; + } + digitalWrite (12, LOW); + digitalWrite (13, HIGH); + delay(100); + } + lcd.clear(); + lcd.print("Kalibrasi DONE!!"); + Serial.println("Kalibrasi DONE!!"); + digitalWrite (12, HIGH); + digitalWrite (13, HIGH); + for(i=0;i<8;i++){ + nilaiRef[i] = (nilaiMax[i] + nilaiMin[i])/2.1; + EEPROM.write(i,nilaiRef[i]); + } + delay(500); +} +void bacaSensorbiner(){ + KendaliBacasensor(); + if (sensor[0] > nilaiRef[0]){ + biner[0] = 0; + } + else { + biner[0] = 1; + } + if (sensor[1] > nilaiRef[1]){ + biner[1] = 0; + } + else { + biner[1] = 1; + } + if (sensor[2] > nilaiRef[2]){ + biner[2] = 0; + } + else { + biner[2] = 1; + } + if (sensor[3] > nilaiRef[3]){ + biner[3] = 0; + } + else { + biner[3] = 1; + } + if (sensor[4] > nilaiRef[4]){ + biner[4] = 0; + } + else { + biner[4] = 1; + } + if (sensor[5] > nilaiRef[5]){ + biner[5] = 0; + } + else { + biner[5] = 1; + } + if (sensor[6] > nilaiRef[6]){ + biner[6] = 0; + } + else { + biner[6] = 1; + } + if (sensor[7] > nilaiRef[7]){ + biner[7] = 0; + } + else { + biner[7] = 1; + } +} +void tampilDatasensor(){ + for(i=0;i<8;i++){ + Serial.print(sensor[i]); + Serial.print(" "); + } + Serial.println(" "); + delay(100); +} +void dataSensor(){ + for(i=0;i<8;i++){ + nilaiRef[i]=EEPROM.read(i); + } +} diff --git a/line_follower_basic/line_follower_basic.ino b/line_follower_basic/line_follower_basic.ino new file mode 100644 index 0000000..9df4e6b --- /dev/null +++ b/line_follower_basic/line_follower_basic.ino @@ -0,0 +1,71 @@ +#define m1 3 +#define m2 5 +#define m3 9 +#define m4 10 + +int arrow =0; +void setup() { + + +pinMode(m1,OUTPUT); +pinMode(m2,OUTPUT); +pinMode(m3,OUTPUT); +pinMode(m4,OUTPUT); +pinMode(12,INPUT); +pinMode(13,INPUT); + +} + +void loop() { + +// pembacaan sensor pada pin 12 dan 13 + +int lsensor=digitalRead(12); +int rsensor=digitalRead(13); + +//logika robot menggunakan prinsip AND +if((lsensor == LOW)&&(rsensor== HIGH)) +{ +// maju dengan kecepatan 100 +motorOut(100,100,2); + +} +if((lsensor== HIGH)&&(rsensor== LOW)) +{ +//belok kiri +motorOut(0,100,2); + +} + +if((lsensor==HIGH)&&(rsensor== HIGH)) +{ +motorOut(0,100,2); + +//belok kiri + +} +if((lsensor== LOW)&&(rsensor==LOW)) +{ +//belok kanan +motorOut(100,0,2); +} +} + +//Fungsi untuk menggerakkan motor +void motorOut(unsigned char lpwm, unsigned char rpwm, int arrow){ +//arrow =1 mundur, 2 maju, +if(arrow==1){ +digitalWrite(m3,HIGH); +digitalWrite(m1,LOW); +analogWrite(m4,255-lpwm); +analogWrite(m2,rpwm); +} +else if (arrow==2) +{ +digitalWrite(m3,LOW); +digitalWrite(m1,HIGH); +analogWrite(m4,lpwm); +analogWrite(m2,255-rpwm); +} + +} diff --git a/milis_3Led/milis_3Led.ino b/milis_3Led/milis_3Led.ino new file mode 100644 index 0000000..2970fa9 --- /dev/null +++ b/milis_3Led/milis_3Led.ino @@ -0,0 +1,43 @@ +int pin1 = 8; // Pin LED1 +int pin2 = 9; // Pin LED2 +int pin3 = 10; // Pin LED3 +long tunggu1 = 3000; // Waktu tunggu LED1 +long tunggu2 = 4000; // Waktu tunggu LED2 +long tunggu3 = 5000; // Waktu tunggu LED3 +long mati = 6000; // Waktu tunggu MATI +long mulai; // Waktu mulai + +void setup() +{ + // Set pin sebagai output + pinMode(pin1, OUTPUT); + pinMode(pin2, OUTPUT); + pinMode(pin3, OUTPUT); + + // Catat waktu sekarang ke variable mulai + mulai = millis(); +} + +void loop() { + awal: + // Apakah waktu kini sudah melewati waktu tunggu1 ? + if ( millis() > mulai + tunggu1 ) { + digitalWrite(pin1, HIGH); // Bila ya, nyalakan LED1 + } + + // Apakah waktu kini sudah melewati waktu tunggu2 ? + if ( millis() > mulai + tunggu2 ) { + digitalWrite(pin2, HIGH); // Bila ya, nyalakan LED2 + } + + // Apakah waktu kini sudah melewati waktu tunggu3 ? + if ( millis() > mulai + tunggu3 ) { + digitalWrite(pin3, HIGH); // Bila ya, nyalakan LED3 + } + if ( millis() > mulai + mati ) { + digitalWrite(pin3, LOW); // mati + digitalWrite(pin2, LOW); // mati + digitalWrite(pin1, LOW); // mati + } + goto awal; +} diff --git a/motor_stepper_stepOne/motor_stepper_stepOne.ino b/motor_stepper_stepOne/motor_stepper_stepOne.ino new file mode 100644 index 0000000..8e609ba --- /dev/null +++ b/motor_stepper_stepOne/motor_stepper_stepOne.ino @@ -0,0 +1,42 @@ +/* + Stepper Motor Control - one step at a time + + This program drives a unipolar or bipolar stepper motor. + The motor is attached to digital pins 8 - 11 of the Arduino. + + The motor will step one step at a time, very slowly. You can use this to + test that you've got the four wires of your stepper wired to the correct + pins. If wired correctly, all steps should be in the same direction. + + Use this also to count the number of steps per revolution of your motor, + if you don't know it. Then plug that number into the oneRevolution + example to see if you got it right. + + Created 30 Nov. 2009 + by Tom Igoe + + */ + +#include + +const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution +// for your motor + +// initialize the stepper library on pins 8 through 11: +Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); + +int stepCount = 0; // number of steps the motor has taken + +void setup() { + // initialize the serial port: + Serial.begin(9600); +} + +void loop() { + // step one step: + myStepper.step(1); + Serial.print("steps:"); + Serial.println(stepCount); + stepCount++; + delay(500); +} diff --git a/mq2_blynk/mq2_blynk.ino b/mq2_blynk/mq2_blynk.ino new file mode 100644 index 0000000..9101df9 --- /dev/null +++ b/mq2_blynk/mq2_blynk.ino @@ -0,0 +1,55 @@ +#include +#define BLYNK_PRINT Serial +#include +#include + +#include +#include + + +//change this with the pin that you use +int pin = A0; +int lpg, co, smoke; + +MQ2 mq2(pin); + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +char auth[] = "********************************"; +char ssid[] = "********************************"; +char pass[] = "********************************"; + +SimpleTimer timer; + +void setup() { + Blynk.begin(auth, server, 8080); + mq2.begin(); + timer.setInterval(2000L, gas); +} + +void gas() { + + /*read the values from the sensor, it returns + an array which contains 3 values. + 1 = LPG in ppm + 2 = CO in ppm + 3 = SMOKE in ppm + */ + float* values = mq2.read(true); //set it false if you don't want to print the values in the Serial + + //lpg = values[0]; + lpg = mq2.readLPG(); + Blynk.virtualWrite(1, lpg); + //co = values[1]; + co = mq2.readCO(); + Blynk.virtualWrite(2, co); + //smoke = values[2]; + smoke = mq2.readSmoke(); + Blynk.virtualWrite(3, smoke); +} + +void loop() +{ + Blynk.run(); + timer.run(); +} diff --git a/music_visualizer/music_visualizer.ino b/music_visualizer/music_visualizer.ino new file mode 100644 index 0000000..3a0119f --- /dev/null +++ b/music_visualizer/music_visualizer.ino @@ -0,0 +1,148 @@ +const int DA = A0; +const int led_01 = 4; +const int led_02 = 5; +const int led_03 = 6; +const int led_04 = 7; +const int led_05 = 8; +const int led_06 = 9; +const int led_07 = 10; +const int led_08 = 11; +const int led_09 = 12; + +int sVal_01 = 500; // Initial Threshold +int sVal_02 = 504; +int sVal_03 = 508; +int sVal_04 = 508; +int sVal_05 = 512; +int sVal_06 = 516; +int sVal_07 = 520; +int sVal_08 = 524; +int sVal_09 = 528; + +int lastPin = 12; +int totalLED = 9; + +int debugSwitch = true; +int ledTest = true; + + +int sensorvalue = 0; + +void setup() { + Serial.begin(9600); + for (int i = 3; i <= lastPin; i++) { + pinMode(i, OUTPUT); + } + + if (ledTest == true) { + testLight(); + } +} + +void loop() { + sensorvalue = analogRead(DA); + if (debugSwitch == true) { + debug(); + } else { + Serial.println("The debugging mode is set to false!"); + } + musicLights(); +} + +void debug() { + Serial.print("Sound Value: "); + + if (sensorvalue >= sVal_01) { + Serial.print(sensorvalue); + Serial.println(" - LED ON!"); + } else { + Serial.println(sensorvalue); + } +} + +void testLight() { + digitalWrite(led_05, HIGH); + delay(1000); + digitalWrite(led_04, HIGH); + digitalWrite(led_06, HIGH); + delay(1000); + digitalWrite(led_03, HIGH); + digitalWrite(led_07, HIGH); + delay(1000); + digitalWrite(led_02, HIGH); + digitalWrite(led_08, HIGH); + delay(1000); + digitalWrite(led_01, HIGH); + digitalWrite(led_09, HIGH); + delay(2000); + digitalWrite(led_01, LOW); + digitalWrite(led_09, LOW); + delay(500); + digitalWrite(led_02, LOW); + digitalWrite(led_08, LOW); + delay(500); + digitalWrite(led_03, LOW); + digitalWrite(led_07, LOW); + delay(500); + digitalWrite(led_04, LOW); + digitalWrite(led_06, LOW); + delay(500); + digitalWrite(led_05, LOW); +} + +void musicLights() { + + if(sensorvalue >= sVal_01) { + digitalWrite(led_05, HIGH); + } else { + digitalWrite(led_05, LOW); + } + + if(sensorvalue >= sVal_02) { + digitalWrite(led_04, HIGH); + } else { + digitalWrite(led_04, LOW); + } + + if(sensorvalue >= sVal_03) { + digitalWrite(led_06, HIGH); + } else { + digitalWrite(led_06, LOW); + } + + if(sensorvalue >= sVal_04) { + digitalWrite(led_03, HIGH); + } else { + digitalWrite(led_03, LOW); + } + + if(sensorvalue >= sVal_05) { + digitalWrite(led_07, HIGH); + } else { + digitalWrite(led_07, LOW); + } + + if(sensorvalue >= sVal_06) { + digitalWrite(led_02, HIGH); + } else { + digitalWrite(led_02, LOW); + } + + if(sensorvalue >= sVal_07) { + digitalWrite(led_08, HIGH); + } else { + digitalWrite(led_08, LOW); + } + + if(sensorvalue >= sVal_08) { + digitalWrite(led_01, HIGH); + } else { + digitalWrite(led_01, LOW); + } + + if(sensorvalue >= sVal_09) { + digitalWrite(led_09, HIGH); + } else { + digitalWrite(led_09, LOW); + } +} diff --git a/parkingLot/parkingLot.ino b/parkingLot/parkingLot.ino new file mode 100644 index 0000000..2076b5c --- /dev/null +++ b/parkingLot/parkingLot.ino @@ -0,0 +1,101 @@ +/*ParkingL02.pde +Arduining.com 08 JUL 2012 +Code used in the production of the Youtube material. +*/ + +#include +Servo myservo; // create servo object to control a servo + +#define ServoM 12 //Connected to the servo motor. +#define Bright 11 //servo library disable PWM on pins 9 and 10. +#define Exit 9 //Pin connected to the EXIT button. +#define In 8 //Pin connected to the IN button. + +#define BarLow 177 //Low position of the barrier. +#define BarUp 95 //Up position of the barrier. +#define CAPACITY 8 //Capacity of the parking lot. +#define INTEN 80 //Display intensity % + +//Pins conections to segments (cathodes). +#define segA 0 +#define segB 1 +#define segC 2 +#define segD 3 +#define segE 4 +#define segF 5 +#define segG 6 + +//Array with the segments to represent the decimal numbers (0-9). +byte segments[10] = { +// pgfedcba <--- segments + B00111111, // number 0 + B00000110, // number 1 + B01011011, // number 2 + B01001111, // number 3 + B01100110, // number 4 + B01101101, // number 5 + B01111101, // number 6 + B00000111, // number 7 + B01111111, // number 8 + B01101111 // number 9 +}; + +void setup(){ + myservo.attach(ServoM); // attaches the servo. + + pinMode(Exit, INPUT); // set "EXIT" button pin to input + pinMode(In, INPUT); // set "IN" button pin to input + digitalWrite(Exit, HIGH); // Connect Pull-Up resistor. + digitalWrite(In, HIGH); // Connect Pull-Up resistor. + pinMode(segA,OUTPUT); + pinMode(segB,OUTPUT); + pinMode(segC,OUTPUT); + pinMode(segD,OUTPUT); + pinMode(segE,OUTPUT); + pinMode(segF,OUTPUT); + pinMode(segG,OUTPUT); + pinMode(Bright,OUTPUT); + analogWrite(Bright,255*INTEN/100); + myservo.write(BarLow); //Barrier in the low position +// delay(1000); +} + +int Available= 9; // Number of places available. + +//================================================================ +void loop(){ +Display(Available); +if(digitalRead(In)==0) +{ + if(Available != 0){ + Available--; + myservo.write(BarUp); + delay(3000); + myservo.write(BarLow); + } + } +if(digitalRead(Exit)==0) +{ + if(Available != CAPACITY){ + Available++; + myservo.write(BarUp); + delay(3000); + myservo.write(BarLow); + } + } +} + +/*------------------------------------------------------------------- +Put the segments according to the number. +--------------------------------------------------------------------*/ +void Display(int number){ +byte segs = ~segments[number]; //"~" is used for commom anode. + +digitalWrite(segA, bitRead(segs, 0) ); +digitalWrite(segB, bitRead(segs, 1) ); +digitalWrite(segC, bitRead(segs, 2) ); +digitalWrite(segD, bitRead(segs, 3) ); +digitalWrite(segE, bitRead(segs, 4) ); +digitalWrite(segF, bitRead(segs, 5) ); +digitalWrite(segG, bitRead(segs, 6) ); +} diff --git a/parking_lot_LED/parking_lot_LED.ino b/parking_lot_LED/parking_lot_LED.ino new file mode 100644 index 0000000..a7716bc --- /dev/null +++ b/parking_lot_LED/parking_lot_LED.ino @@ -0,0 +1,237 @@ +// out1 & in1 = button +// in & out = sensor IR +#define out1 22 +#define in1 24 +#define in 26 +#define out 28 +#include +#include +#include + +LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE); +// Number of steps per internal motor revolution +const float STEPS_PER_REV = 32; + +// Amount of Gear Reduction +const float GEAR_RED = 64; + +const float STEPS_PER_OUT_REV = STEPS_PER_REV * GEAR_RED; + +// Number of Steps Required +int StepsRequired; + +Stepper steppermotor(STEPS_PER_REV, 8, 10, 9, 11); + +int state=0; +int lastState=0; +int counter=0; +int value = 0; +int kondisi=0; + +// slot parkir +#define s1 A6 +#define s2 A7 +#define s3 A8 +#define s4 A9 +#define s5 A10 +#define s6 A11 +#define s7 A12 +#define s8 A13 +#define s9 A14 +#define s10 A15 +// indikator +#define Led1 53 +#define Led2 51 +#define Led3 49 +#define Led4 47 +#define Led5 45 +#define Led6 43 +#define Led7 41 +#define Led8 39 +#define Led9 37 +#define Led10 35 + +int nilait=350; + +int slot1=0; +int slot2=0; +int slot3=0; +int slot4=0; +int slot5=0; +int slot6=0; +int slot7=0; +int slot8=0; +int slot9=0; +int slot10=0; + +void setup() { + // put your setup code here, to run once: +lcd.begin(16,2); +pinMode(in , INPUT_PULLUP); +pinMode(out, INPUT_PULLUP); +pinMode(in1,INPUT); +pinMode(out1,INPUT); + +// led +pinMode(Led1,OUTPUT); +pinMode(Led2,OUTPUT); +pinMode(Led3,OUTPUT); +pinMode(Led4,OUTPUT); +pinMode(Led5,OUTPUT); +pinMode(Led6,OUTPUT); +pinMode(Led7,OUTPUT); +pinMode(Led8,OUTPUT); +pinMode(Led9,OUTPUT); +pinMode(Led10,OUTPUT); + + // Print a message to the LCD. + lcd.backlight(); + // Print a message to the LCD. + lcd.backlight(); + lcd.setCursor(9, 1); + delay(1500); +lcd.clear(); +Serial.begin(9600); +} + +void loop() { +// portal sensor IR Plus button + if(digitalRead(in)==LOW){ + state=1; + } + else if(digitalRead(out)==LOW){ + state=2; + } + else if(digitalRead(in1)==LOW){ + state=3; + } + else if(digitalRead(out1)==LOW){ + state=4; + } + +if(state != lastState){ + if(value!=10){ + //angkat portal + if(state==1 && kondisi==0){ + // value++; + StepsRequired = - STEPS_PER_OUT_REV / 4; + steppermotor.setSpeed(500); + steppermotor.step(StepsRequired); + kondisi=1; + }} + if(value!=0){ + if(state==2 && kondisi == 0){ + + StepsRequired = - STEPS_PER_OUT_REV / 4; + steppermotor.setSpeed(500); + steppermotor.step(StepsRequired); + kondisi=2; + }} + + //tutup portal + if(state==3 && kondisi==1) { + value++; + StepsRequired = STEPS_PER_OUT_REV / 4; + steppermotor.setSpeed(500); + steppermotor.step(StepsRequired); + //delay(100); + kondisi=0; + } + if(state==4 && kondisi==2) { + value--; + StepsRequired = STEPS_PER_OUT_REV / 4; + steppermotor.setSpeed(500); + steppermotor.step(StepsRequired); + //delay(100); + kondisi=0; + } + + + if(value==10 && state==1){ + lcd.setCursor(0, 1); + lcd.print("parkir penuh"); + delay(1500); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("PARLING LOT"); + lcd.setCursor(0, 1); + lcd.print("Sisa Parkir:"); + } + + + lastState=state; + +// slot parkir +} + if(slot1>=nilait){ + digitalWrite(Led1,HIGH); + + } + else if(slot1<=nilait){ + digitalWrite(Led1,LOW); + } + if(slot2>=nilait){ + digitalWrite(Led2,HIGH); + + } + else if(slot2<=nilait){ + digitalWrite(Led2,LOW); + } + + if(slot3>=200){ + digitalWrite(Led3,HIGH); + } + else if(slot3<=200){ + digitalWrite(Led3,LOW); + } + + if(slot4>=nilait){ + digitalWrite(Led4,HIGH); + } + else if(slot4<=nilait){ + digitalWrite(Led4,LOW); + } + + if(slot5>=nilait){ + digitalWrite(Led5,HIGH); + } + else if(slot5<=nilait){ + digitalWrite(Led5,LOW); + } + + if(slot6>=nilait){ + digitalWrite(Led6,HIGH); + } + else if(slot6<=nilait){ + digitalWrite(Led6,LOW); + } + + if(slot7>=nilait){ + digitalWrite(Led7,HIGH); + } + else if(slot7<=nilait){ + digitalWrite(Led7,LOW); + } + + if(slot8>=nilait){ + digitalWrite(Led8,HIGH); + } + else if(slot8<=nilait){ + digitalWrite(Led8,LOW); + } + + if(slot9>=nilait){ + digitalWrite(Led9,HIGH); + } + else if(slot9<=nilait){ + digitalWrite(Led9,LOW); + } + + if(slot10>=nilait){ + digitalWrite(Led10,HIGH); + } + else if(slot10<=nilait){ + digitalWrite(Led10,LOW); + } +} + diff --git a/pengaris_digital/pengaris_digital.ino b/pengaris_digital/pengaris_digital.ino new file mode 100644 index 0000000..993f05d --- /dev/null +++ b/pengaris_digital/pengaris_digital.ino @@ -0,0 +1,54 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +#define echoPin 4 // echo +#define trigPin 5 // trig + +int maximumRange = 200; //kebutuhan akan maksimal range +int minimumRange = 0; //kebutuhan akan minimal range +long durasi, jarak; //waktu untuk kalkulasi jarak + +void setup() { + //type lcd + Serial.begin(9600); + lcd.begin(16, 2); // ukuran lcd 16 baris 2 kolom + lcd.setCursor(3,0); + lcd.print ("Penggaris"); + lcd.setCursor(4,1); + lcd.print ("Digital"); + delay(1500); + lcd.clear(); + lcd.setCursor(3,0); + lcd.print ("READY...!!"); + delay(500); + lcd.clear(); + + pinMode(echoPin, INPUT); + pinMode(trigPin, OUTPUT); +} + +void loop() { + digitalWrite(trigPin, LOW); + delayMicroseconds(2); + + digitalWrite(trigPin, HIGH); + delayMicroseconds(10); + + digitalWrite(trigPin, LOW); + + durasi = pulseIn(echoPin, HIGH); + jarak = durasi/58.2; + + lcd.setCursor(0,0); + lcd.print("Jarak ="); + lcd.print(jarak); + lcd.print("cm "); + + Serial.println("Jarak ="); + Serial.println(jarak); + Serial.println("cm "); + + delay(500); + +} + diff --git a/pengendali_servo_ultrasonic/pengendali_servo_ultrasonic.ino b/pengendali_servo_ultrasonic/pengendali_servo_ultrasonic.ino new file mode 100644 index 0000000..e5256db --- /dev/null +++ b/pengendali_servo_ultrasonic/pengendali_servo_ultrasonic.ino @@ -0,0 +1,51 @@ + +#include //Library untuk Servo +#define trigPin 12 //Set Trigger HCSR04 di Pin digital 6 +#define echoPin 13 //Set Echo HCSR04 di Pin digital 7 +#define MAX_DISTANCE 500 //Set jarak maksimal + +int LEDhijau = 3, LEDmerah = 2; //Set Pin LEDhijau dan LEDmerah +Servo myservo; //Buat object 1 buah motor servo + +void setup() { + Serial.begin (9600); //Kecepatan komunikasi serial + pinMode(trigPin, OUTPUT); //Set pin Trigger sebagai output + pinMode(echoPin, INPUT); //Set pin Echo sebagai input + pinMode(LEDmerah, OUTPUT); //Set LEDmerah sebagai output + pinMode(LEDhijau, OUTPUT); //Set LEDhijau sebagai output + myservo.attach(9); //Set servo pada pin PWM 9 +} + +void loop() { +int duration, jarak,posisi=0,i; + digitalWrite(trigPin, LOW); + delayMicroseconds(2); + digitalWrite(trigPin, HIGH); + delayMicroseconds(10); + digitalWrite(trigPin, LOW); + duration = pulseIn(echoPin, HIGH); + jarak = (duration/2) / 29.1; + Serial.print(jarak); + Serial.println(" cm"); + +if(jarak<=15) // Jarak (Cm) dapat anda sesuaikan + + { + digitalWrite(LEDhijau, LOW); //LEDhijau mati + digitalWrite(LEDmerah, HIGH); //LEDmerah hidup + myservo.write(90); //Posisi servo pada 180 derajat + delay(450); //Delay + digitalWrite(LEDmerah, LOW); //LEDmerah mati + myservo.write(0); //Posisi servo pada 90 derajat + delay(450); //Delay + digitalWrite(LEDmerah, HIGH); //LEDmerah hidup + +} + + else{ //Jika jarak lebih dari yang ditentukan + digitalWrite(LEDmerah, LOW); //LEDmerah mati + digitalWrite(LEDhijau, HIGH); //LEDhijau hidup + myservo.write(90); //Posisi servo pada 90 derajat + } +delay(450); //Delay +} diff --git a/penyiram_otomatis/penyiram_otomatis.ino b/penyiram_otomatis/penyiram_otomatis.ino new file mode 100644 index 0000000..b171014 --- /dev/null +++ b/penyiram_otomatis/penyiram_otomatis.ino @@ -0,0 +1,52 @@ +#include +LiquidCrystal_I2C lcd(0x27, 16, 2); // alamat i2c lcd dan type lcd 16x2 + +const byte pump = 8; +#define LIMIT 600 // kelembapan tanah + +void setup() { +// put your setup code here, to run once: +Serial.begin(9600); +lcd.begin(); +lcd.backlight(); +pinMode(A0, INPUT_PULLUP); +pinMode(pump, OUTPUT); +pinMode(LED_BUILTIN, OUTPUT); + +lcd.setCursor(0,0); +lcd.print("PENYIRAMAN CABAI"); +lcd.setCursor(0,1); +lcd.print("OTOMATIS..."); +delay(3000); +lcd.clear(); +} + +void loop() { +// put your main code here, to run repeatedly: +int s_soil = analogRead(A0); +Serial.println(s_soil); + if ( s_soil > LIMIT){ + lcd.setCursor(0,0); + lcd.clear(); + lcd.print("Ukur: "); + lcd.print(s_soil); + + lcd.setCursor(0,1); + lcd.print("POMPA HIDUP.."); + digitalWrite(pump, HIGH); + digitalWrite(LED_BUILTIN, HIGH); + Serial.println("POMPA HIDUP"); + } + else{ + lcd.clear(); + lcd.setCursor(0,0); + lcd.print("Ukur: "); + lcd.print(s_soil); + lcd.setCursor(0,1); + lcd.print("POMPA MATI..."); + digitalWrite(pump, LOW); + digitalWrite(LED_BUILTIN, LOW); + Serial.println("POMPA MATI"); + } + delay(250); +} diff --git a/potensio_test/potensio_test.ino b/potensio_test/potensio_test.ino new file mode 100644 index 0000000..0803bdb --- /dev/null +++ b/potensio_test/potensio_test.ino @@ -0,0 +1,34 @@ +const int analogInPin = A0; // pin potensiometer +const int analogOutPin = 13; // pin indikator + +int sensorValue = 0; // value read from the pot +int outputValue = 0; // value output to the PWM (analog out) + +void setup() { + + Serial.begin(9600); +} + +void loop() { + + sensorValue = analogRead(analogInPin); + outputValue = map(sensorValue, 0, 1023, 0, 255); + analogWrite(analogOutPin, outputValue); + +// keluaran Vout dari sensor + int nilai = analogRead (A0); + float tegangan_hasil = 5.0 * nilai / 1024; + //tampilan hasil output nilai analog + Serial.print ("Vout="); + Serial.print (tegangan_hasil); + Serial.print (" V"); + +// tampilan hasil nilai digital sensor + Serial.print("\t sensor = "); + Serial.print(sensorValue); + Serial.print("\t output = "); + Serial.println(outputValue); + +// waktu data masuk + delay(1000); +} diff --git a/project_uts/project_uts.ino b/project_uts/project_uts.ino new file mode 100644 index 0000000..3dba667 --- /dev/null +++ b/project_uts/project_uts.ino @@ -0,0 +1,103 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +const int analogInPin = A0; // pin potensiometer +const int analogOutPin = 13; // pin indikator + +int sensorValue ; // value read from the pot +int outputValue ; // value output to the PWM (analog out) +int led1 = 4 ; +int led2 = 5; +int button = 3; + +void setup() { + + pinMode(led1, OUTPUT); + pinMode(led2, OUTPUT); + pinMode(button, INPUT); + lcd.begin(16, 2); // ukuran lcd 16 baris 2 kolom + + lcd.setCursor(0,0); // kordinat (baris,kolom) + lcd.print ("Ath Thaareq M"); + lcd.setCursor(0,1); + lcd.print ("16202006"); + delay(1000); + lcd.clear(); + + lcd.setCursor(0,0); + lcd.print ("Sensor Actuator"); + lcd.setCursor(6,1); + lcd.print ("UTS"); + delay(1000); + lcd.clear(); + + lcd.setCursor(3,0); + lcd.print ("READY...!!"); + delay(500); + + lcd.clear(); +} + +void loop() { + + sensorValue = analogRead(analogInPin); + outputValue = map(sensorValue, 0, 1023, 0, 255); + analogWrite(analogOutPin, outputValue); + +// keluaran Vout dari sensor + //int nilai = analogRead (A0); + //float tegangan_hasil = 5.0 * nilai / 1024; + //tampilan hasil output nilai analog + //Serial.print ("Vout="); + //Serial.print (tegangan_hasil); + //Serial.print (" V"); + +// tampilan hasil nilai digital sensor +lcd.setCursor(0,0); + lcd.print("Sensor ="); + lcd.print(outputValue); + lcd.print(" "); + +//lcd.setCursor(0,1); + //lcd.print("Output ="); + //lcd.print(outputValue); + //lcd.print(" "); + + + // check if the pushbutton is pressed. + // if it is, the buttonState is HIGH: + if (digitalRead(button) == HIGH) { + + // digitalWrite(led1, HIGH); + digitalWrite(led2, HIGH); + lcd.setCursor(0,1); + lcd.print("Led 1 Menyala"); + + } + else if (digitalRead(button) == LOW) { + + digitalWrite(led1, HIGH); + digitalWrite(led2, LOW); + lcd.setCursor(0,1); + lcd.print("Led 2 Menyala"); + lcd.print(" "); + } + else if (digitalRead(button) == LOW){ + + digitalWrite(led1, LOW); + digitalWrite(led2, HIGH); + lcd.setCursor(0,1); + lcd.print("Led 1 Menyala"); + lcd.print(" "); + } + else if (digitalRead(button) == LOW) { + + digitalWrite(led1, HIGH); + digitalWrite(led2, LOW); + lcd.setCursor(0,1); + lcd.print("Led 2 Menyala"); + lcd.print(" "); + } + + delay(200); +} diff --git a/relay_test/relay_test.ino b/relay_test/relay_test.ino new file mode 100644 index 0000000..351c513 --- /dev/null +++ b/relay_test/relay_test.ino @@ -0,0 +1,27 @@ + +const int relay2 = 10; +const int relay3 = 11; +const int relay4 = 12; +void setup() { + // put your setup code here, to run once: +pinMode(relay2, OUTPUT); +pinMode(relay3, OUTPUT); +pinMode(relay4, OUTPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + + digitalWrite(relay2,HIGH); + delay(1000); + digitalWrite(relay2,LOW); + delay(2000); + digitalWrite(relay3,HIGH); + delay(1000); + digitalWrite(relay3,LOW); + delay(2000); + digitalWrite(relay4,HIGH); + delay(1000); + digitalWrite(relay4,LOW); + delay(2500); +} diff --git a/rfid_pintu/rfid_pintu.ino b/rfid_pintu/rfid_pintu.ino new file mode 100644 index 0000000..45ed066 --- /dev/null +++ b/rfid_pintu/rfid_pintu.ino @@ -0,0 +1,87 @@ +#include +#include + +// Set the LCD address to 0x27 for a 16 chars and 2 line display +LiquidCrystal_I2C lcd(0x27, 16, 2); + +#include "SPI.h" +#include "MFRC522.h" + +#include + +Servo myservo; + +#define SS_PIN 10 +#define RST_PIN 9 + + +MFRC522 rfid(SS_PIN, RST_PIN); + +MFRC522::MIFARE_Key key; + +void setup() { + // put your setup code here, to run once: + Serial.begin(9600); + SPI.begin(); + rfid.PCD_Init(); +myservo.attach(4); + Serial.println("I am waiting for card..."); + lcd.begin(16,2); + myservo.write(90); +} + +void loop() { + // put your main code here, to run repeatedly: + lcd.clear(); + lcd.print("Tap your Card"); + + if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial()) + return; + + // Serial.print(F("PICC type: ")); + MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak); + // Serial.println(rfid.PICC_GetTypeName(piccType)); + + // Check is the PICC of Classic MIFARE type + if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI && + piccType != MFRC522::PICC_TYPE_MIFARE_1K && + piccType != MFRC522::PICC_TYPE_MIFARE_4K) { + Serial.println(F("Your tag is not of type MIFARE Classic.")); + return; + } + String strID = ""; + for (byte i = 0; i < 4; i++) { + strID += + (rfid.uid.uidByte[i] < 0x10 ? "0" : "") + + String(rfid.uid.uidByte[i], HEX) + + (i != 3 ? ":" : ""); + } + + + strID.toUpperCase(); + Serial.print("Tap card key: "); + Serial.println(strID); + delay(1000); + + if (strID.indexOf("E4:4C:33:D0") >= 0) { //put your own tap card key; + myservo.write(0); // sets the servo position according to the scaled value + delay(1); + Serial.println("********************"); + Serial.println("**Authorised acces**"); + Serial.println("********************"); + lcd.clear(); + lcd.print("Kartu Anda Cocok"); + delay(1500); + myservo.write(90); + } + else { + Serial.println("****************"); + Serial.println("**Acces denied**"); + Serial.println("****************"); + lcd.clear(); + lcd.print("Kartu Tk Cocok"); + delay(1500); + + } + +} diff --git a/rfid_toll_system/rfid_toll_system.ino b/rfid_toll_system/rfid_toll_system.ino new file mode 100644 index 0000000..701dd88 --- /dev/null +++ b/rfid_toll_system/rfid_toll_system.ino @@ -0,0 +1,360 @@ +#include +#include +#include +#include +#include + +LiquidCrystal lcd(7, 6, 5, 4, 3, 2); + +Servo servo; +int servoPos = 0; + +#define sensorPin1 A2 +#define sensorPin2 A3 +#define buzzerPin A4 + +int senVal1 = 0; +int senVal2 = 0; + +#define RST_PIN 8 +#define SS_PIN 10 + +int card1Balance = 5000; +int card2Balance = 300; + +#define num 7 +char Data[num]; +byte data_count = 0; + +String num1, num2, card, card2; +int a, b; +char Key; + +bool recharge = true; + +MFRC522 mfrc522(SS_PIN, RST_PIN); + +int state = 0; + +char KEYS[] = { + '1', '2', '3', 'A', + '4', '5', '6', 'B', + '7', '8', '9', 'C', + '*', '0', '#', 'D' +}; + +OnewireKeypad KP2(Serial, KEYS, 4, 4, A0, 4700, 1000, ExtremePrec ); + +void setup () { + lcd.begin(16, 2); + Serial.begin(9600); + + servo.attach(9); + + servo.write(30); + + pinMode(sensorPin1, INPUT); + pinMode(sensorPin2, INPUT); + pinMode(buzzerPin, OUTPUT); + + KP2.SetKeypadVoltage(5.0); + + SPI.begin(); + mfrc522.PCD_Init(); + + lcd.setCursor(0, 0); + lcd.print(" Automatic toll"); + lcd.setCursor(0, 1); + lcd.print("colection system"); + delay(3000); + lcd.clear(); +} +void loop() +{ + + if (recharge == 0) + { + reCharge(); + } + else + { + lcd.setCursor(0, 0); + lcd.print(" Welcome!!!"); + sensorRead(); + rfid(); + KeyPad(); + if (senVal1 == 0) + { + servoDown(); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Vehicle detected"); + delay(1000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Put your card to"); + lcd.setCursor(0, 1); + lcd.print("the reader......"); + delay(2000); + lcd.clear(); + + } + else if (senVal2 == 0 && state == 1) + { + servoUp(); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Have a safe"); + lcd.setCursor(0, 1); + lcd.print("journey"); + delay(1000); + lcd.clear(); + state = 0; + } + } +} + +void servoDown() +{ + servo.attach(9); + for (servoPos = 30; servoPos <= 120; servoPos += 1) + { + servo.write(servoPos); + delay(5); + } +} + +void servoUp() +{ + servo.attach(9); + for (servoPos = 120; servoPos >= 30; servoPos -= 1) + { + servo.write(servoPos); + delay(5); + } +} + +void sensorRead() +{ + senVal1 = digitalRead(sensorPin1); + senVal2 = digitalRead(sensorPin2); +} + +void rfid() +{ + if ( ! mfrc522.PICC_IsNewCardPresent()) + { + return; + } + if ( ! mfrc522.PICC_ReadCardSerial()) + { + return; + } + + String content = ""; + for (byte i = 0; i < mfrc522.uid.size; i++) + { + content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); + content.concat(String(mfrc522.uid.uidByte[i], HEX)); + } + content.toUpperCase(); + + if (content.substring(1) == "73 50 76 2E") + { + if (card1Balance >= 500) + { + lcdPrint(); + card1Balance = card1Balance - 500; + lcd.setCursor(9, 1); + lcd.print(card1Balance); + delay(2000); + lcd.clear(); + state = 1; + } + else + { + card = content.substring(1); + LcdPrint(); + lcd.setCursor(9, 1); + lcd.print(card1Balance); + lcd.print(" Tk"); + delay(2000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Please Recharge"); + delay(1000); + lcd.clear(); + state = 0; + } + } + else if (content.substring(1) == "F4 C2 37 BB") + { + if (card2Balance >= 500) + { + lcdPrint(); + card2Balance = card2Balance - 500; + lcd.setCursor(9, 1); + lcd.print(card2Balance); + delay(2000); + lcd.clear(); + state = 1; + } + else + { + card = content.substring(1); + LcdPrint(); + lcd.setCursor(9, 1); + lcd.print(card2Balance); + lcd.print(" Tk"); + delay(2000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Please Recharge"); + lcd.clear(); + delay(1000); + state = 0; + } + } + + else { + digitalWrite(buzzerPin, HIGH); + lcd.setCursor(0, 0); + lcd.print("Unknown Vehicle"); + lcd.setCursor(0, 1); + lcd.print("Access denied"); + delay(1500); + lcd.clear(); + digitalWrite(buzzerPin, LOW); + } +} + +void KeyPad() +{ + byte KState = KP2.Key_State(); + + if (KState == PRESSED) + { + Key = KP2.Getkey(); + if (Key) + { + if (Key == 'A') + { + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Recharging Mode."); + lcd.setCursor(0, 1); + lcd.print("................"); + delay(1500); + lcd.clear(); + recharge = 0; + } + } + } +} + +void clearData() +{ + while (data_count != 0) + { + Data[data_count--] = 0; + } + return; +} + +void reCharge() +{ + + lcd.setCursor(0, 0); + lcd.print ("Enter the amount"); + + byte KState = KP2.Key_State(); + + if (KState == PRESSED) + { + Key = KP2.Getkey(); + if (Key) + { + if (Key == 'D') + { + if (card == "73 50 76 2E") + { + num1 = Data; + card1Balance = num1.toInt() + card1Balance; + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your current"); + lcd.setCursor(0, 1); + lcd.print("balance: "); + lcd.setCursor(9, 1); + lcd.print (card1Balance); + lcd.print(" Tk"); + delay(3000); + clearData(); + lcd.clear(); + recharge = 1; + } + else if (card == "F4 C2 37 BB") + { + num2 = Data; + card2Balance = num2.toInt() + card2Balance; + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your current"); + lcd.setCursor(0, 1); + lcd.print("balance: "); + lcd.setCursor(9, 1); + lcd.print (card2Balance); + lcd.print(" Tk"); + delay(3000); + clearData(); + lcd.clear(); + recharge = 1; + } + } + else + { + Data[data_count] = Key; + lcd.setCursor(data_count, 1); + lcd.print(Data[data_count]); + data_count++; + } + } + } +} +void lcdPrint() +{ + digitalWrite(buzzerPin, HIGH); + delay(200); + digitalWrite(buzzerPin, LOW); + delay(100); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" Successfully"); + lcd.setCursor(0, 1); + lcd.print(" paid your bill"); + delay(1500); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your Remaining"); + lcd.setCursor(0, 1); + lcd.print("balance: "); +} + +void LcdPrint() +{ + digitalWrite(buzzerPin, HIGH); + delay(200); + digitalWrite(buzzerPin, LOW); + delay(100); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" Your balance"); + lcd.setCursor(0, 1); + lcd.print(" is insufficent"); + delay(1500); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your Remaining"); + lcd.setCursor(0, 1); + lcd.print("balance: "); +} diff --git a/rfid_toll_system_ultrasonic/rfid_toll_system_ultrasonic.ino b/rfid_toll_system_ultrasonic/rfid_toll_system_ultrasonic.ino new file mode 100644 index 0000000..987f4d6 --- /dev/null +++ b/rfid_toll_system_ultrasonic/rfid_toll_system_ultrasonic.ino @@ -0,0 +1,346 @@ +#include +#include +#include +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + + +Servo servo; +int servoPos = 0; +long duration, distance; + + +#define buzzerPin A1 +#define trigPin 13 +#define echoPin 12 + +int senVal1 = 0; +int senVal2 = 0; + +#define RST_PIN 8 +#define SS_PIN 10 + +int card1Balance = 1000; +int card2Balance = 300; + +#define num 7 +char Data[num]; +byte data_count = 0; + +String num1, num2, card, card2; + + +bool recharge = true; + +MFRC522 mfrc522(SS_PIN, RST_PIN); + + + + +void setup () { + lcd.begin(16, 2); + Serial.begin(9600); + + servo.attach(9); + + servo.write(30); + + pinMode(trigPin, OUTPUT); + pinMode(echoPin, INPUT); + pinMode(buzzerPin, OUTPUT); + + KP2.SetKeypadVoltage(5.0); + + SPI.begin(); + mfrc522.PCD_Init(); + + lcd.setCursor(0, 0); + lcd.print(" Automatic toll"); + lcd.setCursor(0, 1); + delay(3000); + lcd.clear(); +} +void loop() +{ + + if (recharge == 0) + { + reCharge(); + } + else + { + lcd.setCursor(0, 0); + lcd.print(" Welcome!!!"); + sensorRead(); + rfid(); + KeyPad(); + if (distance < 16) + { + servoDown(); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Vehicle detected"); + delay(1000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Put your card to"); + lcd.setCursor(0, 1); + lcd.print("the reader......"); + delay(2000); + lcd.clear(); + + } + } +} + +void servoDown() +{ + servo.attach(9); + for (servoPos = 30; servoPos <= 120; servoPos += 1) + { + servo.write(servoPos); + delay(5); + } +} + +void servoUp() +{ + servo.attach(9); + for (servoPos = 120; servoPos >= 30; servoPos -= 1) + { + servo.write(servoPos); + delay(5); + } +} + +void sensorRead() +{ + digitalWrite(trigPin, LOW); + delayMicroseconds(2); + digitalWrite(trigPin, HIGH); + delayMicroseconds(10); + digitalWrite(trigPin, LOW); + duration = pulseIn(echoPin, HIGH); + distance = (duration/2) / 29.1; + Serial.print("Jarak: "); + Serial.println(distance); +} + +void rfid() +{ + if ( ! mfrc522.PICC_IsNewCardPresent()) + { + return; + } + if ( ! mfrc522.PICC_ReadCardSerial()) + { + return; + } + + String content = ""; + for (byte i = 0; i < mfrc522.uid.size; i++) + { + content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ")); + content.concat(String(mfrc522.uid.uidByte[i], HEX)); + } + content.toUpperCase(); + + if (content.substring(1) == "2F 7D 68 68") + { + if (card1Balance >= 500) + { + lcdPrint(); + card1Balance = card1Balance - 500; + lcd.setCursor(9, 1); + lcd.print(card1Balance); + delay(2000); + lcd.clear(); + state = 1; + } + else + { + card = content.substring(1); + LcdPrint(); + lcd.setCursor(9, 1); + lcd.print(card1Balance); + // lcd.print(" Tk"); + delay(2000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Please Recharge"); + delay(1000); + lcd.clear(); + state = 0; + } + } + else if (content.substring(1) == "F4 C2 37 BB") + { + if (card2Balance >= 500) + { + lcdPrint(); + card2Balance = card2Balance - 500; + lcd.setCursor(9, 1); + lcd.print(card2Balance); + delay(2000); + lcd.clear(); + state = 1; + } + else + { + card = content.substring(1); + LcdPrint(); + lcd.setCursor(9, 1); + lcd.print(card2Balance); + lcd.print(" Tk"); + delay(2000); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Please Recharge"); + lcd.clear(); + delay(1000); + state = 0; + } + } + + else { + digitalWrite(buzzerPin, HIGH); + lcd.setCursor(0, 0); + lcd.print("Unknown Vehicle"); + lcd.setCursor(0, 1); + lcd.print("Access denied"); + delay(1500); + lcd.clear(); + digitalWrite(buzzerPin, LOW); + } +} + +void KeyPad() +{ + byte KState = KP2.Key_State(); + + if (KState == PRESSED) + { + Key = KP2.Getkey(); + if (Key) + { + if (Key == 'A') + { + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Recharging Mode."); + lcd.setCursor(0, 1); + lcd.print("................"); + delay(1500); + lcd.clear(); + recharge = 0; + } + } + } +} + +void clearData() +{ + while (data_count != 0) + { + Data[data_count--] = 0; + } + return; +} + +void reCharge() +{ + + lcd.setCursor(0, 0); + lcd.print ("Enter the amount"); + + byte KState = KP2.Key_State(); + + if (KState == PRESSED) + { + Key = KP2.Getkey(); + if (Key) + { + if (Key == 'D') + { + if (card == "73 50 76 2E") + { + num1 = Data; + card1Balance = num1.toInt() + card1Balance; + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your current"); + lcd.setCursor(0, 1); + lcd.print("balance: "); + lcd.setCursor(9, 1); + lcd.print (card1Balance); + lcd.print(" Tk"); + delay(3000); + clearData(); + lcd.clear(); + recharge = 1; + } + else if (card == "F4 C2 37 BB") + { + num2 = Data; + card2Balance = num2.toInt() + card2Balance; + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your current"); + lcd.setCursor(0, 1); + lcd.print("balance: "); + lcd.setCursor(9, 1); + lcd.print (card2Balance); + lcd.print(" Tk"); + delay(3000); + clearData(); + lcd.clear(); + recharge = 1; + } + } + else + { + Data[data_count] = Key; + lcd.setCursor(data_count, 1); + lcd.print(Data[data_count]); + data_count++; + } + } + } +} +void lcdPrint() +{ + digitalWrite(buzzerPin, HIGH); + delay(200); + digitalWrite(buzzerPin, LOW); + delay(100); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" Successfully"); + lcd.setCursor(0, 1); + lcd.print(" paid your bill"); + delay(1500); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your Remaining"); + lcd.setCursor(0, 1); + lcd.print("balance: "); +} + +void LcdPrint() +{ + digitalWrite(buzzerPin, HIGH); + delay(200); + digitalWrite(buzzerPin, LOW); + delay(100); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print(" Your balance"); + lcd.setCursor(0, 1); + lcd.print(" is insufficent"); + delay(1500); + lcd.clear(); + lcd.setCursor(0, 0); + lcd.print("Your Remaining"); + lcd.setCursor(0, 1); + lcd.print("balance: "); +} diff --git a/rgb_control_blynk/rgb_control_blynk.ino b/rgb_control_blynk/rgb_control_blynk.ino new file mode 100644 index 0000000..cac1305 --- /dev/null +++ b/rgb_control_blynk/rgb_control_blynk.ino @@ -0,0 +1,124 @@ +/************************************************************* + Download latest Blynk library here: + https://github.com/blynkkk/blynk-library/releases/latest + + Blynk is a platform with iOS and Android apps to control + Arduino, Raspberry Pi and the likes over the Internet. + You can easily build graphic interfaces for all your + projects by simply dragging and dropping widgets. + + Downloads, docs, tutorials: http://www.blynk.cc + Sketch generator: http://examples.blynk.cc + Blynk community: http://community.blynk.cc + Follow us: http://www.fb.com/blynkapp + http://twitter.com/blynk_app + + Blynk library is licensed under MIT license + This example code is in public domain. + + ************************************************************* + This example runs directly on ESP8266 chip. + + Note: This requires ESP8266 support package: + https://github.com/esp8266/Arduino + + Please be sure to select the right ESP8266 module + in the Tools -> Board menu! + + Change WiFi ssid, pass, and Blynk auth token to run :) + Feel free to apply it to any other example. It's simple! + *************************************************************/ + +/* Comment this out to disable prints and save space */ +#define BLYNK_PRINT Serial + +#define RedPin D1 // Set RED RGB pin +#define GrnPin D2 // Set GREEN RGB pin +#define BluPin D3 // Set BLUE RGB pin + + +#define zeRGBa V0 // Set virtual RGB widget +#define rSlide V1 // Set virtual RGB widget +#define gSlide V2 // Set virtual RGB widget +#define bSlide V3 // Set virtual RGB widget + +int rrr, ggg, bbb; // Set RED BLUE GREEN channels + +#include +#include + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +char auth[] = "6f0ab9c206aa4dc2ab16232d83ca5672"; + +// Your WiFi credentials. +// Set password to "" for open networks. +char ssid[] = "smarthome"; +char pass[] = "smarthomes"; + +void setup() +{ + // Debug console + Serial.begin(115200); + + pinMode(RedPin, OUTPUT); // Set RED pinMode + pinMode(GrnPin, OUTPUT); // Set GREEN pinMode + pinMode(BluPin, OUTPUT); // Set BLUE pinMode + + + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + + Blynk.begin(auth, ssid, pass,"blynk-cloud.com", 8442); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); +} + +void loop() +{ + Blynk.run(); +} + //===== RED slider ===== +BLYNK_WRITE(rSlide) { // START Blynk Function + rrr = param.asInt(); // get a RED channel value + // Blynk.virtualWrite(vRed, rrr); // Red LED intensity + Blynk.virtualWrite(zeRGBa, rrr, ggg, bbb); // Sync zeRGBa position +} // END Blynk Function + + +//===== GREEN slider ===== +BLYNK_WRITE(gSlide) { // START Blynk Function + ggg = param.asInt(); // get a GREEN channel value + // Blynk.virtualWrite(vGreen, ggg); // Green LED intensity + Blynk.virtualWrite(zeRGBa, rrr, ggg, bbb); // Sync zeRGBa position +} // END Blynk Function + + +//===== BLUE slider ===== +BLYNK_WRITE(bSlide) { // START Blynk Function + bbb = param.asInt(); // get a BLUE channel value + // Blynk.virtualWrite(vBlue, bbb); // Blue LED intensity + Blynk.virtualWrite(zeRGBa, rrr, ggg, bbb); // Sync zeRGBa position + } // END Blynk Function + + + +//===== zeRGBa Widget ===== +BLYNK_WRITE(zeRGBa) { // START Blynk Function + rrr = param[0].asInt(); // get a RED channel value + ggg = param[1].asInt(); // get a GREEN channel value + bbb = param[2].asInt(); // get a BLUE channel value +} + + diff --git a/robo_avoider/robo_avoider.ino b/robo_avoider/robo_avoider.ino new file mode 100644 index 0000000..9ef37d0 --- /dev/null +++ b/robo_avoider/robo_avoider.ino @@ -0,0 +1,225 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); +int progressBari = 0; +int i = 0; + +// Kararter progress bar untuk LCD +byte progressBar[8] = { + B11111, + B11111, + B11111, + B11111, + B11111, + B11111, + B11111, +}; + +#include +#include +#include +#define echo A2 +#define trigger A3 +#define pinServo 9 + +AF_DCMotor motor1(3); +AF_DCMotor motor2(4); +Servo servo; +NewPing sonar(trigger,echo); +int x=160; //kecepatan; + +void setup() { + Serial.begin(9600); + lcd.begin(16,2); + lcd.createChar(0, progressBar); + servo.attach(pinServo); + servo.write(90); + //delay(1000); + lcd.setCursor(3,0); + lcd.print("Eunbi Line"); + delay(2000); + lcd.clear(); + + lcd.setCursor(0,0); + lcd.print("Loading:"); + + progressBari= 16; + + for (i=0; i0) + { + while(1) + { + mundur(); + delay(200); + berhenti(); + delay(1500); + servo.write(0); + delay(1000); + jarak = sonar.ping_cm(); + if(jarak > 20) + { + kanan = true; + } + servo.write(180); + delay(1000); + jarak = sonar.ping_cm(); + if(jarak > 20) + { + kiri = true; + servo.write(90); + delay(1000); + } + else + { + servo.write(90); + delay(1000); + } + while(kanan == true && kiri == false) + { + jarak = sonar.ping_cm(); + if(jarak < 50) + { + belokkiri(); + } + else + { + kanan = false; kiri = false; + goto awal; + } + } + while(kanan == false && kiri == true) + { + jarak = sonar.ping_cm(); + if(jarak < 50) + { + belokkanan(); + } + else + { + kanan = false; kiri = false; + goto awal; + } + } + while(kanan == true && kiri == true) + { + jarak = sonar.ping_cm(); + if(jarak < 50) + { + belokkanan(); + } + else + { + kanan = false; kiri = false; + goto awal; + } + } + while(kanan == false && kiri == false) + { + jarak = sonar.ping_cm(); + if(jarak < 50) + { + belokkanan(); + } + else + { + kanan = false; kiri = false; + goto awal; + } + } + } + } + else + { + maju(); + } +} + +void maju() +{ + motor1.setSpeed(x); + motor1.run(FORWARD); + motor2.setSpeed(x); + motor2.run(FORWARD); + Serial.println("maju"); + lcd.setCursor(0,0); + lcd.print("Maju "); + +} +void mundur() +{ + motor1.setSpeed(x); + motor1.run(BACKWARD); + motor2.setSpeed(x); + motor2.run(BACKWARD); +} +void belokkiri() +{ + motor1.setSpeed(x-30); + motor1.run(BACKWARD); + motor2.setSpeed(x); + motor2.run(FORWARD); + Serial.println("kiri"); + lcd.setCursor(0,0); + lcd.print("Kiri "); + +} +void belokkanan() +{ + motor1.setSpeed(x); + motor1.run(FORWARD); + motor2.setSpeed(x-30); + motor2.run(BACKWARD); + Serial.println("kanan"); + lcd.setCursor(0,0); + lcd.print("Kanan"); + +} +void berhenti() +{ + motor1.setSpeed(0); + motor2.run(RELEASE); + motor2.setSpeed(0); + motor2.run(RELEASE); + Serial.println("Stop"); + lcd.setCursor(0,0); + lcd.print("Stop "); +} + + diff --git a/robot_arduino/robot_arduino.ino b/robot_arduino/robot_arduino.ino new file mode 100644 index 0000000..30d02c4 --- /dev/null +++ b/robot_arduino/robot_arduino.ino @@ -0,0 +1,190 @@ +#include +#include +#include +#include + +long startTime ; +int secTime; + +int randTurn; +/* + *1. kanan + *2. lurus + *3. kiri + */ + +int waktu[20]; +int T=0; + +int tengah=500; +int sen[5]; +unsigned char sensor; +int PV; +int error,P,D1,D3,last_error; +float D2,Pd,D,pwmL,pwmR; + +void setup() { + // initialize the robot + Robot.begin(); + + // initialize the serial port + Serial.begin(9600); + + randomSeed(analogRead(0)); + + pinMode(A0, INPUT_PULLUP); + pinMode(A1, INPUT_PULLUP); + pinMode(A2, INPUT_PULLUP); + pinMode(A3, INPUT_PULLUP); + pinMode(A4, INPUT_PULLUP); +} +void convertLogic(){ + Robot.updateIR(); + for(int i=0;i<5;i++){ + if(Robot.IRarray[i]>=tengah){ + sen[i]=0; + }else{ + sen[i]=1; + } + } +} + +void convertBiner(){ + sensor=(sen[4]*1)+(sen[3]*2)+(sen[2]*4)+(sen[1]*8)+(sen[0]*16); +} +void PID(){ + convertLogic(); + convertBiner(); + switch(sensor){ + //deteksi 1 sensor pergaris + case 0b00001: + PV = -4; + break; + case 0b00011: + PV = -3; + break; + case 0b00010: + PV = -2; + break; + case 0b00110: + PV = -1; + break; + case 0b00100: + PV = 0; + break; + case 0b01100: + PV = 1; + break; + case 0b01000: + PV = 2; + break; + case 0b11000: + PV = 3; + break; + case 0b10000: + PV = 4; + break; + + case 0b00000: // loss + if (PV <= -3) + { + PV = -5; + } + else if(PV >= 3) + { + PV = 5; + } + else + { + Robot.motorsStop(); + delay(100); + PV = 5; + } + break; + + } + error = 0 - PV; + P = (5 * error); + + D1 = 50 * 8; + D2 = D1 / 15; + D3 = error - last_error; + D = D2 * D3; + + last_error = error; + + Pd = P + D; + + if(Pd==0){ + //Serial.println("0"); + pwmL=pwmR=150; + Robot.motorsWrite(pwmL,pwmR); + } + else if(Pd>0 && Pd<=20){ + //Serial.println("1"); + pwmL=150-Pd; + pwmR=150+Pd; + if(pwmL > 250) pwmL=250; + if(pwmL < 10) pwmL=0; + if(pwmR > 250) pwmR=250; + if(pwmR < 10) pwmR=0; + Robot.motorsWrite(pwmL,pwmR); + } + else if(Pd<0 && Pd>=-20){ + //Serial.println("2"); + pwmL=150-Pd; + pwmR=150+Pd; + if(pwmL > 250) pwmL=250; + if(pwmL < 10) pwmL=0; + if(pwmR > 250) pwmR=250; + if(pwmR < 10) pwmR=0; + Robot.motorsWrite(pwmL,pwmR); + } + else if(Pd>20){ + //Serial.println("3"); + Robot.motorsWrite(-100,100); + } + else if(Pd<20){ + //Serial.println("4"); + Robot.motorsWrite(100,-100); + } + else{ + //Serial.println("5"); + Robot.motorsWrite(pwmL,pwmR); + } + + //Serial.print(error); + + //delay(500); + + for (int i = 0; i < 5; i++) { + Serial.print(Robot.IRarray[i]); + Serial.print(" "); + } + Serial.println(""); + +} +void loop() { + + //read the pushbutton value into a variable + int tDown = digitalRead(A0); + int tRight = digitalRead(A1); + int tOK = digitalRead(A2); + int tLeft = digitalRead(A3); + int tUp = digitalRead(A4); + +mulai: + if(tDown == LOW) + { + while(1) + { + convertLogic(); + convertBiner(); + PID(); + if ( sensor!=0b11111){ + PID(); + } + goto mulai; + } + } +} diff --git a/robot_pemadam_api/robot_pemadam_api.ino b/robot_pemadam_api/robot_pemadam_api.ino new file mode 100644 index 0000000..87a7386 --- /dev/null +++ b/robot_pemadam_api/robot_pemadam_api.ino @@ -0,0 +1,198 @@ +//========================================================================================== +// Progam ini di buat oleh Misbah najh (FB) +// Program dikendalikan menguanakan sensor jarak Ultrasonic +// mengunakan motor servo MG995,sensor hc-sr04,flame sensor 5channel, fan L9110, arduino uno,dan chassis +// Chassis+servo modif didapatkan https://www.tokopedia.com/microbot/frame-chassis-robot-pemadam-api-servo-roda +// Tutorial dan video klik https://www.sinauduino.blogspot.co.id +// full tutorial video https://www.youtube.com/watch?v=BL8ZB5-ql9Q +//========================================================================================== + +//inisialisai motor servo +#include +#define RODA1 4 +#define RODA2 5 +Servo Roda1; Servo Roda2; + +#include +LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); + +//KALIBRASI KECEPATAN DAN SETPOIN SENSOR +int kecepataan =650; // NILAI RESPON BELOK 90* (500-1000); +int rodakanan =65; // NILAI RESPON RODA KANAN (75-90); +int rodakiri =80; // NILAI RESPON RODA KIRI (75-80); +int setpoin =7; // NILAI TOLERANSI JARAK HINDAR (7-15); +int lintasan =200; // NILAI TOLERANSI WARNA LINTASAN (0-1024) +int api =500; // NILAI TOLERANSI CAHAYA API (0-1024) + +//inisialisasi sensor 1 sebelah kiri +#include +#define echo1 8 +#define trigger1 7 +NewPing sonar1(trigger1,echo1,100); + +//inisialisasi sensor 2 sebelah depan +#define echo2 12 +#define trigger2 11 +NewPing sonar2(trigger2,echo2,100); + +//inisialisasi sensor 2 sebelah kanan +#define echo3 10 +#define trigger3 9 +NewPing sonar3(trigger3,echo3,100); + +//definisi pin kipas dan pin buzzer +#define kipas 6 +#define buzzer 3 +bool keadaan; +void setup() { + Serial.begin(9600); // serial monitor "menampilkan data sensor" + lcd.begin(16,2); + diam(3000); + Roda1.attach(RODA1); //pin motor servo + Roda2.attach(RODA2); + pinMode(kipas,INPUT); + pinMode(buzzer,OUTPUT); + keadaan = 0; + + lcd.setCursor(0,0); + lcd.print(" Astro-Tech "); + lcd.setCursor(0,1); + ldc.print("Stmik ASIA Ready") + delay(500); + lcd.clear(); + } + +void loop() { +// sensor mengukur dan membaca +int jarak1 =sonar1.ping_cm(); // sensor kiri +int jarak2 =sonar2.ping_cm(); // sensor depan +int jarak3 =sonar3.ping_cm(); // sensor kanan +int sensor = analogRead(A0); // pin sensor tcr5000 +int api = analogRead(A1); // pin sensor Api A1-A5 +//sensor menampilkan data yang dibaca +Serial.print(jarak1); +Serial.print(" || "); +Serial.print(jarak2); +Serial.print(" || "); +Serial.print(jarak3); +Serial.print(" || "); +Serial.print(api); +Serial.print(" || "); +Serial.println(sensor); + +//tampilan sensor lcd +lcd.setCursor(1,0); +lcd.print(jarak1); +lcd.print(""); +lcd.setCursor(5,0); +lcd.print(jarak2); +lcd.print(""); +lcd.setCursor(9,0); +lcd.print(jarak3); +lcd.print(""); +lcd.setCursor(13,0); +lcd.print(api); +lcd.print(""); +lcd.setCursor(0,5); +lcd.print(sensor); + +//case utama jika api terdeteksi maka exsekusi +if ((api2>api||api3>api||api4>api) && (jarak2>1&&jarak2<15)){ +digitalWrite(buzzer,HIGH); //buzzer bunyi +pinMode(kipas, OUTPUT); digitalWrite(kipas,LOW);//kipas bergerak +diam(2000); // panggil diam "lihat inisialisasi progam pangillan" +tiup(kecepataan); //panggil tiup +diam(1000); //panggil diam +keadaan = 1; +} + +//case terakhir jika api tidak terdeteksi maka exsekusi +else{ +digitalWrite(buzzer,LOW); // buzzer mati +pinMode(kipas, INPUT); digitalWrite(kipas,HIGH); // kipas berhenti +if (sensor>lintasan && keadaan > 0){ + maju(); + delay(kecepataan); + diam (100000); +} +//jika sensor kiri terdeteksi maka belok kanan +else if (jarak11){ + kanan(); //panggil kanan + delay(50); + } +//jika sensor kanan terdeteksi maka belok kiri +else if (jarak31){ + kiri(); + delay(50); + } +//jika sensor depan terdeteksi maka balik (balik belum ditentukan) +else if (jarak21){ + //jika sensor kiri < sensor kanan maka ditentukan "balik kanan" + if (jarak1 sensor kanan maka ditentukan "balik kiri" + else if (jarak1>jarak3){ + balik_kiri(); + delay(kecepataan); +} +} +//jika semua sensor (sensor api dan sensor ultrasonik tidak terdeteksi) maka maju +else{ + maju(); + delay(100); +} +} +} + +// inisialisasi progam pangillan +void maju(){ + Roda1.write(380); + Roda2.write(-380); +} +void mundur(){ + Roda1.write(-380); + Roda2.write(380); +} +void balik_kiri(){ + Roda1.write(-380); + Roda2.write(-380); +} +void balik_kanan(){ + Roda1.write(380); + Roda2.write(380); +} +void kanan(){ + Roda1.write(380); + Roda2.write(rodakanan); //nilai roda2 agak lambat +} +void kiri(){ + Roda1.write(rodakiri); //nilai roda1 agak lambat + Roda2.write(-380); +} +void diam(int x){ + pinMode(RODA1,INPUT); + pinMode(RODA2,INPUT); + digitalWrite(RODA1,LOW); + digitalWrite(RODA2,LOW); + delay(x); + pinMode(RODA1,OUTPUT); + pinMode(RODA2,OUTPUT); + } +void tiup(int x){ +balik_kanan(); +delay(x/4); +diam(x); +balik_kiri(); +delay(x/2); +diam(x); +balik_kanan(); +delay(x/2); +diam(x); +balik_kiri(); +delay(x/4); +diam(x); +} + + diff --git a/rotary/rotary.ino b/rotary/rotary.ino new file mode 100644 index 0000000..2d1f7ee --- /dev/null +++ b/rotary/rotary.ino @@ -0,0 +1,86 @@ +#include +#include +LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); + + +int pinA = 3; // Connected to CLK on KY-040 + int pinB = 4; // Connected to DT on KY-040 + int encoderPosCount = 0; + int pinALast; + int aVal; + + boolean bCW; + + + void setup() { + pinMode (pinA,INPUT); + pinMode (pinB,INPUT); + /* Read Pin A + Whatever state it's in will reflect the last position + */ + pinALast = digitalRead(pinA); + Serial.begin (9600); + lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight + + } + + void loop() { + +Serial.begin(9600); + + +// lcd.backlight(); +// delay(250); +// lcd.noBacklight(); +// delay(250); +// lcd.backlight(); + + int kel=18.9; + int bag=28; + +float rumus =(kel)*(encoderPosCount)/bag; + + aVal = digitalRead(pinA); + if (aVal != pinALast){ + + if (digitalRead(pinB) != aVal) { // Means pin A Changed first - We're Rotating Clockwise + encoderPosCount ++; + bCW = true; + } else {// Otherwise B changed first and we're moving CCW + bCW = false; + encoderPosCount--; + } + lcd.setCursor(0,0); + //lcd.clear(); + lcd.print ("PUTARAN:"); + // delay(1000); + if (bCW == true){ + + lcd.setCursor(0,0); + lcd.print ("MAJU "); + //delay(1000); + } + if (bCW == false){ + + lcd.setCursor(0,0); + lcd.print("MUNDUR "); + + } + + if ( rumus <= 0 ){ + lcd.setCursor(0,0); + lcd.print("STOP "); + + } + + lcd.setCursor(0,1); + lcd.print("POSISI:"); + lcd.print(float (kel)*(encoderPosCount)/bag);; + lcd.print("CM "); + //delay(100); + + } + pinALast = aVal; + // delay(100); + } + diff --git a/runningLed_jamSholat/runningLed_jamSholat.ino b/runningLed_jamSholat/runningLed_jamSholat.ino new file mode 100644 index 0000000..54b4c93 --- /dev/null +++ b/runningLed_jamSholat/runningLed_jamSholat.ino @@ -0,0 +1,1178 @@ +/////////////////////////////diolah dari berbagai sumber hasil browsing dan copas sana-sini///////////////////////////// +////////tutorial lebih lengkap kunjungi : www.rokhmad.com ////// + +//////ini library nya/// jika belum punya kunjungi github.com ////// +#include +#include +#include +#include +#include "PrayerTimes.h" +#include +#include +#include +#include + +#include + +#include +char weekDay[][7] = {"SENIN" , "SELASA", "RABU", "KAMIS", "JUM'AT", "SABTU", "AHAD",}; // array hari, dihitung mulai dari senin, hari senin angka nya =0, +int langkah; +int lama_tampilnya; +boolean Waduh_Setting = false; +///////////////////////////////// Mendifinisikan Pin Tombol //////////////////////////////////////// +#define Jam_bUP A1 // Tombol setting sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 3 Digital +#define tombol_bOK A2 // Tombol OK sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 5 Digital +#define Jam_bDN A3 //tombol setting sesuaikan dengan PIN di arduino anda mana klo ini terhubung dengan PIN 4 Digital + +///////////////////koding ini untuk setting rtc sesuai dengan laptop//// ///// +//year, month, date, hour, min, sec and week-day(starts from 0 and goes to 6) +//writing any non-existent time-data may interfere with normal operation of the RTC. +//Take care of week-day also. +//DateTime dt(2017, 5, 4, 15, 11, 0, 4); + +/* + * PIN YANG DISAMBUNG + * Arduino P-10 + * -D6 -> -A + * -D7 -> -B + * -D8 -> -SCLK + * -D9 -> -OE + * -D11 -> -DATA + * -D13 -> -CLK + * -GND -> -GND + */ + +DMD dmd(1, 1); //untuk mengatur jumlah panel yang kamu pakai + +double times[sizeof(TimeName) / sizeof(char*)]; + +void ScanDMD() +{ + dmd.scanDisplayBySPI(); +} + + +void setup() +{ + + pinMode(2, OUTPUT);//----pin 2 untuk alarm adzan maghrib ---hubungkan dengan buzzer + + digitalWrite(2,HIGH); + delay(1000); + digitalWrite(2,LOW); + delay (500); + digitalWrite(2,HIGH); + delay(1000); + digitalWrite(2,LOW); + + langkah = 0; + rtc.begin(); + //rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above (ini untuk setting jam) + Wire.begin(); + Timer1.initialize( 500 ); + Timer1.attachInterrupt( ScanDMD ); + dmd.clearScreen( true ); + + pinMode(tombol_bOK, INPUT_PULLUP); // Mode Pin Sebagai Input dengan Pull Up Internal + pinMode(Jam_bUP, INPUT_PULLUP); // Mode Pin Sebagai Input dengan Pull Up Internal + pinMode(Jam_bDN, INPUT_PULLUP); // Mode Pin Sebagai Input dengan Pull Up Internal + + attachInterrupt(0, Setting, FALLING); +} +////////////////////////////////// Fungsi Looping/Pengulangan /////////////////////////////////////// +void loop() { + if (Waduh_Setting) { + + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + } + mulai(); +} + + +/////////////////////////////////// Interrupt Button Setting //////////////////////////////////////// +void Setting() { + Waduh_Setting = true; // Aktifkan Menu Setting +} + +////////////////////////////////////// Fungsi Menu Setting ////////// +void MenuSetting() { + DateTime now = rtc.now(); + String Teks; + int tgl = now.date(); //Tanggal + int bln = now.month(); //Bulan + int thn = now.year(); //Tahun + int hours, minutes; //jam dan menit jawdwal sholat + int jame = now.hour(); //jam + int menit_e = now.minute(); //menit + + int harin_e = harin_e; //hari + detachInterrupt(0);// Matikan interrupt "0" + delay(500); + + /////////////////////////////////////// Setting Jam & Menit /////// + + int kasus = 0; +setTimes: // Setting Times (Jam & Menit) + if (digitalRead(Jam_bUP) == LOW ) { // Tombol Setting Menit + delay(10); menit_e++; // Delay Tombol & Tambah Nilai Menit + if (menit_e >= 60) { + menit_e = 0; // Batas Nilai Menit Lebih dari 59 Kembali ke 0 + } + while (digitalRead(Jam_bUP) == LOW) {} // Kunci Tombol Setting Menit Sampai Lepas Tombol + } + if (digitalRead(Jam_bDN) == LOW) { // Tombol Setting Menit + delay(10); jame++; // Delay Tombol & Tambah Nilai Jam + if (jame >= 24) { + jame = 0; // Batas Nilai Jam Lebih dari 23 Kembali ke 0 + } + while (digitalRead(Jam_bDN) == LOW) {} // Kunci Tombol Setting Jam Sampai Lepas Tombol + } + + + +setTgl: // Setting tanggal + if (digitalRead(Jam_bUP) == LOW ) { // Tombol Setting tanggal + delay(10); tgl++; + if (tgl >= 32) { + tgl = 1; // Batas Nilai tgl Lebih dari 31 Kembali ke 1 + } + while (digitalRead(Jam_bUP) == LOW) {} // Kunci Tombol Setting tgl Sampai Lepas Tombol + } + if (digitalRead(Jam_bDN) == LOW) { // Tombol Setting bln + delay(10); bln++; // Delay Tombol & Tambah Nilai bln + if (bln >= 13) { + bln = 1; // Batas Nilai bln Lebih dari 12 Kembali ke 1 + } + while (digitalRead(Jam_bDN) == LOW) {} // Kunci Tombol Setting blnSampai Lepas Tombol + } + + + + + // ///////=======setting thn== + +setThn: // Setting thn + if (digitalRead(Jam_bUP) == LOW ) { // Tombol Setting thn + delay(10); thn++; // Delay Tombol & Tambah Nilai thn + if (thn >= 9999) { + thn = 0; // Batas Nilai Menit Lebih dari 9999 Kembali ke 0 + } + while (digitalRead(Jam_bUP) == LOW) {} // Kunci Tombol Setting thn Sampai Lepas Tombol + } + if (digitalRead(Jam_bDN) == LOW) { // Tombol Setting thn + delay(10); thn--; // Delay Tombol & Tambah Nilai thn + if (thn <= 0) { + thn = 0; // Batas Nilai kurang dari 0 Kembali ke 0 + } + while (digitalRead(Jam_bDN) == LOW) {} // Kunci Tombol Setting thn Sampai Lepas Tombol + } + + + + + // =======setting Hari====== + //hitungan hari mulai dari 0,1,2,3,4,5,6 = senin, selasa, rabu, kamis, jumat, sabtu, minggu + +setHari: // Setting Times hari + if (digitalRead(Jam_bUP) == LOW ) { // Tombol Setting hari + harin_e = harin_e; + delay(10); + harin_e++; // Delay Tombol & Tambah Nilai hari, + if (harin_e >= 7) { + harin_e = 0; // Batas Nilai Menit Lebih dari 6 Kembali ke 0 + } + while (digitalRead(Jam_bUP) == LOW) {} // Kunci Tombol Setting hariSampai Lepas Tombol + } + if (digitalRead(Jam_bDN) == LOW) { // Tombol Setting hari + harin_e = harin_e; + delay(10); + harin_e--; // Delay Tombol & Tambah Nilai hari + if (harin_e <= 0) { + harin_e = 0; // Batas Nilai kurang dari 0 Kembali ke 0 + } + while (digitalRead(Jam_bDN) == LOW) {} // Kunci Tombol Setting hari Sampai Lepas Tombol + } + + ///============Tombol OKE ======================= + + + if (digitalRead(tombol_bOK) == LOW) { // Tombol Selesai Setting + + kasus = kasus + 1; + dmd.clearScreen(true); // Hapus Tampilan P10 + DateTime dt(thn, bln, tgl, jame, menit_e, 0, harin_e); + // DateTime dt(2017, 5, 4, 15, 11, 0, 4); + rtc.setDateTime(dt); //Adjust date-time as defined 'dt' above + while (digitalRead(tombol_bOK) == LOW) {} + delay(500); + + // ============================================kasus-kasus=================== + + } if (kasus == 1) { //kasus seting jam + + dmd.clearScreen(true); + dmd.selectFont(SystemFont5x7); + dmd.drawString(0, 0, "set-J", 5, 0); + String xjam = Konversi(jame) + ":" + Konversi(menit_e) ; + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + delay (100); + goto setTimes; //lari ke fungsi seting jam + + } + if (kasus == 2) { //kasus seting tanggal + + dmd.clearScreen(true); + dmd.selectFont(SystemFont5x7); + dmd.drawString(0, 0, "Tgl", 3, 0); + String xjam = Konversi(tgl) + "/" + Konversi(bln) ; + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + delay (100); + goto setTgl;//lari ke fungsi setting tanggal + + } if (kasus == 3) { ///kasus seting tahun + + dmd.clearScreen(true); + dmd.selectFont(SystemFont5x7); + dmd.drawString(0, 0, "Thn", 3, 0); + String xjam = Konversi(thn) ; + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + delay (100); + goto setThn; //lari ke fungsi setting tahun + + } + + if (kasus == 4) { //kasus seting hari + + dmd.clearScreen(true); + dmd.selectFont(SystemFont5x7); + dmd.drawString(0, 0, "Hari", 4, 0); + String xjam = Konversi(harin_e) ; + if (harin_e == 0) { + xjam = "SEN"; + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + } if (harin_e == 1) { + xjam = "SEL"; + + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + } + if (harin_e == 2) { + xjam = "RAB"; + + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + } if (harin_e == 3) { + xjam = "KAM"; + + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + } if (harin_e == 4) { + xjam = "JUM"; + + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + } if (harin_e == 5) { + xjam = "SAB"; + + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + } if (harin_e == 6) { + xjam = "MIN"; + + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(0, 9, sjam, pjg, 0); + } + delay (100); + goto setHari; //lari ke seting hari + + } + + + if (kasus == 5) { //kasus wis Rampung + dmd.clearScreen(true); + goto endSetting; + delay(500); + + } + +endSetting: // Label End Setting + attachInterrupt(0, Setting, FALLING); // Interrupt Tombol OK + Waduh_Setting = false; + + kasus = 0; + + +} + + + +//////////////////////==========================Program Jam============== + +int menite = 1; ///waktu iqomah lamanya +void mulai() +{ + dmd.clearScreen( true ); + long mulai = millis(); + while (millis() - mulai < 3000) { + + DateTime now = rtc.now(); + String Teks; + + ///================pengaturan koordinat-gunakan gps android untuk menentukan posisi anda================= + double lintang =-7.983908; //Latitude malang + double bujur = 112.621391; //Longitude malang + //Latitude -6.178306 banten + //Longitude 106.631889 banten + int Z = 7 ; //Zona Waktu GMT WIB biasanya 7 + + + int tgl = now.date(); //Tanggal + int bln = now.month(); //Bulan + int thn = now.year(); //Tahun + int hours, minutes; //jam sholat dan menit sholat + + long mulai = millis(); + + set_calc_method(ISNA); //Methode perhitungan mengikuti ISNA + set_asr_method(Shafii); //Pendapat Imam Syafi'i + set_high_lats_adjust_method(AngleBased); + set_fajr_angle(20); //Sudut Waktu Subuh + set_isha_angle(18); ////Sudut Waktu Isya + get_prayer_times(thn, bln, tgl, lintang, bujur, Z, times); + + + + + ///jam--besar/// + dmd.clearScreen( true ); + dmd.selectFont(angka6x13); + int menit_e = now.minute(); + int jame = now.hour(); + + String xjam = Konversi(jame) ; //tampilan jam + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.drawString(1, 0, sjam, pjg, 0); + + /////menit/// + String xxjam = Konversi(now.minute()) ; //tampilan menit + int xpjg = xxjam.length() + 1; + char xsjam[xpjg]; + xxjam.toCharArray(xsjam, xpjg); + dmd.drawString(18, 0, xsjam, xpjg, 0); + + ///titik dua : + + dmd.selectFont(SystemFont5x7); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_OR ); // clock colon overlay off + delay( 1000 ); + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + dmd.selectFont(SystemFont5x7); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_OR ); // clock colon overlay off + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_OR ); // clock colon overlay off + delay( 1000 ); + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + dmd.selectFont(SystemFont5x7); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_OR ); // clock colon overlay off + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_OR ); // clock colon overlay off + delay( 1000 ); + dmd.selectFont(SystemFont5x7); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_OR ); // clock colon overlay off + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + dmd.drawChar( 14, 4, ':', GRAPHICS_OR ); // clock colon overlay off + delay( 1000 ); + dmd.selectFont(SystemFont5x7); + dmd.drawChar( 14, 4, ':', GRAPHICS_NOR ); // clock colon overlay on + delay( 1000 ); + + ////subuh + dmd.clearScreen( true ); + get_float_time_parts(times[0], hours, minutes); + Teks = "SUBUH"; //baris atas + char pj = Teks.length() + 1; + char tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.clearScreen( true ); + dmd.selectFont(Font3x5); + dmd.drawString(7, -2, tampil, pj, 0); //koordinat tampilan + Teks = Konversi(hours) + ":" + Konversi(minutes); //baris kedua + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, tampil, pj, 0); //koordinat tampilan + delay(2000); + ///////// + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + ////dzuhur + dmd.clearScreen( true ); + get_float_time_parts(times[2], hours, minutes); + Teks = "DZUHUR"; //baris atas + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(Font3x5); + dmd.drawString(4, -2, tampil, pj, 0); //koordinat tampilan + Teks = Konversi(hours) + ":" + Konversi(minutes); //baris kedua + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, tampil, pj, 0); //koordinat tampilan + delay(2000); + + ///////// + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + ////Asar + dmd.clearScreen( true ); + get_float_time_parts(times[3], hours, minutes); + Teks = "ASHAR"; //baris atas + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(Font3x5); + dmd.drawString(7, -2, tampil, pj, 0); //koordinat tampilan + Teks = Konversi(hours) + ":" + Konversi(minutes); //baris kedua + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, tampil, pj, 0); //koordinat tampilan + delay(2000); + ///////// + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + ////Maghrib + dmd.clearScreen( true ); + get_float_time_parts(times[4], hours, minutes); + Teks = "MAGHRIB"; //baris atas + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); +dmd.selectFont(Font3x5); + dmd.drawString(1, -2, tampil, pj, 0); //koordinat tampilan + Teks = Konversi(hours) + ":" + Konversi(minutes); //baris kedua + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, tampil, pj, 0); //koordinat tampilan + delay(2000); + ///////// + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + ///Isya' + dmd.clearScreen( true ); + get_float_time_parts(times[6], hours, minutes); + Teks = "ISYA'"; //baris atas + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); +dmd.selectFont(Font3x5); + dmd.drawString(7, -2, tampil, pj, 0); //koordinat tampilan + Teks = Konversi(hours) + ":" + Konversi(minutes); //baris kedua + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, tampil, pj, 0); //koordinat tampilan + delay(2000); + ///////// + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + //imsak + dmd.clearScreen( true ); + + get_float_time_parts(times[0], hours, minutes); + if (minutes < 11) + { + minutes = 60 - minutes; + hours --; + } + else { + minutes = minutes - 10 ; + } + Teks = "IMSAK"; //baris atas + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + dmd.selectFont(Font3x5); + dmd.drawString(6, -2, tampil, pj, 0); //koordinat tampilan + + Teks = Konversi(hours) + ":" + Konversi(minutes); //baris kedua + pj = Teks.length() + 1; + tampil[pj]; + Teks.toCharArray(tampil, pj); + + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, tampil, pj, 0); //koordinat tampilan + delay(2000); + ///TOMBOL SET JAM// + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + } + + } + + + + ///=============================PROGRAM ADZAN DAN IQOMAH=================== + //jam adzan Subuh---------------------------------------------------------- + int hours; + int minutes; + dmd.clearScreen( true ); + while (millis() - mulai < 28000) { + /////////////////////// + + DateTime now = rtc.now(); + String hariku = Konversi(now.date()) + "/" + Konversi(now.month()) ; //tampilan tanggal + int dowo = hariku.length() + 1; + char detikanku[dowo]; + hariku.toCharArray(detikanku, dowo); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 0, detikanku, dowo, 0); + dmd.selectFont(Font3x5); + dmd.drawString(5, 6, (weekDay[now.dayOfWeek()]), 7, 0); //tampilan hari + ///////////////interupsi tombol menu----------- + + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + + + ///////////////////// + + get_float_time_parts(times[0], hours, minutes); + if ((now.hour() == hours && now.minute() == minutes) || (now.hour() == hours && now.minute() == minutes + 1) || (now.hour() == hours && now.minute() == minutes + 2) + || (now.hour() == hours && now.minute() == minutes + 3) + || (now.hour() == hours && now.minute() == minutes + 4) + || (now.hour() == hours && now.minute() == minutes + 5)) { + + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(1000); + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(1000); + + dmd.clearScreen( true ); + dmd.selectFont(SystemFont5x7); + dmd.drawString(2, 0, "ADZAN ", 5, 0); //koordinat tampilan + dmd.selectFont(Font3x5); + dmd.drawString(3, 7, "SUBUH", 5, 0); //koordinat tampilan + delay(150000); + + //iqomah---------------------------------- + int langkah; + int waktu_iqomah; + int panjang_iqomah; + int iqomah; + dmd.clearScreen( true ); + + + dmd.selectFont(Font3x5); + dmd.clearScreen( true ); + dmd.drawString(3, -2, "IQOMAH", 6, 0); //koordinat tampilan + int tampil; + int detik = 60, menit = 10; + for (detik = 60; detik >= 0; detik--) { + delay(1000); + String iqomah = Konversi(menit) + ":" + Konversi(detik); + int panjang_iqomah = iqomah.length() + 1; + char waktu_iqomah[panjang_iqomah]; + iqomah.toCharArray(waktu_iqomah, panjang_iqomah); + dmd.selectFont(SystemFont5x7); + dmd.drawString(0, 9, waktu_iqomah, panjang_iqomah, 0); + if (detik <= 0) { + detik = 60; + menit = menit - 1; + } if (menit <= 0 && detik <= 1) { + for (tampil = 0; tampil < 300 ; tampil++) { + menit = 0; + detik = 0; + dmd.clearScreen( true ); + dmd.selectFont(Font3x5); + dmd.drawString(4, -2, "SHOLAT", 6, 0); //koordinat tampilan + /////////////////////// + now = rtc.now(); + String xjam = Konversi(now.hour()) + ":" + Konversi(now.minute()) ; //tampilan jam + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, sjam, pjg, 0); + + ///////////////////// + delay (1000); + + + + } + } + } + } + } + + + //jam adzan Dzuhur-------------------WAKTU DZUHUR MODIFIED-------------------------------------- + dmd.clearScreen( true ); + while (millis() - mulai <29000) { + /////////////////////// + + DateTime now = rtc.now(); + String hariku = Konversi(now.date()) + "/" + Konversi(now.month()) ; //tampilan tanggal + int dowo = hariku.length() + 1; + char detikanku[dowo]; + hariku.toCharArray(detikanku, dowo); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 0, detikanku, dowo, 0); + dmd.selectFont(Font3x5); + dmd.drawString(5, 6, (weekDay[now.dayOfWeek()]), 7, 0); //tampilan hari + + + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + + ///////////////////// + int harin_e = now.dayOfWeek(); + get_float_time_parts(times[2], hours, minutes); + if ((now.hour() == hours && now.minute() == minutes && harin_e != 4 ) || (now.hour() == hours && now.minute() == minutes + 1 && harin_e != 4 ) || (now.hour() == hours && now.minute() == minutes + 2 && harin_e != 4 ) + || (now.hour() == hours && now.minute() == minutes + 3 && harin_e != 4 ) + || (now.hour() == hours && now.minute() == minutes + 4 && harin_e != 4 ) + || (now.hour() == hours && now.minute() == minutes + 5 && harin_e != 4 )) { + + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(3000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + + dmd.clearScreen( true ); + dmd.selectFont(SystemFont5x7); + dmd.drawString(2, 0, "ADZAN ", 5, 0); //koordinat tampilan + dmd.selectFont(Font3x5); + dmd.drawString(1, 6, "DZUHUR", 6, 0); //koordinat tampilan + delay(150000); + + + //iqomah---------------------------------- + int langkah; + int waktu_iqomah; + int panjang_iqomah; + int iqomah; + dmd.clearScreen( true ); + + + dmd.selectFont(Font3x5); + dmd.clearScreen( true ); + dmd.drawString(3, -2, "IQOMAH", 6, 0); //koordinat tampilan + int tampil; + int detik = 60, menit = 10; + for (detik = 60; detik >= 0; detik--) { + delay(1000); + String iqomah = Konversi(menit) + ":" + Konversi(detik); + int panjang_iqomah = iqomah.length() + 1; + char waktu_iqomah[panjang_iqomah]; + iqomah.toCharArray(waktu_iqomah, panjang_iqomah); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, waktu_iqomah, panjang_iqomah, 0); + if (detik <= 0) { + detik = 60; + menit = menit - 1; + } if (menit <= 0 && detik <= 1) { + for (tampil = 0; tampil < 300 ; tampil++) { + menit = 0; + detik = 0; + dmd.clearScreen( true ); + dmd.selectFont(Font3x5); + dmd.drawString(4, -2, "SHOLAT", 6, 0); //koordinat tampilan + /////////////////////// + now = rtc.now(); + String xjam = Konversi(now.hour()) + ":" + Konversi(now.minute()) ; //tampilan jam + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, sjam, pjg, 0); + ///////////////////// + /////////////////////// + delay (1000); + + } + } + } + } + } + + + //---------------------------------------------------------------------- + //jam hari Jum'at----JUM'AT--------JUM'AT--------JUM'AT----JUM'AT----JUM'AT----JUM'AT----JUM'AT----JUM'AT----JUM'AT------------------------------------------ + dmd.clearScreen( true ); + + while (millis() - mulai < 30000) { + /////////////////////// + + DateTime now = rtc.now(); + String hariku = Konversi(now.date()) + "/" + Konversi(now.month()) ; //tampilan tanggal + int dowo = hariku.length() + 1; + char detikanku[dowo]; + hariku.toCharArray(detikanku, dowo); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 0, detikanku, dowo, 0); + dmd.selectFont(Font3x5); + dmd.drawString(5, 6, (weekDay[now.dayOfWeek()]), 7, 0); //tampilan hari + + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + + ///////////////////// + int harin_e = now.dayOfWeek(); + get_float_time_parts(times[2], hours, minutes); + if ((now.hour() == hours && now.minute() == minutes && harin_e == 4) || (now.hour() == hours && now.minute() == minutes + 1 && harin_e == 4) || (now.hour() == hours && now.minute() == minutes + 2 && harin_e == 4) + || (now.hour() == hours && now.minute() == minutes + 3 && harin_e == 4) + || (now.hour() == hours && now.minute() == minutes + 4 && harin_e == 4) + || (now.hour() == hours && now.minute() == minutes + 5 && harin_e == 4)) { + int tampil; + dmd.clearScreen( true ); + for (tampil = 0; tampil < 1550 ; tampil++) { + dmd.selectFont(Font3x5); + dmd.drawString(1, -2, "Jum'at", 10, 0); //koordinat tampilan + /////////////////////// + now = rtc.now(); + String xjam = Konversi(now.hour()) + ":" + Konversi(now.minute()) ; //tampilan jam + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, sjam, pjg, 0); + + ///////////////////// + delay (1000); + + } + + } + + + } + + + + ////-----AKHIR CODING JIKA HARI JUM'AT----- + + + + + + + + + //---------------------------------------------------------------------- + + + //jam adzan Asar---------------------------------------------------------- + dmd.clearScreen( true ); + while (millis() - mulai < 31000) { + /////////////////////// + + DateTime now = rtc.now(); + String hariku = Konversi(now.date()) + "/" + Konversi(now.month()) ; //tampilan tanggal + int dowo = hariku.length() + 1; + char detikanku[dowo]; + hariku.toCharArray(detikanku, dowo); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 0, detikanku, dowo, 0); + dmd.selectFont(Font3x5); + dmd.drawString(5, 6, (weekDay[now.dayOfWeek()]), 7, 0); //tampilan hari + ///////////////////// + get_float_time_parts(times[3], hours, minutes); + if ((now.hour() == hours && now.minute() == minutes) || (now.hour() == hours && now.minute() == minutes + 1) || (now.hour() == hours && now.minute() == minutes + 2) + || (now.hour() == hours && now.minute() == minutes + 3) + || (now.hour() == hours && now.minute() == minutes + 4) + || (now.hour() == hours && now.minute() == minutes + 5)) { + + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(3000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + + dmd.clearScreen( true ); + dmd.selectFont(SystemFont5x7); + dmd.drawString(2, 0, "ADZAN ", 5, 0); //koordinat tampilan + dmd.selectFont(Font3x5); + dmd.drawString(7, 7, "ASHAR", 4, 0); //koordinat tampilan + delay(150000); + + //iqomah---------------------------------- + int langkah; + int waktu_iqomah; + int panjang_iqomah; + int iqomah; + dmd.clearScreen( true ); + + + dmd.selectFont(Font3x5); + dmd.clearScreen( true ); + dmd.drawString(3, -2, "IQOMAH", 6, 0); //koordinat tampilan + int tampil; + int detik = 60, menit = 10; + for (detik = 60; detik >= 0; detik--) { + delay(1000); + String iqomah = Konversi(menit) + ":" + Konversi(detik); + int panjang_iqomah = iqomah.length() + 1; + char waktu_iqomah[panjang_iqomah]; + iqomah.toCharArray(waktu_iqomah, panjang_iqomah); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, waktu_iqomah, panjang_iqomah, 0); + if (detik <= 0) { + detik = 60; + menit = menit - 1; + } if (menit <= 0 && detik <= 1) { + for (tampil = 0; tampil < 300 ; tampil++) { + menit = 0; + detik = 0; + dmd.clearScreen( true ); + dmd.selectFont(Font3x5); + dmd.drawString(4, -2, "SHOLAT", 6, 0); //koordinat tampilan + /////////////////////// + now = rtc.now(); + String xjam = Konversi(now.hour()) + ":" + Konversi(now.minute()) ; //tampilan jam + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, sjam, pjg, 0); + + ///////////////////// + /////////////////////// + delay (1000); + + } + } + } + } + } + + + + + + + //---------------------------------------------------------------------- + + //jam adzan Maghrib---------------------------------------------------------- + dmd.clearScreen( true ); + while (millis() - mulai <32000) { + /////////////////////// + + DateTime now = rtc.now(); + String hariku = Konversi(now.date()) + "/" + Konversi(now.month()) ; //tampilan tanggal + int dowo = hariku.length() + 1; + char detikanku[dowo]; + hariku.toCharArray(detikanku, dowo); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 0, detikanku, dowo, 0); + dmd.selectFont(Font3x5); + dmd.drawString(5, 6, (weekDay[now.dayOfWeek()]), 7, 0); //tampilan hari + + ///////////////interupsi tombol menu----------- + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + ///////////////////// + get_float_time_parts(times[4], hours, minutes); + if ((now.hour() == hours && now.minute() == minutes) || (now.hour() == hours && now.minute() == minutes + 1) || (now.hour() == hours && now.minute() == minutes + 2) + || (now.hour() == hours && now.minute() == minutes + 3) + || (now.hour() == hours && now.minute() == minutes + 4) + || (now.hour() == hours && now.minute() == minutes + 5)) { + + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(3000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + + dmd.clearScreen( true ); + dmd.selectFont(SystemFont5x7); + dmd.drawString(2, 0, "ADZAN ", 5, 0); //koordinat tampilan + dmd.selectFont(Font3x5); + dmd.drawString(1, 7, "MAGHRIB", 7, 0); //koordinat tampilan + delay(150000); + + + + + //iqomah---------------------------------- + int langkah; + int waktu_iqomah; + int panjang_iqomah; + int iqomah; + dmd.clearScreen( true ); + + + dmd.selectFont(Font3x5); + dmd.clearScreen( true ); + dmd.drawString(3, -2, "IQOMAH", 6, 0); //koordinat tampilan + int tampil; + int detik = 60, menit = 10; + for (detik = 60; detik >= 0; detik--) { + delay(1000); + String iqomah = Konversi(menit) + ":" + Konversi(detik); + int panjang_iqomah = iqomah.length() + 1; + char waktu_iqomah[panjang_iqomah]; + iqomah.toCharArray(waktu_iqomah, panjang_iqomah); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, waktu_iqomah, panjang_iqomah, 0); + if (detik <= 0) { + detik = 60; + menit = menit - 1; + } if (menit <= 0 && detik <= 1) { + for (tampil = 0; tampil < 300 ; tampil++) { + menit = 0; + detik = 0; + dmd.clearScreen( true ); + dmd.selectFont(Font3x5); + dmd.drawString(4, -2, "SHOLAT", 6, 0); //koordinat tampilan + /////////////////////// + now = rtc.now(); + String xjam = Konversi(now.hour()) + ":" + Konversi(now.minute()) ; //tampilan jam + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, sjam, pjg, 0); + + ///////////////////// + /////////////////////// + delay (1000); + + } + } + } + } + } + + //jam adzan isya---------------------------------------------------------- + dmd.clearScreen( true ); + while (millis() - mulai < 33000) { + /////////////////////// + + DateTime now = rtc.now(); + String hariku = Konversi(now.date()) + "/" + Konversi(now.month()) ; //tampilan tanggal + int dowo = hariku.length() + 1; + char detikanku[dowo]; + hariku.toCharArray(detikanku, dowo); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 0, detikanku, dowo, 0); + dmd.selectFont(Font3x5); + dmd.drawString(5, 6, (weekDay[now.dayOfWeek()]), 7, 0); //tampilan hari + ///////////////interupsi tombol menu----------- + + if (digitalRead(tombol_bOK) == LOW) { + MenuSetting(); // Jika Tombol OK/Interrupt ditekan maka masuk menu setting Manual + + } + + ///////////////////// + get_float_time_parts(times[6], hours, minutes); + if ((now.hour() == hours && now.minute() == minutes) || (now.hour() == hours && now.minute() == minutes + 1) || (now.hour() == hours && now.minute() == minutes + 2) + || (now.hour() == hours && now.minute() == minutes + 3) + || (now.hour() == hours && now.minute() == minutes + 4) + || (now.hour() == hours && now.minute() == minutes + 5)) { + + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(1000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + digitalWrite(2, HIGH);//alarm sholat + delay(3000); + digitalWrite(2, LOW);//alarm sholat + delay(500); + + dmd.clearScreen( true ); + dmd.selectFont(SystemFont5x7); + dmd.drawString(2, 0, "ADZAN", 5, 0); //koordinat tampilan + dmd.selectFont(Font3x5); + dmd.drawString(7, 7, "ISYA'", 4, 0); //koordinat tampilan + delay(150000); + + + + + //iqomah---------------------------------- + int langkah; + int waktu_iqomah; + int panjang_iqomah; + int iqomah; + dmd.clearScreen( true ); + + + dmd.selectFont(Font3x5); + dmd.clearScreen( true ); + dmd.drawString(3, -2, "IQOMAH", 6, 0); //koordinat tampilan + int tampil; + int detik = 60, menit = 10; + for (detik = 60; detik >= 0; detik--) { + delay(1000); + String iqomah = Konversi(menit) + ":" + Konversi(detik); + int panjang_iqomah = iqomah.length() + 1; + char waktu_iqomah[panjang_iqomah]; + iqomah.toCharArray(waktu_iqomah, panjang_iqomah); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, waktu_iqomah, panjang_iqomah, 0); + if (detik <= 0) { + detik = 60; + menit = menit - 1; + } if (menit <= 0 && detik <= 1) { + for (tampil = 0; tampil < 300 ; tampil++) { + menit = 0; + detik = 0; + dmd.clearScreen( true ); + dmd.selectFont(Font3x5); + dmd.drawString(4, -2, "SHOLAT", 6, 0); //koordinat tampilan + /////////////////////// + now = rtc.now(); + String xjam = Konversi(now.hour()) + ":" + Konversi(now.minute()) ; //tampilan jam + int pjg = xjam.length() + 1; + char sjam[pjg]; + xjam.toCharArray(sjam, pjg); + dmd.selectFont(SystemFont5x7); + dmd.drawString(1, 9, sjam, pjg, 0); + + ///////////////////// + /////////////////////// + delay (1000); + + } + } + } + } + } + +} + + + +//---------------------------------------------------------------------- +///konversi angka agar ada nol didepannya jika diawah 10 + +String Konversi(int sInput) { + if (sInput < 10) + { + return"0" + String(sInput); + } + else + { + return String(sInput); + } +} + diff --git a/running_led/running_led.ino b/running_led/running_led.ino new file mode 100644 index 0000000..8b6537a --- /dev/null +++ b/running_led/running_led.ino @@ -0,0 +1,109 @@ +int ledPin1 = 0; +int ledPin2 = 1; +int ledPin3 = 2; +int ledPin4 = 3; +int ledPin5 = 4; +// type data yang berfungsi sebagai penyimpan bilangan bulat + +void setup() +{ +pinMode(ledPin1, OUTPUT); +pinMode(ledPin2, OUTPUT); +pinMode(ledPin3, OUTPUT); +pinMode(ledPin4, OUTPUT); +pinMode(ledPin5, OUTPUT); +// menjadikan PIN 0, 1, 2, 3, dan 4 sebagai OUTPUT +} + +void loop() +// Menyalakan LED sacara bergilir +{ +digitalWrite(ledPin1, HIGH); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, LOW); +delay(100); +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, HIGH); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, LOW); +delay(100); +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, HIGH); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, LOW); +delay(100); +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, HIGH); +digitalWrite(ledPin5, LOW); +delay(100); +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, HIGH); +delay(100); +//MODE 2 +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, HIGH); +delay(100); +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, HIGH); +digitalWrite(ledPin5, LOW); +delay(100); +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, HIGH); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, LOW); +delay(100); +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, HIGH); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, LOW); +delay(100); +digitalWrite(ledPin1, HIGH); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, LOW); +delay(100); +//MODE 3 +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, HIGH); +digitalWrite(ledPin3, HIGH); +digitalWrite(ledPin4, HIGH); +digitalWrite(ledPin5, LOW); +delay(300); +//MODE 4 +digitalWrite(ledPin1, LOW); +digitalWrite(ledPin2, HIGH); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, HIGH); +digitalWrite(ledPin5, LOW); +delay(250); +digitalWrite(ledPin1, HIGH); +digitalWrite(ledPin2, LOW); +digitalWrite(ledPin3, LOW); +digitalWrite(ledPin4, LOW); +digitalWrite(ledPin5, HIGH); +delay(250); +//MODE 5 +digitalWrite(ledPin1, HIGH); +digitalWrite(ledPin2, HIGH); +digitalWrite(ledPin3, HIGH); +digitalWrite(ledPin4, HIGH); +digitalWrite(ledPin5, HIGH); +delay(350); +} diff --git a/running_text/running_text.ino b/running_text/running_text.ino new file mode 100644 index 0000000..cd664c2 --- /dev/null +++ b/running_text/running_text.ino @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +const int WIDTH = 1; // jumlah panel led matrik yang digunakan + +const uint8_t *FONT = Arial14; +//const uint8_t *FONT = SystemFont5x7; + +const char *MESSAGE = "SELAMAT DATANG DI SISTEM KOMPUTER STMIK ASIA MALANG, Go PIMNAS 2019..... "; // text / tulisan yang ingin ditampilkan + +SoftDMD dmd(WIDTH,1); +DMD_TextBox box(dmd); + +void setup() { + Serial.begin(9600); + dmd.setBrightness(255); + dmd.selectFont(FONT); + dmd.begin(); +} + +void loop() { + const char *next = MESSAGE; + while(*next) { + box.print(*next); + delay(200); + next++; + } +} diff --git a/scan_rfid/scan_rfid.ino b/scan_rfid/scan_rfid.ino new file mode 100644 index 0000000..f5ebd38 --- /dev/null +++ b/scan_rfid/scan_rfid.ino @@ -0,0 +1,94 @@ +#include //library serial parallel interface +#include //library untuk wire i2c +#include //library RFID +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +#define sda 10 //Pin Serialdata (SDA) +#define rst 9 //pin Reset + +RFID rfid(sda,rst); + + int serNum[5]; //Variable buffer Scan Card + int cards[][5] = {{47,125,104,104,82}}; // yang diizinkan + + bool access = false; + +void setup(){ + Serial.begin(9600); //baud komunikasi serial monitor + lcd.begin(16,2); //ukuran LCD 16 x 2 + SPI.begin(); //Prosedur antarmuka SPI + rfid.init(); //Memulai inialisasi module RFID + + lcd.setCursor (0,0); + lcd.print("***RFID RF522***"); + lcd.setCursor (0,1); + lcd.print(" scan card RFID "); + delay (4000); + lcd.clear(); +} + +void loop(){ + lcd.setCursor (0,0); + lcd.print("Please scan card"); + lcd.setCursor (0,1); + lcd.print(" ...<<< Here "); + +if(rfid.isCard()){ +if(rfid.readCardSerial()){ + lcd.setCursor (0,0); + lcd.print("ID Card : "); + + lcd.setCursor (0,1); + Serial.print(rfid.serNum[0]); //serial no.1 + Serial.print(" "); + lcd.print(rfid.serNum[0]); + + Serial.print(rfid.serNum[1]); //serial no.2 + Serial.print(" "); + lcd.print(rfid.serNum[1]); + + Serial.print(rfid.serNum[2]); //serial no.3 + Serial.print(" "); + lcd.print(rfid.serNum[2]); + + Serial.print(rfid.serNum[3]); //serial no.4 + Serial.print(" "); + lcd.print(rfid.serNum[3]); + + Serial.print(rfid.serNum[4]); //serial no.5 + Serial.println(""); + lcd.print(rfid.serNum[4]); + + delay(3000); + lcd.clear(); + } + for(int x = 0; x < sizeof(cards); x++){ + for(int i = 0; i < sizeof(rfid.serNum); i++ ){ + if(rfid.serNum[i] != cards[x][i]) { + access = false; + break; + } else { + access = true; + } + } + if(access) break; + } + } + if(access){ + Serial.println("Welcome!"); + lcd.setCursor (0,0); + lcd.print(F(" Akses diterima ")); + lcd.setCursor (0,1); + lcd.print("ID:"); + lcd.print(rfid.serNum[0]); lcd.print(rfid.serNum[1]); + lcd.print(rfid.serNum[2]); lcd.print(rfid.serNum[3]); + lcd.print(rfid.serNum[4]); + // tampilan sukses + lcd.setCursor(0,0); + lcd.print("E Money"); + lcd.setCursor(0,1); + lcd.print("Mandiri"); + } +} + diff --git a/scan_rfid_monitor/scan_rfid_monitor.ino b/scan_rfid_monitor/scan_rfid_monitor.ino new file mode 100644 index 0000000..9d86d5f --- /dev/null +++ b/scan_rfid_monitor/scan_rfid_monitor.ino @@ -0,0 +1,39 @@ +#include //library serial parallel interface +#include //library untuk wire i2c +#include //library RFID +#define sda 10 //Pin Serialdata (SDA) +#define rst 9 //pin Reset + +RFID rfid(sda,rst); + +void setup(){ + Serial.begin(9600); //baud komunikasi serial monitor + SPI.begin(); //Prosedur antarmuka SPI + Serial.println(" test RFID PN 532"); + Serial.println(" tap Please...."); + rfid.init(); //Memulai inialisasi module RFID +} + +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(""); + + } + } + } diff --git a/scanner_I2C_LCD/scanner_I2C_LCD.ino b/scanner_I2C_LCD/scanner_I2C_LCD.ino new file mode 100644 index 0000000..f103a11 --- /dev/null +++ b/scanner_I2C_LCD/scanner_I2C_LCD.ino @@ -0,0 +1,58 @@ +/*... www.nyebarilmu.com ...*/ + +#include + +void setup() +{ + //prosedur pembacaan i2c + Wire.begin(); + + Serial.begin(9600); //komunikasi serial menggunakan kecepatan 9600 bps + while (!Serial); // Arduino Uno: wait for serial monitor + Serial.println("\nI2C Scanner"); +} + +void loop() //fungsi yang berjalan terus menerus +{ + int nDevices; + byte error, address; //tipe data untuk address dan error yaitu byte + //ditampilkan diserial monitor "Scanning..." + Serial.println("Scanning..."); + + nDevices = 00; + for(address = 1; address < 127; address++ ) + { + // The i2c_scanner menggunakan pembalik nilai + // Write.endTransmisstion untuk melihat jika perangkat pada alamat dimana + Wire.beginTransmission(address); + error = Wire.endTransmission(); + + if (error == 00) //jika sudah tidak ada keerroran + { + Serial.print("I2C device found at address 0x"); + //menuliskan di serial monitor "i2c ditemukan" + if (address<16) + Serial.print("0"); + Serial.print(address,HEX); + Serial.println(" !"); + + nDevices++; + } + else if (error==4) //jika error == 4 + //menuliskan di serial monitor di tidak diketahui alamat i2c + { + Serial.print("Unknow error at address 0x"); //menuliskan jika eror tidak diketahui + if (address<16) + Serial.print("0"); + Serial.println(address,HEX); //format penulisan address dalam bentuk heksa + } + } + if (nDevices == 00) //jika tidak ada perangkat yang terhubung + Serial.println("No I2C devices found\n"); +//ditampilkan peringatan tidak ada i2c yang ditemukan + else + Serial.println("done\n"); + + delay(5000); // diberikan waktu tunda 5 detik untuk scan berikutnya +} + diff --git a/sensor_IR_counter/sensor_IR_counter.ino b/sensor_IR_counter/sensor_IR_counter.ino new file mode 100644 index 0000000..a945ad1 --- /dev/null +++ b/sensor_IR_counter/sensor_IR_counter.ino @@ -0,0 +1,38 @@ +#define sensorIn 6 +#define sensorOut 7 + +int count = 0; + +void setup() { + // put your setup code here, to run once: +Serial.begin(9600); +pinMode(sensorIn,INPUT); +pinMode(sensorOut,INPUT); +pinMode(13,OUTPUT); +} +void IN(){ + count++; + delay(500); +} + +void OUT(){ + count--; + delay(500); +} +void loop() { + // put your main code here, to run repeatedly: + if (digitalRead(sensorIn)) + IN(); + if (digitalRead(sensorOut)) + OUT(); + + Serial.println(count); + + if(count<=0){ + digitalWrite(13,LOW); + } + +else{ + digitalWrite(13,HIGH); +} +} diff --git a/sensor_api/sensor_api.ino b/sensor_api/sensor_api.ino new file mode 100644 index 0000000..f0deeec --- /dev/null +++ b/sensor_api/sensor_api.ino @@ -0,0 +1,43 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +const int sensorApi = 2; +const int led = 13; +const int buzzer = 12; + +// variables will change: +int bacasensor = 0; + +void setup() { + lcd.begin(16,2); + pinMode(led, OUTPUT); + pinMode(buzzer, OUTPUT); + pinMode(sensorApi, INPUT); + Serial.begin(9600); +} + +void loop() { + bacasensor = digitalRead(sensorApi); + + if ((bacasensor) == HIGH) { + digitalWrite(led, LOW); + noTone(buzzer); + lcd.setCursor(0,0); + lcd.print("Kondisi Api :"); + lcd.setCursor(0,1); + lcd.print("Tidak Terdeteksi"); + Serial.println("tidak ada api..."); + } + else { + digitalWrite(led, HIGH); + tone(buzzer, 500 ,200); + lcd.setCursor(0,0); + lcd.print("Kondisi Api :"); + lcd.setCursor(0,1); + lcd.print("Terdeteksi "); + delay(100); + Serial.println("ada api..."); + } + delay(500); +} + diff --git a/sensor_dht11_lcd/sensor_dht11_lcd.ino b/sensor_dht11_lcd/sensor_dht11_lcd.ino new file mode 100644 index 0000000..0f576e7 --- /dev/null +++ b/sensor_dht11_lcd/sensor_dht11_lcd.ino @@ -0,0 +1,59 @@ +#include "DHT.h" +//#include +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +#define DHTPIN A2 // pin 2 +#define DHTTYPE DHT11// sesnor kelembaban dan suhu + +DHT dht(DHTPIN, DHTTYPE); +void setup() { + // put your setup code here, to run once: + lcd.begin (16,2); //LCD untuk ukuran 16x2 + dht.begin(); + + lcd.setCursor(0,0); + lcd.print("Pengujian DHT11"); + delay(1000); + lcd.setCursor(4,1); + lcd.print("Ready...!"); + delay(1000); + lcd.clear(); + +} + +void loop() { + delay(100); //menunggu beberapa detik untuk pembacaan + + //pembacaan sensor membutuhkan waktu 250ms + + //Pembacaan untuk data kelembaban + float humidity_1 = dht.readHumidity(); + //Pembacaan dalam format celcius (c) + float celcius_1 = dht.readTemperature(); + //pembacaan dalam format Fahrenheit + + //mengecek pembacaan apakah terjadi kegagalan atau tidak + if (isnan(humidity_1) || isnan(celcius_1)) { + lcd.setCursor(0,0); + lcd.print(" Sensor error!!!"); + lcd.setCursor(0,1); + lcd.print(" "); + return; + } + float htoc = dht.computeHeatIndex(celcius_1, humidity_1, false); + //Prosedur pembacaaan data indeks panas dalam bentuk celcius + + //pembacaan nilai pembacaan data kelembaban + lcd.setCursor(0,0); + lcd.print("H :"); + lcd.print(humidity_1); + lcd.print(" % "); + + //pembacaan nilai pembacaan data suhu + lcd.setCursor(0,1); + lcd.print("Suhu:"); + lcd.print(celcius_1); //format derajat celcius + lcd.print(" C "); + +} diff --git a/sensor_dht11_test/sensor_dht11_test.ino b/sensor_dht11_test/sensor_dht11_test.ino new file mode 100644 index 0000000..c6ab43b --- /dev/null +++ b/sensor_dht11_test/sensor_dht11_test.ino @@ -0,0 +1,53 @@ +#include "DHT.h" //library sensor yang telah diimportkan + +#define DHTPIN A2 //Pin apa yang digunakan + +#define DHTTYPE DHT11 // DHT 11 + +DHT dht(DHTPIN, DHTTYPE); + +void setup() { + Serial.begin(9600); //baud komunikasi serial + Serial.println("Pengujian DHT11!"); //penulisan di serial monitor + dht.begin(); //prosedur memulai pembacaan module sensor +} + +void loop() { + delay(1500); //menunggu beberapa detik untuk pembacaan + + //pembacaan sensor membutuhkan waktu 250ms + + //Pembacaan untuk data kelembaban + float humidity_1 = dht.readHumidity(); + //Pembacaan dalam format celcius (c) + float celcius_1 = dht.readTemperature(); + //pembacaan dalam format Fahrenheit + float fahrenheit_1 = dht.readTemperature(true); + + //mengecek pembacaan apakah terjadi kegagalan atau tidak + if (isnan(humidity_1) || isnan(celcius_1) || isnan(fahrenheit_1)) { + Serial.println("Pembacaan data dari module sensor gagal!"); + return; + } + + float htof = dht.computeHeatIndex(fahrenheit_1, humidity_1); + //Prosedur pembacaaan data indeks panas dalam bentuk fahreheit + float htoc = dht.computeHeatIndex(celcius_1, humidity_1, false); + //Prosedur pembacaaan data indeks panas dalam bentuk celcius + + //pembacaan nilai pembacaan data kelembaban + Serial.print("Kelembaban: "); + Serial.print(humidity_1); + Serial.print(" %\t"); + + //pembacaan nilai pembacaan data suhu + Serial.print("Suhu : "); + Serial.print(celcius_1); //format derajat celcius + Serial.print(" 'C "); + Serial.print(fahrenheit_1); //format derajat fahrenheit + Serial.print(" 'F\t"); + + Serial.print("Indeks Panas: "); + Serial.print(htof); + Serial.println(" *F"); +} diff --git a/sensor_gas/sensor_gas.ino b/sensor_gas/sensor_gas.ino new file mode 100644 index 0000000..0259b95 --- /dev/null +++ b/sensor_gas/sensor_gas.ino @@ -0,0 +1,49 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +int redLed = 13; +int greenLed = 11; +int buzzer = 12; +int smokeA0 = A2; +// Your threshold value +int sensorThres = 100; + +void setup() { + pinMode(redLed, OUTPUT); + pinMode(greenLed, OUTPUT); + pinMode(buzzer, OUTPUT); + pinMode(smokeA0, INPUT); + Serial.begin(9600); + lcd.begin(16,2); +} + +void loop() { + int analogSensor = analogRead(smokeA0); + + Serial.print("Pin A0: "); + Serial.println(analogSensor); + lcd.setCursor(0,0); + lcd.print("kadar Gas :"); + lcd.print(analogSensor); + lcd.print("%"); + lcd.print(" "); + // Checks if it has reached the threshold value + if (analogSensor > sensorThres) + { + digitalWrite(redLed, HIGH); + digitalWrite(greenLed, LOW); + tone(buzzer, 1000, 200); + lcd.setCursor(0,1); + lcd.print("Gas Bocor Gan..!"); + + } + else + { + digitalWrite(redLed, LOW); + digitalWrite(greenLed, HIGH); + noTone(buzzer); + lcd.setCursor(0,1); + lcd.print("Kondisi Aman.. "); + } + delay(500); +} diff --git a/sensor_gerak/sensor_gerak.ino b/sensor_gerak/sensor_gerak.ino new file mode 100644 index 0000000..23e5e5b --- /dev/null +++ b/sensor_gerak/sensor_gerak.ino @@ -0,0 +1,49 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +int led = 3; +int sensor = 2; +int pirState = LOW; +int val = 0; +int speaker = 10; + +void setup() { + pinMode(led, OUTPUT); + pinMode(sensor, INPUT); + pinMode(speaker, OUTPUT); + lcd.begin(16,2); +} +void loop(){ + val = digitalRead(sensor); + if (val == HIGH) { + digitalWrite(led, HIGH); + + if (pirState == LOW) { + lcd.setCursor(0,0); + lcd.print(" Terdeksi!! "); + pirState = HIGH; + } + } else { + digitalWrite(led, LOW); + playTone(0, 0); + delay(300); + if (pirState == HIGH){ + lcd.setCursor(0,0); + lcd.print("tidak terdteksi!"); + pirState = LOW; + } + } +} +// Durasi msecs dalam, hertz Frekuensi +void playTone(long duration, int freq) { + duration *= 1000; + int period = (1.0 / freq) * 1000000; + long elapsed_time = 0; + while (elapsed_time < duration) { + digitalWrite(speaker,HIGH); + delayMicroseconds(period / 2); + digitalWrite(speaker, LOW); + delayMicroseconds(period / 2); + elapsed_time += (period); + } +} diff --git a/sensor_getar/sensor_getar.ino b/sensor_getar/sensor_getar.ino new file mode 100644 index 0000000..6de9c4f --- /dev/null +++ b/sensor_getar/sensor_getar.ino @@ -0,0 +1,19 @@ +int getar =0; +int sensor = A0; + +void setup() { + Serial.begin(9600); +} + +void loop() { + getar = analogRead(sensor); + Serial.println(getar); + if ( getar >=200) { + Serial.println("bergetar gan!"); + delay(1000); + } + else { + Serial.println("Menunggu getaran..."); + delay(1000); + } +} diff --git a/sensor_getar_lcd/sensor_getar_lcd.ino b/sensor_getar_lcd/sensor_getar_lcd.ino new file mode 100644 index 0000000..c853ac9 --- /dev/null +++ b/sensor_getar_lcd/sensor_getar_lcd.ino @@ -0,0 +1,38 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +int sensorGetar = 2; +int led1 = 3; // Set Pin 3 untuk LED Hijau +int led2 = 4; // Set Pin 4 untuk LED Merah +int buzzer = 5; // Set Pin 5 untuk Buzzer + +void setup() { + lcd.begin(16, 2); + pinMode(sensorGetar, INPUT); // Jadikan Vibration sensor sebagai input + pinMode(led1, OUTPUT); // Jadikan indikatorHijau sebagai Output + pinMode(led2, OUTPUT); // Jadiikan indikatorMerah sebagai Output + pinMode(buzzer, OUTPUT); // Jadikan indikatorBuzzer sebagai Output +} + +void loop() { + if ( digitalRead(sensorGetar) == HIGH) { // Jika ada getaran di sensor = HIGH + digitalWrite(led1, HIGH); // Aktifkan indikator Hijau + digitalWrite(led2, LOW); // Matikan indikator Merah + digitalWrite(buzzer, HIGH); // // Aktifkan indikator Buzzer + lcd.setCursor(0, 0); + lcd.print("bergetar gan !!!"); + delay(5000); // Tunda 5 detik + digitalWrite(led1, LOW); // Matikan indikator Hijau + digitalWrite(led2, HIGH); // Aktifkan indikator Merah + delay(100); // Delay untuk menunggu getaran selanjutnya + } + else + { + digitalWrite(led1, LOW); // Matikan indikator Hijau + digitalWrite(led2, HIGH); // Aktifkan indikator Merah + digitalWrite(buzzer, LOW); // Matikan indikator Buzzer + lcd.setCursor(0, 0); + lcd.print("Menunggu getaran"); + delay(1000); + } +} diff --git a/sensor_parkir/sensor_parkir.ino b/sensor_parkir/sensor_parkir.ino new file mode 100644 index 0000000..0674217 --- /dev/null +++ b/sensor_parkir/sensor_parkir.ino @@ -0,0 +1,33 @@ +#include + +#define echoPin 7 // echo +#define trigPin 8 // trig + +LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); + +void setup() { + lcd.begin(16,2); +} + +void loop() +{ + long durasi, inches, cm, jarak; + digitalWrite(trigPin, LOW); + delayMicroseconds(2); + + digitalWrite(trigPin, HIGH); + delayMicroseconds(10); + + digitalWrite(trigPin, LOW); + + durasi = pulseIn(echoPin, HIGH); + jarak = durasi/58.2; + + lcd.setCursor(0,0); + lcd.print("Jarak ="); + lcd.print(jarak); + lcd.print("cm "); + delay(500); + + } + diff --git a/servo_control_blynk/servo_control_blynk.ino b/servo_control_blynk/servo_control_blynk.ino new file mode 100644 index 0000000..46d41ca --- /dev/null +++ b/servo_control_blynk/servo_control_blynk.ino @@ -0,0 +1,54 @@ +#define BLYNK_PRINT Serial + +#include +#include + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +char auth[] = "46cfcffb810d409abc329ca1d92693d6"; + +// Your WiFi credentials. +// Set password to "" for open networks. +char ssid[] = "IoT_smartHome"; +char pass[] = "robotics"; + +#include + +Servo myservo; // create servo object to control a servo + +BLYNK_WRITE(V3) +{ +myservo.write(param.asInt()); +} + + +void setup() { + + myservo.attach(D3); // attaches the servo on pin 9 to the servo object + + Serial.begin(115200); + + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + + Blynk.begin(auth, ssid, pass,"blynk-cloud.com", 8442); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); +} + +void loop() +{ + Blynk.run(); +} + diff --git a/servo_controller_potensio/servo_controller_potensio.ino b/servo_controller_potensio/servo_controller_potensio.ino new file mode 100644 index 0000000..2b9c830 --- /dev/null +++ b/servo_controller_potensio/servo_controller_potensio.ino @@ -0,0 +1,15 @@ +#include + +Servo servo1; +int angle = 0; +void setup() +{ +servo1.attach(10); +} +void loop() +{ +analogRead(0); +angle=map(angle, 0, 1023, 0, 180); +servo1.write(angle); +delay(15); +} diff --git a/servo_test/servo_test.ino b/servo_test/servo_test.ino new file mode 100644 index 0000000..d149dff --- /dev/null +++ b/servo_test/servo_test.ino @@ -0,0 +1,37 @@ +#include +// membuat nama objek servo untuk pengontrolan servo +Servo servo1; +// variable untuk menyimpan posisi servo +int awal = 0; +int buttonStatus = 1; + +int sensorPin = A0; +int sensorValue = 0; +#define button 7 +void setup() +{ + Serial.begin(9600); + servo1.attach(8); // data di pin 9 + pinMode(button,INPUT_PULLUP); +} +void loop() +{ + sensorValue = analogRead(sensorPin); // read the value from the sensor +Serial.println(sensorValue); + buttonStatus = digitalRead(button); + if (buttonStatus == LOW) { + // start dari 0 derajar sampai 90 derajat + for(awal = 0; awal < 180;) + { + // pada posisi 1 derajat + // memberitahu servo untuk pergi ke posisi awal + servo1.write(awal); + // tunggu untuk pencapaian posisi servo + delay(10); + } + } + else{ + + } +} + diff --git a/sesnor_kalibrasi_lcd/sesnor_kalibrasi_lcd.ino b/sesnor_kalibrasi_lcd/sesnor_kalibrasi_lcd.ino new file mode 100644 index 0000000..260c331 --- /dev/null +++ b/sesnor_kalibrasi_lcd/sesnor_kalibrasi_lcd.ino @@ -0,0 +1,196 @@ +/* FFT_TEST4 + Ray Burnette 20130810 function clean-up & 1284 port (328 verified) + Uses 2x16 Parallel LCD in 4-bit mode, see LiquidCrystal lib call for details + http://forum.arduino.cc/index.php?PHPSESSID=4karr49jlndufvtlqs9pdd4g96&topic=38153.15 + Modified by varind in 2013: this code is public domain, enjoy! + http://www.variableindustries.com/audio-spectrum-analyzer/ + 328P = Binary sketch size: 5,708 bytes (of a 32,256 byte maximum) + 1284P= Binary sketch size: 5,792 bytes (of a 130,048 byte maximum) Free RAM = 15456 + Binary sketch size: 8,088 bytes (of a 130,048 byte maximum) (Debug) +*/ + +#include +//#include + +#define DEBUG 0 +#define L_IN 1 // Audio input A0 Arduino +#define R_IN 0 // Audio input A1 Arduino + +const int Yres = 8; +const int gain = 3; +float peaks[64]; +char im[64], data[64]; +char Rim[64], Rdata[64]; +char data_avgs[64]; +int debugLoop; +int i; +int load; + +LiquidCrystal lcd(11, 10, 7, 6, 5, 4); // pins to LCD + +// Custom CHARACTERS +byte v1[8] = { + B00000, B00000, B00000, B00000, B00000, B00000, B00000, B11111 +}; +byte v2[8] = { + B00000, B00000, B00000, B00000, B00000, B00000, B00000, B11111 +}; +byte v3[8] = { + B00000, B00000, B00000, B00000, B00000, B11111, B11111, B11111 +}; +byte v4[8] = { + B00000, B00000, B00000, B00000, B11111, B11111, B11111, B11111 +}; +byte v5[8] = { + B00000, B00000, B00000, B11111, B11111, B11111, B11111, B11111 +}; +byte v6[8] = { + B00000, B00000, B11111, B11111, B11111, B11111, B11111, B11111 +}; +byte v7[8] = { + B00000, B11111, B11111, B11111, B11111, B11111, B11111, B11111 +}; +byte v8[8] = { + B11111, B11111, B11111, B11111, B11111, B11111, B11111, B11111 +}; + +void setup() { + + if (DEBUG) { + Serial.begin(9600); // hardware serial + Serial.print("Debug ON"); + Serial.println(""); + } + + lcd.begin(16, 2); + lcd.clear(); + lcd.createChar(1, v1); + lcd.createChar(2, v2); + lcd.createChar(3, v3); + lcd.createChar(4, v4); + lcd.createChar(5, v5); + lcd.createChar(6, v6); + lcd.createChar(7, v7); + lcd.createChar(8, v8); + + for (i=0;i<80;i++) + { + for (load = 0; load < i / 5; load++) + { + lcd.setCursor(load, 1); + lcd.write(5); + } + if (load < 1) + { + lcd.setCursor(0, 1); + lcd.write(5); + } + + lcd.setCursor(load + 1, 1); + lcd.write((i - i / 5 * 5) + 1); + for (load = load + 2; load < 16; load++) + { + lcd.setCursor(load, 1); + lcd.write(9); + } + lcd.setCursor(0, 0); + lcd.print("LOADING........."); + delay(50); + } + lcd.clear(); + delay(500); +} + +void loop() { + + for (int i = 0; i < 64; i++) { // 64 bins = 32 bins of usable spectrum data + data[i] = ((analogRead(L_IN) / 4 ) - 128); // chose how to interpret the data from analog in + im[i] = 0; // imaginary component + Rdata[i] = ((analogRead(R_IN) / 4 ) - 128); // chose how to interpret the data from analog in + Rim[i] = 0; // imaginary component + } + +// fix_fft(data, im, 6, 0); // Send Left channel normalized analog values through fft + //fix_fft(Rdata, Rim, 6, 0); // Send Right channel normalized analog values through fft + + // At this stage, we have two arrays of [0-31] frequency bins deep [32-63] duplicate + + // calculate the absolute values of bins in the array - only want positive values + for (int i = 0; i < 32; i++) { + data[i] = sqrt(data[i] * data[i] + im[i] * im[i]); + Rdata[i] = sqrt(Rdata[i] * Rdata[i] + Rim[i] * Rim[i]); + + // COPY the Right low-band (0-15) into the Left high-band (16-31) for display ease + if (i < 16) { + data_avgs[i] = data[i]; + } + else { + data_avgs[i] = Rdata[i - 16]; + } + + // Remap values to physical display constraints... that is, 8 display custom character indexes + "_" + data_avgs[i] = constrain(data_avgs[i], 0, 9 - gain); //data samples * range (0-9) = 9 + data_avgs[i] = map(data_avgs[i], 0, 9 - gain, 0, Yres); // remap averaged values + } + + Two16_LCD(); + decay(1); +} + +void Two16_LCD() { + lcd.setCursor(0, 0); + lcd.print("L"); // Channel ID replaces bin #0 due to hum & noise + lcd.setCursor(0, 1); + lcd.print("R"); // ditto + + for (int x = 1; x < 16; x++) { // init 0 to show lowest band overloaded with hum + int y = x + 16; // second display line + if (data_avgs[x] > peaks[x]) peaks[x] = data_avgs[x]; + if (data_avgs[y] > peaks[y]) peaks[y] = data_avgs[y]; + + lcd.setCursor(x, 0); // draw first (top) row Left + if (peaks[x] == 0) { + lcd.print("_"); // less LCD artifacts than " " + } + else { + lcd.write(peaks[x]); + } + + lcd.setCursor(x, 1); // draw second (bottom) row Right + if (peaks[y] == 0) { + lcd.print("_"); + } + else { + lcd.write(peaks[y]); + } + } + + debugLoop++; + if (DEBUG && (debugLoop > 99)) { + Serial.print( "Free RAM = " ); + Serial.println( freeRam(), DEC); + Serial.println( millis(), DEC); + debugLoop = 0; + } +} + + +int freeRam () { + extern int __heap_start, *__brkval; + int v; + return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); +} + + +void decay(int decayrate) { + int DecayTest = 1; + // reduce the values of the last peaks by 1 + if (DecayTest == decayrate) { + for (int x = 0; x < 32; x++) { + peaks[x] = peaks[x] - 1; // subtract 1 from each column peaks + DecayTest = 0; + } + } + + DecayTest++; +} diff --git a/setup_modul_GSM800l/setup_modul_GSM800l.ino b/setup_modul_GSM800l/setup_modul_GSM800l.ino new file mode 100644 index 0000000..3470de3 --- /dev/null +++ b/setup_modul_GSM800l/setup_modul_GSM800l.ino @@ -0,0 +1,34 @@ + +#include +SoftwareSerial SIM800L(2, 3); // RX | TX +// CHubungkan TXD untuk Arduino pin 2 +// Hubungkan RXD untuk Arduino pin 3 +char c = ' '; +void setup() +{ + Serial.begin(9600); //Menggunakan komunikasi serial pada 9600bps + while(!Serial); + Serial.println("Arduino with Module GSM is ready"); + + // memulai komunikasi dengan + SIM800L.begin(9600); + Serial.println("Module GSM started at 9600"); + delay(1000); //nilai tunda 1 second + Serial.println("Setup Complete! SIM800 is Ready!"); +} + +void loop() +{ + + // memastikan pembacaan dari SIM800 dan dikirim datanya ke Arduino(Serial Monitor) + if (SIM800L.available()) + { c = SIM800L.read(); + Serial.write(c);} + + // memastikan pembacaan dari SIM800 dan dikirim datanya ke Arduino(Serial Monitor) + if (Serial.available()) + { c = Serial.read(); + SIM800L.write(c); + } + +} diff --git a/smart_lamp1_stmikAsiA/smart_lamp1_stmikAsiA.ino b/smart_lamp1_stmikAsiA/smart_lamp1_stmikAsiA.ino new file mode 100644 index 0000000..5b1655b --- /dev/null +++ b/smart_lamp1_stmikAsiA/smart_lamp1_stmikAsiA.ino @@ -0,0 +1,32 @@ +#include +#include + +#define USERNAME "lamp_smart" +#define DEVICE_ID "smart_lamp1" +#define DEVICE_CREDENTIAL "NDBZj8AF3ixk" + +#define SSID "Pkm_asia" +#define SSID_PASSWORD "sistemkomputer" + +ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); + +void setup() { + pinMode(D4, OUTPUT); + pinMode(D6, OUTPUT); + pinMode(D7, OUTPUT); + + thing.add_wifi(SSID, SSID_PASSWORD); + + // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) + thing["Lamp 1"] << digitalPin(D6); + thing["Lamp 2"] << digitalPin(D7); + digitalWrite(D4, HIGH); + // resource output example (i.e. reading a sensor value) + //thing["millis"] >> outputValue(millis()); + + // more details at http://docs.thinger.io/arduino/ +} + +void loop() { + thing.handle(); +} diff --git a/smart_lamp2_stmikAsiA/smart_lamp2_stmikAsiA.ino b/smart_lamp2_stmikAsiA/smart_lamp2_stmikAsiA.ino new file mode 100644 index 0000000..2556468 --- /dev/null +++ b/smart_lamp2_stmikAsiA/smart_lamp2_stmikAsiA.ino @@ -0,0 +1,32 @@ +#include +#include + +#define USERNAME "lamp_smart" +#define DEVICE_ID "smart_lamp2" +#define DEVICE_CREDENTIAL "P9O6MEu3rgGv" + +#define SSID "Pkm_asia" +#define SSID_PASSWORD "sistemkomputer" + +ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); + +void setup() { + pinMode(D4, OUTPUT); + pinMode(D6, OUTPUT); + pinMode(D7, OUTPUT); + + thing.add_wifi(SSID, SSID_PASSWORD); + + // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) + thing["Lamp 1"] << digitalPin(D6); + thing["Lamp 2"] << digitalPin(D7); + digitalWrite(D4, HIGH); + // resource output example (i.e. reading a sensor value) + //thing["millis"] >> outputValue(millis()); + + // more details at http://docs.thinger.io/arduino/ +} + +void loop() { + thing.handle(); +} diff --git a/smarthome/smarthome.ino b/smarthome/smarthome.ino new file mode 100644 index 0000000..9f45a7e --- /dev/null +++ b/smarthome/smarthome.ino @@ -0,0 +1,39 @@ +const int sensorApi = 2; +const int kipas = 3; +const int buzz = 5; +const int sensorGas = 6; + +int deteksiApi = 0; +int deteksiGas=0; +int kadarGas = 100; +void setup() { + // put your setup code here, to run once: +Serial.begin(9600); +pinMode(sensorApi,INPUT); +pinMode(sensorGas,INPUT); +pinMode(kipas,OUTPUT); +pinMode(buzz,OUTPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + deteksiApi = digitalRead(sensorApi); +deteksiGas = digitalRead(sensorGas); +Serial.println(sensorGas); + if ((deteksiApi)==HIGH) { + digitalWrite(kipas, HIGH); + digitalWrite(buzz, HIGH); + // Serial.println("Bahaya...!!!"); + } + if (deteksiGas ==HIGH) + { + digitalWrite(kipas, HIGH); + digitalWrite(buzz, HIGH);} + else { + digitalWrite(kipas, LOW); + digitalWrite(buzz, LOW); + // Serial.println("Bahaya...!!!"); + + } + delay(100); +} diff --git a/smarthome_blynk/smarthome_blynk.ino b/smarthome_blynk/smarthome_blynk.ino new file mode 100644 index 0000000..4d5609b --- /dev/null +++ b/smarthome_blynk/smarthome_blynk.ino @@ -0,0 +1,83 @@ +/************************************************************* + Download latest Blynk library here: + https://github.com/blynkkk/blynk-library/releases/latest + + Blynk is a platform with iOS and Android apps to control + Arduino, Raspberry Pi and the likes over the Internet. + You can easily build graphic interfaces for all your + projects by simply dragging and dropping widgets. + + Downloads, docs, tutorials: http://www.blynk.cc + Sketch generator: http://examples.blynk.cc + Blynk community: http://community.blynk.cc + Follow us: http://www.fb.com/blynkapp + http://twitter.com/blynk_app + + Blynk library is licensed under MIT license + This example code is in public domain. + + ************************************************************* + This example runs directly on ESP8266 chip. + + Note: This requires ESP8266 support package: + https://github.com/esp8266/Arduino + + Please be sure to select the right ESP8266 module + in the Tools -> Board menu! + + Change WiFi ssid, pass, and Blynk auth token to run :) + Feel free to apply it to any other example. It's simple! + *************************************************************/ + +/* Comment this out to disable prints and save space */ +#define BLYNK_PRINT Serial + +#include +#include +#include + +// You should get Auth Token in the Blynk App. +// Go to the Project Settings (nut icon). +//char auth[] = "46cfcffb810d409abc329ca1d92693d6"; +char auth[] = "ebb0613fcc614681b5b62773de43d72b"; + +// Your WiFi credentials. +// Set password to "" for open networks. +char ssid[] = "@wifi.sk"; +char pass[] = "12345678"; + +#define relay D2 +#define indicator D4 + + +void setup() +{ + // Debug console + Serial.begin(115200); + + Serial.println(); + Serial.println(); + Serial.print("Connecting to "); + Serial.println(ssid); + + Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442); + + while (WiFi.status() != WL_CONNECTED) { + delay(500); + Serial.print("."); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.println("IP address: "); + Serial.println(WiFi.localIP()); + + pinMode(relay, OUTPUT); +} + + +void loop() +{ + Blynk.run(); +} + diff --git a/sms_control_led/sms_control_led.ino b/sms_control_led/sms_control_led.ino new file mode 100644 index 0000000..ea35a33 --- /dev/null +++ b/sms_control_led/sms_control_led.ino @@ -0,0 +1,109 @@ +#include +#include + +#define TIMEOUT 5000 +#define LED_PIN 13 +#define ON 1 +#define OFF 0 + +const int MERAH = 5; +const int BIRU = 6; + +int StatusMerah; +int StatusBIRU; +GPRS gprs; + +void setup() { + pinMode (MERAH , OUTPUT); + pinMode (BIRU , OUTPUT); + Serial.begin(9600); + while(!Serial); + + Serial.println("Starting SIM800 Auto Read SMS"); + gprs.preInit(); + delay(1000); + + while(0 != gprs.init()) { + delay(1000); + Serial.print("init error\r\n"); + } + + //Set SMS mode to ASCII + if(0 != gprs.sendCmdAndWaitForResp("AT+CMGF=1\r\n", "OK", TIMEOUT)) { + ERROR("ERROR:CNMI"); + return; + } + + //Start listening to New SMS Message Indications + if(0 != gprs.sendCmdAndWaitForResp("AT+CNMI=1,2,0,0,0\r\n", "OK", TIMEOUT)) { + ERROR("ERROR:CNMI"); + return; + } + + Serial.println("Init success"); +} + +//Variable to hold last line of serial output from SIM800 +char currentLine[500] = ""; +int currentLineIndex = 0; + +//Boolean to be set to true if message notificaion was found and next +//line of serial output is the actual SMS message content +bool nextLineIsMessage = false; + +void loop() { + //Write current status to LED pin + digitalWrite(MERAH, StatusMerah); + digitalWrite(BIRU, StatusBIRU); + + //If there is serial output from SIM800 + if(gprs.serialSIM800.available()){ + char lastCharRead = gprs.serialSIM800.read(); + //Read each character from serial output until \r or \n is reached (which denotes end of line) + if(lastCharRead == '\r' || lastCharRead == '\n'){ + String lastLine = String(currentLine); + + //If last line read +CMT, New SMS Message Indications was received. + //Hence, next line is the message content. + if(lastLine.startsWith("+CMT:")){ + + Serial.println(lastLine); + nextLineIsMessage = true; + + } else if (lastLine.length() > 0) { + + if(nextLineIsMessage) { + Serial.println(lastLine); + + +// ########## MEMBACA KONTEN SMS DAN MENCARI+MENGARTIKAN KONTEN SMS KE PROGRAM ######### + //Kendali LED MERAH + if(lastLine.indexOf("MERAH ON") >= 0){ + StatusMerah = 1; + Serial.println("LED MERAH DINYALAKAN");} + else if(lastLine.indexOf("MERAH OFF") >= 0) { + StatusMerah = 0; + Serial.println("LED MERAH DIMATIKAN");} + //Kendali LED BIRU + if(lastLine.indexOf("BIRU ON") >= 0){ + StatusBIRU = 1; + Serial.println("LED BIRU DINYALAKAN");} + else if(lastLine.indexOf("BIRU OFF") >= 0) { + StatusBIRU = 0; + Serial.println("LED BIRU DIMATIKAN");} + + nextLineIsMessage = false; + } + + } + + //Clear char array for next line of read + for( int i = 0; i < sizeof(currentLine); ++i ) { + currentLine[i] = (char)0; + } + currentLineIndex = 0; + } else { + currentLine[currentLineIndex++] = lastCharRead; + } + } +} diff --git a/stepper_motof_fix/stepper_motof_fix.ino b/stepper_motof_fix/stepper_motof_fix.ino new file mode 100644 index 0000000..356e028 --- /dev/null +++ b/stepper_motof_fix/stepper_motof_fix.ino @@ -0,0 +1,29 @@ +// MultiStepper.pde +// -*- mode: C++ -*- +// +// Shows how to multiple simultaneous steppers +// Runs one stepper forwards and backwards, accelerating and decelerating +// at the limits. Runs other steppers at the same time +// +// Copyright (C) 2009 Mike McCauley +// $Id: HRFMessage.h,v 1.1 2009/08/15 05:32:58 mikem Exp mikem $ + +#include + +// Define some steppers and the pins the will use +AccelStepper stepper1; // Defaults to 4 pins on 2, 3, 4, 5 + +void setup() +{ + stepper1.setMaxSpeed(400.0); + stepper1.setAcceleration(100.0); + stepper1.moveTo(20000); +} + +void loop() +{ + // Change direction at the limits + if (stepper1.distanceToGo() == 0) + stepper1.moveTo(-stepper1.currentPosition()); + stepper1.run(); +} diff --git a/stopWatch/stopWatch.ino b/stopWatch/stopWatch.ino new file mode 100644 index 0000000..f58d0e9 --- /dev/null +++ b/stopWatch/stopWatch.ino @@ -0,0 +1,123 @@ +//created by Jimmi Kardo Sitepu +//Founder of https://mikroavr.com +//make easy project seven segment with modul mikro7 +//contact me any qustion to +6285207770631 --> whatsapp, SMS +#include +// Arduino pin configuration to modul mikro7 +// D7 connected to Data Pin +// D8 connected to latch pin +// DS connected to clock pin +mikro7 mikro(7, 8, 9); // dis(data, latch, clock +int i; +char hold0 = 0; +char hold1 = 0; +char hold2 = 0; +char data0, data1, data2; + +#define READY 0 +#define START 1 +#define STOP 2 +#define RESET 3 +#define TIPE_TIME 500 // speed of stop watch + +char state = 0; +unsigned long get_time, get_time2; +unsigned long cur_time0; +unsigned long cur_time1; +unsigned long hold_time, hold_time2, run_time; + +void setup() { + // put your setup code here, to run once: + pinMode(A0, INPUT_PULLUP); + pinMode(A1, INPUT_PULLUP); + pinMode(A2, INPUT_PULLUP); + mikro.off(); +} +void loop() { + // put your main code here, to run + Serial.begin(9600); + key(); + display7(); +} +void key(){ + data0 = digitalRead(A0); + data1 = digitalRead(A1); + data2 = digitalRead(A2); + if ( data0 == 0){ + if(hold0 == 0){ + hold0 = 1; + state = START; + } + } + else{ + hold0 = 0; + } + + if ( data1 == 0){ + if(hold1 == 0){ + hold1 = 1; + state = STOP; + } + } + else{ + hold1 = 0; + } + + if ( data2 == 0){ + if(hold2 == 0){ + hold2 = 1; + state = RESET; + } + } + else{ + hold2 = 0; + } +} + +void get_clock(){ + switch(state){ + case READY: + get_time = 0; + hold_time = 0; + break; + + case START: + cur_time0 = millis()/TIPE_TIME; + run_time = (cur_time0 - cur_time1); + hold_time = run_time; + get_time = hold_time + hold_time2; + break; + + case STOP: + cur_time1 = millis()/TIPE_TIME; + hold_time2 = get_time; + break; + + case RESET: + cur_time1 = millis()/TIPE_TIME; + get_time = 0; hold_time = 0; hold_time2 = 0; + //state = READY; + break; + } +} + +void display7(){ + get_clock(); + switch(state){ + case READY: + mikro.display(get_time,NOT); + break; + + case START: + mikro.display(get_time,NOT); + break; + + case STOP: + mikro.display(get_time,NOT); + break; + + case RESET: + mikro.display(get_time,NOT); + break; + } +} diff --git a/stpper_CW_CWW/stpper_CW_CWW.ino b/stpper_CW_CWW/stpper_CW_CWW.ino new file mode 100644 index 0000000..92f9ae6 --- /dev/null +++ b/stpper_CW_CWW/stpper_CW_CWW.ino @@ -0,0 +1,27 @@ +#include + +#define STEPS_PER_MOTOR_REVOLUTION 32 +#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048 + +Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11); + +int Steps2Take; + +void setup(){ + +} + +void loop(){ + + Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / .05; + small_stepper.setSpeed(400); + small_stepper.step(Steps2Take); + delay(1000); + + Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION / .05; + small_stepper.setSpeed(700); + small_stepper.step(Steps2Take); + delay(2000); + +} + diff --git a/telegram_test_nodeMCU/telegram_test_nodeMCU.ino b/telegram_test_nodeMCU/telegram_test_nodeMCU.ino new file mode 100644 index 0000000..c0e56f8 --- /dev/null +++ b/telegram_test_nodeMCU/telegram_test_nodeMCU.ino @@ -0,0 +1,42 @@ +#include +#include +#include + +char ssid[] = "Pkm_asia"; +char password[] = "sistemkomputer"; +#define BOTtoken "872146786:AAFqUC58J3mU5eNv271lfjYEozV_dj_qdzQ" +String chatid = "661147716"; + +WiFiClientSecure client; +UniversalTelegramBot bot(BOTtoken, client); + +void setup() { + Serial.begin(9600); + WifiStatus(); + + bot.sendMessage(chatid, "Hello Buddy, Aku Sinb"); + Serial.println("Pesan Terkirim ke Telegram"); +} + +void loop() { + +} + +void WifiStatus() { + WiFi.mode(WIFI_STA); + WiFi.disconnect(); + delay(100); + Serial.print("Connecting Wifi: "); + Serial.println(ssid); + WiFi.begin(ssid, password); + + while (WiFi.status() != WL_CONNECTED) { + Serial.print("."); + delay(500); + } + + Serial.println(""); + Serial.println("WiFi connected"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); +} diff --git a/test/test.ino b/test/test.ino new file mode 100644 index 0000000..2c0fcec --- /dev/null +++ b/test/test.ino @@ -0,0 +1,82 @@ +void setup() { + // put your setup code here, to run once: + +{ +#define selA A0 +#define selB A1 +#define selC A2 +void setup(){ +Serial.begin(9600); +pinMode(selA, OUTPUT); +pinMode(selB, OUTPUT); +pinMode(selC, OUTPUT); +} +int line[17]; +void switchMUX(int a, int b, int c) +{ + digitalWrite(selA, a); + digitalWrite(selB, b); + digitalWrite(selC, c); +} +void readMux() +{ + switchMUX(0,0,0); + line[9] = analogRead(A3); + line[6] = analogRead(A4); + switchMUX(0,0,1); + line[15] = analogRead(A3); + line[3] = analogRead(A4); + switchMUX(0,1,0); + line[11] = analogRead(A3); + line[4] = analogRead(A4); + switchMUX(0,1,1); + line[14] = analogRead(A3); + line[2] = analogRead(A4); + switchMUX(1,0,0); + line[10] = analogRead(A3); + line[5] = analogRead(A4); + switchMUX(1,0,1); + line[12] = analogRead(A3); + line[0] = analogRead(A4); + switchMUX(1,1,0); + line[8] = analogRead(A3); + line[7] = analogRead(A4); + switchMUX(1,1,1); + line[13] = analogRead(A3); + line[1] = analogRead(A4); +} +void loop() +{ + readMux(); + Serial.print(line[0]); + Serial.print(" "); + Serial.print(line[1]); + Serial.print(" "); + Serial.print(line[2]); + Serial.print(" "); + Serial.print(line[3]); + Serial.print(" "); + Serial.print(line[4]); + Serial.print(" "); + Serial.print(line[5]); + Serial.print(" "); + Serial.print(line[6]); + Serial.print(" "); + Serial.print(line[7]); + Serial.print(" "); + Serial.print(line[8]); + Serial.print(" "); + Serial.print(line[9]); + Serial.print(" "); + Serial.print(line[10]); + Serial.print(" "); + Serial.print(line[11]); + Serial.print(" "); + Serial.print(line[12]); + Serial.print(" "); + Serial.print(line[13]); + Serial.print(" "); + Serial.print(line[14]); + Serial.print(" "); + Serial.println(line[15]); + delay(1000); diff --git a/test_7segment/test_7segment.ino b/test_7segment/test_7segment.ino new file mode 100644 index 0000000..614f1c3 --- /dev/null +++ b/test_7segment/test_7segment.ino @@ -0,0 +1,69 @@ +int a = 2; //For displaying segment "a" + +int b = 3; //For displaying segment "b" +int c = 4; //For displaying segment "c" +int d = 5; //For displaying segment "d" +int e = 6; //For displaying segment "e" +int f = 8; //For displaying segment "f" +int g = 9; //For displaying segment "g" + +void setup() { + pinMode(a, OUTPUT); //A + pinMode(b, OUTPUT); //B + pinMode(c, OUTPUT); //C + pinMode(d, OUTPUT); //D + pinMode(e, OUTPUT); //E + pinMode(f, OUTPUT); //F + pinMode(g, OUTPUT); //G +} + +void displayDigit(int digit) +{ + //Conditions for displaying segment a + if(digit!=1 && digit != 4) + digitalWrite(a,HIGH); + + //Conditions for displaying segment b + if(digit != 5 && digit != 6) + digitalWrite(b,HIGH); + + //Conditions for displaying segment c + if(digit !=2) + digitalWrite(c,HIGH); + + //Conditions for displaying segment d + if(digit != 1 && digit !=4 && digit !=7) + digitalWrite(d,HIGH); + + //Conditions for displaying segment e + if(digit == 2 || digit ==6 || digit == 8 || digit==0) + digitalWrite(e,HIGH); + + //Conditions for displaying segment f + if(digit != 1 && digit !=2 && digit!=3 && digit !=7) + digitalWrite(f,HIGH); + if (digit!=0 && digit!=1 && digit !=7) + digitalWrite(g,HIGH); + +} +void turnOff() +{ + digitalWrite(a,LOW); + digitalWrite(b,LOW); + digitalWrite(c,LOW); + digitalWrite(d,LOW); + digitalWrite(e,LOW); + digitalWrite(f,LOW); + digitalWrite(g,LOW); +} + + +void loop() { + + for(int i=0;i<10;i++) + { + displayDigit(i); + delay(1000); + turnOff(); + } +} diff --git a/test_IR-obstacle/test_IR-obstacle.ino b/test_IR-obstacle/test_IR-obstacle.ino new file mode 100644 index 0000000..1ea3b06 --- /dev/null +++ b/test_IR-obstacle/test_IR-obstacle.ino @@ -0,0 +1,23 @@ +int LED = 13; // Use the onboard Uno LED +int obstaclePin = 6; // This is our input pin +int hasObstacle = HIGH; // HIGH MEANS NO OBSTACLE + +void setup() { + pinMode(LED, OUTPUT); + pinMode(obstaclePin, INPUT); + Serial.begin(9600); +} +void loop() { + hasObstacle = digitalRead(obstaclePin); //Reads the output of the obstacle sensor from the 7th PIN of the Digital section of the arduino + if (hasObstacle == LOW) //LOW means something is ahead, so illuminates the 13th Port connected LED + { + Serial.println("Stop something is ahead!!"); + digitalWrite(LED, HIGH);//Illuminates the 13th Port LED + } + else + { + Serial.println("Path is clear"); + digitalWrite(LED, LOW); + } + delay(200); +} diff --git a/test_soundactivision/test_soundactivision.ino b/test_soundactivision/test_soundactivision.ino new file mode 100644 index 0000000..15d0f45 --- /dev/null +++ b/test_soundactivision/test_soundactivision.ino @@ -0,0 +1,18 @@ +int led = 1 ; +int sensor = 2 ; +void setup() { + // put your setup code here, to run once: +pinMode(led, OUTPUT); +pinMode(sensor, INPUT); +} + +void loop() { + // put your main code here, to run repeatedly: + +if (digitalRead(sensor)==HIGH){ + digitalWrite(led, HIGH); +} +else { + digitalWrite(led, LOW); +} +} diff --git a/test_stepper/test_stepper.ino/test_stepper.ino.ino b/test_stepper/test_stepper.ino/test_stepper.ino.ino new file mode 100644 index 0000000..b920d38 --- /dev/null +++ b/test_stepper/test_stepper.ino/test_stepper.ino.ino @@ -0,0 +1,63 @@ +int A=8; //pin 8 - pin 11 +int B=9; +int C=10; +int D=11; + +void setup(){ + //di deklarasikan sebagai output +pinMode(A,OUTPUT); pinMode(B,OUTPUT); +pinMode(C,OUTPUT); pinMode(D,OUTPUT); + + pinMode(2,INPUT_PULLUP); + pinMode(3,INPUT_PULLUP); + pinMode(4,INPUT_PULLUP); +} + +void pergerakan_1(){ +digitalWrite(A,0); +digitalWrite(D,1); +digitalWrite(B,0); +digitalWrite(C,1); +} + +void pergerakan_2(){ +digitalWrite(A,0); +digitalWrite(D,0); +digitalWrite(B,1); +digitalWrite(C,1); +} + +void pergerakan_3(){ +digitalWrite(A,1); +digitalWrite(D,0); +digitalWrite(B,1); +digitalWrite(C,0); +} + +void pergerakan_4(){ +digitalWrite(A,1); +digitalWrite(D,0); +digitalWrite(B,0); +digitalWrite(C,0); +} + +void pergerakan(){ + pergerakan_1(); delay(1000); + pergerakan_2(); delay(1000); + pergerakan_3(); delay(1000); + pergerakan_4(); delay(1000); +} + +void loop(){ +if (digitalRead(2) == LOW) { + pergerakan_2(); +} + +if (digitalRead(3) == LOW) { + pergerakan_3(); +} + +if (digitalRead(4) == LOW) { + pergerakan_4(); +} +} diff --git a/thinger.io_test/thinger.io_test.ino b/thinger.io_test/thinger.io_test.ino new file mode 100644 index 0000000..5b1655b --- /dev/null +++ b/thinger.io_test/thinger.io_test.ino @@ -0,0 +1,32 @@ +#include +#include + +#define USERNAME "lamp_smart" +#define DEVICE_ID "smart_lamp1" +#define DEVICE_CREDENTIAL "NDBZj8AF3ixk" + +#define SSID "Pkm_asia" +#define SSID_PASSWORD "sistemkomputer" + +ThingerESP8266 thing(USERNAME, DEVICE_ID, DEVICE_CREDENTIAL); + +void setup() { + pinMode(D4, OUTPUT); + pinMode(D6, OUTPUT); + pinMode(D7, OUTPUT); + + thing.add_wifi(SSID, SSID_PASSWORD); + + // digital pin control example (i.e. turning on/off a light, a relay, configuring a parameter, etc) + thing["Lamp 1"] << digitalPin(D6); + thing["Lamp 2"] << digitalPin(D7); + digitalWrite(D4, HIGH); + // resource output example (i.e. reading a sensor value) + //thing["millis"] >> outputValue(millis()); + + // more details at http://docs.thinger.io/arduino/ +} + +void loop() { + thing.handle(); +} diff --git a/uas_fix/uas_fix.ino b/uas_fix/uas_fix.ino new file mode 100644 index 0000000..ac19ba0 --- /dev/null +++ b/uas_fix/uas_fix.ino @@ -0,0 +1,71 @@ +#include +LiquidCrystal_I2C lcd(0x3F ,2,1,0,4,5,6,7,3, POSITIVE); + +const int bt = 5; +const int bt2 = 6; +int st = 0; + +void setup() { + // put your setup code here, to run once: + pinMode(bt, INPUT_PULLUP); + pinMode(bt2, INPUT_PULLUP); + pinMode(8, OUTPUT); + pinMode(9, OUTPUT); + int bt = 0; + int bt2 = 0; + Serial.begin(9600); + lcd.begin(16,2); +} + +void loop() { + // put your main code here, to run repeatedly: + if(digitalRead(bt)==0 && st == 0){ + // lcd.clear(); + delay(100); + digitalWrite(8, HIGH); + digitalWrite(9, LOW); + + st =1; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("kanan"); + + } + if(digitalRead(bt)==0 && st == 1){ + // lcd.clear(); + delay(100); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + st =0; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("Stop "); + } + + if(digitalRead(bt2)==0 && st == 0){ + // lcd.clear(); + delay(100); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + + st =1; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("Kiri "); + } + + if(digitalRead(bt2)==0 && st == 1){ + // lcd.clear(); + delay(100); + digitalWrite(8, LOW); + digitalWrite(9, HIGH); + st =0; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("Stop "); + } + } diff --git a/uji_coba_modul_GSM800l/uji_coba_modul_GSM800l.ino b/uji_coba_modul_GSM800l/uji_coba_modul_GSM800l.ino new file mode 100644 index 0000000..f10c6fd --- /dev/null +++ b/uji_coba_modul_GSM800l/uji_coba_modul_GSM800l.ino @@ -0,0 +1,39 @@ +#include +SoftwareSerial SIM800L(2, 3); // RX | TX +// Connect the SIM800L TX to Arduino pin 2 RX. +// Connect the SIM800L RX to Arduino pin 3 TX. +void setup() { + // start th serial communication with the host computer + Serial.begin(9600); + while(!Serial); + Serial.println("Arduino with SIM800L is ready"); + + // start communication with the SIM800L in 9600 + SIM800L.begin(9600); + Serial.println("SIM800L started at 9600"); + delay(1000); + Serial.println("Setup Complete! SIM800L is Ready!"); + + Serial.println("Set format SMS ke ASCII"); + SIM800L.write("AT+CMGF=1\r\n"); + delay(1000); + + Serial.println("SIM800L Set SMS ke Nomor Tujuan"); + SIM800L.write("AT+CMGS=\"08973234445\"\r\n"); + delay(1000); + + Serial.println("SIM800L Send SMS content"); + SIM800L.write("Testing Kirim SMS via SIM800L, Siap Maju Tugas Akhir"); + delay(1000); + + Serial.println("Mengirim Char Ctrl+Z / ESC untuk keluar dari menu SMS"); + SIM800L.write((char)26); + delay(1000); + + Serial.println("SMS Selesai Dikirim!"); +} + +void loop() { + // put your main code here, to run repeatedly: + +} diff --git a/uji_coba_motorStepper/uji_coba_motorStepper.ino b/uji_coba_motorStepper/uji_coba_motorStepper.ino new file mode 100644 index 0000000..316ec98 --- /dev/null +++ b/uji_coba_motorStepper/uji_coba_motorStepper.ino @@ -0,0 +1,71 @@ +#include +LiquidCrystal_I2C lcd(0x3F ,2,1,0,4,5,6,7,3, POSITIVE); + +const int bt = 5; +const int bt2 = 6; +int st = 0; + +void setup() { + // put your setup code here, to run once: + pinMode(bt, INPUT_PULLUP); + pinMode(bt2, INPUT_PULLUP); + pinMode(8, OUTPUT); + pinMode(9, OUTPUT); + lcd.begin(16,2); + int bt = 0; + int bt2 = 0; + Serial.begin(9600); +} + +void loop() { + // put your main code here, to run repeatedly: + if(digitalRead(bt)==0 && st == 0){ + // lcd.clear(); + delay(100); + digitalWrite(8, HIGH); + digitalWrite(9, LOW); + + st =1; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("kanan"); + + } + if(digitalRead(bt)==0 && st == 1){ + // lcd.clear(); + delay(100); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + st =0; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("Stop "); + } + + if(digitalRead(bt2)==0 && st == 0){ + // lcd.clear(); + delay(100); + digitalWrite(8, LOW); + digitalWrite(9, LOW); + + st =1; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("Kiri "); + } + + if(digitalRead(bt2)==0 && st == 1){ + // lcd.clear(); + delay(100); + digitalWrite(8, LOW); + digitalWrite(9, HIGH); + st =0; + lcd.setCursor(0, 0); + lcd.print("Arah putaran : "); + lcd.setCursor(0, 1); + lcd.print("Stop "); + } + } diff --git a/uji_coba_motorStepper/uji_coba_motorStepper.ino.eightanaloginputs.hex b/uji_coba_motorStepper/uji_coba_motorStepper.ino.eightanaloginputs.hex new file mode 100644 index 0000000..b1f56ee --- /dev/null +++ b/uji_coba_motorStepper/uji_coba_motorStepper.ino.eightanaloginputs.hex @@ -0,0 +1,303 @@ +:100000000C9462000C948A000C948A000C948A0070 +:100010000C948A000C948A000C948A000C948A0038 +:100020000C948A000C948A000C948A000C948A0028 +:100030000C948A000C948A000C948A000C948A0018 +:100040000C9412060C948A000C94E0050C94BA05EA +:100050000C948A000C948A000C948A000C948A00F8 +:100060000C945C060C948A00000000002400270019 +:100070002A0000000000250028002B0000000000DE +:1000800023002600290004040404040404040202DA +:100090000202020203030303030301020408102007 +:1000A0004080010204081020010204081020000012 +:1000B0000008000201000003040700000000000027 +:1000C00000008A0711241FBECFEFD8E0DEBFCDBFEE +:1000D00011E0A0E0B1E0E8E7F2E102C005900D9286 +:1000E000AC35B107D9F722E0ACE5B1E001C01D9213 +:1000F000AD3BB207E1F710E0C2E6D0E004C02197C3 +:10010000FE010E942F09C136D107C9F70E94E907F5 +:100110000C943A090C9400002091FA019091F90195 +:10012000213208F04AC08091D6018111FCCF32E023 +:100130003093D60131E03093D5013FEF3093D401B5 +:100140001092D3012093D201A9EDB1E042EB51E02E +:10015000FA013E2F341B321718F43D913193F9CF39 +:100160001092B1012091B101990F922B9093B1019E +:100170009091B001913061F41092B0019091B10171 +:100180009093BB009091BC0093FDF8CF95EC01C01B +:1001900095EE9093BC009091D6019230E1F390914E +:1001A000D4019F3F79F08091D401803241F0809159 +:1001B000D401803331F084E005C081E003C082E0E7 +:1001C00001C083E01092D8011092FA011092D70179 +:1001D0000895CF92DF92EF92FF920F931F93CF93E8 +:1001E000DF936C017A018B01C0E0D0E0CE15DF0512 +:1001F00089F0D8016D918D01D601ED91FC910190AE +:10020000F081E02DC6010995892B11F47E0102C011 +:100210002196ECCFC701DF91CF911F910F91FF90F5 +:10022000EF90DF90CF900895FC01538D448D252FE2 +:1002300030E0842F90E0821B930B541710F0CF9680 +:10024000089501970895FC01918D828D981761F0B2 +:10025000828DDF01A80FB11D5D968C91928D9F5FFD +:100260009F73928F90E008958FEF9FEF0895FC01A8 +:10027000918D828D981731F0828DE80FF11D858D5B +:1002800090E008958FEF9FEF0895FC01918D228DEE +:10029000892F90E0805C9F4F821B91098F73992773 +:1002A00008958BEF91E00E94450121E0892B09F42C +:1002B00020E0822F0895FC01848DDF01A80FB11D7D +:1002C000A35ABF4F2C91848D90E001968F7399278C +:1002D000848FA689B7892C93A089B1898C91806479 +:1002E0008C93938D848D981306C00288F389E02D3A +:1002F00080818F7D80830895EF92FF920F931F93EB +:10030000CF93DF93EC0181E0888F9B8D8C8D9813C8 +:1003100005C0E889F989808185FD24C0F62E0B8D02 +:1003200010E00F5F1F4F0F731127E02E8C8DE81226 +:100330000CC00FB607FCFACFE889F989808185FFE8 +:10034000F5CFCE010E945B01F1CF8B8DFE01E80F4E +:10035000F11DE35AFF4FF0820B8FEA89FB89808100 +:10036000806207C0EE89FF896083E889F98980810E +:100370008064808381E090E0DF91CF911F910F91A5 +:10038000FF90EF900895CF93DF93EC01888D882341 +:10039000C9F0EA89FB89808185FD05C0A889B989F2 +:1003A0008C9186FD0FC00FB607FCF5CF808185FFCD +:1003B000F2CFA889B9898C9185FFEDCFCE010E943B +:1003C0005B01E7CFDF91CF91089580E090E0892B2A +:1003D00029F00E94510181110C940000089583308E +:1003E00081F028F4813099F08230A1F008958730AF +:1003F000A9F08830B9F08430D1F4809180008F7DED +:1004000003C0809180008F7780938000089584B529 +:100410008F7702C084B58F7D84BD08958091B00030 +:100420008F7703C08091B0008F7D8093B0000895D6 +:10043000CF93DF93282F30E0F901E255FF4F8491ED +:10044000F901E656FF4FD491F901EA57FF4FC491E5 +:10045000CC2391F081110E94EF01EC2FF0E0EE0F20 +:10046000FF1FE458FF4FA591B491EC91ED2381E07B +:1004700090E021F480E002C080E090E0DF91CF9135 +:1004800008951F93CF93DF93282F30E0F901E255B1 +:10049000FF4F8491F901E656FF4FD491F901EA57D5 +:1004A000FF4FC491CC23C9F0162F81110E94EF0198 +:1004B000EC2FF0E0EE0FFF1FEE58FF4FA591B49127 +:1004C0008FB7F894111105C09C91ED2FE095E923A9 +:1004D00002C0EC91ED2BEC938FBFDF91CF911F9178 +:1004E0000895CF93DF9390E0FC01E656FF4F2491EF +:1004F000FC01EA57FF4F8491882361F190E0880F57 +:10050000991FFC01E859FF4FC591D491FC01EE58A9 +:10051000FF4FA591B491611109C09FB7F8948881EC +:10052000209582238883EC912E230BC0623061F4E6 +:100530009FB7F8943881822F809583238883EC912C +:100540002E2B2C939FBF06C08FB7F894E8812E2BDB +:1005500028838FBFDF91CF9108953FB7F8948091A2 +:10056000AA019091AB01A091AC01B091AD0126B56B +:10057000A89B05C02F3F19F00196A11DB11D3FBFDB +:10058000BA2FA92F982F8827820F911DA11DB11D69 +:10059000BC01CD0142E0660F771F881F991F4A9565 +:1005A000D1F708958F929F92AF92BF92CF92DF9230 +:1005B000EF92FF926B017C010E94AD024B015C0146 +:1005C000C114D104E104F104F1F00E94AD02DC0198 +:1005D000CB0188199909AA09BB09883E9340A10556 +:1005E000B10570F321E0C21AD108E108F10888EEE4 +:1005F000880E83E0981EA11CB11CC114D104E10433 +:10060000F10419F7DDCFFF90EF90DF90CF90BF900E +:10061000AF909F908F90089585ED8093BC0080915E +:10062000BC0084FDFCCF1092D6010895409180015A +:10063000262F30E0240F311D21323105DCF42091CA +:10064000D6012430C9F4FC0180E090E0861758F40C +:10065000309180012191DC01A25ABE4FA30FB11D40 +:100660002C930196F3CF80918001680F60938001F5 +:1006700080E0089581E0089582E00895089581E082 +:1006800090E030915D0120915C01321710F480E020 +:1006900090E0919581959109089580915D019091E7 +:1006A0005C01891730F48F5F80935D0180E090E0FA +:1006B00008958FEF9FEF089580915C0190E0209165 +:1006C0005D01821B91090895CF92DF92EF92FF9214 +:1006D0000F931F93CF93DF937C01262F972F8A01CF +:1006E0008091D701882391F0C62FD72F6E01C40EB9 +:1006F000D51ECC15DD0571F06991D701ED91FC9106 +:100700000190F081E02DC7010995F3CF642F822F6E +:100710000E941603C801DF91CF911F910F91FF90A6 +:10072000EF90DF90CF900895CF93DF931F92CDB7D6 +:10073000DEB769832091D7012223D1F02091FA01FD +:10074000203240F021E030E0FC013383228380E05E +:1007500090E015C08091D801E82FF0E0E752FE4FFD +:10076000998190838F5F8093D8018093FA0105C0AF +:1007700061E0CE0101960E94160381E090E00F90A7 +:10078000DF91CF91089521E001C0220F6A95EAF729 +:10079000DC011C962C931C971A965C934E93199728 +:1007A000ED91FC910484F585E02D60E00994DC0175 +:1007B000ED91FC910684F785E02D41E0099581E0FB +:1007C00090E00895DC01ED91FC910684F785E02D21 +:1007D00040E00994CF93DF93CDB7DEB728970FB6EB +:1007E000F894DEBF0FBECDBF1D8290E49E8324E14E +:1007F0002F8324E5288719829A8390E19B8390E5D3 +:100800009C832091AB02821710F08FEF820F309102 +:10081000AC0290E0FE01E80FF91F303121F42430E2 +:1008200011F4618101C06581606884EA92E02896D4 +:100830000FB6F894DEBF0FBECDBFDF91CF910C9401 +:10084000E2030F931F93CF93DF93EC01423018F034 +:100850008C8188608C834F836887222329F0413004 +:1008600019F48C8184608C8364E670E080E090E011 +:100870000E94D2026C8164FD31C0E881F981068456 +:10088000F785E02D42E063E0CE0109958BE496E424 +:100890000197F1F7E881F9810684F785E02D42E0C0 +:1008A00063E0CE01099503E512E0C8010197F1F775 +:1008B000E881F9810684F785E02D42E063E0CE010E +:1008C0000995C8010197F1F7E881F9810684F78558 +:1008D000E02D42E062E0CE01099517C06062CE01D2 +:1008E0000E94E2038BE496E40197F1F76C81606269 +:1008F000CE010E94E20303E512E0C8010197F1F77F +:100900006C816062CE010E94E203C8010197F1F799 +:100910006C816062CE010E94E2038BEE90E0019751 +:10092000F1F784E08D836CE0CE010E94E20361E088 +:10093000CE010E94E2038BE39FE10197F1F782E091 +:100940008E8366E0CE010E94E203E881F98104848F +:10095000F585E02D6FEFCE01DF91CF911F910F91C3 +:10096000099408950895089580E090E00895FC01A9 +:1009700023812223B9F0918190956923608382813C +:1009800091E09093D7018093F9011092D8011092D1 +:10099000FA0188E992E00E9494030E948C00282FBB +:1009A00030E002C020E030E081E090E0232B11F045 +:1009B00080E090E00895EF92FF920F931F93CF9302 +:1009C0008C01FC01759684E0C0E060FF02C090815C +:1009D000C92B6695815031968111F7CF413011F4C2 +:1009E000F8014489F8018585C82BC42B7801FEE005 +:1009F000EF0EF11CF80162896C2BC7010E94B7044D +:100A0000F801628960956C23C701CF911F910F9106 +:100A1000FF90EF900C94B7040F931F93CF93DF9345 +:100A2000062F0F70423019F440E0602F10C0142FD1 +:100A3000262FEC0130E0B90184E0759567958A9521 +:100A4000E1F7CE010E94DB04412F602FCE01DF9140 +:100A5000CF911F910F910C94DB04FC0184858823B6 +:100A6000A9F0218532852115310519F4611106C0DF +:100A700007C02130310521F4611102C0858701C012 +:100A800015866585CF010E960C94B7040895EF92F4 +:100A9000FF920F931F93CF93DF93EC01062FF42E59 +:100AA000E22E8B85888B10925D0110925C01109272 +:100AB000D8011092FA011092D60111E01093D501DD +:100AC0001092B00161E082E10E94410261E083E1A5 +:100AD0000E9441028091B9008E7F8093B90080917D +:100AE000B9008D7F8093B90088E48093B80085E4D5 +:100AF0008093BC0088891093D7018093F9011092EC +:100B0000D8011092FA010E948C0091E0811190E0CE +:100B1000998B992329F088E992E00E944D038E87F2 +:100B20008989882339F01F861C8260E0CE010E96E9 +:100B30000E94B7042E2D4F2D602FCE01DF91CF9153 +:100B40001F910F91FF90EF900C942104009769F092 +:100B5000FC0101900020E9F73197AF01481B590BC8 +:100B6000BC0184EA92E00C94E90080E090E00895F2 +:100B70000E9435091F920F920FB60F9211242F93E6 +:100B80003F934F935F936F937F938F939F93AF9315 +:100B9000BF93EF93FF938BEF91E00E945B01FF9176 +:100BA000EF91BF91AF919F918F917F916F915F91E5 +:100BB0004F913F912F910F900FBE0F901F9018955E +:100BC0001F920F920FB60F9211242F938F939F9322 +:100BD000EF93FF93E0910B02F0910C028081E09182 +:100BE0001102F091120282FD12C0908180911402D4 +:100BF0008F5F8F7320911502821751F0E0911402DC +:100C0000F0E0E550FE4F958F8093140201C0808183 +:100C1000FF91EF919F918F912F910F900FBE0F90A9 +:100C20001F9018951F920F920FB60F9211242F93B9 +:100C30003F938F939F93AF93BF938091A601909121 +:100C4000A701A091A801B091A9013091A50123E0CD +:100C5000230F2D3720F40196A11DB11D05C026E8F4 +:100C6000230F0296A11DB11D2093A5018093A6011B +:100C70009093A701A093A801B093A9018091AA0124 +:100C80009091AB01A091AC01B091AD010196A11D75 +:100C9000B11D8093AA019093AB01A093AC01B093D6 +:100CA000AD01BF91AF919F918F913F912F910F9087 +:100CB0000FBE0F901F9018951F920F920FB60F92B4 +:100CC00011242F933F934F935F936F937F938F9351 +:100CD0009F93AF93BF93EF93FF938091B900887F69 +:100CE000803609F49CC068F5883209F45BC090F442 +:100CF000803109F454C038F4882309F4F6C08830F0 +:100D000009F44DC0F6C0883109F44CC0803209F4B2 +:100D10005DC0EFC0803409F468C048F4803309F442 +:100D200055C0883309F0E5C08093D401D8C0803520 +:100D300009F44FC0883509F45DC0883409F0D9C082 +:100D4000D6C0883909F4C7C0A8F4883709F467C049 +:100D500038F4883609F463C0803709F460C0C9C02C +:100D6000883809F4B8C0803909F45FC0803809F0C8 +:100D7000C0C05BC0803B09F486C038F4803A09F4F7 +:100D800066C0883A09F47FC0B4C0803C09F4A7C0AB +:100D9000883C09F4A4C0883B09F48AC0AAC08091A9 +:100DA000B10110C09091D3018091D201981770F5D4 +:100DB000E091D30181E08E0F8093D301F0E0EE54F7 +:100DC000FE4F80818093BB0085EC86C08093D40168 +:100DD0008EC0E091D30181E08E0F8093D30180918A +:100DE000BB00F0E0EE54FE4F80839091D3018091E0 +:100DF000D2016EC0E091D30181E08E0F8093D301C8 +:100E00008091BB00F0E0EE54FE4F80838091D501CD +:100E100081116DC081E08093B00184EA61C083E0FC +:100E20008093D6011092A401CFCF8091A40180328B +:100E300008F051C0E091A40181E08E0F8093A401DD +:100E40008091BB00F0E0EC57FE4F8083BDCF85EC76 +:100E50008093BC001092D6018091A401803230F4BE +:100E6000E091A401F0E0EC57FE4F10826091A401E4 +:100E700070E0E0918201F091830184E891E00995AE +:100E80001092A40136C084E08093D60110928101B3 +:100E900010928001E0917E01F0917F01099580918F +:100EA0008001811105C081E08093800110925E0174 +:100EB000E091810181E08E0F80938101F0E0E25AA0 +:100EC000FE4F80818093BB009091810180918001D1 +:100ED000981708F479CF85E88093BC000AC085ECA8 +:100EE0008093BC001092D60104C01092D4010E94DD +:100EF0000C03FF91EF91BF91AF919F918F917F91E3 +:100F00006F915F914F913F912F910F900FBE0F9076 +:100F10001F901895EBEFF1E01382128288EE93E0B8 +:100F2000A0E0B0E084839583A683B78324E031E01A +:100F30003183208325EC30E03587248724EC30E0B2 +:100F40003787268720EC30E0318B208B21EC30E096 +:100F5000338B228B22EC30E0358B248B26EC30E077 +:100F6000378B268B118E128E138E148EE8E9F2E0E9 +:100F70001382128284839583A683B78386E191E0EE +:100F800091838083E4EAF2E01382128288E291E0A6 +:100F900091838083108A8FEF87871686118A8FE36B +:100FA0008387148615861286118684E0828B82E000 +:100FB000838B81E0848B80E1858B80E2868B80E46B +:100FC000878B80E8808F40E050E063E0CF010C9495 +:100FD000C303789484B5826084BD84B5816084BD88 +:100FE00085B5826085BD85B5816085BD80916E00C7 +:100FF000816080936E0010928100809181008260F8 +:101000008093810080918100816080938100809134 +:1010100080008160809380008091B1008460809323 +:10102000B1008091B00081608093B00080917A001F +:10103000846080937A0080917A00826080937A0045 +:1010400080917A00816080937A0080917A00806834 +:1010500080937A001092C10062E085E00E947102E4 +:1010600062E086E00E94710261E088E00E94710205 +:1010700061E089E00E94710220E042E060E184EAE0 +:1010800092E00E944705E0910B02F0910C0282E091 +:101090008083E0910702F09108021082E09109023A +:1010A000F0910A028FEC808310921302E0910F02FC +:1010B000F091100286E08083E0910D02F0910E0223 +:1010C000808180618083E0910D02F0910E02808129 +:1010D00088608083E0910D02F0910E02808180682B +:1010E0008083E0910D02F0910E0280818F7D8083DC +:1010F000C1E0D0E085E00E941802892B31F4809194 +:10110000AE019091AF01892B31F185E00E94180268 +:10111000892B31F48091AE019091AF010197E1F1FB +:1011200086E00E941802892B39F48091AE019091DB +:10113000AF01892B09F451C086E00E941802892B67 +:1011400039F48091AE019091AF01019709F466C026 +:101150000E94E501CFCF68EE73E080E090E00E944E +:10116000D20261E088E00E94410260E089E00E94D2 +:101170004102D093AF01C093AE0180E00E94EA0328 +:1011800088E391E00E94A60581E00E94EA0388E4DA +:1011900091E00E94A605B9CF68EE73E080E090E090 +:1011A0000E94D20260E088E00E94410261E089E092 +:1011B0000E9441021092AF011092AE0180E00E94A5 +:1011C000EA0388E391E00E94A60581E00E94EA0319 +:1011D0008EE491E00E94A605A3CF68EE73E080E064 +:1011E00090E00E94D20260E088E00E94410260E04C +:1011F00089E00E944102D093AF01C093AE0180E02C +:101200000E94EA0388E391E00E94A60581E00E9423 +:10121000EA0385E591E00E94A6058ECF68EE73E0B3 +:1012200080E090E00E94D20260E088E00E944102EB +:1012300060E089E00E9441021092AF011092AE017D +:1012400080E00E94EA0388E391E00E94A60581E025 +:101250000E94EA038EE491E00E94A60579CFEE0F8A +:10126000FF1F0590F491E02D099481E090E0F8943F +:081270000C943A09F894FFCF39 +:10127800000000007C01E9001401C30145012301BD +:1012880037010000000094036403B4043E035C03C8 +:101298004D033F0300000000D703E900B404B30482 +:1012A8004705C3032D050C054172616820707574EC +:1012B8006172616E203A20006B616E616E0053743A +:0C12C8006F702020004B6972692020002C +:00000001FF diff --git a/uji_coba_motorStepper/uji_coba_motorStepper.ino.with_bootloader.eightanaloginputs.hex b/uji_coba_motorStepper/uji_coba_motorStepper.ino.with_bootloader.eightanaloginputs.hex new file mode 100644 index 0000000..cb6a63e --- /dev/null +++ b/uji_coba_motorStepper/uji_coba_motorStepper.ino.with_bootloader.eightanaloginputs.hex @@ -0,0 +1,427 @@ +:100000000C9462000C948A000C948A000C948A0070 +:100010000C948A000C948A000C948A000C948A0038 +:100020000C948A000C948A000C948A000C948A0028 +:100030000C948A000C948A000C948A000C948A0018 +:100040000C9412060C948A000C94E0050C94BA05EA +:100050000C948A000C948A000C948A000C948A00F8 +:100060000C945C060C948A00000000002400270019 +:100070002A0000000000250028002B0000000000DE +:1000800023002600290004040404040404040202DA +:100090000202020203030303030301020408102007 +:1000A0004080010204081020010204081020000012 +:1000B0000008000201000003040700000000000027 +:1000C00000008A0711241FBECFEFD8E0DEBFCDBFEE +:1000D00011E0A0E0B1E0E8E7F2E102C005900D9286 +:1000E000AC35B107D9F722E0ACE5B1E001C01D9213 +:1000F000AD3BB207E1F710E0C2E6D0E004C02197C3 +:10010000FE010E942F09C136D107C9F70E94E907F5 +:100110000C943A090C9400002091FA019091F90195 +:10012000213208F04AC08091D6018111FCCF32E023 +:100130003093D60131E03093D5013FEF3093D401B5 +:100140001092D3012093D201A9EDB1E042EB51E02E +:10015000FA013E2F341B321718F43D913193F9CF39 +:100160001092B1012091B101990F922B9093B1019E +:100170009091B001913061F41092B0019091B10171 +:100180009093BB009091BC0093FDF8CF95EC01C01B +:1001900095EE9093BC009091D6019230E1F390914E +:1001A000D4019F3F79F08091D401803241F0809159 +:1001B000D401803331F084E005C081E003C082E0E7 +:1001C00001C083E01092D8011092FA011092D70179 +:1001D0000895CF92DF92EF92FF920F931F93CF93E8 +:1001E000DF936C017A018B01C0E0D0E0CE15DF0512 +:1001F00089F0D8016D918D01D601ED91FC910190AE +:10020000F081E02DC6010995892B11F47E0102C011 +:100210002196ECCFC701DF91CF911F910F91FF90F5 +:10022000EF90DF90CF900895FC01538D448D252FE2 +:1002300030E0842F90E0821B930B541710F0CF9680 +:10024000089501970895FC01918D828D981761F0B2 +:10025000828DDF01A80FB11D5D968C91928D9F5FFD +:100260009F73928F90E008958FEF9FEF0895FC01A8 +:10027000918D828D981731F0828DE80FF11D858D5B +:1002800090E008958FEF9FEF0895FC01918D228DEE +:10029000892F90E0805C9F4F821B91098F73992773 +:1002A00008958BEF91E00E94450121E0892B09F42C +:1002B00020E0822F0895FC01848DDF01A80FB11D7D +:1002C000A35ABF4F2C91848D90E001968F7399278C +:1002D000848FA689B7892C93A089B1898C91806479 +:1002E0008C93938D848D981306C00288F389E02D3A +:1002F00080818F7D80830895EF92FF920F931F93EB +:10030000CF93DF93EC0181E0888F9B8D8C8D9813C8 +:1003100005C0E889F989808185FD24C0F62E0B8D02 +:1003200010E00F5F1F4F0F731127E02E8C8DE81226 +:100330000CC00FB607FCFACFE889F989808185FFE8 +:10034000F5CFCE010E945B01F1CF8B8DFE01E80F4E +:10035000F11DE35AFF4FF0820B8FEA89FB89808100 +:10036000806207C0EE89FF896083E889F98980810E +:100370008064808381E090E0DF91CF911F910F91A5 +:10038000FF90EF900895CF93DF93EC01888D882341 +:10039000C9F0EA89FB89808185FD05C0A889B989F2 +:1003A0008C9186FD0FC00FB607FCF5CF808185FFCD +:1003B000F2CFA889B9898C9185FFEDCFCE010E943B +:1003C0005B01E7CFDF91CF91089580E090E0892B2A +:1003D00029F00E94510181110C940000089583308E +:1003E00081F028F4813099F08230A1F008958730AF +:1003F000A9F08830B9F08430D1F4809180008F7DED +:1004000003C0809180008F7780938000089584B529 +:100410008F7702C084B58F7D84BD08958091B00030 +:100420008F7703C08091B0008F7D8093B0000895D6 +:10043000CF93DF93282F30E0F901E255FF4F8491ED +:10044000F901E656FF4FD491F901EA57FF4FC491E5 +:10045000CC2391F081110E94EF01EC2FF0E0EE0F20 +:10046000FF1FE458FF4FA591B491EC91ED2381E07B +:1004700090E021F480E002C080E090E0DF91CF9135 +:1004800008951F93CF93DF93282F30E0F901E255B1 +:10049000FF4F8491F901E656FF4FD491F901EA57D5 +:1004A000FF4FC491CC23C9F0162F81110E94EF0198 +:1004B000EC2FF0E0EE0FFF1FEE58FF4FA591B49127 +:1004C0008FB7F894111105C09C91ED2FE095E923A9 +:1004D00002C0EC91ED2BEC938FBFDF91CF911F9178 +:1004E0000895CF93DF9390E0FC01E656FF4F2491EF +:1004F000FC01EA57FF4F8491882361F190E0880F57 +:10050000991FFC01E859FF4FC591D491FC01EE58A9 +:10051000FF4FA591B491611109C09FB7F8948881EC +:10052000209582238883EC912E230BC0623061F4E6 +:100530009FB7F8943881822F809583238883EC912C +:100540002E2B2C939FBF06C08FB7F894E8812E2BDB +:1005500028838FBFDF91CF9108953FB7F8948091A2 +:10056000AA019091AB01A091AC01B091AD0126B56B +:10057000A89B05C02F3F19F00196A11DB11D3FBFDB +:10058000BA2FA92F982F8827820F911DA11DB11D69 +:10059000BC01CD0142E0660F771F881F991F4A9565 +:1005A000D1F708958F929F92AF92BF92CF92DF9230 +:1005B000EF92FF926B017C010E94AD024B015C0146 +:1005C000C114D104E104F104F1F00E94AD02DC0198 +:1005D000CB0188199909AA09BB09883E9340A10556 +:1005E000B10570F321E0C21AD108E108F10888EEE4 +:1005F000880E83E0981EA11CB11CC114D104E10433 +:10060000F10419F7DDCFFF90EF90DF90CF90BF900E +:10061000AF909F908F90089585ED8093BC0080915E +:10062000BC0084FDFCCF1092D6010895409180015A +:10063000262F30E0240F311D21323105DCF42091CA +:10064000D6012430C9F4FC0180E090E0861758F40C +:10065000309180012191DC01A25ABE4FA30FB11D40 +:100660002C930196F3CF80918001680F60938001F5 +:1006700080E0089581E0089582E00895089581E082 +:1006800090E030915D0120915C01321710F480E020 +:1006900090E0919581959109089580915D019091E7 +:1006A0005C01891730F48F5F80935D0180E090E0FA +:1006B00008958FEF9FEF089580915C0190E0209165 +:1006C0005D01821B91090895CF92DF92EF92FF9214 +:1006D0000F931F93CF93DF937C01262F972F8A01CF +:1006E0008091D701882391F0C62FD72F6E01C40EB9 +:1006F000D51ECC15DD0571F06991D701ED91FC9106 +:100700000190F081E02DC7010995F3CF642F822F6E +:100710000E941603C801DF91CF911F910F91FF90A6 +:10072000EF90DF90CF900895CF93DF931F92CDB7D6 +:10073000DEB769832091D7012223D1F02091FA01FD +:10074000203240F021E030E0FC013383228380E05E +:1007500090E015C08091D801E82FF0E0E752FE4FFD +:10076000998190838F5F8093D8018093FA0105C0AF +:1007700061E0CE0101960E94160381E090E00F90A7 +:10078000DF91CF91089521E001C0220F6A95EAF729 +:10079000DC011C962C931C971A965C934E93199728 +:1007A000ED91FC910484F585E02D60E00994DC0175 +:1007B000ED91FC910684F785E02D41E0099581E0FB +:1007C00090E00895DC01ED91FC910684F785E02D21 +:1007D00040E00994CF93DF93CDB7DEB728970FB6EB +:1007E000F894DEBF0FBECDBF1D8290E49E8324E14E +:1007F0002F8324E5288719829A8390E19B8390E5D3 +:100800009C832091AB02821710F08FEF820F309102 +:10081000AC0290E0FE01E80FF91F303121F42430E2 +:1008200011F4618101C06581606884EA92E02896D4 +:100830000FB6F894DEBF0FBECDBFDF91CF910C9401 +:10084000E2030F931F93CF93DF93EC01423018F034 +:100850008C8188608C834F836887222329F0413004 +:1008600019F48C8184608C8364E670E080E090E011 +:100870000E94D2026C8164FD31C0E881F981068456 +:10088000F785E02D42E063E0CE0109958BE496E424 +:100890000197F1F7E881F9810684F785E02D42E0C0 +:1008A00063E0CE01099503E512E0C8010197F1F775 +:1008B000E881F9810684F785E02D42E063E0CE010E +:1008C0000995C8010197F1F7E881F9810684F78558 +:1008D000E02D42E062E0CE01099517C06062CE01D2 +:1008E0000E94E2038BE496E40197F1F76C81606269 +:1008F000CE010E94E20303E512E0C8010197F1F77F +:100900006C816062CE010E94E203C8010197F1F799 +:100910006C816062CE010E94E2038BEE90E0019751 +:10092000F1F784E08D836CE0CE010E94E20361E088 +:10093000CE010E94E2038BE39FE10197F1F782E091 +:100940008E8366E0CE010E94E203E881F98104848F +:10095000F585E02D6FEFCE01DF91CF911F910F91C3 +:10096000099408950895089580E090E00895FC01A9 +:1009700023812223B9F0918190956923608382813C +:1009800091E09093D7018093F9011092D8011092D1 +:10099000FA0188E992E00E9494030E948C00282FBB +:1009A00030E002C020E030E081E090E0232B11F045 +:1009B00080E090E00895EF92FF920F931F93CF9302 +:1009C0008C01FC01759684E0C0E060FF02C090815C +:1009D000C92B6695815031968111F7CF413011F4C2 +:1009E000F8014489F8018585C82BC42B7801FEE005 +:1009F000EF0EF11CF80162896C2BC7010E94B7044D +:100A0000F801628960956C23C701CF911F910F9106 +:100A1000FF90EF900C94B7040F931F93CF93DF9345 +:100A2000062F0F70423019F440E0602F10C0142FD1 +:100A3000262FEC0130E0B90184E0759567958A9521 +:100A4000E1F7CE010E94DB04412F602FCE01DF9140 +:100A5000CF911F910F910C94DB04FC0184858823B6 +:100A6000A9F0218532852115310519F4611106C0DF +:100A700007C02130310521F4611102C0858701C012 +:100A800015866585CF010E960C94B7040895EF92F4 +:100A9000FF920F931F93CF93DF93EC01062FF42E59 +:100AA000E22E8B85888B10925D0110925C01109272 +:100AB000D8011092FA011092D60111E01093D501DD +:100AC0001092B00161E082E10E94410261E083E1A5 +:100AD0000E9441028091B9008E7F8093B90080917D +:100AE000B9008D7F8093B90088E48093B80085E4D5 +:100AF0008093BC0088891093D7018093F9011092EC +:100B0000D8011092FA010E948C0091E0811190E0CE +:100B1000998B992329F088E992E00E944D038E87F2 +:100B20008989882339F01F861C8260E0CE010E96E9 +:100B30000E94B7042E2D4F2D602FCE01DF91CF9153 +:100B40001F910F91FF90EF900C942104009769F092 +:100B5000FC0101900020E9F73197AF01481B590BC8 +:100B6000BC0184EA92E00C94E90080E090E00895F2 +:100B70000E9435091F920F920FB60F9211242F93E6 +:100B80003F934F935F936F937F938F939F93AF9315 +:100B9000BF93EF93FF938BEF91E00E945B01FF9176 +:100BA000EF91BF91AF919F918F917F916F915F91E5 +:100BB0004F913F912F910F900FBE0F901F9018955E +:100BC0001F920F920FB60F9211242F938F939F9322 +:100BD000EF93FF93E0910B02F0910C028081E09182 +:100BE0001102F091120282FD12C0908180911402D4 +:100BF0008F5F8F7320911502821751F0E0911402DC +:100C0000F0E0E550FE4F958F8093140201C0808183 +:100C1000FF91EF919F918F912F910F900FBE0F90A9 +:100C20001F9018951F920F920FB60F9211242F93B9 +:100C30003F938F939F93AF93BF938091A601909121 +:100C4000A701A091A801B091A9013091A50123E0CD +:100C5000230F2D3720F40196A11DB11D05C026E8F4 +:100C6000230F0296A11DB11D2093A5018093A6011B +:100C70009093A701A093A801B093A9018091AA0124 +:100C80009091AB01A091AC01B091AD010196A11D75 +:100C9000B11D8093AA019093AB01A093AC01B093D6 +:100CA000AD01BF91AF919F918F913F912F910F9087 +:100CB0000FBE0F901F9018951F920F920FB60F92B4 +:100CC00011242F933F934F935F936F937F938F9351 +:100CD0009F93AF93BF93EF93FF938091B900887F69 +:100CE000803609F49CC068F5883209F45BC090F442 +:100CF000803109F454C038F4882309F4F6C08830F0 +:100D000009F44DC0F6C0883109F44CC0803209F4B2 +:100D10005DC0EFC0803409F468C048F4803309F442 +:100D200055C0883309F0E5C08093D401D8C0803520 +:100D300009F44FC0883509F45DC0883409F0D9C082 +:100D4000D6C0883909F4C7C0A8F4883709F467C049 +:100D500038F4883609F463C0803709F460C0C9C02C +:100D6000883809F4B8C0803909F45FC0803809F0C8 +:100D7000C0C05BC0803B09F486C038F4803A09F4F7 +:100D800066C0883A09F47FC0B4C0803C09F4A7C0AB +:100D9000883C09F4A4C0883B09F48AC0AAC08091A9 +:100DA000B10110C09091D3018091D201981770F5D4 +:100DB000E091D30181E08E0F8093D301F0E0EE54F7 +:100DC000FE4F80818093BB0085EC86C08093D40168 +:100DD0008EC0E091D30181E08E0F8093D30180918A +:100DE000BB00F0E0EE54FE4F80839091D3018091E0 +:100DF000D2016EC0E091D30181E08E0F8093D301C8 +:100E00008091BB00F0E0EE54FE4F80838091D501CD +:100E100081116DC081E08093B00184EA61C083E0FC +:100E20008093D6011092A401CFCF8091A40180328B +:100E300008F051C0E091A40181E08E0F8093A401DD +:100E40008091BB00F0E0EC57FE4F8083BDCF85EC76 +:100E50008093BC001092D6018091A401803230F4BE +:100E6000E091A401F0E0EC57FE4F10826091A401E4 +:100E700070E0E0918201F091830184E891E00995AE +:100E80001092A40136C084E08093D60110928101B3 +:100E900010928001E0917E01F0917F01099580918F +:100EA0008001811105C081E08093800110925E0174 +:100EB000E091810181E08E0F80938101F0E0E25AA0 +:100EC000FE4F80818093BB009091810180918001D1 +:100ED000981708F479CF85E88093BC000AC085ECA8 +:100EE0008093BC001092D60104C01092D4010E94DD +:100EF0000C03FF91EF91BF91AF919F918F917F91E3 +:100F00006F915F914F913F912F910F900FBE0F9076 +:100F10001F901895EBEFF1E01382128288EE93E0B8 +:100F2000A0E0B0E084839583A683B78324E031E01A +:100F30003183208325EC30E03587248724EC30E0B2 +:100F40003787268720EC30E0318B208B21EC30E096 +:100F5000338B228B22EC30E0358B248B26EC30E077 +:100F6000378B268B118E128E138E148EE8E9F2E0E9 +:100F70001382128284839583A683B78386E191E0EE +:100F800091838083E4EAF2E01382128288E291E0A6 +:100F900091838083108A8FEF87871686118A8FE36B +:100FA0008387148615861286118684E0828B82E000 +:100FB000838B81E0848B80E1858B80E2868B80E46B +:100FC000878B80E8808F40E050E063E0CF010C9495 +:100FD000C303789484B5826084BD84B5816084BD88 +:100FE00085B5826085BD85B5816085BD80916E00C7 +:100FF000816080936E0010928100809181008260F8 +:101000008093810080918100816080938100809134 +:1010100080008160809380008091B1008460809323 +:10102000B1008091B00081608093B00080917A001F +:10103000846080937A0080917A00826080937A0045 +:1010400080917A00816080937A0080917A00806834 +:1010500080937A001092C10062E085E00E947102E4 +:1010600062E086E00E94710261E088E00E94710205 +:1010700061E089E00E94710220E042E060E184EAE0 +:1010800092E00E944705E0910B02F0910C0282E091 +:101090008083E0910702F09108021082E09109023A +:1010A000F0910A028FEC808310921302E0910F02FC +:1010B000F091100286E08083E0910D02F0910E0223 +:1010C000808180618083E0910D02F0910E02808129 +:1010D00088608083E0910D02F0910E02808180682B +:1010E0008083E0910D02F0910E0280818F7D8083DC +:1010F000C1E0D0E085E00E941802892B31F4809194 +:10110000AE019091AF01892B31F185E00E94180268 +:10111000892B31F48091AE019091AF010197E1F1FB +:1011200086E00E941802892B39F48091AE019091DB +:10113000AF01892B09F451C086E00E941802892B67 +:1011400039F48091AE019091AF01019709F466C026 +:101150000E94E501CFCF68EE73E080E090E00E944E +:10116000D20261E088E00E94410260E089E00E94D2 +:101170004102D093AF01C093AE0180E00E94EA0328 +:1011800088E391E00E94A60581E00E94EA0388E4DA +:1011900091E00E94A605B9CF68EE73E080E090E090 +:1011A0000E94D20260E088E00E94410261E089E092 +:1011B0000E9441021092AF011092AE0180E00E94A5 +:1011C000EA0388E391E00E94A60581E00E94EA0319 +:1011D0008EE491E00E94A605A3CF68EE73E080E064 +:1011E00090E00E94D20260E088E00E94410260E04C +:1011F00089E00E944102D093AF01C093AE0180E02C +:101200000E94EA0388E391E00E94A60581E00E9423 +:10121000EA0385E591E00E94A6058ECF68EE73E0B3 +:1012200080E090E00E94D20260E088E00E944102EB +:1012300060E089E00E9441021092AF011092AE017D +:1012400080E00E94EA0388E391E00E94A60581E025 +:101250000E94EA038EE491E00E94A60579CFEE0F8A +:10126000FF1F0590F491E02D099481E090E0F8943F +:081270000C943A09F894FFCF39 +:10127800000000007C01E9001401C30145012301BD +:1012880037010000000094036403B4043E035C03C8 +:101298004D033F0300000000D703E900B404B30482 +:1012A8004705C3032D050C054172616820707574EC +:1012B8006172616E203A20006B616E616E0053743A +:0C12C8006F702020004B6972692020002C +:107800000C94343C0C94513C0C94513C0C94513CE1 +:107810000C94513C0C94513C0C94513C0C94513CB4 +:107820000C94513C0C94513C0C94513C0C94513CA4 +:107830000C94513C0C94513C0C94513C0C94513C94 +:107840000C94513C0C94513C0C94513C0C94513C84 +:107850000C94513C0C94513C0C94513C0C94513C74 +:107860000C94513C0C94513C11241FBECFEFD8E036 +:10787000DEBFCDBF11E0A0E0B1E0ECE9FFE702C060 +:1078800005900D92A230B107D9F712E0A2E0B1E065 +:1078900001C01D92AD30B107E1F70E942D3D0C945F +:1078A000CC3F0C94003C982F959595959595959582 +:1078B000905D8F708A307CF0282F295A8091C0000B +:1078C00085FFFCCF9093C6008091C00085FFFCCF60 +:1078D0002093C6000895282F205DF0CF982F809127 +:1078E000C00085FFFCCF9093C6000895EF92FF92F1 +:1078F0000F931F93EE24FF2487018091C00087FD22 +:1079000017C00894E11CF11C011D111D81E4E8164B +:1079100082E4F8068FE0080780E0180770F3E09132 +:107920000401F091050109958091C00087FFE9CF1E +:107930008091C6001F910F91FF90EF9008950E94D3 +:10794000763C982F8091C00085FFFCCF9093C600B5 +:1079500091362CF490330CF09053892F089597555D +:10796000892F08951F930E949F3C182F0E949F3CCF +:107970001295107F810F1F9108951F93182F882350 +:1079800021F00E94763C1150E1F71F9108951F935A +:10799000182F0E94763C803249F0809103018F5F5E +:1079A000809303018530C1F01F9108958091C0003C +:1079B00085FFFCCF84E18093C6008091C00085FFE5 +:1079C000FCCF1093C6008091C00085FFFCCF80E102 +:1079D0008093C6001F910895E0910401F091050184 +:1079E00009951F9108950E94763C803241F0809164 +:1079F00003018F5F80930301853081F008958091AA +:107A0000C00085FFFCCF84E18093C6008091C00058 +:107A100085FFFCCF80E18093C6000895E0910401CA +:107A2000F09105010995089540E951E08823A1F0FE +:107A30002D9A28EE33E0FA013197F1F721503040CA +:107A4000D1F72D9828EE33E0FA013197F1F7215064 +:107A50003040D1F7815061F708953F924F925F9285 +:107A60006F927F928F929F92AF92BF92CF92DF924E +:107A7000EF92FF920F931F93CF93DF93000080E16B +:107A80008093C4001092C50088E18093C10086E015 +:107A90008093C2005098589A259A81E00E94143D24 +:107AA00024E1F22E9EE1E92E85E9D82E0FE0C02ECA +:107AB00010E1B12EAA24A394B1E49B2EA6E58A2E50 +:107AC000F2E57F2EE0E26E2E79E4572E63E5462E36 +:107AD00050E5352E0E94763C8033B1F18133B9F107 +:107AE000803409F46FC0813409F476C0823409F41B +:107AF00085C0853409F488C0803531F1823521F1A3 +:107B0000813511F1853509F485C0863509F48DC0BC +:107B1000843609F496C0843709F403C1853709F423 +:107B200072C1863709F466C0809103018F5F80932C +:107B30000301853079F6E0910401F0910501099582 +:107B40000E94763C803351F60E94F33CC3CF0E94E2 +:107B5000763C803249F78091C00085FFFCCFF092DF +:107B6000C6008091C00085FFFCCF9092C600809136 +:107B7000C00085FFFCCF8092C6008091C00085FFC9 +:107B8000FCCF7092C6008091C00085FFFCCF609250 +:107B9000C6008091C00085FFFCCF5092C600809146 +:107BA000C00085FFFCCF4092C6008091C00085FFD9 +:107BB000FCCF3092C6008091C00085FFFCCFB09210 +:107BC000C60088CF0E94763C863808F4BDCF0E945C +:107BD000763C0E94F33C7ECF0E94763C803809F4CC +:107BE0009CC0813809F40BC1823809F43CC1883942 +:107BF00009F48FC080E00E94C73C6CCF84E10E94F2 +:107C0000BD3C0E94F33C66CF85E00E94BD3C0E94D3 +:107C1000F33C60CF0E94763C809306010E94763C44 +:107C2000809307010E94F33C55CF0E94763C80333D +:107C300009F41DC183E00E94BD3C80E00E94C73C66 +:107C400049CF0E94763C809309020E94763C809343 +:107C5000080280910C028E7F80930C020E94763C79 +:107C6000853409F415C18091080290910902892B8D +:107C700089F000E010E00E94763CF801E85FFE4FDA +:107C800080830F5F1F4F80910802909109020817AF +:107C9000190788F30E94763C803209F045CF809125 +:107CA0000C0280FF01C16091060170910701660F0F +:107CB000771F7093070160930601A0910802B091AD +:107CC00009021097C9F0E8E0F1E09B01AD014E0F09 +:107CD0005F1FF999FECF32BD21BD819180BDFA9A17 +:107CE000F99A2F5F3F4FE417F50799F76A0F7B1F4B +:107CF00070930701609306018091C00085FFFCCF5F +:107D0000F092C6008091C00085FFFCCFB092C60003 +:107D1000E1CE83E00E94C73CDDCE82E00E94C73CFA +:107D2000D9CE0E94763C809309020E94763C8093D3 +:107D300008028091060190910701880F991F909386 +:107D40000701809306010E94763C853409F4A6C0A1 +:107D500080910C028E7F80930C020E94763C8032D0 +:107D600009F0B8CE8091C00085FFFCCFF092C6002C +:107D7000609108027091090261157105B9F140E046 +:107D800050E080910C02A82FA170B82FB27011C0E2 +:107D9000BB2309F45CC0E0910601F0910701319624 +:107DA000F0930701E09306014F5F5F4F46175707B7 +:107DB000E8F4AA2369F3F999FECF209106013091E6 +:107DC000070132BD21BDF89A90B58091C00085FFB2 +:107DD000FCCF9093C6002F5F3F4F30930701209355 +:107DE00006014F5F5F4F4617570718F38091C00099 +:107DF00085FDE5CE8091C00085FFF8CFE0CE81E023 +:107E00000E94C73C67CE0E94763C803209F08CCE3F +:107E10008091C00085FFFCCFF092C6008091C00029 +:107E200085FFFCCFE092C6008091C00085FFFCCFAB +:107E3000D092C6008091C00085FFFCCFC092C600E2 +:107E40008091C00085FFFCCFB092C60043CEE09188 +:107E50000601F091070194918091C00085FFFCCF4D +:107E60009093C6009CCF80E10E94C73C33CE0E9415 +:107E7000763C0E94763C182F0E94763C112309F430 +:107E800083C0113009F484C08FE00E94C73C22CE29 +:107E900080910C02816080930C02E5CE80910C02EF +:107EA000816080930C0259CF809107018823880F4D +:107EB000880B8A2180930B02809106019091070123 +:107EC000880F991F90930701809306018091080203 +:107ED00080FF09C080910802909109020196909359 +:107EE000090280930802F894F999FECF1127E091D6 +:107EF0000601F0910701C8E0D1E08091080290915D +:107F00000902103091F40091570001700130D9F34B +:107F100003E000935700E89500915700017001308D +:107F2000D9F301E100935700E89509901990009169 +:107F3000570001700130D9F301E000935700E89534 +:107F40001395103498F011270091570001700130FB +:107F5000D9F305E000935700E895009157000170B0 +:107F60000130D9F301E100935700E895329602976A +:107F700009F0C7CF103011F00296E5CF112480919F +:107F8000C00085FFB9CEBCCE8EE10E94C73CA2CD19 +:0C7F900085E90E94C73C9ECDF894FFCF0D +:027F9C00800063 +:040000030000780081 +:00000001FF diff --git a/uji_coba_pn523/uji_coba_pn523.ino b/uji_coba_pn523/uji_coba_pn523.ino new file mode 100644 index 0000000..de03ff7 --- /dev/null +++ b/uji_coba_pn523/uji_coba_pn523.ino @@ -0,0 +1,63 @@ +#include +#include +#include + +#define SCK (13) +#define MOSI (11) +#define SS (10) +#define MISO (12) + +Adafruit_PN532 nfc(SCK, MISO, MOSI, SS); + +void setup(void) { + Serial.begin(9600); + Serial.println("Test spi port rfid reader PN532 "); + Serial.println("sabar tunggu 3 detik....."); + delay(3000); + nfc.begin(); + + uint32_t versiondata = nfc.getFirmwareVersion(); + if (! versiondata) { + Serial.print("board error"); + while (1); // halt + } + // Got ok data, print it out! + Serial.print("Device Found PN5 Chip"); + Serial.println((versiondata>>24) & 0xFF, HEX); + Serial.print("Firmware version > "); + Serial.print((versiondata>>16) & 0xFF, DEC); + Serial.println((versiondata>>8) & 0xFF, DEC); + nfc.SAMConfig(); //Set to read RFID tags + Serial.println("silahkan tap kartu"); +} + + +void loop(void) { + uint8_t success; + uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID + uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) + + // Wait for an ISO14443A type cards (Mifare, etc.). When one is found + // 'uid' will be populated with the UID, and uidLength will indicate + // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) + success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength); + + if (success) { + + Serial.println("kartu terbaca"); + Serial.print(" UID Length: "); + Serial.print(uidLength, DEC); + Serial.println(" BYTES"); + Serial.print(" UID VAL: "); + nfc.PrintHex(uid, uidLength); + + if (uidLength == 4) + { + Serial.println(" MIFACE CLASSIC CARD > (4 byte UID)"); + + // Factory default keyA is 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF + Serial.println("Authenticating block 4"); + uint8_t keya[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; //Default Key + } + } +} diff --git a/uji_coba_stepper/uji_coba_stepper.ino b/uji_coba_stepper/uji_coba_stepper.ino new file mode 100644 index 0000000..a5f1072 --- /dev/null +++ b/uji_coba_stepper/uji_coba_stepper.ino @@ -0,0 +1,28 @@ +#include +#define HALFSTEP 8 + +//pin driver motor +#define motor1 8 +#define motor2 9 +#define motor3 10 +#define motor4 11 + +//instalasi +AccelStepper stepper1(HALFSTEP, motor1, motor2, motor3, motor4); + +void setup() { + // put your setup code here, to run once: + stepper1.setMaxSpeed(2000.0); + stepper1.setAcceleration(100.0); + stepper1.setSpeed(1000); + stepper1.moveTo(20000); + +} + +void loop() { + // put your main code here, to run repeatedly: + if (stepper1.distanceToGo()==0){ + stepper1.moveTo(-stepper1.currentPosition()); + } +stepper1.run(); +} diff --git a/ultrasonic/ultrasonic.ino b/ultrasonic/ultrasonic.ino new file mode 100644 index 0000000..cc00c74 --- /dev/null +++ b/ultrasonic/ultrasonic.ino @@ -0,0 +1,47 @@ +#define echoPin 8 //Echo Pin +#define trigPin 9 //Trigger Pin +#define LEDPin 13 //Led default dari Arduino uno + +int maximumRange = 200; //kebutuhan akan maksimal range +int minimumRange = 0; //kebutuhan akan minimal range +long duration, distance; //waktu untuk kalkulasi jarak + +void setup() { +Serial.begin (9600); //inisialiasasi komunikasi serial +//deklarasi pin +pinMode(trigPin, OUTPUT); +pinMode(echoPin, INPUT); +pinMode(LEDPin, OUTPUT); +} + +void loop() { +/* Berikut siklus trigPin atau echo pin yang digunakan +untuk menentukan jarak objek terdekat dengan memantulkan +gelombang suara dari itu. */ +digitalWrite(trigPin, LOW);delayMicroseconds(2); + +digitalWrite(trigPin, HIGH);delayMicroseconds(10); + +digitalWrite(trigPin, LOW); + +duration = pulseIn(echoPin, HIGH); + +//perhitungan untuk dijadikan jarak +distance = duration/58.2; + +/* Kirim angka negatif ke komputer dan Turn LED ON +untuk menunjukkan "di luar jangkauan" * / + +if (distance >= maximumRange || distance <= minimumRange) +{ +Serial.println("-1");digitalWrite(LEDPin, HIGH); +} +else { +/*Kirim jarak ke komputer menggunakan Serial protokol, dan +menghidupkan LED OFF untuk menunjukkan membaca sukses. */ +Serial.println(distance); +digitalWrite(LEDPin, LOW); + +//waktu tunda 50mS +delay(50); +} diff --git a/uts/uts.ino b/uts/uts.ino new file mode 100644 index 0000000..99fb98a --- /dev/null +++ b/uts/uts.ino @@ -0,0 +1,54 @@ +#include +LiquidCrystal_I2C lcd(0x27 ,2,1,0,4,5,6,7,3, POSITIVE); + +const int analogIn = A0; +const int analogOut =13; + +int led = 1; +int push = 3; +int sensor ; +int output ; + +int button = 0; + +void setup() { + // put your setup code here, to run once: +// led dan push button + pinMode(led,OUTPUT); + pinMode(push,INPUT); + +//lcd + lcd.begin(16,2); + lcd.setCursor(0,0); + lcd.print("Ath Thaareq M"); + lcd.setCursor(0,1); + lcd.print("16202006"); + delay(2000); + lcd.clear(); +} + +void loop() { + // put your main code here, to run repeatedly: +//data sensor + + sensor = analogRead(analogIn); + output = map(sensor, 0, 1023, 0, 255); + analogWrite(analogOut, analogOut); + +//tampilan lcd + + lcd.setCursor(0,0); + lcd.print("Sensor = "); + Serial.print(analogOut); + + + + button = digitalRead(push); +if (button == HIGH) { + // LED on: + digitalWrite(led, HIGH); + } else { + // LED off: + digitalWrite(led, LOW); + } +}