John Bradnam
Published © GPL3+

Inductance Meter

An Arduino based meter to measure inductors.

IntermediateFull instructions provided8 hours2,989
Inductance Meter

Things used in this project

Hardware components

Microchip ATtiny1614
×1
Standard LCD - 16x2 White on Blue
Adafruit Standard LCD - 16x2 White on Blue
×1
LM1117-33 3.3V Regulator
SOT-223 Package
×1
LMV331 comparator IC
SC70-5 Package
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
DO-214AC package
×1
Passive components
1 x 150R 0805, 1 x 220R 0805, 1 x 330R 0805, 4 x 0.1uF 0805, 1 x 47uF/10V Tantalum 3528, 1 x 10K trimpot
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
13mm shaft with button top
×1
Banana Jack, Panel Mount
Banana Jack, Panel Mount
2mm
×2

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

STL Files

STL files for 3D printing

Schematics

Schematic

PCB

Eagle Files

Schematic and PCB in Eagle format

Code

Inductance_Meter_V1.ino

C/C++
/**************************************************************************
 LCD Inductance Meter

 Concept: sagar saini - https://www.hackster.io/sainisagar7294/how-to-make-inductance-meter-using-arduino-b9cb20

 Schematic & PCB at https://www.hackster.io/john-bradnam/inductance-meter-15c031
 
 2021-07-11 John Bradnam (jbrad2089@gmail.com)
   Create program for ATtiny1614

 --------------------------------------------------------------------------
 Arduino IDE:
 --------------------------------------------------------------------------
  BOARD: ATtiny1614/1604/814/804/414/404/214/204
  Chip: ATtiny1614
  Clock Speed: 8MHz
  millis()/micros(): "Enabled (default timer)"
  Programmer: jtag2updi (megaTinyCore)

  ATTiny1614 Pins mapped to Ardunio Pins
 
              +--------+
          VCC + 1   14 + GND
  (SS)  0 PA4 + 2   13 + PA3 10 (SCK)
        1 PA5 + 3   12 + PA2 9  (MISO)
  (DAC) 2 PA6 + 4   11 + PA1 8  (MOSI)
        3 PA7 + 5   10 + PA0 11 (UPDI)
  (RXD) 4 PB3 + 6    9 + PB0 7  (SCL)
  (TXD) 5 PB2 + 7    8 + PB1 6  (SDA)
              +--------+
  
 **************************************************************************/

//#define DEBUG     //Uncomment to output to pulse and frequency

#include <avr/pgmspace.h>
#include <avr/sleep.h>
#include <avr/power.h>
#include <LiquidCrystal.h>

#define adc_disable()  (ADC0.CTRLA &= ~ADC_ENABLE_bm)
#define adc_enable()   (ADC0.CTRLA |=  ADC_ENABLE_bm) // re-enable ADC

//LCD Screen
#define LCD_RS 1  //PA5
#define LCD_EN 2  //PA6
#define LCD_D4 3  //PA7
#define LCD_D5 4  //PB3
#define LCD_D6 5  //PB2
#define LCD_D7 9  //PA2

//Switches
#define SW_TEST 10 //PA3

//Other
#define POWER 0    //PA4
#define LIGHT 8    //PA1
#define TANK 6     //PB1
#define COMP 7     //PB0
 
//Initialize the LCD
LiquidCrystal lcd(LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7);

#define RESULT_DELAY 500  //Time result is displayed before retesting
#define AUTO_SWITCH_OFF_TIME 10000  //Time to auto switch off if nothing is measured

double pulse, frequency, capacitance, inductance, inductance_mH;
long loopTimeOut;
long autoOffTimeOut;

//-------------------------------------------------------------------------
// Initialise Hardware
void setup(void)
{
  pinMode(POWER, OUTPUT);
  digitalWrite(POWER, HIGH);
  pinMode(LIGHT, OUTPUT);
  digitalWrite(LIGHT, HIGH);

  pinMode(SW_TEST, INPUT_PULLUP);
  
  pinMode(COMP, INPUT); //Input from the comparator output
  pinMode(TANK, OUTPUT);//output through a 150 ohm resistor to thr LC circuit
  
  adc_disable(); // Doesn't use ADC
  
  goToSleep();  
}

