226

I would like to start the development of some basic Arduino projects but I don't own an Arduino board yet. Is there a way I can write my code and emulate/test it using a desktop computer so after my board arrives I just have to upload and run my project on it?

3

13 Answers 13

136

There are a whole slew of Arduino simulators out there, many free, and some paid products as well.

  • The CodeBlocks Arduino development environment includes a free Arduino simulator, still under development but functional.
  • Simuino simulates the Arduino Uno and Mega pins - not a pretty-looking realistic simulator, but it works.
  • The Python based Arduino Simulator is another option, that plays well with the official IDE
  • Virtronics Simulator for Arduino looks promising, but I don't see why I would pay $14.99 for it, when I could buy one or more actual Arduino clones for that price

Many other Arduino simulators are out there if you search, and new ones are being announced, even crowdfunded, all the time.

5
  • 10
    as a note, those are not emulators but simulators, the most important difference is that it does not run the code on a AVR virtual machine (like what qemu does), but binds the Arduino functions to native code. So basically they won't be able to run native AVR stuff and register/timer behavior will not be the same as on real AVR hardware. See the difference well explained in that answer. It is, though, theoretically possible to emulate Arduino Due code with qemu. – zmo Mar 13 '14 at 19:33
  • 6
    You "don't see why [one] would pay $14.99 for it, when [one] could buy one or more actual Arduino clones for that price"? I can tell you why: because the hardware doesn't have a built-in debugger with the features that can be provided by a simulator. – R. Martinho Fernandes Jul 16 '14 at 22:16
  • 9
    The Arduino Simulator piqued my interest, but unfortunately appears to have no files related to it on the sourceforge site. Am I missing something, or has it become deprecated since you wrote your answer? – Greenonline Feb 21 '15 at 17:46
  • 1
    As noted in above comment, there are no files in the arduino simulator source forge site. Is there a website for it or is there another simulator that works well in mac, with official IDE? – gordanvij Mar 27 '16 at 15:28
  • 4
    Simuino is terrible, unprofessional and useless. They have no clue how to code. Arduino Simulator has no releases. CodeBlocks is Windows only. Simulator for Arduino isn't open-source. – dhchdhd Apr 25 '16 at 2:03
90

I like to use circuits.io aka TinkerCAD for this.

It's cloud based and has some nice features including PCB design and collaboration.

IMO the Arduino simulation and capability is impressive and intuitive.

7
  • 3
    It is very nice and clean and basic functionality is really impressive, easy to use and powerful. However many common parts (including LCD and temperature sensors) are not supported yet. I doubt you can test anything but very basic designs at this stage. I hope this will get better over time. – Suma Aug 7 '14 at 14:07
  • I gave it a quick try and found it very impressive for a free product. I don't know its limitations in terms of simulation realism, but the editor is very friendly and just placing a led into the proper slot automagically created code with the correct pin and a blinking loop! – heltonbiker Mar 26 '15 at 20:20
  • even my choice would be 123d but my only complain about this site is they don't add new components. It would be really great if they can have some new components on their list – KD. Oct 7 '15 at 13:41
  • 3
    The electronic labs part of circuits.io site has moved to tinkercad.com, where you can find it under circuits. – SiggyF Jul 23 '17 at 16:00
  • 1
    I have edited it and updated the links. – sa_leinad Jun 12 '18 at 12:45
43

Plenty of options exist in the world of electronics simulators, but circuits.io aka TinkerCAD is probably the most versatile one out there.

  • You can compose your circuit on a virtual breadboard which looks just like real.
  • You can actually watch a LED blinking or press a button during real-time simulation rather than struggling with abstract waveforms.
  • You can combine digital devices like a 555 timer or shift registers with (interactive) analog components like resistors and LEDs.
  • You can program an Arduino and simulate the microcontroller together with your analog circuit around it.
  • You can debug an Arduino: when the simulator reaches your breakpoint, the simulation is paused and you can easily check every variable in your code and every voltage or current in your circuit.
  • You can use and observe different communication protocols like UART, I2C and SPI.
  • You can pause the simulation in the middle of an I2C sequence by putting a breakpoint in the driver code (e.g. interrupt service routine for I2C events)
  • It's FREE!

Example

This is an example circuit that has with an IR Remote and an LCD Screen.

Disclaimer: We are the makers of 123D Circuits

1
  • 1
    How does it play with the Arduino IDE? would it be available to flash, debug, etc? – rraallvv Apr 11 '16 at 14:14
18

Be aware that no simulator will reproduce real-life situations. There have been plenty of posts on the Arduino forum about problems with code or electronics, which turn out to be something subtle, such as:

  • Timing issues
  • Race conditions (related/dependent events not always happening in the same order)
  • Voltage levels, eg. floating input pins
  • Driving motors which drop the Arduino voltage enough that it resets
  • Not having decoupling capacitors
  • Input pins being in an "undefined" state (eg. 2.5V on a pin where 2 or less V is LOW and 3V or more is HIGH)
  • Problems with interrupt handlers, such as variables not being declared volatile
  • Voltage spikes due to not having flyback diodes on motors
  • The processor resetting once more than 10 LEDs are turned on because the current draw exceeds the amount the hardware can supply
  • Interrupt handlers taking 10 µS to process an interrupt when only 9 µS is available.

By their nature simulators can't reproduce all of this. Even if they could, would you think to toggle the "insert random noise from motors" option?


As for getting ready for the board to arrive, download the IDE and start programming. You can get libraries installed, code written and free of syntax errors, organize it neatly, and be generally ready for the big day when the hardware is in your hands.


Have fun and enjoy experimenting with your Arduino!

2
  • This is a good troubleshooting checklist for when a circuit is misbehaving seaport appearit "logically" correct. – misterbee Jan 8 '20 at 2:05
  • There is one point I would like to thank you for. The bounce effect of the pushbuttons creating so many problems for beginners unless addressed. inspired b your list, I had asked to add this feature in the wokwi and now the simulator supports bounce feature in the push buttons! – ArduinoFan Apr 9 at 10:53
14

You can use Yenka (free for home use) to simulate Arduino, PIX, PIXACE and other boards with digital, analog and serial I/O. It provides a lot of components and sample projects.

Screenshot:

Yenka Arduino simulation

1
13

Yes, you can, try using Proteus ISIS for simulating your code...

For full emulation of Arduino, there is a shareware program called VBB (Virtual BreadBoard), I tried it too and it was nice.

Edit: You can check my detailed tutorial here on how to simulate on Proteus ISIS

11

I believe this website has a list of both emulators and simulators along with their price and availability.

Update:

Since some users mentioned there are broken links in that website, here's a selection of emulators I found. Note that some descriptions may have been taken from the mentioned link:

  • Emulino: Is an open source linux based software in early development that emulates Arduino-specific MCUs.

  • Emulare: is a general purpose hardware emulator. It aims to provide a central interface to build electronic simulations for embedded software development. At present emulare focuses on the ATMega line of microcontrollers (Arduino UNO has the ATMega processor).

  • SimAVR: is a new AVR simulator for linux, or any platform that uses avr-gcc. The simulator loads ELF files directly, and there is even a way to specify simulation parameters directly in the emulated code using an .elf section. It supports emulation of many ATMega processors and it is mentioned that it's easy to even add new ones.

  • Amtel Studio: This doesn't seem to mention the term emulation, but it is a sophisticated IDE to debug your code for many platforms specially Arduino. Atmel Studio 7 features seamless one-click import of projects created in the Arduino development environment. Your sketch, including any libraries it references, will be imported into Studio 7 as a C++ project. Once imported, you can leverage the full capabilities of Studio 7 to fine-tune and debug your design. Atmel Studio 7 fully supports the powerful embedded debugger on the Arduino Zero board. For other Arduino boards, shield-adapters that expose debug connectors are available, or switch to one of the many available Xplained-Mini/PRO boards to fully leverage the Atmel HW eco-system.

You can still use simulators such as EasyEDA to test your code and in most cases be able to run it on the device. But note that given the nature of electronic components, you may have to provide external resistors, capacitors etc to get the expected results.

