Difference between revisions of "Virtual Circuit Simulation Guide"

From EG1004 Lab Manual
Jump to: navigation, search
Line 59: Line 59:
[[File:VCSG Figure 9.png|400px|thumb|center|Figure 9: Setting Resistor Value]]
[[File:VCSG Figure 9.png|400px|thumb|center|Figure 9: Setting Resistor Value]]


As seen in the figure above, the RPM of the motor is decreased greatly, despite the input voltage being the same. By utilizing a breadboard, one is able to directly control how fast the motor will spin purely using resistors.
As seen in Figure 8, the RPM of the motor decreased greatly to 41 RPM, despite the input voltage being the same. By utilizing a resistor, one is able to directly control how fast the motor will rotate.


However, this is an example of a circuit where the user has no control over the system; the motor can only run continuously in a single direction. Let’s look at an example where the motor is coded to spin back and forth on a timer.
However, this is an example of a circuit where the user has no control over the system; the motor can only run continuously in a single direction. Let’s look at an example where the motor is programmed to spin back and forth on a timer.


[[File:Vc10.png|400px|thumb|center|Figure 10: Motor programmed to run and pause]]
[[File:Vc10.png|400px|thumb|center|Figure 10: Motor programmed to run and pause]]


* In the above figure, note that the power supply now is wired from pin 8. As pin 8 is a digital pin, it only has two values: HIGH or LOW.  In our code, the function digitalWrite is sending signals to the specified pin. Here, HIGH will cause the pin to supply power, while LOW shuts off the power being supplied to the circuit. For the Arduinos, we will be using digital pins that will convey signals utilizing 5 Volts, hence a resistor is used to protect the motor from burning out from too much voltage. The delay function tells the microcontroller how long to follow the prior line. In this example, the motor is running for one second, then stopping for one second. As it is in a loop, it then repeats.
* In the above figure, note that the power supply now is wired from pin 8. As pin 8 is a digital pin, it only has two values: HIGH or LOW.  In our code, the function digitalWrite is sending signals to the specified pin. Here, HIGH will cause the pin to supply power, while LOW shuts off the power being supplied to the circuit. For the Arduinos, we will be using digital pins that will convey signals utilizing 5 Volts, hence a resistor is used to protect the motor from burning out from too much voltage. The delay function tells the microcontroller how long to follow the prior line. In this example, the motor is running for one second, then stopping for one second. As it is in a loop, it then repeats.

Revision as of 00:24, 12 July 2020

Circuitry

Please refer to the Overview section of Lab 5 if you are unfamiliar with prototyping or electrical components. It is important to have a good understanding of how circuits, microcontrollers, and breadboards work to be able to simulate these components virtually.

This guide will focus on two options for virtual circuitry, one for simulation called TinkerCAD and one for more advanced circuit creation called Fritzing. It is highly recommended that you utilize these software, but you are welcome to use any form of simulation that you deem satisfactory.

TinkerCAD

TinkerCAD is a free in-browser software that will be used for the simulation of microcontrollers and associated electrical components. A link to the website can be found here. You can sign into TinkerCAD with your Autodesk account, which you should have created in Lab 1. After logging in, a circuit project can be created by clicking Create new Circuit (Figure 1).

Figure 1: Creating a Circuit in TinkerCAD

The sidebar allows for access to common electrical components, as well as generic setups for prototyping for microcontrollers (Figure 2).

Figure 2: TinkerCAD Sidebar

TinkerCAD allows for the user to directly write and execute code within the software. When the circuit is ready, click Start Simulation to simulate powering the circuit (Figure 3).

Figure 3: TinkerCAD Simulation

Click Code to open the panel to write code, which is based in the Arduino programming language. A guide to coding with Arduino can be found here. The Serial Monitor window functions the same as it would in the Arduino IDE, and has the same setup and loop areas (Figure 4). Note that the circuit cannot be adjusted while the code tab is opened.

Figure 4: TinkerCAD Code Area

Frtizing

Fritzing is a free, open-source software that includes a variety of tools. A link to download the software can be found here. Extract the ZIP file to a folder on your computer and run the EXE file.

Fritzing has a very similar interface to TinkerCAD, with the exception that it cannot perform simulations. However, Fritzing provides a much greater variety of components that are not included in TinkerCAD.

Upon installation, the following tabs are shown (Figure 5). The Breadboard tab is the visual interaction with the components, and the Code tab is the in-program access to Arduino.

Figure 5: Fritzing Tabs

The Parts menu has the same interface as that of TinkerCAD, but with many more options (Figure 6).

Figure 6: Fritzing Parts Menu

Examples

In this guide, two basic example projects will be shown to you in TinkerCAD, but can be easily replicated in Fritzing. The examples include a DC motor rotating continuously in one direction and a DC motor that rotates based on the input of the user.

Continuous DC Motor

After dragging in a DC motor and Arduino from the TinkerCAD sidebar (Figure 7), the proper wiring is drawn and the simulation is run.

Figure 7: Continuous DC Motor Example

The DC motor now displays the revolutions per minute (RPM) that it rotates at for this amount of voltage, specifically 6586 RPM at 3.3 V. The RPM is directly proportional to the input voltage, so one can vary the motor speed by varying the input voltage. Note that in this situation, the microcontroller is functioning directly as a battery to the motor. Were this a 9 V battery instead of a microcontroller, the displayed RPM would be much higher, if the DC motor is able to take it.

When creating this same circuit in a real scenario, it is highly unlikely that the motor will be directly connected to the power supply. Additionally, buffers such as resistors are used to prevent damage to the motor from being directly exposed to the full voltage from the power supply and are used to manipulate the RPM to a desired quantity. Therefore, we will drag a breadboard and resistor into the circuit (Figure 8).

Figure 8: Continuous DC Motor with 10 kΩ Resistor

With all electrical components, TinkerCAD allows for the user to directly set the value of the component, such as the resistance for a resistor or voltage for a power supply. A resistor is dragged in and set to 10 kΩ (Figure 9).

Figure 9: Setting Resistor Value

As seen in Figure 8, the RPM of the motor decreased greatly to 41 RPM, despite the input voltage being the same. By utilizing a resistor, one is able to directly control how fast the motor will rotate.

However, this is an example of a circuit where the user has no control over the system; the motor can only run continuously in a single direction. Let’s look at an example where the motor is programmed to spin back and forth on a timer.

Figure 10: Motor programmed to run and pause
  • In the above figure, note that the power supply now is wired from pin 8. As pin 8 is a digital pin, it only has two values: HIGH or LOW. In our code, the function digitalWrite is sending signals to the specified pin. Here, HIGH will cause the pin to supply power, while LOW shuts off the power being supplied to the circuit. For the Arduinos, we will be using digital pins that will convey signals utilizing 5 Volts, hence a resistor is used to protect the motor from burning out from too much voltage. The delay function tells the microcontroller how long to follow the prior line. In this example, the motor is running for one second, then stopping for one second. As it is in a loop, it then repeats.