Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. int analogPin= 0; // Pin Analogico A0
  2. int raw= 0;
  3. int Vin= 5; // Volt in uscita dal Pin 5V di Arduino
  4. float Vout= 0;
  5. float R1= 1000; // impostare il valore della resistenza nota in Ohm
  6. float R2= 0;
  7. float buffer= 0;
  8.  
  9. #include <Wire.h> // Libreria wire già presente in Arduino ide
  10. #include <LiquidCrystal_I2C.h> // Libreria display I2C
  11.  
  12. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  13.  
  14. void setup()
  15. {
  16. lcd.begin(16, 2); //Inizializzazione display
  17. Serial.begin(9600); //Apro la comunicazione seriale
  18. }
  19.  
  20. void loop()
  21. {
  22. raw= analogRead(analogPin);
  23. if(raw)
  24. {
  25. buffer= raw * Vin;
  26. Vout= (buffer)/1024.0;
  27. buffer= (Vin/Vout) -1;
  28. R2= R1 * buffer;
  29. Serial.print("Vout: ");
  30. Serial.println(Vout);
  31. Serial.print("R2: ");
  32. Serial.println(R2);
  33. lcd.print("OHM METER");
  34. lcd.setCursor(0, 1);
  35. lcd.print("R2: ");
  36. lcd.print(R2);
  37. delay(1000);
  38. lcd.clear();
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement