Go Down

Topic: Common Cathode 7-Segment Display and Temp. Sensor  (Read 183 times) previous topic - next topic

mubuca

Hi everyone.

 I'm a rookie in PIC world.After i've learnt about the circuit construction of 7 segment displays and Temp. Sensors(5v as far as i know).I wanted the connect them to each other and build a little Tool ,which shows me the the Temperature.But i failed.

I would've upload the circuit drawings but unfortunately eventually  i've no software for that in my computer.

 I have a right built 7 seg-cathode Display on my breadboard(It works perfect without Temp-Sensor).Along with Display i connected the wires from Temp.-Sensor (midde goes to analog 0 and the other to 5V and GND).

 When i let the circuit run display shows the numbers randomly,not the ones i get from sensors and send to function.

also here is my code (to understand if the sensor works well, i've added serial Monitor codes).

Thanks a lot for your interest.Sorry for my English i hope that it is clear.   


Code: [Select]
int a=2,b=3,c=4,d=5,e=6,f=7,g=8,dp=9;
int sensorPin=0;

void setup() {           
 
  Serial.begin(9600);   
  pinMode(a, OUTPUT); 
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(dp, OUTPUT);
  digitalWrite(dp, 0);  // start with the "dot" off
}

void loop(){
int a,b;
int reading = analogRead(sensorPin);
float voltage=reading*(5000/1024); //voltage in Milivolts
int centigrade=(voltage)/10;
Serial.print(voltage);Serial.println("miliVolts");
Serial.print(centigrade); Serial.println("Centigrade\n");
b=centigrade%10;
a=(centigrade%100)/10;
Serial.print(a);Serial.print("\n");
show(a);
delay(1000);
show(b);
Serial.print(b);Serial.print("\n");
delay(1000);
show(10);
delay(1000);


}

void show(int i) {
  switch(i){
   
  case 9:
 // write '9'
 digitalWrite(a, 1);
 digitalWrite(b, 1);
 digitalWrite(c, 1);
 digitalWrite(d, 0);
 digitalWrite(e, 0);
 digitalWrite(f, 1);
 digitalWrite(g, 1);
 break;
 case 8:
 // write '8'
 digitalWrite(a, 1);
 digitalWrite(b, 1);
 digitalWrite(c, 1);
 digitalWrite(d, 1);
 digitalWrite(e, 1);
 digitalWrite(f, 1);
 digitalWrite(g, 1);
 break;
case 7:
 // write '7'
 digitalWrite(a, 1);
 digitalWrite(b, 1);
 digitalWrite(c, 1);
 digitalWrite(d, 0);
 digitalWrite(e, 0);
 digitalWrite(f, 0);
 digitalWrite(g, 0);
 break;
 case 6:
 // write '6'
 digitalWrite(a, 1);
 digitalWrite(b, 0);
 digitalWrite(c, 1);
 digitalWrite(d, 1);
 digitalWrite(e, 1);
 digitalWrite(f, 1);
 digitalWrite(g, 1);
 break;
case 5:
 // write '5'
 digitalWrite(a, 1);
 digitalWrite(b, 0);
 digitalWrite(c, 1);
 digitalWrite(d, 1);
 digitalWrite(e, 0);
 digitalWrite(f, 1);
 digitalWrite(g, 1);
 break;
case 4:
 // write '4'
 digitalWrite(a, 0);
 digitalWrite(b, 1);
 digitalWrite(c, 1);
 digitalWrite(d, 0);
 digitalWrite(e, 0);
 digitalWrite(f, 1);
 digitalWrite(g, 1);
 break;
 case 3:
 // write '3'
 digitalWrite(a, 1);
 digitalWrite(b, 1);
 digitalWrite(c, 1);
 digitalWrite(d, 1);
 digitalWrite(e, 0);
 digitalWrite(f, 0);
 digitalWrite(g, 1);
 break;
case 2:
 // write '2'
 digitalWrite(a, 1);
 digitalWrite(b, 1);
 digitalWrite(c, 0);
 digitalWrite(d, 1);
 digitalWrite(e, 1);
 digitalWrite(f, 0);
 digitalWrite(g, 1);
 break;
case 1:
 // write '1'
 digitalWrite(a, 0);
 digitalWrite(b, 1);
 digitalWrite(c, 1);
 digitalWrite(d, 0);
 digitalWrite(e, 0);
 digitalWrite(f, 0);
 digitalWrite(g, 0);
 break;
 case 0:
 // write '0'
 digitalWrite(a, 1);
 digitalWrite(b, 1);
 digitalWrite(c, 1);
 digitalWrite(d, 1);
 digitalWrite(e, 1);
 digitalWrite(f, 1);
 digitalWrite(g, 0);
 break;
 case 10:
 //write dot
  digitalWrite(dp, 1);
  break;
 
  }
}
 

 

mubuca

Problem solved, there was a mistake in the code .I

Go Up