Temperature sensor with multiple 74HC4511's and 7 segments.

Hi, I'm in the progress of making a celsius temperature sensor, with the temperature shown on the two 7-segments, the temperature sensor is a LM35, but the temperature part is not what I am going to ask about. I am totally new to arduino, so sorry for "silly" questions!

I want to make the first 7-segment write the first digit in the temperature, and the second one write the second digit in the temperature. But I can not figure out how to e.g make the first 7-segment write "2" when the temperature is 20-29, and "30" if the temperature is in the 30's.

74HC4511 datasheet: http://www.sparkfun.com/datasheets/IC/74HC4511.pdf

But I can not figure out how to e.g make the first 7-segment write "2" when the temperature is 20-29, and "30" if the temperature is in the 30's.

What code do you have to display [u]anything[/u] on the displays?

I left my USB in class, when playing with this arduino, so I can't give you the code right now.

but when I want to write a number like 00, or whatever.

I just use something simply like

digitalWrite(Bin1, B0);
digitalWrite(Bin2, B0);
digitalWrite(Bin3, B0);
digitalWrite(Bin4, B0);

digitalWrite(Bin5, B0);
digltalWrite(Bin6, B0);
digitalWrite(Bin7, B0);
digitalWrite(Bin8, B0);

The first four is the first segment, the next four is the second segment. What I cannot figure out how to do is make e.g the first segment write "2" if the temperature is measured 20-29.

Get the value you want and divide it by 10. That is the first digit. Then again divide by 10 but get the remainder (the % operator) and that is your second digit.

I've tried what you said, but with no luck yet. Could you possible give me an example?

Thanks in advance.

Luck does not enter into it. What you do on this forum is do what you are requested and if it dosn't work like you hoped post the code you have say what it does and what you want it to do and we go from there.

In this case it sounds like you haven't got a routine that you pass a number to and it lights up a specific pattern. You need that bit first.

That's the problem, I have coded the part with getting the temperature to the computer, and it will be shown in serial monitor. But I am having trouble making it show on the 7-segments, without having to make a "if" for every number from -9 to 99 celsius.

I have tried to divide the temperature with 10, and make it show the first digit on the first 7-segment, but It just seems that I can't make it work right. The problem would be that I have no "code" for the 7-segments to show the temperature, as I mentioned before I can make it say whatever number I want, with simply digitalWrite, but I need help getting started on how I might get the value to 7-segment part right.

I'm sorry for sounding so demanding, and for the errors in my english. It's not my first language, but I try my best.

EDIT: But what I have for the temperature part,

const int Bin1 = 12; 
const int Bin2 = 8; 
const int Bin3 = 9;
const int Bin4 = 11;
const int Bin5 = 7;
const int Bin6 = 3;
const int Bin7 = 4;
const int Bin8 = 6;
int Sensorben = 0;
float tempc;
int i;

void setup()
{
  Serial.begin(9600);
  pinMode(Bin1, OUTPUT);
  pinMode(Bin2, OUTPUT);
  pinMode(Bin3, OUTPUT);
  pinMode(Bin4, OUTPUT);
  pinMode(Bin5, OUTPUT);
  pinMode(Bin6, OUTPUT);
  pinMode(Bin7, OUTPUT);
  pinMode(Bin8, OUTPUT);
  pinMode(Sensorben, INPUT);
}

void loop()
{

  tempc = analogRead(Sensorben);
  tempc = (5.0 * tempc * 100.0)/1024.0;
  Serial.print(tempc, 0);
  Serial.println(" Grader celsius ");
  
  tempc = 0;
  
  delay(500);
  }

OK so what you need to tell is how you have the 4511 connected. Use a bit more descriptive names than just Bin0 ... that tells nothing. Once it is clear how it is wired up then we can begin to help you write the code for it.

Grumpy_Mike: OK so what you need to tell is how you have the 4511 connected. Use a bit more descriptive names than just Bin0 ... that tells nothing. Once it is clear how it is wired up then we can begin to help you write the code for it.

I'm not in class at the moment, but I will try to explain the "setup", the best I can.

Alright so the two 4511's are connected seperately at the moment. (Should I connect these two together, and only run the Latch enable seperately?) - "Bin" in my code represents Binær / Binary. Bin1-4 is connected to D1-4 on one 4511, and Bin5-8 is connected to D1-4 on the second 4511, and then ofcourse It's connected to ground, and power, and then one 7-segment is connected to each of these.

I'm not sure if this is good enough described at all, but thanks in advance!

  • Saur

(Should I connect these two together, and only run the Latch enable seperately?)

Yes that would be much better.

So define an array specifying the the four pins you have connected to D1 to D4. Like pins[] = { 12, 8, 9, 11}; or what ever pins you use.
Then create a function to write a number passed to it. Like:-

void display( int val){
}

Inside that function you want to put a loop that will output the number one bit at a time to the appropriate pin. To do this you need to use bit math so look up the tutorial about it so you understand it.
A number called mask will have just one bit set, when you AND it with the number you want to display the result will be zero if there is a zero in the bit of your value that corresponds to the bit in mask. Each time round the loop you shift the bit in mask to cover the next significant digit.
Something like this:-

int mask = 1;
for(int i = 0; i<4; i++) {
if( (mask & val) == 0 ) digitalWrite(pins[i], LOW); else digitalWrite(pins[i], HIGH); 
mask = mask << 1;
}

Then finish it off by pulsing the latch pin.
Try that and get as much as you can going and try and understand what is going on.

Thank you a ton mate!

Should help me get a good push in the right direction!

I'll update on this later.

  • Saur