Daily Water Tracker!

Have you ever wanted to keep track of how many cups of water you've had in a day? Now you can, easier than ever before!

BeginnerWork in progress431
Daily Water Tracker!

Things used in this project

Hardware components

EK-TM4C123GXL TM4C Tiva LaunchPad
Texas Instruments EK-TM4C123GXL TM4C Tiva LaunchPad
×1
Breadboard (generic)
Breadboard (generic)
×1
Single Turn Potentiometer- 10k ohms
Single Turn Potentiometer- 10k ohms
×1
Tilt Switch, Encapsulated
Tilt Switch, Encapsulated
×1
7 Segment LED Display, InfoVue
7 Segment LED Display, InfoVue
×1
Jumper wires (generic)
Jumper wires (generic)
×13

Story

Read more

Schematics

Main Schematic

Note that this schematic shows the Launchpad from the front, while in our images we have wired it up from the back.

Code

display_potentiometer

Arduino
The main piece of code for this project: make sure to specify the correct pins based on how exactly you wire it up.
/*
 * Script that constantly updates a seven-segment display with a value 0-9 based on a 12-bit ADC reading (from a potentiometer).
 */

int val, num; 

// Build an array which holds the bit patterns which correspond to each display digit
int digits[10][8] = {
  {1,1,1,1,1,1,0,1},
  {0,1,1,0,0,0,0,1},
  {1,1,0,1,1,0,1,1},
  {1,1,1,1,0,0,1,1},
  {0,1,1,0,0,1,1,1},
  {1,0,1,1,0,1,1,1},
  {1,0,1,1,1,1,1,1},
  {1,1,1,0,0,0,0,1},
  {1,1,1,1,1,1,1,1},
  {1,1,1,1,0,1,1,1}
};

// Specify which pins are connected to which parts of the seven-segment display
// {a, b, c, d, e, f, g, DP}
int pins[8] = {9,8,7,5,4,3,2,6};

// Specify which pin is connected to pin 2 on the potentiometer
int potPin = 28;

// Defines a function that changes the number currently being displayed by updating each pin with a loop
void displayNum(int num) {
  int i;
  for (i = 0; i <= 7; i++){
    if (digits[num][i] == 1){
      digitalWrite(pins[i], LOW);
    } else {
      digitalWrite(pins[i], HIGH);
    }
  }
}

void setup() {
  int i;
  // Initialize pins by setting them to be outputs and setting them high
  for (i = 2; i <= 9; i++){
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH);
  }
  // Set the ADC's resolution to the full 12 bits
  analogReadResolution(12);
}

void loop() {
  val = analogRead(potPin);
  // Use a linear function to map the ADC reading 0-4095 to a digit 0-9
  if (val != 4095) {
    num = (10 * val) / 4095;
  } else {
    num = 9;
  }
  displayNum(num);
  delay(50);
}

Credits

Eliot Solomon

Eliot Solomon

2 projects • 0 followers
Aman Shanbhag

Aman Shanbhag

2 projects • 0 followers
Charan Santhirasegaran

Charan Santhirasegaran

2 projects • 0 followers
Fadil Eledath

Fadil Eledath

3 projects • 1 follower
Kaitlin Rodriguez

Kaitlin Rodriguez

2 projects • 0 followers
Manan Bajaj

Manan Bajaj

2 projects • 0 followers
Tate Ward

Tate Ward

2 projects • 0 followers
Yuliia Suprun

Yuliia Suprun

2 projects • 0 followers

Comments