#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7); //rs,e,d4,d5,d6,d7
// SELECTOR
int select =A0;
int selvalue;
int selvout;
float selvin;
// DC VOLTMETER
int dc =A1;
int dcvalue;
int dcvout;
float dcvin;
// frequency meter
int X;
int Y;
float Time;
float frequencyA;
const int input = 9;
int mode=1;
// inductor meter 13 is the input to the circuit (connects to 150ohm resistor), 11 is the comparator/op-amp output.
double pulse, frequency, capacitance, inductance;
void setup()
{
lcd.begin(16,2);
pinMode(11, INPUT);
pinMode(input,INPUT);
pinMode(13, OUTPUT);
pinMode(select, INPUT);
pinMode(dc, INPUT);
analogReference(INTERNAL); // set ADC positive reference voltage to 1.1V (internal)
lcd.print("AKINFOYEKU SAM");
lcd.setCursor(0, 1);
lcd.print("MULTIMETER ----");
delay(5000);
lcd.clear();
} // end setup
// get maximum reading value
uint16_t get_max() {
uint16_t max_v = 0;
for(uint8_t i = 0; i < 100; i++) {
uint16_t r = analogRead(A2); // read from analog channel 3 (A3)
if(max_v < r) max_v = r;
delayMicroseconds(200);
}
return max_v;
}
void loop() {
selvalue = analogRead(select);
selvout = selvalue * (5.0*11 / 1023);
selvin=selvout*0.09;
if (selvin >4.6)
{
mode=1; // 50V DC VOLTMETER
}
else if (selvin >4.3)
{
mode=2; // 150V DC VOLTMETER
}
else if (selvin >4.0)
{
mode=3; // 500V DC VOLTMETER
}
else if (selvin >3.7)
{
mode=4;// 1000 DC VOLTMETER
}
else if (selvin >3.4)
{
mode=5; // AC VOLTMETER
}
else if (selvin >3.1)
{
mode=6;// 2K OHM METER
}
else if (selvin >2.8)
{
mode=7;// 20KOHM METER
}
else if (selvin >2.5)
{
mode=8;//200K OHM METER
}
else if (selvin >2.2)
{
mode=9;//1M OHM METER
}
else if (selvin >1.9)
{
mode =10; // INDUCTOR METER
}
else if (selvin >1.6)
{
mode=11; // CONUITY TESTER
}
else if (selvin >1.3)
{
mode=12; // DOIDE AND LED TESTER
}
else if (selvin >1.0)
{
mode=13; // FREQUCY METER
}
else
{
mode=14; // CAPACITOR TESTER
}
//////////////////////////////// 50V DC VOLTMETER MODE 1//////////////////////////////////
if( mode == 1 )
{
lcd.setCursor(0, 0);
lcd.print("DC Voltmeter 50V");
dcvalue = analogRead(dc);
dcvout = dcvalue * (5.0*11 / 1023);
dcvin=dcvout*0.9;
lcd.setCursor(0, 1);
lcd.print("DC volt=");
lcd.print(dcvin,1);
lcd.print("V ");
}
//////////////////////////////// 150V DC VOLTMETER MODE 2//////////////////////////////////
if( mode == 2 )
{
lcd.setCursor(0, 0);
lcd.print("DC Voltmeter150V");
dcvalue = analogRead(dc);
dcvout = dcvalue * (5.0*33 / 1023);
dcvin=dcvout*0.9;
lcd.setCursor(0, 1);
lcd.print("DC volt=");
lcd.print(dcvin,1);
lcd.print("V ");
}
//////////////////////////////// 500V DC VOLTMETER MODE 3//////////////////////////////////
if( mode == 3)
{
lcd.setCursor(0, 0);
lcd.print("DC Voltmete500V");
dcvalue = analogRead(dc);
dcvout = dcvalue * (5.0*111 / 1023);
dcvin=dcvout*0.9;
lcd.setCursor(0, 1);
lcd.print("DC volt=");
lcd.print(dcvin,1);
lcd.print("V ");
}
//////////////////////////////// 1000V DC VOLTMETER MODE 4//////////////////////////////////
if( mode == 4 )
{
lcd.setCursor(0, 0);
lcd.print("DC Voltmet1000V");
dcvalue = analogRead(dc);
dcvout = dcvalue * (5.0*221 / 1023);
dcvin=dcvout*0.9;
lcd.setCursor(0, 1);
lcd.print("DC volt=");
lcd.print(dcvin,1);
lcd.print("V ");
}
//////////////////////////////// AC VOLTMETER MODE 5//////////////////////////////////
if( mode == 5 )
{
lcd.setCursor(0, 0);
lcd.print("AC Voltmete600V");
char buf[10];
// get amplitude (maximum - or peak value)
uint32_t v = get_max();
// get actual voltage (ADC voltage reference = 1.1V)
v = v * 1100/1023;
// calculate the RMS value ( = peak/√2 )
v /= sqrt(2);
sprintf(buf, "%03u Volts", v);
lcd.setCursor(0, 1);
lcd.print("AC volt=");
lcd.print(buf);
}
//////////////////////////////// 2K OHM METER MODE 6//////////////////////////////////
if( mode == 6 )
{
lcd.setCursor(0, 0);
lcd.print("2K OHM METER ");
}
//////////////////////////////// 20K OHM METER MODE 7//////////////////////////////////
if( mode == 7)
{
lcd.setCursor(0, 0);
lcd.print("20K OHM METER ");
}
//////////////////////////////// 200K OHM METER MODE 8//////////////////////////////////
if( mode == 8 )
{
lcd.setCursor(0, 0);
lcd.print("200K OHM METER ");
}
//////////////////////////////// 1M OHM METER MODE 9//////////////////////////////////
if( mode == 9 )
{
lcd.setCursor(0, 0);
lcd.print("1M OHM METER ");
}
//////////////////////////////// INDUCTOR METER MODE 10//////////////////////////////////
if( mode == 10 )
{
lcd.setCursor(0, 0);
lcd.print("INDUCTOR METER");
digitalWrite(13, HIGH);
delay(5);//give some time to charge inductor.
digitalWrite(13,LOW);
delayMicroseconds(100); //make sure resination is measured
pulse = pulseIn(11,HIGH,5000);//returns 0 if timeout
if(pulse > 0.1){ //if a timeout did not occur and it took a reading:
//#error insert your used capacitance value here. Currently using 2uF. Delete this line after that
capacitance = 2.E-6; // - insert value here
frequency = 1.E6/(2*pulse);
inductance = 1./(capacitance*frequency*frequency*4.*3.14159*3.14159);//one of my profs told me just do squares like this
inductance *= 1E6; //note that this is the same as saying inductance =
lcd.setCursor(0,1);
lcd.print("Inductance=");
lcd.print(inductance);
lcd.print("uH");
}
}
//////////////////////////////// CONTINUITY MODE 11//////////////////////////////////
if( mode == 11 )
{
lcd.setCursor(0, 0);
lcd.print("CONTINUITY TEST");
}
//////////////////////////////// DOIDE AND LED MODE 12//////////////////////////////////
if( mode == 12 )
{
lcd.setCursor(0, 0);
lcd.print("DOIDE AND LED");
}
//////////////////////////////// FREQUNCY METER MODE 13//////////////////////////////////
if( mode == 13 )
{
lcd.setCursor(0, 0);
lcd.print("FREQUNCY METER");
X=pulseIn(input,HIGH);
Y=pulseIn(input,LOW);
Time = X+Y;
frequencyA=1000000/Time;
if (frequencyA>1000000)
{
lcd.setCursor(0,1);
lcd.print("FRE INPUT=");
lcd.print(frequencyA/1000000);
lcd.print(" Mhz");
}
else if (frequencyA>1000)
{
lcd.setCursor(0,1);
lcd.print("FRE INPUT=");
lcd.print(frequencyA/1000);
lcd.print(" Khz");
}
else
{
lcd.setCursor(0,1);
lcd.print("FRE INPUT=");
lcd.print(frequencyA);
lcd.print(" hz");
}
}
//////////////////////////////// CAPACITPR METER MODE 14//////////////////////////////////
if( mode == 14 )
{
lcd.setCursor(0, 0);
lcd.print("CAPACITOR METER ");
}
} // END LOOP