Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //If you found my video helpful, please SUBSCRIBE: https://www.youtube.com/channel/UCKp1MzuAceJnDqAvsZl_46g
- //The code belongs to the following tutorial videos:
- //Part 1: https://youtu.be/imcAITmccLQ
- //Part 2: https://youtu.be/2JsQ76EohDE
- /*PINS:
- * SDA: A4
- * SCL: A5
- * ADR: GND
- */
- #include <Wire.h>
- #include <Adafruit_ADS1015.h>
- Adafruit_ADS1115 ads;
- //-------Variables-------------
- int16_t channel_1, channel_2;
- float voltage_1, voltage_2;
- float distance_1, distance_2;
- float percentage_1, percentage_2;
- //-----------------------------
- void setup() {
- Serial.begin(115200);
- //----Set default------
- ads.setSPS(DR_128SPS); //Sampling speed 128 SPS
- ads.setGain(GAIN_TWO); //PGA settings +/- 2.048 V
- ads.begin();
- //------------------------------------------------------
- Serial.println("ADS1115 linear potmeter");
- }
- void loop()
- {
- readPotmeter_Diff();
- //readPotmeter_Sing();
- delay(1000);
- }
- void readPotmeter_Diff()
- {
- channel_1 = ads.readADC_Differential_0_1(); //A0 + A1
- Serial.print("D= "); Serial.println(channel_1);
- channel_2 = ads.readADC_Differential_2_3(); //A2 + A3
- percentage_1 = (channel_1 / 327.68);
- Serial.print("p= "); Serial.print(percentage_1,3); Serial.println(" %");
- voltage_1 = (channel_1 * 0.0625)/1000;
- Serial.print("U= "); Serial.print(voltage_1,6); Serial.println(" V");
- voltage_2 = (channel_2 * 0.0625)/1000;
- distance_1 = 0;
- distance_2 = 0;
- }
- void readPotmeter_Sing()
- {
- channel_1 = ads.readADC_SingleEnded(0); //A0
- Serial.println(channel_1);
- channel_2 = ads.readADC_SingleEnded(1); //A1
- percentage_1 = 100 * (channel_1 / 32768);
- Serial.println(percentage_1, 2);
- voltage_1 = (channel_1 * 0.125)/1000;
- Serial.println(voltage_1,6);
- voltage_2 = (channel_2 * 0.125)/1000;
- distance_1 = 0;
- distance_2 = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement