Interfacing AHT10 with 7 segment display

I want to print AHT10 humidity sensor data on a 2 digit 7 segment common anode display. i have made a code for that but when i used it on protious simulation it did not work.. could anyone solve my problem?

#include <SevenSegmentDisplay.h>




//============================================================================
// Name        : TempControl.ino
// Author      : Romualdo Dasig
// Version     : v0.1
// Copyright   : MIT License
// Description : Display temperature to a Seven Segment LED Display
//============================================================================

// Libraries
#include <AHT10.h>

AHT10 myAHT10(0x38);

// Setup Sensor.

// Variables
float rel_hum;  // Humidity

// Variable to store current time.
unsigned long previousMillis = 0;

// Set interval to read temperature.
const long interval = 5000;

// Configure a 2-Digit 7-Segment Display.
int segments[7] = {3, 4, 7, 6, 5, 10, 8}; // Display segments (a,b,c,d,e,f,g)
int displays[2] = {12, 11}; // Display digits (00 - 99)
int type = COMMON_ANODE; // Type

SevenSegmentDisplay sevenSegmentDisplay(
  segments[0],
  segments[1],
  segments[2],
  segments[3],
  segments[4],
  segments[5],
  segments[6],
  displays[0],
  displays[1],
  type
);

void setup()
{
  Serial.begin(9600);
  
  sevenSegmentDisplay.begin();
}

void loop()
{
    float temp = myAHT10.readTemperature();
    float rel_hum = myAHT10.readHumidity();
  // Get current time in milliseconds.
  unsigned long currentMillis = millis();

  // Read temperature every 2 seconds.
  if (currentMillis - previousMillis >= interval) {
    // Save the last time we've read the temperature.
    previousMillis = currentMillis;

    // Read data and store it to variables hum and temp.
        rel_hum = myAHT10.readHumidity();
    //temp= dht.readTemperature();
  }

  // Display temperature.
  sevenSegmentDisplay.display(rel_hum);
}

i would develop code and understanding for each device: display and sensor, separately before combining.

verify the sensor by report values on the serial interface

develop code for the 7-seg display and test it using the serial interface. you might be able to use 7-seg display code from the Multi-function shield

one both work, combine and continue to use the serial interface for debugging

I do not want to spend the time going through your code to determine what the hardware is.Post a Schematic of how you have your project wired, not a frizzy picture. Also post links to "Technical Information" on each of the hardware devices. Note: Links to azon and other sales outlets are basically useless.

What did it do?

It shows 5 on display and nothing change on display...

Can you export your schematic from Proteus and post it here? Do the seven segment library examples work in Proteus?

Also please provide a link to the Seven Segment library you are using. Unfortunately, there are dozens of them with the same name.

proteus schematic file
schematic.PDF (21.2 KB)

seven segment library
SevenSegmentDisplay.cpp (2.0 KB)
SevenSegmentDisplay.h (1.3 KB)

Have you tried a simple test sketch that only tests the display, like count from 00-99?

Have you tried running it on a different simulator, like Wokwi, or else on prototype board?

You posted attachments instead of links. For the library, it forces us to download it which is inconvenient for many readers. Also, it deprives us of any context or documentation for the library. Does the library have any example sketches you can try?

The display working prperly when i use display testing code... apart from this do u have any code that print a sensor data on 7 segment diaplay . My aht10 humidity sensor intreface with atduino scl and sda ...

Please post the test code that works. Generally, you should provide more information than you are asked for, and you should answer all reasonable questions that are asked of you.

Otherwise this might turn into a 100 post thread with no results for you.

Sure, I have display code for about 20 different 7 segment display types. But if you already have code that works, why would you need it?

Your search for a sensor specific code is probably futile, it depends on someone having used exactly the same hardware that you have, not very likely. But you can put it together from sketches that only perform single functions. Most Arduino users have done that.

I have made a code for 7 segment display interfacing with AHT10 but not get stable data could u help me?

#include <Adafruit_AHTX0.h>   // Library for AHT10
Adafruit_AHTX0 AHT10;
float AHT10_Humidity;   
int a = 3;
int b = 4;
int c = 7;
int d = 6;
int e = 5;
int f = 10;
int g = 8;
int GND1 = 12;
int GND2 = 11;
int GND3 = 13;
int GND4 = 9;
int dig1 = 0;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int Humi;

// Variable to store current time.
unsigned long previousMillis = 0;

// Set interval to read temperature.
const long interval = 5000;


void setup()
{
  Serial.begin(9600);  // Use a 9600 Baud Rate - basically a speed of communication

 
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(GND1, OUTPUT);
  pinMode(GND2, OUTPUT);
  pinMode(GND3, OUTPUT);
  pinMode(GND4, OUTPUT);

if (! AHT10.begin()) {
    //Removed this info print statement so as not to interfere with the plotting and labels
    //You can uncomment it
    //Serial.println("Could not find the AHT10 sensor. Please check wiring");
    
    while (1) delay(10);
  } else {
    //Removed this info print statement so as not to interfere with the plotting and labels
    //You can uncomment it
    //Serial.println("The AHT10 sensor was found & is ready");
  }
}

void loop()
{
  Get_AHT10_Data();

 Humi = (AHT10_Humidity);

    dig1 = Humi / 10;
    dig2 = Humi - (dig1 * 10);
    dig3 =  12;
    dig4 = 12;

// Get current time in milliseconds.
  unsigned long currentMillis = millis();

  // Read temperature every 2 seconds.
  if (currentMillis - previousMillis >= interval) {
    // Save the last time we've read the temperature.
    previousMillis = currentMillis;
    
        digitalWrite( GND4, HIGH);    //digit 4
        DisplayNumber(dig4);
        delay(4);
        digitalWrite( GND4, LOW);

        digitalWrite( GND3, HIGH);    //digit 3
        DisplayNumber(dig3);
        delay(4);
        digitalWrite( GND3, LOW);

        digitalWrite( GND2, HIGH);   //digit 2
        DisplayNumber(dig2);
        delay(4);
        digitalWrite( GND2, LOW);

        digitalWrite( GND1, HIGH);   //digit 1
        DisplayNumber(dig1);
        delay(4);
        digitalWrite( GND1, LOW);
  
  }
}
void DisplayNumber(int x) {
  switch (x) {
    case 0: zero(); break;
    case 1: one(); break;
    case 2: two(); break;
    case 3: three(); break;
    case 4: four(); break;
    case 5: five(); break;
    case 6: six(); break;
    case 7: seven(); break;
    case 8: eight(); break;
    case 9: nine(); break;
    case 12: oo(); break;
  }
}



void zero()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, HIGH);
}

void one()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void two()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, HIGH);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, HIGH);
  digitalWrite( g, LOW);
}

void three()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, LOW);
}

void four()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void five()
{
  digitalWrite( a, LOW);
  digitalWrite( b, HIGH);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, HIGH);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void six()
{
  digitalWrite( a, LOW);
  digitalWrite( b, HIGH);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void seven()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void eight()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void nine()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, HIGH);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}
void oo()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, HIGH);
  digitalWrite( g, LOW);
}

void Get_AHT10_Data(){
 // Communicate with the humidity and temp sensor and get data
  sensors_event_t Humidity, Temp;

  // Now get the data
  AHT10.getEvent(&Humidity, &Temp); // Get Temp and humidity data
  AHT10_Humidity =Humidity.relative_humidity;
  
}

what do you mean by "stable"?

in the above code, the delay is only 4 msec which is too short to see the digit before it changes. try 1000 msec

This doesn't look like how an Adafruit library would return values. Are you sure? Did you look at the Adafruit example sketches?

The brackets do nothing, you are just assigning the value of a variable to another one:

 Humi = AHT10_Humidity;

So my question is, where does the value of 'AHT10_Humidity' get assigned?

Did you follow the examples and documentation on this point, or did you take a guess?

using AHT10 temperature and humidity sensor I have already print it's data on a 16*2 lcd display. but now I wants to print only its humidity value on a 7 segment common anode display. that's why I have made a code but fails to do that .. can anyone help me in this project?

#include <Adafruit_AHTX0.h>   // Library for AHT10
Adafruit_AHTX0 AHT10;
float AHT10_Humidity;   
int a = 3;
int b = 4;
int c = 7;
int d = 6;
int e = 5;
int f = 10;
int g = 8;
int GND1 = 12;
int GND2 = 11;
int GND3 = 13;
int GND4 = 9;
int dig1 = 0;
int dig2 = 0;
int dig3 = 0;
int dig4 = 0;
int Humi;

// Variable to store current time.
unsigned long previousMillis = 0;

// Set interval to read temperature.
const long interval = 5000;


void setup()
{
  Serial.begin(9600);  // Use a 9600 Baud Rate - basically a speed of communication

 
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
  pinMode(GND1, OUTPUT);
  pinMode(GND2, OUTPUT);
  pinMode(GND3, OUTPUT);
  pinMode(GND4, OUTPUT);

if (! AHT10.begin()) {
    //Removed this info print statement so as not to interfere with the plotting and labels
    //You can uncomment it
    //Serial.println("Could not find the AHT10 sensor. Please check wiring");
    
    while (1) delay(10);
  } else {
    //Removed this info print statement so as not to interfere with the plotting and labels
    //You can uncomment it
    //Serial.println("The AHT10 sensor was found & is ready");
  }
}

void loop()
{
  Get_AHT10_Data();

 Humi = (AHT10_Humidity);

    dig1 = Humi / 10;
    dig2 = Humi - (dig1 * 10);
    dig3 =  12;
    dig4 = 12;

// Get current time in milliseconds.
  unsigned long currentMillis = millis();

  // Read temperature every 2 seconds.
  if (currentMillis - previousMillis >= interval) {
    // Save the last time we've read the temperature.
    previousMillis = currentMillis;
    
        digitalWrite( GND4, HIGH);    //digit 4
        DisplayNumber(dig4);
        delay(1000);
        digitalWrite( GND4, LOW);

        digitalWrite( GND3, HIGH);    //digit 3
        DisplayNumber(dig3);
        delay(1000);
        digitalWrite( GND3, LOW);

        digitalWrite( GND2, HIGH);   //digit 2
        DisplayNumber(dig2);
        delay(1000);
        digitalWrite( GND2, LOW);

        digitalWrite( GND1, HIGH);   //digit 1
        DisplayNumber(dig1);
        delay(1000);
        digitalWrite( GND1, LOW);
  
  }
}
void DisplayNumber(int x) {
  switch (x) {
    case 0: zero(); break;
    case 1: one(); break;
    case 2: two(); break;
    case 3: three(); break;
    case 4: four(); break;
    case 5: five(); break;
    case 6: six(); break;
    case 7: seven(); break;
    case 8: eight(); break;
    case 9: nine(); break;
    case 12: oo(); break;
  }
}



void zero()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, HIGH);
}

void one()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void two()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, HIGH);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, HIGH);
  digitalWrite( g, LOW);
}

void three()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, LOW);
}

void four()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void five()
{
  digitalWrite( a, LOW);
  digitalWrite( b, HIGH);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, HIGH);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void six()
{
  digitalWrite( a, LOW);
  digitalWrite( b, HIGH);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void seven()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, HIGH);
  digitalWrite( e, HIGH);
  digitalWrite( f, HIGH);
  digitalWrite( g, HIGH);
}

void eight()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}

void nine()
{
  digitalWrite( a, LOW);
  digitalWrite( b, LOW);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, HIGH);
  digitalWrite( f, LOW);
  digitalWrite( g, LOW);
}
void oo()
{
  digitalWrite( a, HIGH);
  digitalWrite( b, HIGH);
  digitalWrite( c, LOW);
  digitalWrite( d, LOW);
  digitalWrite( e, LOW);
  digitalWrite( f, HIGH);
  digitalWrite( g, LOW);
}

void Get_AHT10_Data(){
 // Communicate with the humidity and temp sensor and get data
  sensors_event_t Humidity, Temp;

  // Now get the data
  AHT10.getEvent(&Humidity, &Temp); // Get Temp and humidity data
  AHT10_Humidity =Humidity.relative_humidity;
  
}

Ok. What doesn't work?

You are stepping through the digits very slowly.

duplicate thread
https://forum.arduino.cc/t/interfacing-aht10-with-7-segment-display/1055948

Your two topics on the same or similar subject have been merged.

Please do not duplicate your questions as doing so wastes the time and effort of the volunteers trying to help you as they are then answering the same thing in different places.

Please create one topic only for your question and choose the forum category carefully. If you have multiple questions about the same project then please ask your questions in the one topic as the answers to one question provide useful context for the others, and also you won’t have to keep explaining your project repeatedly.

Repeated duplicate posting could result in a temporary or permanent ban from the forum.

Could you take a few moments to Learn How To Use The Forum

It will help you get the best out of the forum in the future.

Thank you.

It shows 66 on 7 segment display and does not change even sensors value change in real...

I follow the example scketch but i am a noob in this field... so after changing in this code 7 segment display shows 66 and not change even sensor value change in real time... please guide me..thanks in advance...

How much time do you have to learn? You have overlooked really obvious problems. For example, it is plainly evident that the schematic shows 2 digits and the code is written for 4 digits. You need to fix such basic issues before attempting to adapt the LCD sketch.