I am using an Arduino simulator on www.tinkercad.com (a seemingly nice free product from Autodesk). Working on conversion of an integer to a 16 bit binary string for output to a DAC, but unfortunately even at the first step I am getting unexpected behavior.

void setup()
  pinMode(13, OUTPUT);
  Serial.print("Sanity Check\n");
  uint16_t num = 12000;
  Serial.print("\nNumber: " + String(num) + "\n");

Surprisingly the above code gave the following output:

Sanity Check

Number: 12222

Is there something I am doing wrong, or something wrong with the simulator? The error seems to crop up with any value over 10000. 10001, 10002, 10003 all print as 10000. 11000, 11001, 11002, 11003 all print as 11111. etc, etc. What could be going on?

  • My Uno prints “Number: 12000”. – Edgar Bonet Mar 23 '18 at 19:34

Bug. No other explanation. Real hardware (Arduino Uno) prints 12000.

Even the debugger tells me that the value of that variable is 12000.



Number: 12222 
12222 something 

Most interestingly if you Serial.println() the number, it is outputted correctly. The bug must be in the constructor of the String object, as demonstrated by the "test" String. This bug also occurs on other data types, e.g. int.

If you only use direct Serial.print[ln] calls you should be able to workaround that bug.


Try using Simulator for Arduino from Virtronics. We have a unit testing feature (under Tools > Unit Testing) so bugs like this would never happen. This is probably the only Arduino Simulator with a self-test feature.

  • The question wasn't which simulator to use. – gre_gor Sep 12 '18 at 21:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.