Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //************************************************
- //* learnelectronics *
- //* Arduino Ohm Meter *
- //* original code by Iasonas Christoulakis *
- //* *
- //* Modified by learnelectronics 9/28/21 *
- //* www.youtube.com/learnelectronics *
- //* *
- //* email: arduino0169@gmail.com *
- //************************************************
- #include <Wire.h> //library for I2C
- #include <Adafruit_SSD1306.h> //OLED driver
- #define OLED_RESET 4 //required by the OLED driver
- Adafruit_SSD1306 display(OLED_RESET); //initiate library
- int analogPin= 0; //pin to read voltage divider
- int raw= 0; //reading from pin
- int Vin= 5; //voltage out from arduino
- float Vout= 0; //initial value
- float R1= 974; //actual reading of known resistor
- float R2= 0; //initial value for UNKNOWN resistor
- float buffer= 0; //initail buffer value
- void setup() {
- display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //startup the display
- display.display(); //show display buffer
- delay(2); //wait very briefly
- display.clearDisplay(); //clear the display
- }
- void loop() {
- raw= analogRead(analogPin); //read voltage at analog pin 0
- if(raw) //if there is a reading, then
- {
- buffer= raw * Vin; //multiply the reading by the value of vin
- Vout= (buffer)/1024.0; //set value of Vout to the whats in the buffer divided by 1024, the max value of the ADC
- buffer= (Vin/Vout) -1; //now make the buffer voltage in divided by voltage out -1
- R2= R1 * buffer; //and the value of the unknown is the known divided by the buffer
- }
- display.clearDisplay(); //show the answer
- display.setCursor(0,0);
- display.setTextSize(1);
- display.setTextColor(WHITE);
- display.print("Vout: ");
- display.println(Vout);
- display.print("R2: ");
- display.println(R2);
- display.display();
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement