Here is a version of code including LCD. Attention: I had an exotic old customized LCD 2X20, some MIDAS brand with ST7036 controller. You must replace/include appropriate libraries for your LCD.
I built several versions of code as I kept schematics with one OpAmp either MCP601 or MCP6041 and using ADC of Arduino, doing conversion on 10 bits as it is below code or more, ie 16 bits, by oversampling in order to keep it simple and cheap. I reduced the number of digits to 4 instead of 5.
I am really very satisfied with results. I tested it in several conditions and always it was very easy to locate the short helped by readings, sound and led light. Also, the accuracy is quite impressive with 4 wires probes.
I attached a picture with one of prototypes.
//by Zoli on March 2021 version 12
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <stdint.h>
#include <EEPROM.h>
#include <util/delay.h>
//this code section I found out on the arduino forum
#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
double sensorPin = A1; // select the input pin for sensor
int buzzer = 9;//audio output
int led = 8; //signal led
long sensorValue = 0; // variable to store the value coming from the sensor
long real_sensorValue = 0;
int pnp = A3; //transistor base
float voltage;
float voltagei;
double ohm;
double real_ohm;
double ohmCal;
int address = 0;
byte value;
unsigned int button_delay; // to detect long press of the button
double vRef = 1070;
#define VERSION "1.X"
#define BUTTON 11
#define EEPROM_OHMCAL_LOCATION 16
#include "ST7036.h"
#include "LCD_C0220BiZ.h"
#include <Wire.h>
#include <inttypes.h>
ST7036 lcd( 2, 20, 0x78 );
uint8_t rows = 2;
uint8_t cols = 20;
void setup() {
Serial.begin(9600);
analogReference(INTERNAL);//using internal 1100mV reference
pinMode(sensorPin, INPUT);
pinMode(buzzer, OUTPUT);
pinMode(pnp, OUTPUT);
pinMode(led, OUTPUT);
pinMode( BUTTON, INPUT_PULLUP);
lcd.init(); // Init the display, clears the display
lcd.clear ();
lcd.setCursor ( 0, 0 );
lcd.print("Sa ai o zi buna!"); // Classic Hello World!
delay(2000);
eeprom_read_block(
(void*) &ohmCal,
(void*) EEPROM_OHMCAL_LOCATION,
sizeof( ohmCal ) );
if (FASTADC) {
sbi(ADCSRA,ADPS2);
cbi(ADCSRA,ADPS1);
sbi(ADCSRA,ADPS0);
}
noTone( buzzer);}
void(* resetFunc) (void) = 0;
double calcREZ()
{
for (int i=0; i < 20; i++) {
sensorValue = sensorValue + analogRead(sensorPin);
}
sensorValue =sensorValue/20;
voltage = ((sensorValue * 1100)/1024 );
voltagei = voltage / 27.45;
ohm = ( voltagei/25.5);
return ohm;}
void loop() {
value = EEPROM.read(EEPROM_OHMCAL_LOCATION);
Serial.print(EEPROM_OHMCAL_LOCATION);
Serial.print("\t");
Serial.print(value, DEC);
Serial.println();
delay(100);
digitalWrite(pnp,LOW);
digitalWrite(led, HIGH);
//Procedure found out on forum
if (digitalRead( BUTTON) == 0) // check D11 button state
{
noTone( buzzer);
lcd.clear();
lcd.setCursor ( 0, 9 );
lcd.print("COMPENSATION");
delay(400);
button_delay = 0;
while ((digitalRead( BUTTON) == 0) && (button_delay<10))
{
button_delay++;
delay(120);
}
if (button_delay>5)
{
lcd.clear();
lcd.setCursor ( 0, 8 );
lcd.print("ZEROING PROCEDURE");
delay(2000);
ohmCal = calcREZ();
//writing calibration value into EEPROM so we don't have to calibrate on restart
// store calibration value in EEPROM
eeprom_write_block(
(const void*) &ohmCal,
(void*) EEPROM_OHMCAL_LOCATION,
sizeof( ohmCal ) );
lcd.print(" done!");
lcd.setCursor(0,1);
lcd.print("saved to EEPROM");
delay(500);
}}
ohm = calcREZ();
real_ohm = (ohm - ohmCal)*1.15;// correction factor precision class
if (real_ohm<=0) real_ohm = 0;
// print out the value you read:
//Serial.println(ohm,5);
//Serial.println(voltage , 5);
// Serial.println(real_sensorValue , 5);
Serial.println(real_ohm , 5);
delay (10);
if (real_ohm <1.5){
float ftone = -800 + (4000 +800)/(1 + pow(real_ohm,0.66));
//float ftone = 4500*real_ohm;//can replace above tone (resistance value) convertor
tone( buzzer, ftone);
lcd.clear();
lcd.print ("Resistor measurement");
lcd.setCursor ( 1, 0 );
lcd.print ("Value = ");
lcd.print (real_ohm,4);
lcd.print (" ohms");
delay(200);}
else{noTone( buzzer);
lcd.clear();
lcd.print ("Resistor measurement");
lcd.setCursor ( 1, 0 );
lcd.print ("Value > 1.5 ohms");
delay(200);}
if (real_ohm <1.5){if (real_ohm <0.00001){
lcd.clear();
lcd.print ("Resistor measurement");
lcd.setCursor ( 1, 0 );
lcd.print ("Value = ");
lcd.print (0.0000,4);
lcd.print (" ohms");
delay(5000);
lcd.clear();
lcd.print ("Acesta este scurtul");
delay (1000);
resetFunc();
}
} }