Potentiometer and 7 Segment

Hi first time here and barely have basic knowledge on using arduino.

I have this Sequence If i turn on the Switch (1A) the 7 segment will project the number "0". Then if i turn on the Switch (3A) which is the Potentiometer connected to the Analog pin (A1). The potentiometer then will function and will control the brightness of the 7 segment. The first sequence is done.
I've been researching in the net on how to control it but did not accomplish anything. It Will be really helpful if anyone of you will give me tips and insight on figuring this out.

You will want to use one of your digital pins as a ground pin by making it an output and setting it low. Preferably one that can be controlled by PWM (Pulse Width Modulation). You will then use the pot to change the duty cycle of that pin thus changing the brightness of your 7 segment display.

  1. Look up Pulse Width Modulation and how to use it.
  2. Look up how to read the value of a potentiometer.
  3. Map the range of the pot (usually 0 - 1023) to 0 - 255 or just divide the pot value by 4... bit shifting work too.
  4. Use the mapped value to control the PWM signal of that "ground" pin

Please note I am not very active on this site anymore these days... sorry in advance.

Can you draw a schematic showing how the various parts are connected? And provide more information about your 7-segment display? How much current does each segment draw? Is it Common Anode or Common Cathode?


Im using a software tinkercad for this, as i dont have any arduino at the moment. I dont know how much current it draw, and it is Common Anode

Will try this, Thank you

Being that this is a simulation, you might not see the 7 segment brightness change with the potentiometer.

No, it certainly worked. Someone helped me and give me a code for this sequence but its way too advanced for me to work at it.

So is everything working now?

No, The code he gave me is way to advanced for me. I got more sequence to add on this circuit. I still have the LDR that if a light come near its sensor the value or the number on the 7 segment will rise up. And im still stuck here.

So is the final goal to measure the amount of light with the LDR and display the brightness level on the 7seg display? With 0 being dark and 9 being full brightness?

Here are the sequence
The first Switch (1A) is connected to the 7 segment, if turned on the 7 segment will display 0. If turned off the 7 segment will not display.
The LDR is connected to the Analog pin (A0) and also connected to Switch (2A) if turned on it will function and if off will not function and if light come near its sensor the value on the 7 segment should also rise up.
The Pontentiometer is Connected to the Analog pin (A1), and also connected to Switch (3A) if the switch is turned on the Potentiometer will function and if turn right or left will control the brightness of the 7 segment Display.

Ok. Have you had a chance to try my solution yet?

Im currently working on it, racking my brains here hahaha.

Hello!
I've done what you told me to do i use the PWM. It only works on 1 specific segment of the 7 segment display which is the G segment. What do you think should i add on my code? I think its because of the Switch 1 Value "0".

multiple
lines

int a = 4;
int b = 5;
int c = 6;
int d = 7;
int e = 8;
int f = 3;
int g = 2;
int potValue = A1;
int segmentPins[] = {a, b, c, d, e, f, g};

void setup() {
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(A1,INPUT);
Serial.begin(9600);
for (int i = 0; i < 7; i++) {
pinMode(segmentPins[i], OUTPUT);
}
pinMode(potValue, INPUT);
}

void loop(){

int s1 = digitalRead(s1);
int s3 = digitalRead(s3);
if (s1 == HIGH){
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}
int potValue = analogRead(potValue);
int brightness = map(potValue, 0, 1023, 0, 255);

for (int i = 0; i < 7; i++) {
analogWrite(segmentPins[i], brightness);
}
}

Hi,
Welcome to the forum.

To add code please click this link;

Check what pins you can use as PWM. Not all are PWM.

Your pinMode needs to be in a for loop like your brightness for loop to assign OUTPUT status to those pins.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Which pin on the display is going to ground? You need to change the wiring and move the displays ground to one of the Arduino’s other pins.

Use pin 10 on the Arduino to be the displays new ground pin. Set it as an output and Low by default.

Then you can control it using the analogWrite function on that pin alone and the brightness value.

Not all the segment pins, just pin 10.

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Your "circuit" in post #4 assumes we know the pinout of the display.

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

Its working now, it took me an hour to get what you are talking about.

Great! Have you hooked up the LDR yet?

Im currently browsing on the net, youtube. Any idea how can i do it >_<.