RAPIFIRE

Blog

Prototype IoT Devices with 123D Circuits Arduino Simulator

Arduino Simulator

Autodesk 123D Circuits provides an electronics lab which has an electronic lab simulator to test your IoT sensor design and code for an Arduino board. The advantages of using such a lab is that it's faster to connect virtual components than using real ones. This blog will show how to use this powerful electronics lab with an easy example on the Arduino Uno device.

Here are the steps for creating an Arduino Uno app which blinks and buzzes on and off repeatly.

  • First create an account at the website here on the Sign Up

  • Click on the Open Electronics Lab Hub button.

  • Click on the New Electronics Lab button.

This will open up an empty breadboard.

  • Click on the bottom button for the Arduino Basic Kit button. This will show the list of electonic componets most useful to work with Arduino. Scroll down and drag the Arduino Uno to the white design area at the top.

  • We will not need the breadboard in this example so we will delete it. Click on the breadboard and press the Delete button on the top left corner.

  • Click the rotate button to the rotate the Arduino Uno so the pin numbers on the board are readable and the USB port is at the top.

  • Click the Code Editor on the top. It will show the blink code for the built in LED on the Arduino board. Then click the Start Simulation button. This LED will blink as the simulation runs. Click the Stop Simulation button to stop the simulation.

  • Place the red LED on the design area from Components, rotate it, and place the long bent lead on the input pin 13 and the shorter lead in the GND pin in the board. Press the Start Simulation button. The red LED component will blink with a very bright light. This is because there is too much current for the red LED flowing through it. The red LED requires about 1.8 volts while the output on pin 13 pin is 5 volts. A resister needs to be added between the LED and the pin to reduce the current flowing through it.

  • Move the LED off the Arduino board to the work area and click on the pin GND. It will start to draw a green wire. Join the green wire to the short lead on the red LED.

  • Add the 1K ohms resistor from the components between the pin 13 and the red LED. Rotate it to be horizontal. It does not matter which way the colored bands are pointing on the resistor. Draw lines connecting the GND pin to the resistor and from the other end of the resistor to the red LED to complete the circuit. Press the Start Simulation button. The red LED light will blink on and off every second.

  • For debugging purposes we will now add print out statements to the Serial Monitor to see what is going on. Press the Stop Simulation button. Click on the Code Editor button and change the code to add the Serial.begin() and Serial.println() statements.
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;


// the setup routine runs once when you press reset:
void setup() {  
  // initialize the digital pin as an output.
  Serial.begin(9600); 
  pinMode(led, OUTPUT);
  Serial.println("Setup initialized");
}

// the loop routine runs over and over again forever:
void loop() {  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  Serial.println("LED is ON"); 
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  Serial.println("LED is OFF");
  delay(1000);               // wait for a second
}
  • Press the Serial Monitor button in the Code Editor to open this output window. Then press the Upload & Run button to upload the changed code the Arduino device. You will see statements "Setup Initialized" and "LED is ON", and "LED is OFF" appear in the Serial Monitor window.

  • Press the Stop Simulation button. Next are going to add a piezo buzzer to the example so that it buzzers when the LED blinks. Press the Components button and add the piezo buzzer to the work area. Connect a wire from the GND pin to one end of the buzzer and another wire to the pin 7.

  • We can change the colors on the wire. Click on a wire and the wire component box will show. Use the dropdown to change from the color from green to purple for the 2 buzzer wires.

  • Click on the Code Editor and change the code to turn on and off to the buzzer on pin 7 as below:
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;  
int buzzer = 7;

// the setup routine runs once when you press reset:
void setup() {  
  // initialize the digital pin as an output.
  Serial.begin(9600); 
  pinMode(led, OUTPUT);
  pinMode(buzzer, OUTPUT);
  Serial.println("Setup initialized");
}

// the loop routine runs over and over again forever:
void loop() {  
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(buzzer, HIGH);   // turn the buzzer on (HIGH is the voltage level)
  Serial.println("LED, buzzer are ON"); 
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(buzzer, LOW);   // turn the buzzer on (HIGH is the voltage level)
  Serial.println("LED, buzzer are OFF");
  delay(1000);               // wait for a second
}
  • Press the Upload & Run button. The buzzer will emit a buzzing sound when the LED is on. The Serial Monitor will show a new output for "LED, buzzer are ON", and "LED, buzzer are OFF".

Another nice feature in the Code Editor is the Debugger. You can set break points by clicking on a line of code and when you place your cursor on a variable it will show the value of it.

  • Now that you are done you can download the code as a .ino file by pressing the Download Code button. This file can then be imported the Arduino IDE.

Lastly the electronics lab allows you to search other projects and duplicate a project to your workspace. You can then run it and edit it to your needs. Below is an IR sensor project duplicated from here

That's it. Now go ahead and now try it.

Author image
About Mark Garzone