Advertisement
Guest User

Ardu Voltmeter

a guest
Apr 7th, 2021
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Wire.h>
  2. #include <Adafruit_ADS1015.h>
  3.  
  4. int r1 = 20000;
  5. int r2 = 5000;
  6. float Voltage;
  7. float supply;
  8.  
  9. Adafruit_ADS1115 ads;  /* Use this for the 16-bit version */
  10. void setup(void)
  11. {
  12.  
  13.   Serial.begin(9600);
  14.   Serial.println("Hello!");
  15.  
  16.   Serial.println("Getting differential reading from AIN0 (P) and AIN1 (N)");
  17.   Serial.println("ADC Range: +/- 6.144V (1 bit = 3mV/ADS1015, 0.1875mV/ADS1115)");
  18.                                                                
  19.   // ads.setGain(GAIN_TWOTHIRDS);  // 2/3x gain +/- 6.144V  1 bit = 3mV      0.1875mV (default)
  20.  
  21.  
  22.   ads.begin();
  23. }
  24.  
  25. void loop(void)
  26. {
  27.   float results;
  28.   float multiplier = 0.1875F; /* ADS1115  @ +/- 6.144V gain (16-bit results) */
  29.  
  30.   results = ads.readADC_Differential_0_1();  
  31.   Voltage = results * multiplier;
  32.   supply = (Voltage*(r1+r2))/r2;
  33.  
  34.   Serial.print("Differential: ");
  35.   Serial.print(results);
  36.   Serial.print("(");
  37.   Serial.print(Voltage);
  38.   Serial.println("mV)");
  39.   Serial.println(supply);
  40.  
  41.   delay(2000);
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement