/**************************************************************
Ohm Meter V5.0
vcc------
|
R2 = ??? Ohm // r yg diukur
|
A1-------
|
R1 = 470 ohm
|
gnd------
Board : Arduino Uno
Date : 27/11/2022
By : Arf S
- penambahan sw mode 1 2 ( Push Button ) --> Switch 3 Posisi
- Penambahan pembacaan voltmeter di A3 dan A4
Catatan Penting :
Wokwi only has a very basic analog circuit simulation.
You won't be able to use resistors together with analog
components (e.g. potentiometer or NTC temperature sensor).
You can still use the resistors as external pull-up/pull-down
resistors.
Note: Wokwi does not support full analog simulation,
so you will get the same results even if you don't connect the GND/VCC pins.
**************************************************************/
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7); //RS,RW,E,4567
#define sw1 A0
int analogPin = A1;
int analogPin2 = A2;
int raw=0,raw2 = 0;
int Vin = 5;
float Vout = 0;
float R1 = 460; // value of 470 resistor
float R2 = 0;
float buffer = 0;
int mode=1; // mode 1 open,
bool swF=true; // flag sw
int R2b,R2c;
byte rt,pl,st,ko;
//============================================ SETUP ======
void setup()
{
pinMode(sw1, INPUT_PULLUP);
lcd.begin(16, 2);
lcd.clear();
// lcd.setCursor(0,0); lcd.print(" ArduOhmMeter ");
// lcd.setCursor(0,1); lcd.print(" by : Arf V2.0");
lcd.setCursor(0,0); lcd.print("TERMINATOR DG-1 ");
lcd.setCursor(0,1); lcd.print("--------------- ");
delay(2000);
lcd.clear();
// lcd.setCursor(0,0); lcd.print("-- Coil Open --");
}
//=========================================== LOOP ========
void loop(){
readsw();
if(mode==2){
raw = analogRead(analogPin);
if(raw==0){lcd.setCursor(0, 1); lcd.print("CO: OP");}
if(raw){
buffer = raw * Vin;
Vout = (buffer)/1023.0;
buffer = (Vin/Vout) - 1;
R2 = R1 * buffer;
R2b=R2;
R2c=R2*10;
if (R2<1000){
rt = R2 / 100; // hasil pembagian 100
pl = ( R2b % 100 ) / 10; // sisa pembagian 100 dibagi 10
st = R2b % 10 ; // sisa pembagian 10
ko = R2c % 10 ; // sisa pembagian 10
// lcd.setCursor(0, 1); lcd.print("Value: ");
lcd.setCursor(0, 1); lcd.print("CO:");
lcd.print(rt);lcd.print(pl);lcd.print(st);//lcd.print(",");lcd.print(ko);
// lcd.print(" Ohm ");
// lcd.print(" <> ");
}
if (R2>999){
lcd.setCursor(0, 1); lcd.print("CO: OF");
}
}
raw2 = analogRead(analogPin2);
if(raw2==0){lcd.setCursor(10, 1); lcd.print("CC: OP");}
if(raw2){
buffer = raw2 * Vin;
Vout = (buffer)/1023.0;
buffer = (Vin/Vout) - 1;
R2 = R1 * buffer;
R2b=R2;
R2c=R2*10;
if (R2<1000){
rt = R2 / 100; // hasil pembagian 100
pl = ( R2b % 100 ) / 10; // sisa pembagian 100 dibagi 10
st = R2b % 10 ; // sisa pembagian 10
ko = R2c % 10 ; // sisa pembagian 10
// lcd.setCursor(0, 1); lcd.print("Value: ");
lcd.setCursor(10, 1); lcd.print("CC:");
lcd.print(rt);lcd.print(pl);lcd.print(st);//lcd.print(",");lcd.print(ko);
// lcd.print(" Ohm ");
// lcd.print(" <> CC:123");
}
if (R2>999){
lcd.setCursor(10, 1); lcd.print("CC: OF");
}
}
delay(250);
}
}
//=========================================== LOOP ========
void readsw(){
swF=digitalRead(sw1);
if(!swF){
mode=1;
lcd.setCursor(0, 0); lcd.print("Uji Keserempakan");
lcd.setCursor(0, 1); lcd.print("Kontak ");}
if(swF){
mode=2;
lcd.setCursor(0, 0); lcd.print(" TAHANAN COIL ");
lcd.setCursor(6, 1); lcd.print(" <> ");}
delay(200);
}