I cant connect AHT20 temp&humd sensor to adafruit io

I have tried various diffrent codes but still cant seem being able to connect to adafruit. And if the code runs fine it show "netowrk disconnected" in the arduino serial monitor.

code:
#include <Adafruit_AHTX0.h>

#define DATA_PIN 5
Adafruit_AHTX0 aht;

void setup() {

// start the serial connection
Serial.begin(115200);

while(! Serial);

aht.begin();

// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();

// wait for a connection
while(io.status() < AIO_CONNECTED) {
Serial.print(io.statusText());
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());

}

void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");

delay(500);
}

Hi, @abbas212121
What are you connecting the AHT20 to?
What controller?

Can you post link to AHT20?
Can you please post a circuit diagram and the code that you have been trying?

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

I am connecting the AHT20 to an ESP32. I dont know what you mean with a controller (I am new to arduino). The code I am using is already there and I dont know the circuit diagram (the wiring?).

Hi,
To add code please click this link;

ESP32 is your controller, a microcontroller in fact.

How have you connected the AHT20 to the ESP32?
Please draw, using pen(cil) and paper,a circuit diagram of how connnected the AHT10 and the ESP32.

Thansk, Tom.. :smiley: :+1: :coffee: :australia:

I just got told from my friend that I have to use arduino uno. I am gonna try again if it not works then I will seek help from you again. I am sorry for taking from your time.

Now my teacher is telling something new. I am gonna try and if i still need help i'll tell u

Hi,
When you have more instructions from your teacher, can you post the exact words he/she gives in those instructions, or post an image of the problem sheet.
This will give us a better idea of what you are having problems with.

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

Hello. Look, what I am trying to do is getting the aht20 sensor send information to adafruit io dashboard. But when I run the code, it says in the serial monitor "network disconnected"
// Adafruit IO Temperature & Humidity Example
// Tutorial Link: Overview | Adafruit IO Basics: Temperature & Humidity | Adafruit Learning System
//
// Adafruit invests time and resources providing this open source code.
// Please support Adafruit and open source hardware by purchasing
// products from Adafruit!
//
// Written by Todd Treece for Adafruit Industries
// Copyright (c) 2016-2017 Adafruit Industries
// Licensed under the MIT license.
//
// All text above must be included in any redistribution.

/************************** Configuration ***********************************/

// edit the config.h tab and enter your Adafruit IO credentials
// and any additional configuration needed for WiFi, cellular,
// or ethernet clients.
#include "config.h"

/************************ Example Starts Here *******************************/
#include <Adafruit_AHTX0.h>

Adafruit_AHTX0 aht;

// set up the 'temperature' and 'humidity' feeds
AdafruitIO_Feed *temperature = io.feed("temperature");
AdafruitIO_Feed *humidity = io.feed("humidity");

void setup() {

// start the serial connection
Serial.begin(115200);

// wait for serial monitor to open
while (! Serial);

// initialize dht22
aht.begin();

// connect to io.adafruit.com
Serial.print("Connecting to Adafruit IO");
io.connect();

// wait for a connection
while (io.status() < AIO_CONNECTED) {
Serial.print(io.statusText());
delay(500);
}

// we are connected
Serial.println();
Serial.println(io.statusText());

}

void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);// populate temp and humidity objects with fresh data
Serial.print("Temperature: "); Serial.print(temp.temperature); Serial.println(" degrees C");
Serial.print("Humidity: "); Serial.print(humidity.relative_humidity); Serial.println("% rH");

delay(500);
}

I did the auto format thing but I dont know if it worked or not

Got some news. I got to work. I was that I did not have the io.run(); code in there.