2
  • Link only answers not a good thing here because they will be useless when the linked site goes down. Please write a summary and also make sure that your answer adds value and not just repeating the ones we already have. – totymedli Jan 20 '16 at 18:54
  • I agree with @totymedli - if that link goes dead the answer becomes useless. Please summarize, at least, the emulators mentioned and the current price. You can start lines with an asterisk to make bullet points, if that helps. – Nick Gammon Jan 20 '16 at 20:07
8

Virtualbreadboard has a new VBB4Arduino 'Two Arduino's' edition which includes BOTH a JVM Arduino emulator AND a AVR Instruction set simulator with examples that cover almost all of the Arduino distribution examples and a bunch of peripheral hardware - LCD's, WS2812 Neo LEDS, Motors, Servo's, Logic Analyser and more.

http://www.virtualbreadboard.com

Disclaimer: I am the author of Virtual Breadboard

8

Edit 2:

I am working with the new Wokwi Arduino Simulator. Wokwi Arduino simulator is based on AVR8js engine which is made open-source. You can find the link here

Following are the main features of the simulator

• Supports multiple file projects

• Supports the Arduino libraries

• Whatever compiles on the Arduino IDE will compile on the simulator

• Supported by all browsers

• Compiles with latest Arduino IDE

• Supports FastLED and many other peripherals

No download or installation needed

Easy to share the code and project with just a single click

• Smart - Code Autocompletion, Code auto-formatting are supported

• Provides standard library demo examples

• Project can be compiled on RUN on Mobile browsers as well

• Tries to be closer to real circuits – Example – Button bounce like in real hardware

• Supports Arduino Mega, Arduino Nano, Arduino UNO, ATtiny85

• Supports assembly instruction execution

• Provides LED power and FPS features for FastLED projects

• Supports a plethora of Arduino peripherals for the project – Ultrasonic sensors, Slide switches, NeoPixel matrix, Potentiometer, Servo motors, SSD1306 OLED displays, temperature and humidity sensors, rotary dialer, membrane keypad and more

Serial monitor is supported as well

A few Arduino Examples

Simon game using ATTiny85, buttons, buzzer, and LEDs

Project link: https://wokwi.com/arduino/projects/285525640477671948

• Note the use of the same pins for both output and input • The code can be written for ATTiny85 the same way how it is written for Arduino

enter image description here


Slide switch demo example

Project link: https://wokwi.com/arduino/projects/292033853022798344

The slide switch can also be used as an ON-OFF switch

enter image description here


Simple Piano Example

Project link: https://wokwi.com/arduino/projects/291958456169005577

Plays several notes based on Arduino built-in library support

enter image description here


Max7219 LED dot matrix Arduino UNO project Example

Project link: https://wokwi.com/arduino/projects/290144516831183368

Supports concatenation of the Max7219 modules

enter image description here


HC-SR04 Ultrasonic sensor Example

Project link: https://wokwi.com/arduino/projects/290056311044833800

A very useful project to build several interesting projects (RADAR 3D mapping and more 😉 )

enter image description here


Bounce feature example in Arduino Simulator

Project link: https://wokwi.com/arduino/projects/288332630964830728

Bounce is the basic problem in most beginner projects. That can create multiple input triggers, unwanted noise and makes the project to misbehave. Sometimes can be difficult to identify without proper debug or measurement tools. Knowing about the bounce in switches and tips and tricks on how to solve it is an interesting study for every beginner hobbyist.

enter image description here


LCD1602 display example in Wokwi Arduino Simulator

Project link: https://wokwi.com/arduino/projects/287736345015616008

LCD1602 is one of the best HMI and has been here for a long time. It helps in debugging projects during run time, we can also use it along with a keypad to make a completely practical HMI (human-machine interface). Very easy to use, and easy to learn about programming.

enter image description here


FastLED example with FPS and LED power

Project link: https://wokwi.com/arduino/projects/287736345015616008

Second link: https://wokwi.com/arduino/projects/281176629596652040

FastLED is a second revolution in the history of LEDs. It was never easier than now to program multiple LEDs with just one Arduino Pin. With the growing FastLED community (reddit, wokwi-Discord, and others) and FastLED examples and libraries, This is one of the most important elements in the wokwi Simulator.

enter image description here enter image description here


Temperature and humidity sensor, Real time clock module example

Project link: https://wokwi.com/arduino/projects/287736345015616008

enter image description here


