flavios
Published © GPL3+

Finally a way to sort out your resistors

OK! There's the color codes but small as they are we can use a simple "ohmmeter" that just gives us the value with a single move.

IntermediateProtip4,430
Finally a way to sort out your resistors

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Alphanumeric LCD, 16 x 2
Alphanumeric LCD, 16 x 2
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 100k ohm
Resistor 100k ohm
×1
Resistor 1M ohm
Resistor 1M ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Lazy Ohm

Code

lazyRmeter_v3_16x2.ino

Arduino
// lazyRmeter by FEDERICO VIVALDI all references to OLE display removed - pins relocated
// lazyRmeter_v2_16x2 semplified by F.Stella 20200221 for UNO and serial print to be ported to simple 16x2 display

// LCD 16x2 code - example added 9 Jul 2009 by Tom Igoe - modFS2020
//include the LCD library code:
#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

//Resistenze di comparazione sul circuito:
//compR1 = 100   Ohm  collegata a PIN  6 (lowest)
//compR2 =   1  kOhm  collegata a PIN  7
//compR3 =  10  kOhm  collegata a PIN  8
//compR4 = 100  kOhm  collegata a PIN  9
//compR5 =   1  MOhm  collegata a PIN 10 (top)

int R1 = 100; 
int R2 = 1000;
int R3 = 10000;
long R4 = 100000;
long R5 = 1000000;
long Rn;

float Input;

String valore;
String suffisso;
float trans;

int compR1 = 6;
int compR2 = 7;
int compR3 = 8;
int compR4 = 9;
int compR5 = 10;

float raw = 0;
float Vout = 0;
float Ru = 0;
int analogOhm = A0;

void setup() {
  Serial.begin(9600);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a fixed message title to the LCD.
  lcd.print("Resistenza da: ");
}

void loop() {
    //attivazione porte a cui sono collegate le resistenze campione
    pinMode(compR1, OUTPUT);   //parto attivando il pin 2 che va alla resistenza test pi alta da 1M
    pinMode(compR2, INPUT);
    pinMode(compR3, INPUT);
    pinMode(compR4, INPUT);
    pinMode(compR5, INPUT);

    digitalWrite(compR1, HIGH);     //attiva la tensione a 5V sulla resistenza a 1 MOhm e resistenza da misurare
    raw = analogRead(analogOhm);    //legge il valore su A0 della tensione su 1 Ohm
    
    Rn = R5;       
    
    Serial.println(raw);            //DEBUG
    Serial.println("ref 1M");       //DEBUG

    int rawLimitLow = 350; //originale 350
    int rawLimitTop = 850; //originale 800
   
    if (raw < rawLimitLow || raw > rawLimitTop){
      digitalWrite(compR1, LOW);
      pinMode(compR1, INPUT);
      pinMode(compR2, OUTPUT);
      digitalWrite(compR2, HIGH);
      raw = analogRead(analogOhm);
      Rn = R4;
      
      Serial.println(raw);
      Serial.print("ref 100k: ");
      Serial.println(Rn);

      if (raw < rawLimitLow || raw > rawLimitTop){
        digitalWrite(compR2, LOW);
        pinMode(compR2, INPUT);
        pinMode(compR3, OUTPUT);
        digitalWrite(compR3, HIGH);
        raw = analogRead(analogOhm);
        Rn = R3;
        
        Serial.println(raw);
        Serial.println("ref 10k");

        if (raw < rawLimitLow || raw > rawLimitTop){
          digitalWrite(compR3, LOW);
          pinMode(compR3, INPUT);
          pinMode(compR4, OUTPUT);
          digitalWrite(compR4, HIGH);
          raw = analogRead(analogOhm);
          Rn = R2;
          
          Serial.println(raw);
          Serial.println("ref 1k");
          
          if (raw < rawLimitLow || raw > rawLimitTop){
            digitalWrite(compR4, LOW);
            pinMode(compR4, INPUT);
            pinMode(compR5, OUTPUT);
            digitalWrite(compR5, HIGH);
            raw = analogRead(analogOhm);
            Rn = R1;
            
            Serial.println(raw);      // DEBUG
            Serial.println("ref 100");// DEBUG
          }
        }
      }
    }

    Vout = 5*(raw/1024);
   
    Ru = (Rn*Vout)/(5-Vout);
    Serial.print("Ru: ");             // DEBUG
    Serial.println(Ru);               // DEBUG

    String resOhm = OhmFormattingFunction(Ru);
    delay(1000); 
    
    Serial.print("Resistenza da: ");  // DEBUG
    Serial.println(resOhm);           // DEBUG

    lcd.setCursor(0,1);   
    lcd.print(resOhm);
}

String OhmFormattingFunction(float Input) {
    //FS 20200223 v0 - Ohm values formatting function **

    String Result;
    
    if (Input < 80) {
      valore = (String(round(Input)));
      suffisso = " ";    
    }
    else if (Input < 800){
      valore = (String(10*round(Input/10)));
      suffisso = " Ohm";          
    } 
    else if (Input < 9000){
      trans = float(round(Input/100))/10;
      valore = (String(trans));
      suffisso = " KOhm";          
    }
    else if (Input < 90000){
      valore = (String(10*round(Input/10000)));
      suffisso = " KOhm";          
    }
    else if (Input < 900000){
      valore = (String(10*round(Input/10000)));
      suffisso = " KOhm";          
    }
    else {
      valore = (String(round(Input/1000000)));
      suffisso = " MOhm";          
    }    
    Result = valore + suffisso;
    return Result;
}

Credits

flavios
0 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.