» Electronics » Arduino »Sketch for measuring resistance, and what can be done with it

Sketch for measuring resistance, and what can be done with it



The author of Instructables under the nickname CreativeStuff tells how to implement on Arduino the simplest ohmmeter. To do this, he takes a breadboard type breadboard:



Actually Arduino:



Display on HD44780 (KB1013VG6):



Jumpers "dupont" or home-made:



10 kΩ variable resistor with soldered thin hard leads (for adjusting the image contrast on the display):



Doesn’t resemble anything? That's right, everything new is well forgotten old. Connoisseurs will remember what it is and where:



470 Ohm Permanent Resistor:



And all this connects according to this scheme:



Since the schemes compiled in the Fritzing program are not very informative, the wizard compiles the decryption:

Display Pin 1 - Common Wire

Display Pin 2 - Plus Power

Display Pin 3 - Moving Contact of a Variable Resistor

Display 4 pin - Arduino D12 pin

Display Pin 5 - Common Wire

Display pin 6 - D11 Arduino pin

Display pins 7, 8, 9, 10 are not connected to anything

Display Pin 11 - Arduino D5 Pin

Display 12 pin - Arduino D4 pin

Display Pin 13 - Arduino D3 Pin

Display Pin 14 - Arduino D2 Pin

Display Pin 15 - Plus Power

Display Pin 16 - Common Wire

When repeating the design, it is necessary to study the datasheet on the display to find out if its base is different from the standard.

The master connects one of the fixed contacts of the variable resistor to the power plus, the second to the common wire. A voltage divider is made up of an exemplary and tested resistor: the tested resistor with one output to the plus of the power supply, and the exemplary one with one output to the common wire. The remaining unoccupied outputs of both resistors are connected together and connected to Arduino pin A0. Fill the sketch:

#include 

// LiquidCrystal (rs, sc, d4, d5, d6, d7)
Liquid Crystal lcd (12, 11, 5, 4, 3, 2);

const int analogPin = 0;

int analogval = 0;
int vin = 5;

float buff = 0;
float vout = 0;
float R1 = 0;
float R2 = 470;

void setup () {
  lcd.begin (16, 2);
}

void loop () {

  analogval = analogRead (analogPin);
  if (analogval) {
    buff = analogval * vin;
    vout = (buff) / 1024.0;

    if (vout> 0.9) {
      buff = (vin / vout) - 1;
      R1 = R2 * buff;
      lcd.setCursor (0, 0);
      lcd.print ("-Resistance-");
      lcd.setCursor (0, 1);

      if ((R1)> 999) {
        lcd.print ("");
        lcd.print (R1 / 1000);
        lcd.print ("K ohm");
      }
      else {
        lcd.print ("");
        lcd.print (round (R1));
        lcd.print ("ohm");
      }

      delay (1000);
      lcd.clear ();

    }
    else {
      lcd.setCursor (0, 0);
      lcd.print ("Insert resistor");
      lcd.setCursor (0, 1);

    }
  }
}


The resistance of the reference resistor, as well as the supply voltage, is recommended to be measured more accurately (of course, when measuring the reference resistor should be temporarily removed), and then enter the measurement results in the appropriate lines at the beginning of the sketch. Take the power source with good stabilization of the output voltage. The program calculates the resistance according to the formula:

R2 = Vout * R1 / (Vin - Vout),

derived from the formula:

Vout = Vin * R2 / (R1 + R2),

where R1 is the model resistance, R2 is the measured resistance, Vin is the supply voltage, Vout is the voltage at the midpoint of the divider.

It remains to remove the breadboard, make all the connections by soldering and transfer homemade into the case. But in this form it is impractical, since it duplicates the ohmmeter function available in the multimeter. By redoing the sketch and applying a precision power source and an exemplary resistor, you can use the design, for example, to sort the resistors by accuracy in their production. In order to immediately display information on which of the five groups the component belongs to when connecting a resistor: 1, 2, 5, 10 or 20%.
10
10
10

Add a comment

    • smilesmilesxaxaokdontknowyahoonea
      bossscratchfoolyesyes-yesaggressivesecret
      sorrydancedance2dance3pardonhelpdrinks
      stopfriendsgoodgoodgoodwhistleswoontongue
      smokeclappingcraydeclarederisivedon-t_mentiondownload
      heatirefullaugh1mdameetingmoskingnegative
      not_ipopcornpunishreadscarescaressearch
      tauntthank_youthisto_clueumnikacuteagree
      badbeeeblack_eyeblum3blushboastboredom
      censoredpleasantrysecret2threatenvictoryyusun_bespectacled
      shokrespektlolprevedwelcomekrutoyya_za
      ya_dobryihelperne_huliganne_othodifludbanclose

We advise you to read:

Hand it for the smartphone ...