Lesson 13 Resistor Meter code

Lesson 13 Resistor Meter code

// By Roee Bloch  Resistor-Meter
//All right Reserved
// Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com
//
// This source is subject to the Roee Bloch License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Roee Bloch</author>
// <email>roeebloch@walla.co.il</email>
// <date>June 2015</date>
/*
Part of the CODE is LCD Taken from:

 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe

 Formulas in use are:
 R(measured) = (RKnown(VCC-Vmeasured))/VMeasured
 V(measured) = ((ADC VALUE)/1024)*VCC

*/

#include <LiquidCrystal.h>

#define analog_in 1 // define analog input pin in use
#define VCC 5 //define VCC for calculation
#define R_known 46700 // define Reference resistor in use, I have found this value is very good to many measurements, but if you have another resistor you may change this value according
float R_measured, V_measured, R_measK ;
int analog_read;
char flag = 0;

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

void setup()
{
  Serial.begin(57600);
  Serial.println("Starting");
  lcd.begin(16, 2);
  lcd.print("Resistor Meter");
}
void loop()
{
  analog_read = analogRead(analog_in);
  while (analog_read == 0) {
    if (0 == flag)
    {
      Serial.println("Please connect resistor");
      lcd.setCursor(0, 1);
      lcd.print("Connect Resistor");
      flag = 1;
    }
    analog_read = analogRead(analog_in);
  }
  flag = 0;  // this is in order to print message connect resistor once only!
  V_measured = (analog_read) * VCC; // this is voltage *1024 since we did not divide by 1024
  V_measured = V_measured / 1024.0;
  R_measured = (R_known * (VCC - V_measured)) / V_measured;
  if (R_measured <= 1000)
  {
    Serial.print("Resistor is:");
    Serial.print(R_measured);
    Serial.println(" ohms");
    myclear();
    lcd.setCursor(0, 1);
    lcd.print("R=");
    lcd.print(R_measured);
    lcd.print(" ohms");
  }
  if (R_measured > 1000)
  {
    Serial.print("Resistor is:");
    R_measK = R_measured / 1000;
    Serial.print((R_measK));
    Serial.println(" K ohms");
    myclear();
    lcd.setCursor(0, 1);
    lcd.print("R=");
    lcd.print(R_measK);
    lcd.print(" K ohms");
  }
  delay(1000);
}
void myprint(float x, String param)
{
  int myprint;
  myprint = (x);
  Serial.print(param);
  Serial.print(" is:");
  Serial.println(myprint);
}
void myclear() // clear all second line
{
  lcd.setCursor(0, 1);
  lcd.print("                ");

}

Video Based on This Code: lesson-13-resistor-meter-part-2
Resistor Meter Theory of Operation: lesson-13-arduino-resistor-meter-fluke-like

[adsenseyu6]

Arduino Parts for this project:

[adsenseyu1]