Final project done!
The assignment for this week is to create a smart circuit using Arduino UNO. The circuit should contain 1 input component from a variable resistor or a sensor, and 1 action component.
The circuit has to be wired and simulated on Tinkercad, with Arduino being programmed using code blocks.
Because I am relatively new to coding, and especially new to electronics and Arduino, I have decided to practice during the weeks on my final projects' circuits. This would leave room for me to elevate the outcome of the final project.
For this week, I took one of the minimum features of the Azouz RC car:
Azouz RC car runs when user gets closer
Action: DC motor
Sensing: Infrared sensor
User Input: gets close to Azouz
To practice on that feature, I will create a circuit with an IR sesnor (input) and DC motor (action).
Softwares:
I used Tinercad to prototype and simulate the wiring, then to code the Arduino UNO using code blocks.
I used Arduino IDE software to copy the. Arduino CC text from the code blocks, troubleshoot it, then upload it to the Arduino UNO.
Electronic components:
Arduino UNO, the brain of the smart circuit
IR sensor (input)
DC motor (action)
Breadboard to wire the circuit on
Motor driver to provide the DC motor with sufficient voltage
Jumper wires
Screwdriver
Terminal
9v power supply
FOR PROTOTYPING the wiring of the components, I used Tinkercad.
First, I prepared all the components.
Then I wired the Arduino to the breadboard, by wiring the 5V pin in the Arduino to the positive row in the breadboard and the GND pin in the Arduino to the negative row in the breadboard.
Then I started with wiring the PIR sensor, which I used only on Tinkercad because there's no IR sensor there. The left node of the PIR (signal) is wired to the pin 12 in Arduino, then the middle node (power) to the positive row in the breadboard and the right node (ground) to the negative row in the breadboard. Now, the PIR is operating with 5V from the Arduino, and sending signal to the digital pin 12 on Arduino.
On the other hand, the motor needs 9V, which the Arduino is not able to give. This is why I used L293D motor driver and wired it as illustrated in the pictures.
Second, I prepared THE CODE BLOCKS as follows:
From the Control menu (in orange), I dragged the if/else block.
From the Math menu (in green), I dragged the hexagonal block (2nd one in the options)
Then from the same Math menu, I dragged the last option, which is the High dropdown menu in an oval block and placed it instead on the (1) on the right.
From the Input menu (in purple), I dragged the read digital pin block (first one), and placed it instead of the (1) on the left.
So far, I have set the first condition; if the digital pin 12 (which reads the PIR) reads HIGH, then the following happens:
From the Output menu I dragged the second block in the options twice, and set them as shown in the picture below; given that pin 7 and 8 give the output for the DC motor.
Then I dragged the third block in the options from the Output menu which allows to put. analogue values and set it to give pin 9 the value 180; given that pin 9 gives speed to the DC motor.
So far the code dictates the following: if the digital pin 12 (which reads the PIR) reads HIGH, then the motor operates on speed 180.
Else...
I dragged the second block in the options from the Output menu, and set pin 7 to LOW. This means that pin 7 and 8 would. give LOW and the motor will stop.
The code now dictates that:
If the digital pin 12 (which reads the PIR) reads HIGH, then Pin 7 and 8 (which operate the motor) will read HIGH and LOW respetively, so the motor works on speed 180, as read from pin 9.
Else, pin 7 will read LOW and the motor stops.
First, I prepared all the physical components.
Then I wired the Arduino to the breadboard, by wiring the 5V pin in the Arduino to the positive row in the breadboard and the GND pin in the Arduino to the negative row in the breadboard.
Then I started with wiring the IR sensor, the left node of the IR (OUT) is wired to the pin 12 in Arduino, then the left node (VCC) to the positive row in the breadboard and the middle node (GND) to the negative row in the breadboard. Now, the IR is operating with 5V from the Arduino, and sending signal to the digital pin 12 on Arduino.
On the other hand, the motor needs 9V, which the Arduino is not able to give. This is why I used L298N motor driver and wired it exactly as illustrated in the pictures.
This is the code as exported from Tinkercad. I copied it to Arduino IDE, compiled the code from the tick on the upper left corner, then uploaded it to the Aduino UNO from the right facing arrow also on the upper left corner after connecting it to the laptop.
Here's the working circuit!
It took me time and help from my instructor to figure out the power management in this circuit, from using motor driver to distributing and merging two voltage values. In this picture I thought I figured out the proper power management, then it turned out also messed up! Notice where the 5V pin from the Arduino and the positive of the power supply go, and compare to the previously shown correct wiring.
In Tinkercad, the output of the PIR gives opposing reading the physical IR sensor I have. This means, when the sensor detects something, on Tinkercad it gives HIGH but the physical IR sensor gives LOW. So, this had to be adjusted in the text. Also, the line "digitalRead(12) == HIGH;" was needles so we deleted it.