2 digit 7 Segment Display HELP

Hi to all, I am new at arduino coding. I been using it since a week a ago. And im really trying hard to learn this cool device. So i decided to start my first simple project. It is a Temperature controlled project and im having trouble displaying the current reading temperature on 7 segment, i have read alot of instructables about this and i really cant use it properly. This is my code without the 7 segment display. help me out in understanding on how to use 2 digit 7 segment display on arduino. THANKS in advance.

#define dly (500)
#define tempPin (0)
#define temp20 (1)
#define temp22 (2)
#define temp24 (3)
#define temp26 (4)
#define temp28 (5)
#define fanPin (12)

int celcius = 0;
int temp1 =0;
int temp2 =0;
int temp3 =0;
int temp4 =0;
int temp5 =0;
int setPoint = 0;


void setup() 
{
  Serial.begin(9600);
  pinMode(fanPin, OUTPUT);   
}

void loop() 
{
  temp1 = analogRead(temp20);
  temp2 = analogRead(temp22);
  temp3 = analogRead(temp24);
  temp4 = analogRead(temp26);
  temp5 = analogRead(temp28);
  
  if (temp1 == 0)
  {
    setPoint = 20;
  }
  else if (temp2 == 0)
  {
    setPoint = 22;
  }
  else if (temp3 == 0)
  {
    setPoint = 24;
  }
  else if (temp4 == 0)
  {
    setPoint = 26;
  }
  else if (temp5 == 0)
  {
    setPoint = 28;
  }
  
  celcius = analogRead(tempPin);
  celcius = ((5.0* celcius * 100.0)/1024.0);
  if(celcius>=setPoint)
  {
    digitalWrite (fanPin, HIGH);
  }
  else
  {
    digitalWrite (fanPin, LOW);
  }
}

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom.... :slight_smile:

Also, please read Nick Gammon's two posts at the top of this Forum, especially on the use of code tags when posting source code here.

TomGeorge:
Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Can you please post a copy of your sketch, using code tags?
Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom.... :slight_smile:

Hi, this is my circuit, i still dont have a 7 segment display in this circuit. Sorry for violating some rules. Thank you. The LED at pin 12 represents the 12V fan.

Here's one way, using 2 shift registers and 2 separate displays.
Code is simple, just use SPI.transfer (or shiftout) to send out 2 bytes.
No multiplexing needed in the code.

CrossRoads:
Here's one way, using 2 shift registers and 2 separate displays.
Code is simple, just use SPI.transfer (or shiftout) to send out 2 bytes.
No multiplexing needed in the code.

Shall i connect the registers like this on my arduino? thank you

Well, due to the lousy nature of fritzing not putting any IO pin names in symbols, I can only guess that it's correct if you followed my schematic. It is nicely drawn.
Don't forget 0.1uF caps on the power supply pins.
You used 8,9,10 instead of 10, 11, 13, so you'll need to use shiftout() instead of SPI.transfer() as I noted in my schematic.
Your call, it's just slower to update.

Hi,
I notice you are using analogRead to check the switch position.
The inputs being either LOW or HIGH, you risk the fact that the contact resistance of the switch will not always be zero.
A little contact resistance will see an analog value >0.

If all you want is the switch to select your set temperature, then assign the A1 to A5 as INPUT and digitalRead the pins.

This will allow for some contact resistance to occur and the voltage at the inputs to rise a little and you will still have a digital LOW in.

Your if statements will have to be changed to temp1 == LOW.

Tom... :slight_smile: