Tinkercad Simulation of Arduino Circuit With 3 Inputs
Tinkercad Simulation of Arduino Circuit With 3 Inputs
A1 ESAT
Controlling input and output data in an embedded system
Introduction
In the project to understand the basic principles of the Arduino Uno prototyping platform, the quickest route
is to use simple hardware such as potentiometers and push buttons, to create a functioning system treating and
outputting information from various sources. In this instance, the three sources are a push button, potentiometer (as
cited above) and a photo-resistor. Those three inputs of information plug into the Arduino Uno board which then
with C++ Source Code treats the information and outputs it (in this case) onto an LCD (Liquid-Crystal Display).
Source code as well as hardware setup for inputting and outputting a single source of information can be
easily found online, however, treating three different inputs to output into a single device requires embedding code
into code and a particular disposition of the hardware.
I/ Main Design
The following Arduino Uno R3 circuit board uses 3 input sources:
- Photo-resistor
- Potentiometer
- Push Button
Its output is an LCD Display in order to represent the information given by the inputs.
Arduino Uno circuit board design using Tinkercad (Tinkercad | From mind to design in minutes, 2021) :
: Push Button
: Potentiometer
: Photo-resistor
: LCD Display
a) Potentiometer
The potentiometer is a resistor whose resistance can be modified. In this case a rotary potentiometer has its
resistance changed through turning a knob.
On the circuit board, the potentiometer receives a 5V input on its left pin from the Arduino board which connects its
5V output to the breadboard. The potentiometer is connected to the ground on its right pin from the Arduino’s
ground connected to the breadboard. The middle pin of the potentiometer is connected to the V0 input of the LCD.
This pin controls the brightness of the displayed text on the display.
The lower the resistance of the potentiometer the brighter the text and the higher the resistance the dimmer the
text will be:
b) Photo-resistor
The photo-resistor is a varying resistance component. Its resistance varies inversely proportional to the light
intensity meaning that as the amount of light increases, the resistance decreases, and vice-versa. In this circuit the
amount of light is “measured” through the varying resistance and displayed on the LCD.
The photo-resistor receives voltage through connection to the 5V output from the Arduino board. The
second pin of the photo-resistor is connected to both the A0 analogue input of the Arduino board and the ground.
The ground is connected through a 100Ω resistor, which is necessary as without a resistor connected to the ground,
the entirety of the signal goes directly to the ground and none through the A0 input. Putting a resistance of 100Ω at
the ground output makes it so the lighting level starts at 1, however, a resistance of 1kΩ or 10kΩ can work as well.
The higher the resistance the more voltage goes through the A0 connected wire.
The analogue A0 input permits the input signal from the photo-resistor to be processed by the Arduino board and
affected by the code. In this case, the code retrieves the voltage going through the photo-resistor and through the
A0 analogue input and translates it into a “lighting level” with a number representing low voltage/high resistance
with a low number (lowest being 1 here) and increasing as the voltage input increases (maximum 169 here).
Code for Arduino circuit board: Explanation of code related to the use of the photo-resistor
// Line 1 calls for the library <LiquidCrystal> which lets the user utilise
commands linked to Liquid crystal Displays (LCD).
// Line 3 declares that the LCD uses the digital outputs 12,11,5,4,3 and 2.
// Line 8 opens up a new function names “void”, this signifies that the function
does not have to return anything. In C++ the « main() » function must return
once all the code has been done. The « void » function does not need to do this.
// Line 9 the accolade declares that the next lines of code are part of the “void
setup()” function.
// Line 10 declares that the LCD has 16 columns and 2 rows to display on.
// Line 11 commands to print out on the LCD “Lighting Level” as the rows and
columns are not specified, the system will assume it starts on line 0, column 0.
// Line 14 sets the bitrate connection to the board, in bits per second. Here
connected at a bit rate of 9600 bits per second.
// Line 15 the accolade declares that the function “void setup()” is now over.
// Line 17 opens up the function “void loop()” which, as its name entails, loops
over and over until the simulation is manually stopped.
// Line 20 declares the integer “sensorValue” in which is put the value of
“analogRead(A0)” which reads the voltage input from the photo-resistor.
// Line 25 sets up where the next lines will print on the lcd display, here being
column 0, line 1 (line 1 being the second from the top as in coding numbers start
at 0).
// Line 26 commands to print four underscores, on the second line of the LCD.
// Line 28 sets up once again where the next lines will print on the lcd display,
being the same column 0, line 1.
// Line 29 commands to print the reading of the analogue input A0.
// Line 30 commands that the reading of A0 input be translated into a human
readable value.
// Line 31 delays the repetition of the void loop by 260ms (milliseconds).
// Line 38 end of the “void loop()” goes back to the top of the function and
reads the code inside it once more.
Low light level high resistance High light level low resistance
c) Push Button
The push button has a voltage input and output, the input using the 5V voltage from the Arduino board and
connected to the digital pin 8 as well as the ground at its output. The ground is connected via a resistor to avoid
having all the voltage run directly to the ground, 1kΩ suffices for voltage to go to the digital pin 8. The digital pin 7
outputs to the backlight LED input of the LCD, giving the button possibility to affect the backlight LED. As such, once
Arduino is plugged into the computer, the code will run in order to make it so when the button is pushed, the
backlight LEDs dim for approximately 5 seconds and when unpressed runs through the code for the photo-resistor
without affecting the backlight LED.
Code for Arduino circuit board: Explanation of code related to the use of the push button
// Line 5 declares a constant integer (which means that it will not change),
naming it “inputPin” attributing it the value of 8 meaning it will be using digital
pin 8.
// Line 6 declares a constant integer naming it “outputPin” attributing it the
value of 7 meaning it will be using the digital pin 7.
// Line 12 declares that the integer “inputPin” is the INPUT signal into the
Arduino board.
// Line 13 declares that the integer “outputPin” is the OUTPUT signal out of the
Arduino board.
// Line 19 declares the integer “val” to which is attributed the value of
“digitalRead(inputPin)” which is whichever value will be read at the input digital
pin 8.
// Line 21 The loop “if” states that on the condition that “val” is equal to LOW,
then it will read the code below.
// Line 22 opening of the “if” loop.
// Line 23 commands to have the output pin to emit a “HIGH” voltage
“digitalWrite” being the values that the digital pins on the Arduino board can
output.
// Line 32 closing the “if” loop which thus allows the compiler to read the code
from the top of the “void loop()” and check whether the “if” conditions are met
or not.
// Line 33 following the “if” loop, the “else if” states the other viable condition in
the case that the first one is not fulfilled. In this case, if val is not LOW, then the
condition is that val has to be HIGH to execute the following code.
// Line 34 opening of the “else if” loop
// Line 35 “digitalWrite” acts the same being the output at digitalPin 7 however
this time emitting a “LOW” signal. Thus sending less voltage to the backlight LED
input and dimming the backlight LED.
// Line 36 delays the reading of the next line by 5000ms (5 seconds).
// Line 37 end of the “else if” loop, allowing compiler to read from the top of the
“void loop()”.
Push Button pushed dimmed backlight LED
Liquid Crystal displays or LCDs, are electronically modulated optical devices, meaning that they display
information through an electrical current. As liquid crystals do not emit light directly, the display uses a backlight
with LEDs which are powered by the electrical current. The crystals then modulate the light from the LEDs and
produce images.
Using this type of display with Arduino enables us to code the type of information which will appear on the LCD from
the different inputs.
Referring to the circuit board tinkercad design, we can observe how the LCD is connected to the Arduino Uno board:
Arduino Uno Tinkercad circuit board design
Indeed, the LCD display is powered through the Arduino voltage, thus connected to the voltage line fed by
the Arduino 5V output, and connected to the ground line which itself runs to the Arduino ground.
As seen above, the blue wires connect to the four digital
pins 5,4,3,2 in the Arduino board and to the D4,D5,D6,D7 inputs
on the LCD. These are the four data lines. This type of board can
use up to 8 data lines, however this uses up even more digital
pins on the Arduino and seeing as other components use those
inputs the minimum data lines will suffice in this case. The
orange wires are connected to the screen reset and enable pins
connected to the Arduino digital pins 11 and 12. Thus, whenever
the code runs through the “void loop()” function and restarts it,
the screen will reset to having no information and enabling new
information to be added onto it.
As such, in the code lines when setting up the data input on the
Liquid Crystal display, the first two declared pins are the “reset”
and “enable”, and the following ones are the data pins, having
four pins here means that the LCD will be running at a 4-bit rate.
e) Full Code with explanation
Explanation of code
// Line 1 calls for the library <LiquidCrystal> which lets the user utilise commands
linked to Liquid crystal Displays (LCD).
// Line 3 declares that the LCD uses the digital outputs 12,11,5,4,3 and 2.
// Line 5 declares a constant integer (which means that it will not change), naming it
“inputPin” attributing it the value of 8 meaning it will be using digital pin 8.
// Line 6 declares a constant integer naming it “outputPin” attributing it the value of
7 meaning it will be using the digital pin 7.
// Line 8 opens up a new function names “void”, this signifies that the function does
not have to return anything. In C++ the « main() » function must return once all the
code has been done. The « void » function does not need to do this.
// Line 9 the accolade declares that the next lines of code are part of the “void
setup()” function.
II/ Evaluation
Upon simulating the circuit, the light level values change in proportion to the increasing input of light on the
photo-resistor. The screen dims in proportion to the resistance increase or decrease using the potentiometer. The
backlight is turned off for approximately 5 seconds when the push button is pressed. The sole inconvenience is that
as seen in the code, when fulfilling the “else if” condition, the user is unable to see the change of luminosity be
displayed on the LCD. As the backlights are dimmed, the delay makes it so the code does not continue for another
5000milliseconds (5 seconds), this is made so that the dimming of the backlights can be properly seen. However, due
to this functionality, the code does not continue to reset the screen and check whether the photo-resistor’s
resistance has changed.
Conclusion
To conclude, the circuit created enables the use of three varying inputs and the viewing of information
created by these inputs through a single output. The photo-resistor, potentiometer, and push-button work together
to make a functioning LCD display where the letters can be dimmed by the potentiometer, the “light levels” have a
readable value varying with the luminosity sensed by the photo-resistor, and the push button dims the backlight
dimming the overall display. The circuit uses simple code with an “if” loop and the appropriate libraries for the
proper functioning of the components.
Although this design demonstrates three functioning information sensors and output this info on a display, it
is not a system which would be used in everyday life. It is not a practical system; this design was solely made to
discover the functionalities of Arduino using basic electronic components. However, this also shows that Arduino is
simple to use, but will be able to go as far as creating MIDI devices using this platform.
References