AHT10 does not work on a Uno R4

Hello
I have bought 2 pcs AHT10 sensor and found this website

But when I saw verify in arduibo ide I get a lot of errors that I don't understand.
I just want to test if the two sensors are working?? Using Arduino Uno R4 wifi

Her is the errors

M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:23:2: error: stray '\342' in program
  ​​Serial.println( "Humidity: " ); Serial.print (hum); Serial.println ( " %" ); // print the humidity value.
  ^
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:23:3: error: stray '\200' in program
  ​​Serial.println( "Humidity: " ); Serial.print (hum); Serial.println ( " %" ); // print the humidity value.
   ^
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:23:4: error: stray '\213' in program
  ​​Serial.println( "Humidity: " ); Serial.print (hum); Serial.println ( " %" ); // print the humidity value.
    ^
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:23:5: error: stray '\342' in program
  ​​Serial.println( "Humidity: " ); Serial.print (hum); Serial.println ( " %" ); // print the humidity value.
     ^
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:23:6: error: stray '\200' in program
  ​​Serial.println( "Humidity: " ); Serial.print (hum); Serial.println ( " %" ); // print the humidity value.
      ^
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:23:7: error: stray '\213' in program
  ​​Serial.println( "Humidity: " ); Serial.print (hum); Serial.println ( " %" ); // print the humidity value.
       ^
In file included from m:\Arduino Sketch\libraries\Adafruit_BusIO/Adafruit_BusIO_Register.h:9:0,
                 from m:\Arduino Sketch\libraries\Adafruit_AHT10/Adafruit_AHT10.h:22,
                 from M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:3:
m:\Arduino Sketch\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:10:36: error: 'TwoWire' has not been declared
   Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
                                    ^~~~~~~
m:\Arduino Sketch\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:30:3: error: 'TwoWire' does not name a type; did you mean 'TwoWire_h'?
   TwoWire *_wire;
   ^~~~~~~
   TwoWire_h
m:\Arduino Sketch\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:10:56: error: 'Wire' was not declared in this scope
   Adafruit_I2CDevice(uint8_t addr, TwoWire *theWire = &Wire);
                                                        ^~~~
In file included from M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:3:0:
m:\Arduino Sketch\libraries\Adafruit_AHT10/Adafruit_AHT10.h:82:14: error: 'TwoWire' has not been declared
   bool begin(TwoWire *wire = &Wire, int32_t sensor_id = 0);
              ^~~~~~~
