Close

Finally

A project log for PuriBottle

A bottle that will measure your water intake so you can drink well and enough !

PuriBottlePuriBottle 06/01/2017 at 07:550 Comments

Here is our final program :

int trigPin = A0; //Trig - green Jumper int echoPin = A1; //Echo - yellow Jumper long duration, cm, inches; // on assigne chaque led a une borne de l'arduino // const int A = 2; const int B = 3; const int C = 4; const int D = 5; const int E = 6; const int F = 7; const int G = 8; const int H = 9; const int I = 10; const int J = 11; const int K = 12; const int L = 13; const int M = 1 ; const int N = A5 ; void setup() { //Serial Port begin Serial.begin (9600); //Define inputs and outputs pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(A, OUTPUT); pinMode(B, OUTPUT); pinMode(C, OUTPUT); pinMode(D, OUTPUT); pinMode(E, OUTPUT); pinMode(F, OUTPUT); pinMode(N, OUTPUT); pinMode(G, OUTPUT); pinMode(H, OUTPUT); pinMode(I, OUTPUT); pinMode(J, OUTPUT); pinMode(K, OUTPUT); pinMode(L, OUTPUT); pinMode(M, OUTPUT); pinMode(N, OUTPUT); // Mise a l'etat Haut de ces sortie pour eteindre le Led de l'aficheur// digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } void loop() { // The sensor is triggered by a HIGH pulse of 10 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: digitalWrite(trigPin, LOW); delayMicroseconds(5); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // Read the signal from the sensor: a HIGH pulse whose // duration is the time (in microseconds) from the sending // of the ping to the reception of its echo off of an object. pinMode(echoPin, INPUT); duration = pulseIn(echoPin, HIGH); // convert the time into a distance cm =((duration/2) / 29.1); inches =((duration/2) / 74); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); delay(250); if (inches == 0) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,LOW); digitalWrite (N,LOW); } else if (inches == 1) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,LOW); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,LOW); digitalWrite (N,LOW); } else if (inches == 2) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,LOW); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,LOW); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 3) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 4) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,LOW); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 5) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,LOW); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 6) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,LOW); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 7) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,LOW); digitalWrite (N,LOW); } else if (inches == 8 ) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 9) { digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,HIGH); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 10) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,LOW); digitalWrite (N,LOW); } else if (inches == 11) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,LOW); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,LOW); digitalWrite (N,LOW); } else if (inches == 12) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,LOW); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,LOW); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 13) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 14) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,LOW); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 15) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,LOW); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 16) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,LOW); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 17) { digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,LOW); digitalWrite (N,LOW); } else if (inches == 18) {digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 19) {digitalWrite (A,LOW); digitalWrite (B,HIGH); digitalWrite (C,HIGH); digitalWrite (D,LOW); digitalWrite (E,LOW); digitalWrite (F,LOW); digitalWrite (N,LOW); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,LOW); } else if (inches == 20) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,LOW); digitalWrite (N,HIGH); } else if (inches == 21) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,LOW); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,LOW); digitalWrite (N,HIGH); } else if (inches == 22) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,LOW); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,LOW); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } else if (inches == 23) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } else if (inches == 24) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,LOW); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } else if (inches == 25) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,LOW); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } else if (inches == 26) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,LOW); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } else if (inches == 27) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,LOW); digitalWrite (K,LOW); digitalWrite (L,LOW); digitalWrite (M,LOW); digitalWrite (N,HIGH); } else if (inches == 28) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,HIGH); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } else if (inches == 29) {digitalWrite (A,HIGH); digitalWrite (B,HIGH); digitalWrite (C,LOW); digitalWrite (D,HIGH); digitalWrite (E,HIGH); digitalWrite (F,LOW); digitalWrite (N,HIGH); digitalWrite (G,HIGH); digitalWrite (H,HIGH); digitalWrite (I,HIGH); digitalWrite (J,HIGH); digitalWrite (K,LOW); digitalWrite (L,HIGH); digitalWrite (M,HIGH); digitalWrite (N,HIGH); } }

And that works !

Discussions