Components and supplies
Resistor 100 ohm
Resistor 1k ohm
Resistor 1M ohm
Jumper wires (generic)
Resistor 100k ohm
Alphanumeric LCD, 16 x 2
Resistor 10k ohm
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
lazyRmeter_v3_16x2.ino
arduino
1// lazyRmeter by FEDERICO VIVALDI all references to OLE display removed - pins relocated 2// lazyRmeter_v2_16x2 semplified by F.Stella 20200221 for UNO and serial print to be ported to simple 16x2 display 3 4// LCD 16x2 code - example added 9 Jul 2009 by Tom Igoe - modFS2020 5//include the LCD library code: 6#include <LiquidCrystal.h> 7 8// initialize the library by associating any needed LCD interface pin 9// with the arduino pin number it is connected to 10const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2; 11LiquidCrystal lcd(rs, en, d4, d5, d6, d7); 12 13//Resistenze di comparazione sul circuito: 14//compR1 = 100 Ohm collegata a PIN 6 (lowest) 15//compR2 = 1 kOhm collegata a PIN 7 16//compR3 = 10 kOhm collegata a PIN 8 17//compR4 = 100 kOhm collegata a PIN 9 18//compR5 = 1 MOhm collegata a PIN 10 (top) 19 20int R1 = 100; 21int R2 = 1000; 22int R3 = 10000; 23long R4 = 100000; 24long R5 = 1000000; 25long Rn; 26 27float Input; 28 29String valore; 30String suffisso; 31float trans; 32 33int compR1 = 6; 34int compR2 = 7; 35int compR3 = 8; 36int compR4 = 9; 37int compR5 = 10; 38 39float raw = 0; 40float Vout = 0; 41float Ru = 0; 42int analogOhm = A0; 43 44void setup() { 45 Serial.begin(9600); 46 // set up the LCD's number of columns and rows: 47 lcd.begin(16, 2); 48 // Print a fixed message title to the LCD. 49 lcd.print("Resistenza da: "); 50} 51 52void loop() { 53 //attivazione porte a cui sono collegate le resistenze campione 54 pinMode(compR1, OUTPUT); //parto attivando il pin 2 che va alla resistenza test pi alta da 1M 55 pinMode(compR2, INPUT); 56 pinMode(compR3, INPUT); 57 pinMode(compR4, INPUT); 58 pinMode(compR5, INPUT); 59 60 digitalWrite(compR1, HIGH); //attiva la tensione a 5V sulla resistenza a 1 MOhm e resistenza da misurare 61 raw = analogRead(analogOhm); //legge il valore su A0 della tensione su 1 Ohm 62 63 Rn = R5; 64 65 Serial.println(raw); //DEBUG 66 Serial.println("ref 1M"); //DEBUG 67 68 int rawLimitLow = 350; //originale 350 69 int rawLimitTop = 850; //originale 800 70 71 if (raw < rawLimitLow || raw > rawLimitTop){ 72 digitalWrite(compR1, LOW); 73 pinMode(compR1, INPUT); 74 pinMode(compR2, OUTPUT); 75 digitalWrite(compR2, HIGH); 76 raw = analogRead(analogOhm); 77 Rn = R4; 78 79 Serial.println(raw); 80 Serial.print("ref 100k: "); 81 Serial.println(Rn); 82 83 if (raw < rawLimitLow || raw > rawLimitTop){ 84 digitalWrite(compR2, LOW); 85 pinMode(compR2, INPUT); 86 pinMode(compR3, OUTPUT); 87 digitalWrite(compR3, HIGH); 88 raw = analogRead(analogOhm); 89 Rn = R3; 90 91 Serial.println(raw); 92 Serial.println("ref 10k"); 93 94 if (raw < rawLimitLow || raw > rawLimitTop){ 95 digitalWrite(compR3, LOW); 96 pinMode(compR3, INPUT); 97 pinMode(compR4, OUTPUT); 98 digitalWrite(compR4, HIGH); 99 raw = analogRead(analogOhm); 100 Rn = R2; 101 102 Serial.println(raw); 103 Serial.println("ref 1k"); 104 105 if (raw < rawLimitLow || raw > rawLimitTop){ 106 digitalWrite(compR4, LOW); 107 pinMode(compR4, INPUT); 108 pinMode(compR5, OUTPUT); 109 digitalWrite(compR5, HIGH); 110 raw = analogRead(analogOhm); 111 Rn = R1; 112 113 Serial.println(raw); // DEBUG 114 Serial.println("ref 100");// DEBUG 115 } 116 } 117 } 118 } 119 120 Vout = 5*(raw/1024); 121 122 Ru = (Rn*Vout)/(5-Vout); 123 Serial.print("Ru: "); // DEBUG 124 Serial.println(Ru); // DEBUG 125 126 String resOhm = OhmFormattingFunction(Ru); 127 delay(1000); 128 129 Serial.print("Resistenza da: "); // DEBUG 130 Serial.println(resOhm); // DEBUG 131 132 lcd.setCursor(0,1); 133 lcd.print(resOhm); 134} 135 136String OhmFormattingFunction(float Input) { 137 //FS 20200223 v0 - Ohm values formatting function ** 138 139 String Result; 140 141 if (Input < 80) { 142 valore = (String(round(Input))); 143 suffisso = " "; 144 } 145 else if (Input < 800){ 146 valore = (String(10*round(Input/10))); 147 suffisso = " Ohm"; 148 } 149 else if (Input < 9000){ 150 trans = float(round(Input/100))/10; 151 valore = (String(trans)); 152 suffisso = " KOhm"; 153 } 154 else if (Input < 90000){ 155 valore = (String(10*round(Input/10000))); 156 suffisso = " KOhm"; 157 } 158 else if (Input < 900000){ 159 valore = (String(10*round(Input/10000))); 160 suffisso = " KOhm"; 161 } 162 else { 163 valore = (String(round(Input/1000000))); 164 suffisso = " MOhm"; 165 } 166 Result = valore + suffisso; 167 return Result; 168} 169
Downloadable files
Lazy Ohm
Lazy Ohm
Lazy Ohm
Lazy Ohm
Comments
Only logged in users can leave comments