Hi,
I am simply trying to make an ohm meter inspired by the same setup and some of the code as in this link: How to make an Arduino Ohm Meter - Arduino Project Hub
R1 is a known resistance and I am measuring R2 as an unknown resistance.
For the unknown resistance I am using a component that changes resistance over time. How can I create an interrupt that makes the LCD display the measured resistance only when changing?
The script
#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
int analogPin = 0;
int intensity = 60;
int raw = 0;
int Vin = 5;
float Vout = 0; // voltage drop across unknown resistor
float R1 = 220; //known resistor
float R2 = 0; // unknown resistor
float buffer = 0;
void setup() {
// lcd setup
analogWrite(12,intensity);
lcd.begin(16,2);
// interrupts using timer 0
noInterrupts(); // stop all interrupts
// set timer0 at interrupt 2 kHz
TCCR0A = 0; //register TCCR2A is set to 0
TCCR0B = 0; //register TCCR2B is set to 0
TCNT0 = 0; // initialize counter value to 0
//turn on CTC mode
TCCR0A |= (1 << WGM01); //
// set CS01 and CS00 bits for 64 prescaler
TCCR0B |= (1 << CS01) | (1 << CS00);
// enable timer compare interrupt
TIMSK0 |= (1 << OCIE0A);
interrupts(); // enable all interrupts
}
void loop(){
raw = analogRead(analogPin);
lcd.setCursor(0,1);
}
ISR(TIMER0_COMPA_vect){
if(raw!=raw){
buffer = raw * Vin;
Vout = (buffer)/1024.0;
buffer = (Vin/Vout)-1;
R2=R1*buffer;
lcd.print(R2);
}
}
The script so far only shows 0 on the LCD after uploading the script.
Thank you!
-Victoria