Urgent: Problem in 4 digit 7-segment display

Hello I posting this here because I am absolutely stuck trying to use the 4 digit 7-segment display. I am trying to display the readings of LM35D temperature sensor on the 4561AS 7-seg.
I have referred to this website: https://www.circuitbasics.com/arduino-7-segment-display-tutorial/ .
I made the exact circuit given there. My code is -

#include "SevSeg.h"
SevSeg sevseg;

int val;

void setup() {
  byte numDigits = 4;
  byte digitPins[] = {10, 11, 12, 13};
  byte segmentPins[] = {9, 2, 3, 5, 6, 8, 7, 4};
  bool resistorsOnSegments = true;
  bool updateWithDelaysIn = true;
  byte hardwareConfig = COMMON_CATHODE;
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(100);
}

void loop() {
  val = analogRead(A0);
  float mv = (val/1024.0)*5*1000;
  float cel = mv/10;
  
  static unsigned long timer = millis();
  if (millis() >= timer) {
    timer += 300;
    sevseg.setNumber(cel,2);
  }
  sevseg.refreshDisplay();
}

The problem I am facing is that the 7-seg is not giving me all digits of "cel". I will attach image of my setup and the display. I can assure that the sensor is working right and gives stable readings of around 30.72*C (checked with serial monitor). Please tell me what my issue is, is it code related or circuit?

sevseg.setNumber(cel,2);

Since I am a new user, I cant provide more photos. But, this is what comes on the display when other instructions are given:

for sevseg.setNumber(cel,3);

0.030

for sevseg.setNumber(cel);

30

for sevseg.setNumber(mv);

307

for sevseg.setNumber(val);

63

Try

float cel = mv*10;

Hard to tell form that picture. Try to display some hard-coded, dummy values. Does the display behave like you expect it to? Try to print your variables to serial monitor. Are they alright there? This will isolate the source of the issue.

Well sorry but that is a very very crap circuit. It only has a resistor in the common connection of the display. This results in what you can see in the photo, the brightness of the display depends on how many segments are on.

You should have a resistor in each one of the other lines, that is not the common one. So you need seven resistors not four.

Why is it that every idiot that get things to “work” think it is a design good enough to teach someone?

no the display shows just 30 instead of 30.72 which I get in the serial monitor. All the variables work correctly in the serial monitor. @PaulRB has solved the issue though. Thanks anyway!

Thanks a lot! This work and I think I understand why. Thanks again for the quick response.

Actually, Mike, I seem to remember from another thread that the sevenSeg library will multiplex by segment, if configured correctly, so it would be ok to have the resistors on the digit common pins. Unfortunately...

sevseg.begin(..., resistorsOnSegments);

in this case it isn't configured correctly !

My suggestion worked because the function you used expects an integer. Another way to correct it would be like this:

float cel = mv/10;
...
sevseg.setNumberF(cel, 2);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.