Go Down

Topic: TEMPERATURE DISPLAY ONLY USING 7 SEGMENT DISPLAY AND LM35 (Read 91 times) previous topic - next topic

Shiven_Sharma

May 23, 2018, 07:38 am Last Edit: May 23, 2018, 07:53 am by Shiven_Sharma
hello

Recently i made a project which showed the temperature on a 4 digit 7 segment display but a problem showed up. Before i describe i want to tell you all that i did not use shift register and won't.
the first two digits of the temperature doesnt comes on the display instead the first two digits remain dimly lighted up, if looked closely it seems to show the temperature and i dont understand what could be the problem. i have used switch casein my problem so it actually got upto ....600.... lines of coding.

If anybody understands what the problem is plz tell me i will leave the code below.

i guess it fused




Shiven_Sharma

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int D1 = 9;
int D2 = 10;
int D3 = 11;
int D4 = 12;

float tempe;
float tempe1;
int led = 8;
int buzzer = 9;

void setup() {
pinMode(pinA, OUTPUT);    
pinMode(pinB, OUTPUT);    
pinMode(pinC, OUTPUT);    
pinMode(pinD, OUTPUT);    
pinMode(pinE, OUTPUT);    
pinMode(pinF, OUTPUT);    
pinMode(pinG, OUTPUT);  
pinMode(D1, OUTPUT);  
pinMode(D2, OUTPUT);  
pinMode(D3, OUTPUT);  
pinMode(D4, OUTPUT);
Serial.begin(9600);
}

void loop() {
tempe = analogRead(A0);
tempe = ( tempe/1024.0)*5000;
tempe = tempe/10;
tempe1=tempe;
Serial.println("temperature :");
Serial.println(tempe);
int a = tempe1 * 100;
float b = tempe1 / 1000;
int c = b* 100 ;//for 1st
float d = tempe1/100;
int e = d*100;
int f = e%10;//for 2nd
float g = tempe1/10;
int h = g*100;
int i = h%10;//for 3rd
int j = a%10;//for 4th
Serial.println(a);
Serial.println(b);
Serial.println(c);
Serial.println(f);
Serial.println(i);
Serial.println(j);
switch (c){
 case 1:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, HIGH);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, HIGH);  
 digitalWrite(pinE, HIGH);  
 digitalWrite(pinF, HIGH);  
 digitalWrite(pinG, HIGH);
 break;
 case 2:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, LOW);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, HIGH);  
 digitalWrite(pinD, LOW);  
 digitalWrite(pinE, LOW);  
 digitalWrite(pinF, HIGH);  
 digitalWrite(pinG, LOW);
 break;
 case 3:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, LOW);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, LOW);  
 digitalWrite(pinE, HIGH);  
 digitalWrite(pinF, HIGH);  
 digitalWrite(pinG, LOW);
 break;
 case 4:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, HIGH);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, HIGH);  
 digitalWrite(pinE, HIGH);  
 digitalWrite(pinF, LOW);  
 digitalWrite(pinG, LOW);
 break;
 case 5:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, LOW);  
 digitalWrite(pinB, HIGH);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, LOW);  
 digitalWrite(pinE, HIGH);  
 digitalWrite(pinF, LOW);  
 digitalWrite(pinG, LOW);
 break;
 case 6:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, HIGH);  
 digitalWrite(pinB, HIGH);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, LOW);  
 digitalWrite(pinE, LOW);  
 digitalWrite(pinF, LOW);  
 digitalWrite(pinG, LOW);
 break;
 case 7:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, LOW);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, HIGH);  
 digitalWrite(pinE, HIGH);  
 digitalWrite(pinF, HIGH);  
 digitalWrite(pinG, HIGH);
 break;
 case 8:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, LOW);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, LOW);  
 digitalWrite(pinE, LOW);  
 digitalWrite(pinF, LOW);  
 digitalWrite(pinG, LOW);
 break;
 case 9:
 digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

 digitalWrite(pinA, LOW);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, HIGH);  
 digitalWrite(pinE, HIGH);  
 digitalWrite(pinF, LOW);  
 digitalWrite(pinG, LOW);
 break;
}



Shiven_Sharma

  switch (f){
   case 1:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, HIGH);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, HIGH);
   break;
   case 2:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, HIGH);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, LOW);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, LOW);
   break;
   case 3:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, LOW);
   break;
   case 4:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, HIGH);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 5:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, HIGH);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 6:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, HIGH);  
   digitalWrite(pinB, HIGH);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, LOW);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 7:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, HIGH);
   break;
   case 8:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, LOW);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 9:
   digitalWrite(D1, LOW);
   digitalWrite(D2, HIGH);
   digitalWrite(D3, LOW);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
 }
 
 
 switch (i){
   case 1:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, HIGH);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, HIGH);
   break;
   case 2:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, HIGH);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, LOW);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, LOW);
   break;
   case 3:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, LOW);
   break;
   case 4:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, HIGH);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 5:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, HIGH);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 6:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, HIGH);  
   digitalWrite(pinB, HIGH);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, LOW);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 7:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, HIGH);  
   digitalWrite(pinG, HIGH);
   break;
   case 8:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, LOW);  
   digitalWrite(pinE, LOW);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
   case 9:
   digitalWrite(D1, LOW);
   digitalWrite(D2, LOW);
   digitalWrite(D3, HIGH);
   digitalWrite(D4, LOW);

   digitalWrite(pinA, LOW);  
   digitalWrite(pinB, LOW);  
   digitalWrite(pinC, LOW);  
   digitalWrite(pinD, HIGH);  
   digitalWrite(pinE, HIGH);  
   digitalWrite(pinF, LOW);  
   digitalWrite(pinG, LOW);
   break;
 }
 

Rintin

 * Use the code-tag
* I don't see that you have code for the zero
* You repeat the same code over and over again. Maybe you want to move some to functions and/or use lookup tables
 *
Code: [Select]

digitalWrite(D1, HIGH);
 digitalWrite(D2, LOW);
 digitalWrite(D3, LOW);
 digitalWrite(D4, LOW);

// At this point you have activated the new digit, but the segments are the old values.
// This will cause ghosting.

 digitalWrite(pinA, HIGH);  
 digitalWrite(pinB, LOW);  
 digitalWrite(pinC, LOW);  
 digitalWrite(pinD, HIGH);  
 digitalWrite(pinE, HIGH);  
 digitalWrite(pinF, HIGH);  
 digitalWrite(pinG, HIGH);
 break;


You need something like this:
Code: [Select]

allDigitsOff();
setSegments();
activateDigit();

Go Up