Components and supplies
DMM Shield: 7-Function Digital Multimeter Shield
Jumper wires (generic)
Arduino UNO
7 Segment LED Display, InfoVue
Project description
Code
Code
arduino
1/* 2 3/** This code is edited by www.SetNfix.com **/ 4 5 6int Ntime = 0; 7int Otime = 0; 8float X = 0; 9int time = 4; 10 11int pinA = 2; 12int pinB = 3; 13int pinC = 4; 14int pinD = 5; 15int pinE = 6; 16int pinF = 7; 17int pinG = 8; 18int pinDP = 1; 19 20int DIG1 = 12; 21int DIG2 = 11; 22int DIG3 = 10; 23int DIG4 = 9; 24 25void choose_digit(char num) { 26 switch (num) { 27 default: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, HIGH); digitalWrite(pinDP, HIGH); break; case 1: digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); digitalWrite(pinDP, HIGH); break; case 2: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, HIGH); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 3: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 4: digitalWrite(pinA, HIGH); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 5: digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 6: digitalWrite(pinA, LOW); digitalWrite(pinB, HIGH); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 7: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, HIGH); digitalWrite(pinE, HIGH); digitalWrite(pinF, HIGH); digitalWrite(pinG, HIGH); digitalWrite(pinDP, HIGH); break; case 8: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, LOW); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; case 9: digitalWrite(pinA, LOW); digitalWrite(pinB, LOW); digitalWrite(pinC, LOW); digitalWrite(pinD, LOW); digitalWrite(pinE, HIGH); digitalWrite(pinF, LOW); digitalWrite(pinG, LOW); digitalWrite(pinDP, HIGH); break; 28 29 ; 30 } 31} 32 33void pick_digit(int digit) { 34 digitalWrite(DIG1, LOW); 35 digitalWrite(DIG2, LOW); 36 digitalWrite(DIG3, LOW); 37 digitalWrite(DIG4, LOW); switch (digit) { 38 case 1: digitalWrite(DIG1, HIGH); break; case 2: digitalWrite(DIG2, HIGH); break; case 3: digitalWrite(DIG3, HIGH); break; default: digitalWrite(DIG4, HIGH); break; 39 } 40 41} 42 43void decimal_place() { 44 digitalWrite(pinDP, LOW); 45} 46 47void seven_segment(int number) { 48 unsigned char thousands = int (number / 1000); 49 unsigned char hundreds = int ((number / 100) % 10); 50 unsigned char tens = int ((number / 10) % 10); 51 unsigned char ones = int (number % 10); //1234 52 if (thousands > 0) { 53 choose_digit(thousands); 54 pick_digit(1); 55 } 56 57 if ((hundreds > 0) | (thousands > 0)) { 58 delay(time); choose_digit(hundreds); 59 pick_digit(2); 60 } 61 62 if ((tens > 0) || (hundreds > 0) | (thousands > 0)) { 63 //decimal_place(); 64 delay(time); choose_digit(tens); 65 pick_digit(3); 66 } 67 68 69 // add decimal point 70 delay(time); choose_digit(ones); 71 pick_digit(4); 72 73 delay(time); 74 75} 76 77void setup() { 78 pinMode(DIG1, OUTPUT); 79 pinMode(DIG2, OUTPUT); 80 pinMode(DIG3, OUTPUT); 81 pinMode(DIG4, OUTPUT); 82 pinMode(pinA, OUTPUT); 83 pinMode(pinB, OUTPUT); 84 pinMode(pinC, OUTPUT); 85 pinMode(pinD, OUTPUT); 86 pinMode(pinE, OUTPUT); 87 pinMode(pinF, OUTPUT); 88 pinMode(pinG, OUTPUT); 89 pinMode(pinDP, OUTPUT); 90 91} 92 93void loop() { 94float sensor_value = map(analogRead(A0),0,1023,0,3000); // for Flood level Sensor this Eg:3000 is the maximum level 95 96 97 98 99// Continue counter and Visitors counter 100/** 101 Ntime = millis(); 102 if (analogRead(A0) > 0) { 103 104 if ((Ntime - Otime) > 200) { 105 X = X + 1; 106 Otime = Ntime; // Active this to visitors counter 107 { 108 if (X == 9999) { 109 X = 0; 110 } 111 } 112 } 113 //Otime = Ntime; // Active this to continue counter 114 115 } 116 117 float sensor_value = X; */ 118 119 120 121 122 seven_segment(sensor_value); 123 124}
Downloadable files
Circuit Diagram
Circuit Diagram
Circuit Diagram
Circuit Diagram
Comments
Only logged in users can leave comments
SetNFix
0 Followers
•14 Projects
4
1
OmarLuis
3 years ago
I tried the people counter (for fruits), the display works quite good, making the right sequencing and staying bright as expected, there is an issue about the interval ON of A0, if it is kept ON more than one second it count twice (in fact it becomes a continuous counter if held ON), I am trying to add a second counter on A1 and displaytng the sum but it didnot work yet and the decades does not stays bright but blink once in a time, any suggestion will be apreciated.