Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Wire.h>
- const int DS1115_Address = 0x48; // I2C address of DS1115
- float voltageValue = 0.0;
- void setup() {
- Serial.begin(9600);
- Wire.begin();
- }
- void loop() {
- int rawValue;
- Wire.beginTransmission(DS1115_Address);
- Wire.write(0x00); // address of conversion register
- Wire.endTransmission();
- delay(10); // conversion time for DS1115
- Wire.requestFrom(DS1115_Address, 2);
- if (Wire.available() == 2) {
- rawValue = Wire.read() << 8 | Wire.read();
- voltageValue = rawValue * 5.0 / 32768.0; // 5V reference voltage, 16-bit resolution
- Serial.print("Voltage: ");
- Serial.print(voltageValue);
- Serial.println("V");
- }
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement