Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Seven Segment last digit

Status
Not open for further replies.

dayanpad

New Member
Dear All I written a program with Arduino analog read and send the result to seven segment display . Everything is working and only issue is last digit value is varying even analog input doesn't change

please advice
Thanks in advance
 
Last edited:
How do you expect us to help if you don't give us ANY information about your project? Where is the schematic? Where is the code? How do you have everything hooked up?
 
The ADC value may be fluctuating a few counts even with a steady input signal.
 
Evert hing is working and only issue is last digit value is varying even analog input doesn't change.
The analog signal has noise on it. So, it is changing small amounts all the time. Even if you do not touch it, it is still changing.

Try averaging. Add up four analog readings and then divide the sum by four.
 
How do you expect us to help if you don't give us ANY information about your project? Where is the schematic? Where is the code? How do you have everything hooked up?
Dear Der
Thanks for reply please check the attached code

int sevenSegment[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void setup() {
DDRD = 0XFF;
pinMode(10,OUTPUT); // Controlled Seven Segment 1 Common Cathode
pinMode(11,OUTPUT); // Controlled Seven Segment 2 Common Cathode
pinMode(12,OUTPUT); // Controlled Seven Segment 3 Common Cathode

}

void loop() {
int voltage = analogRead(A0);
int temp_hundred = voltage / 100;
int rest_hundred = voltage % 100;
int hundred = sevenSegment[temp_hundred];
int temp_ten = rest_hundred / 10;
int rest_ten = rest_hundred % 10;
int ten = sevenSegment[temp_ten];
int temp_one = rest_ten / 1;
int one = sevenSegment[temp_one];

PORTD = one;
digitalWrite(10,LOW);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
delay(5);
PORTD = ten;
digitalWrite(10,HIGH);
digitalWrite(11,LOW);
digitalWrite(12,HIGH);
delay(5);
PORTD = hundred;
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,LOW);
delay(5);


}
 
The analog signal has noise on it. So, it is changing small amounts all the time. Even if you do not touch it, it is still changing.

Try averaging. Add up four analog readings and then divide the sum by four.
Dear mister
Thanks for advice and i will check this method and update
 
If speed isnt an issue use a for loop to fill up an array, say 100 samples, then use another for loop to add them up, then divide by 100, theres your average, there are more elegant ways, but that gets the job done.
You'll need to use a long variable to add them up into to avoid rolling.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top