//--------------------------------------------------------------------
// Main program loop
void loop(void)
{ 
  digitalWrite(TANK, HIGH);
  delay(5);//give some time to charge inductor.
  digitalWrite(TANK,LOW);
  delayMicroseconds(100); //make sure resination is measured
  
  pulse = pulseIn(COMP,HIGH,5000);  //returns 0 if timeout
  
  if (pulse > 0.1) //if a timeout did not occur and it took a reading:
  {
    capacitance = 2.0E-7;   // <- insert value here

	//f = 1/(2*pi*sqrt(l*c))
	//f*f = 1/(4*pi*pi*l*c)
	//l = 1/(4*pi*pi*f*f*c)
    
    frequency = 1.0E6 / (2*pulse);
    inductance = 1.0 / (capacitance*frequency*frequency*4.*3.14159*3.14159);
    inductance = inductance * 1E6;
    
    #ifdef DEBUG
      delay(2000);
      lcd.clear();
      lcd.setCursor(0,0); 
      lcd.print("P: " + String(pulse));
      lcd.setCursor(0,1); 
      lcd.print("F: " + String(frequency));
      delay(2000);
      lcd.clear();
      lcd.setCursor(0,0); 
      lcd.print("Inductance");
    #endif

    //LCD print
    lcd.setCursor(0,1); 
    if (inductance < 1000)
    {
      lcd.print(String(inductance)+"uH");
    }
    else
    {
      lcd.print(String(inductance / 1000)+"mH");
    }
    loopTimeOut = millis() + RESULT_DELAY;
    autoOffTimeOut = millis() + AUTO_SWITCH_OFF_TIME;
  }
  else
  {
    lcd.setCursor(0,1); 
    lcd.print("----            ");
    loopTimeOut = millis() + 10;
  }

  //Allow screen to be read before testing again. Power off if button is pressed
  while (millis() < loopTimeOut)
  {
    if (digitalRead(SW_TEST) == LOW)
    {
      delay(10);  //Debounce
      if (digitalRead(SW_TEST) == LOW)
      {
        //wait until release
        while (digitalRead(SW_TEST) == LOW);
        goToSleep();
      }
    }
  }

  //Automatically power down if nothing is measured after AUTO_SWITCH_OFF_TIME milliseconds
  if (millis() >= autoOffTimeOut)
  {
    goToSleep();
  }
}

//--------------------------------------------------------------------
// Show splash screen

void showSplashScreen()
{
  lcd.begin(16, 2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Inductance Meter");
  delay(2000);
  
  lcd.clear();
  lcd.setCursor(0,0); 
  lcd.print("  Measuring...");
}

//--------------------------------------------------------------------
// Handle pin change interrupt when SW_TEST is pressed
void switchInterrupt()
{
}

//--------------------------------------------------------------------
// Set all LCD pins LOW or HIGH
void setLcdPins(int state) 
{
  static char Outputs[] = {LCD_RS, LCD_EN, LCD_D4, LCD_D5, LCD_D6, LCD_D7};
  for (int i=0; i<6; i++) 
  {
    pinMode(Outputs[i], state);
  }
}

//--------------------------------------------------------------------
//Shut down OLED and put ATtiny to sleep
//Will wake up when LEFT button is pressed
void goToSleep() 
{
  attachInterrupt(SW_TEST, switchInterrupt, CHANGE);
  lcd.clear();
  setLcdPins(INPUT);
  digitalWrite(LIGHT, LOW);
  digitalWrite(POWER, LOW);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);  // sleep mode is set here
  sleep_enable();
  sleep_mode();                         // System actually sleeps here
  sleep_disable();                      // System continues execution here when watchdog timed out
  pinMode(POWER, OUTPUT);
  digitalWrite(POWER, HIGH);
  pinMode(LIGHT, OUTPUT);
  digitalWrite(LIGHT, HIGH);
  setLcdPins(OUTPUT);
  detachInterrupt(SW_TEST);
  //wait until release
  while (digitalRead(SW_TEST) == LOW);
  showSplashScreen();
  autoOffTimeOut = millis() + AUTO_SWITCH_OFF_TIME;
}

Credits

John Bradnam

John Bradnam

141 projects • 167 followers
Thanks to sagar saini.

Comments