Serial Monitor example

Project link: https://wokwi.com/arduino/projects/286653669554782732

The serial plotter is a very useful feature when working with analog peripherals.

enter image description here


The Arduino simulator is free for the Arduino Community to use. We are adding more elements one after the other. It is free and we invite you to try it as well.

Please leave a comment to add more libraries or features as well

enter image description here enter image description here

enter image description here

enter image description hereenter image description hereenter image description hereenter image description here

5

You could e.g. use my simulator. It is especially suitable for PLC-like applications, where multitasking is achieved by cyclic evaluation of interconnected circuit-like objects: Timers, Markers, Latches, Oneshots and Registers. You can use it to simulate your controlled system as well, as becomes clear from the examples in the download. It has modest visualisation capacities, can draw timing charts, and allows you to access and alter c.q. force all variables in real time during a running simulation. Also you can freeze time. When you're satisfied with the behavior of your control it generates the C code to be uploaded to an actual Arduino.

https://pypi.python.org/pypi/SimPyLC

3

a way I can write my code and emulate/test it using a desktop computer

If you mean being able to "unit test" using a desktop computer, I can offer a library I wrote called arduino_ci.

It doesn't offer emulation. You would express your tests in code. For example, here is a test pulled from the reference documentation that validates the data written to a port:

unittest(pin_history)
{
  GodmodeState* state = GODMODE();
  int myPin = 3;
  state->reset();            // pin will start LOW
  digitalWrite(myPin, HIGH);
  digitalWrite(myPin, LOW);
  digitalWrite(myPin, LOW);
  digitalWrite(myPin, HIGH);
  digitalWrite(myPin, HIGH);

  // pin history is queued in case we want to analyze it later.
  // we expect 6 values in that queue.
  assertEqual(6, state->digitalPin[1].size());
  bool expected[6] = {LOW, HIGH, LOW, LOW, HIGH, HIGH};
  bool actual[6];

  // convert history queue into an array so we can verify it.
  // we expect to find 6 values: the 5 we set, plus the initial LOW
  // and this is where/how we assert that
  int numMoved = state->digitalPin[myPin].toArray(actual, 6);
  assertEqual(6, numMoved);

  // verify each element
  for (int i = 0; i < 6; ++i) {
    assertEqual(expected[i], actual[i]);
  }
}

In practice, you would probably not be calling the digitalWrite functions directly -- you'd call a function in your library, then verify that the "world state" (represented here by the GODMODE construct) matches what you expected your library to do.

1

Yes you can, and fairly easily. There is a wonderful online simulation (completely free) called TinkerCAD. It has an excellent breadboard simulation, with parts like transistors, LEDs, ICs, and Arduino. You can program the Arduino and run it all in a live simulation that includes interactive inputs (pushbuttons, DIP switches, etc.).


[Edit: The following text refers to functionality that has been moved to Circuits.io, namely Eagle PCB]

That's not all. It also includes in a separate tab schematics for your circuit, and another tab for PCB design of your breadboard circuit! Or, you can just make your schematics from scratch and make your PCB from there.

You can have your circuit designs made and you can buy them. You can do all of this in circuits.io, and you aren't risking messing up your actual Arduino. It also has warning indicators in the simulation (for example, if you didn't use enough resistance on an LED, or an IC).

1

An alternative to simulators are services similar to online compilers like coliru, which allow users to build and run their code on a remote system. This approach has the same limitations as online compilers:

  • The hardware configuration and state cannot be altered remotely, except for explicitly defined interfaces.

  • The changes to the hardware state cannot be observed, again, except for explicitly defined interfaces.

Typically, most online compilers provide users with access to command line and process STDOUT. On Arduino, providing remote access to the serial port would provide a similar degree of control: users would be able to observe and control their running sketch through UART, but would not be able to connect/remove wires, push buttons, act on external sensors, etc.

Surprisingly, I couldn't find any such online services, so I ended up writing my own - HW Farm. If you have a web server and Arduinos you can connect to it, you can install HW Farm on it and let people access those Arduinos through a web interface. I also host such a server myself, which has a single Arduino Mega with a bunch of I2C devices connected to it. You can try it out, but don't expect it to be online and available all the time.

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