m:\Arduino Sketch\libraries\Adafruit_AHT10/Adafruit_AHT10.h:82:31: error: 'Wire' was not declared in this scope
   bool begin(TwoWire *wire = &Wire, int32_t sensor_id = 0);
                               ^~~~
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:5:1: error: 'AHT10' does not name a type
 AHT10 myAHT10(0x38);//AHT10 instance, address 0x38
 ^~~~~
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino: In function 'void setup()':
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:8:2: error: 'Wire' was not declared in this scope
  Wire.begin (); // Function that initializes the Wire library.
  ^~~~
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:13:6: error: 'myAHT10' was not declared in this scope
 if (!myAHT10.begin ()) { // If communication with the sensor fails, an error message is printed
      ^~~~~~~
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino: In function 'void loop()':
M:\Arduino Sketch\AHT10 sensor\sketch_apr7b_aht10_test\sketch_apr7b_aht10_test.ino:20:15: error: 'myAHT10' was not declared in this scope
  float temp = myAHT10.readTemperature (); //read temperature from sensor and store it in a variable.
               ^~~~~~~

exit status 1

Compilation error: stray '\342' in program

This is nothing to do with the sensor or the Arduino.

It's a problem you get sometimes when copying & pasting code from websites.

You should post your full code here, so that forum remembers can see what's causing those other errors.

Once you have done that, you can clear all your code from the IDE and then copy it back from the forum. That might fix the "stray character" errors.

Thanks for reply, here is the code

#include <Wire.h> // Library to establish I2C communication

#include <Adafruit_AHT10.h> // Library to use the AHT10 sensor

AHT10 myAHT10(0x38);//AHT10 instance, address 0x38
void setup () 
{
 Wire.begin (); // Function that initializes the Wire library.

Serial.begin (9600); // initializes Serial communication.

Serial.println ( "Initialising AHT10 Sensor" );
if (!myAHT10.begin ()) { // If communication with the sensor fails, an error message is printed 
Serial.println ( "Sensor error!" );
while (1);
}
}
void loop () 
{
 float temp = myAHT10.readTemperature (); //read temperature from sensor and store it in a variable.
 float hum = myAHT10.readHumidity (); // read humidity from sensor and store it in a variable.
 Serial.println ( "Temp: " ); Serial.print (temp); Serial.print ( "°C  " ); //print the temperature value.
 ​​Serial.println( "Humidity: " ); Serial.print (hum); Serial.println ( " %" ); // print the humidity value.
 delay (1000);
}

Thanks.

If you select Uno R3 do you get the same errors?

The sketch on the page you linked to used #include <AHT10.h>, not #include <Adafruit_AHT10.h>.

The AHT10 type does not exist in Adafruit's library. You can't just substitude one library for another without changing the declarations and calls to it.

If you use the original library, and remove the hidden characters from the line that begins with Serial.println( "Humidity: ");, and remove all the compilation breaking spaces in the original sketch (as you've done), the sketch compiles just fine for both the Uno R3 and R4.

But if you're going to use Adafruit's library rather than the archived, unsupported original, my suggestion would be to throw away that sketch and use one of the examples included with the Adafruit library.

I have corrected Adafruit_AHT10.h to AHT10.h and when I verify my code with the Arduino IDE, I get that the Library does not exist.
Do you know where I can download this Library?? Thanks

#include <Wire.h> // Library to establish I2C communication

#include <AHT10.h> // Library to use the AHT10 sensor

AHT10 myAHT10(0x38);//AHT10 instance, address 0x38
void setup () 
{
 Wire.begin (); // Function that initializes the Wire library.

Serial.begin (9600); // initializes Serial communication.

Serial.println ( "Initialising AHT10 Sensor" );
if (!myAHT10.begin ()) { // If communication with the sensor fails, an error message is printed 
Serial.println ( "Sensor error!" );
while (1);
}
}
void loop () 
{
 float temp = myAHT10.readTemperature (); //read temperature from sensor and store it in a variable.
 float hum = myAHT10.readHumidity (); // read humidity from sensor and store it in a variable.
 Serial.println ( "Temp: " ); 
 Serial.print (temp); 
 Serial.print ( "°C  " ); //print the temperature value.
 ​​Serial.println( "Humidity: " );
 Serial.print (hum); 
 Serial.println ( " %" ); // print the humidity value.
 delay (1000);
}

Fejl
M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test\sketch_apr7a_AHT10_test.ino:3:10: fatal error: AHT10.h: No such file or directory
#include <AHT10.h> // Library to use the AHT10 sensor
^~~~~~~~~
compilation terminated.
exit status 1

Compilation error: AHT10.h: No such file or directory

Hello
I have found the AHT10.h library and inserted it, but when I do a verify in the Arduino IDE I get a lot of errors??

#include <Wire.h> // Library to establish I2C communication

#include <AHT10.h> // Library to use the AHT10 sensor

AHT10 myAHT10(0x38);//AHT10 instance, address 0x38
void setup () 
{
 Wire.begin (); // Function that initializes the Wire library.

Serial.begin (9600); // initializes Serial communication.

Serial.println ( "Initialising AHT10 Sensor" );
if (!myAHT10.begin ()) { // If communication with the sensor fails, an error message is printed 
Serial.println ( "Sensor error!" );
while (1);
}
}
void loop () 
{
 float temp = myAHT10.readTemperature (); //read temperature from sensor and store it in a variable.
 float hum = myAHT10.readHumidity (); // read humidity from sensor and store it in a variable.
 Serial.println ( "Temp: " ); 
 Serial.print (temp); 
 Serial.print ( "°C  " ); //print the temperature value.
 ​​Serial.println("Humidity: ");
 Serial.print (hum); 
 Serial.println ( " %" ); // print the humidity value.
 delay (1000);
}

errors??

M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test_2\sketch_apr7a_AHT10_test_2.ino:4:1: error: 'AHT10' does not name a type
AHT10 myAHT(0x38);
^~~~~
M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test_2\sketch_apr7a_AHT10_test_2.ino: In function 'void setup()':
M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test_2\sketch_apr7a_AHT10_test_2.ino:11:8: error: 'myAHT10' was not declared in this scope
if (!myAHT10.begin ())
^~~~~~~
M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test_2\sketch_apr7a_AHT10_test_2.ino: In function 'void loop()':
M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test_2\sketch_apr7a_AHT10_test_2.ino:18:15: error: 'myAHT10' was not declared in this scope
float temp = myAHT10.readTemperature ();
^~~~~~~
M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test_2\sketch_apr7a_AHT10_test_2.ino:22:14: error: no match for call to '(UART) (const char [4])'
Serial("°C");
^
M:\Arduino Sketch\AHT10 sensor\sketch_apr7a_AHT10_test_2\sketch_apr7a_AHT10_test_2.ino:25:12: error: no match for call to '(UART) (const char [2])'
Serial("%");
^

exit status 1

Compilation error: 'AHT10' does not name a type

Can you explain to me what this error means and when I can fix it??
thanks

That means that the library you are using has no class named AHT10, and the code is not intended to be used with that library.

Find a library intended to be used with the AHT10, wire the sensor as an example in that library expects, and run that library example.

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