Real Life Applications - Engineering - ثاني ثانوي
1. Engineering Fundamentals
2. Electrical Engineering
3. Digital Circuits
4. Circuit Simulation with Tinkercad Circuits
5. Simulating a microcontroller- based system
Lesson 3 Real Life Applications Link to digital lesson www.ien.edu.sa There are two different types of potentiometers: the rotary potentiometer and the linear potentiometer. The rotary potentiometer is the one we have looked at and is the component available in Tinkercad Circuits. The linear potentiometer works with a sliding contact that can be moved along a path connected through the resistor. How a Potentiometer Varies the Voltage A potentiometer is a type of passive electronic device. Potentiometers operate by moving a sliding contact across a uniform resistance. The input voltage is applied across the entire length of the resistor in a potentiometer, and the output voltage is the voltage drop between the fixed and sliding contacts, which changes with the position of the sliding contact. The first project you will create in this lesson uses a potentiometer to regulate voltage. For this project you will use a micro:bit and the following components: • 1 Potentiometer Figure 5.34: Linear potentiometer • 1 LED • 1 1.5V Battery Components that you will use in this project وزارة التعليم Ministry of Education 2024-1446 0:0 2 3V GND B You can use a transistor in a circuit that controls components like motors that require a higher voltage to operate. AA 1.5V + 205
How a Potentiometer Varies the Voltage
Let's go and find the components that you will need for this project. Place a micro:bit, an LED light, a 1.5V battery and a potentiometer in the workplane. To add components: > Find the micro:bit in the components library, drag and drop it into the workplane and change its color to green. 1 > Find a 1.5 V Battery in the components library and drag and drop it into the workplane. 2 > Find the LED in the components library, drag and drop it into the workplane and rotate it so the pins point at the micro:bit. 3 4 > Find a Potentiometer in the components library, drag and drop it into the workplane and rotate it so the pins point towards the micro:bit. 5 وزارة التعليم Ministry of Education 206 2024-1446 3 5 40 B 3V GND AA 1.5V 1 + 2 Wiper Terminal 1 Terminal 2 Figure 5.35: The terminals on a potentiometer KA Code Start Simulation Send To > Components Basic Search Resistor LED 4 Pushbutton Potentiometer Capacitor Slideswitch 9V Battery Coin Cell 3V Battery 1.5V Battery Breadboard Small Figure 5.36: Add components
Add components:
وزارة التعليم Ministry of Education 2024-1446 Next, you will connect the pins of the potentiometer with the pins of the micro:bit. More specifically, you are going to connect: > the potentiometer Terminal 2 to the micro:bit GND. > the potentiometer Wiper to the PO pin of the micro:bit. > the potentiometer Terminal 1 to the 3V power source of the micro:bit. To connect the potentiometer to the micro:bit: > Connect the Potentiometer Terminal 2 to the micro:bit GND and change its color to black. 1 > Connect the Potentiometer Wiper to the micro:bit PO pin and change its color to green. 2 > Connect the Potentiometer Terminal 1 to the micro:bit 3V power source and change its color to red. II 0:1 |||||| 2 ||||||| 3V GND 2 B 1 3 + AA 1.5V Don't forget to bend the wires to have a neat circuit that is easy to read. Figure 5.37: Connect the potentiometer to the micro:bit 207
Connect the potentiometer to the micro:bit:
وزارة التعليم Ministry of Education 208 2024-1446 Now, you will make the connections for the 1.5V battery and the LED. To connect the 1.5V battery and the LED: > Connect the 1.5V Battery negative pin to the micro:bit GND and change its color to black. > Connect the 1.5V Battery positive pin to the cathode of the LED light and change its color to red. 2 > Connect the anode of the LED light to the micro:bit P2 pin and change its color to green. 3 0:1 3V 3 2 Figure 5.38: 1.5V Battery and LED connections GND AA 1.5V B + 1
1.5V battery and LED connections:
Write the code to program the microcontroller and start the simulation. AD Potentiometer 8: AA 1.5V 日 Simulator time: 00:00:23 All changes saved 0 K7 Code Stop Simulation Send To 1 def on forever () : basic.forever (on_forever) 1 (micro:bit) pins.analog_write_pin (AnalogPin. P2, pins.analog_read_pin (AnalogPin.PO)) Serial Monitor Figure 5.39: Test code Notice how the LED changes its brightness according to the voltage applied by the potentiometer. High resistance LED brightness low Low resistance LED brightness high وزارة التعليم Ministry of Education 2024-1446 209
Write the code to program the microcontroller and start the simulation.
وزارة التعليم Ministry of Education 210 2024-1446 . A Basic Transistor Circuit Transistors are required for digital circuits to function. Transistors are electronic components that are used in circuits to amplify or switch electrical signals or power, making them useful in a wide range of electronic devices. The NPN transistor has three terminals: Collector, Base and Emitter. In Tinkercad Circuits the base is called "Terminal 1". A large current can flow from Collector to Emitter, with a small current entering the Base. In this case, it acts like a current controlled switch. NPN circuits are used in digital logic circuits as extremely fast switches. In a later project you will design a circuit that combines a transistor, a potentiometer and a DC motor, but first you will implement a simple circuit to illustrate the basic connections of the NPN transistor. For this project you will use the following components: • 1 BJT-NPN Type Transistor • 1 Pushbutton • 1 LED 11.5V Battery 2 Resistors Components that you will use in this project AA 1.5V + N CBE 715
A Basic Transistor Circuit
وزارة التعليم Ministry of Education 2024-1446 First, you will add a 1.5V Battery and a Pushbutton to the workplane and connect the positive pin of the 1.5V Battery with Terminal 1b of the Pushbutton. To add and connect the 1.5V Battery and Pushbutton: > Find the 1.5V Battery in the components library and drag and drop it into the workplane. 1 > Find the Pushbutton in the components library and drag and drop it into the workplane. 3 > Connect the positive pin to Terminal 1b of the Pushbutton and change its color to red. 4 Terminal 1b Terminal 2b Terminal 1a Terminal 2a 3 4 AA 1.5V Figure 5.40: Pushbutton terminals All changes saved 非 Code Start Simulation Send To + 2 1 Figure 5.41: Add and connect the 1.5V Battery and Pushbutton Components Basic Search Resistor LED Pushbutton Potentiometer Capacitor Slideswitch 9V 211
Add and connect the 1.5V Battery and Pushbutton:
Then, you will add an LED to the workplane and connect its anode to Terminal 2b of the Pushbutton. To add the LED and make the connections: > Find the LED in the components library and drag and drop it into the workplane. 1 > Connect the anode of the LED to Terminal 2b of the Pushbutton. ② Continue by adding a resistor to the workplane. To add the first resistor and make the connections: > Find the Resistor in the components library, drag and drop it into the workplane and rotate it so the pins point horizontally. > Connect the cathode of the LED to one leg of the Resistor and change its color to green. 2 2 1 AA 1.5V + Figure 5.42: Add the LED and make the connections The resistors are used to reduce the current flowing through the circuit. وزارة التعليم Ministry of Education 212 2024-1446 AA 1.5V + Figure 5.43: Add the first resistor and make the connections 1 2
Add the LED and make the connections:
Add the first resistor and make the connections:
Now, you will add the transistor to the workplane and connect it with the second leg of the resistor. To add the transistor and make the connections: > Find the NPN Transistor in the components and drag and drop it into the library workplane. 2 > Connect the Collector of the NPN Transistor to the second leg of the Resistor. 3 Collector N CBE 215 Terminal 1 Figure 5.44: Transistor terminals Emitter All changes saved O 144 非 < Code Start Simulation Send To وزارة التعليم Ministry of Education 2024-1446 AA 1.5V + 3 N Components Basic 2 Search > 1 Micro Servo Hobby Gearmotor N CBE 715 NPN Transistor (BJT) Figure 5.45: Add the transistor and make the connections LED RGB w Diode Photoresistor 213
Add the transistor and make the connections:
Next, add the second resistor and connect Terminal 1 of the transistor to the positive pin of the battery via the second resistor. Finally, connect the emitter of the transistor to the negative pin of the battery. To add the second resistor and make the connections: > Find the Resistor in the components library and drag and drop it into the workplane. 1 > Connect Terminal 1 of the NPN Transistor to the second leg of the Resistor and change its color to red. ② > Connect the positive pin of the 1.5V Battery to the first leg of the Resistor. > Connect the negative pin of the 1.5V Battery to the emitter of the NPN Transistor and change its color to black. 4 وزارة التعليم Ministry of Education 214 2024-1446 AA 1.5V + 1 3 2 4 3 Figure 5.46: Add the second resistor and make the connections N
Add the second resistor and make the connections:
Start the simulation, and when you press the Pushbutton, the LED will light up. CON Transistor CAD وزارة التعليم Ministry of Education 2024-1446 t Simulator time: 00:00:27 Pushbutton LED off not pressed AA 1.5V Figure 5.47: Start the simulation Figure 5.48: LED states Pushbutton pressed LED on All changes saved STA Code 0 m Stop Segulation Send To 1 Basic Search Resor Capacitor Battery Coin Celv Battery 215
Start the simulation and when you press the Pushbutton, the LED will light up.
Build a DC Motor - Resistor Circuit In this project, we will combine elements of the previous projects to connect a potentiometer to a DC motor through a transistor and a resistor. We will also need a battery to supply power to the DC motor. We can use the micro:bit code from our earlier project because, as before, all we need to do is to write the input from the potentiometer at analog pin PO to analog pin P2. You can experiment with making changes to the circuit, for example changing the value of the resistor or switching the 2 AAA batteries connected to the circuit. Notice also how different resistor values affect the RPMs generated by the DC motor. This is the same circuit, but only the resistance values have changed from 100 km to 200 k. For this project you will use a micro:bit and the following components: • 1 Potentiometer • 1 BJT-NPN Type Transistor • 1 Resistor • 2 1.5V Batteries . 1 DC Motor Components that you will use in this project وزارة التعليم Ministry of Education 216 2024-1446 0:11 B 1 2 3V GND N CBE 719 Q You can use a transistor in a circuit that controls components like motors that require a higher voltage to operate. AAA 1.5V 2 x AAA + OFF ON AA 1.5V
Build a DC Motor – Resistor Circuit
Let's start by adding the components to the workplane. Take a potentiometer from the components library and place it on the workplane. Remember that a potentiometer has three ends, Terminal 1, the Wiper and Terminal 2, which need to be connected to the micro:bit. To add the potentiometer and make the connections: > Find the micro:bit in the components library, drag and drop it into the workplane and change its color to green. 1 > Find the Potentiometer in the components library, 2 drag and drop it into the workplane and rotate it so the pins point towards the micro:bit. 3 > Connect the Potentiometer Terminal 2 to the micro:bit GND and change its color to black. 4 > Connect the Potentiometer Wiper to the micro:bit PO pin and change its color to green. 5 > Connect the Potentiometer Terminal 1 to the micro:bit 3V power source and change its color to red. 6 وزارة التعليم Ministry of Education 2024-1446 3 UT 5 0:11 B 1 2 3V GND 6 4 Components Basic Search Resistor LED 1 Figure 5.49: Add the potentiometer and make the connections > Pushbutton Potentiometer Capacitor Slideswitch 9V Battery Coin Cell av Battery 1.5V Battery Breadboard Small micro:bit Arduino Uno R3 2 217
Add the potentiometer and make the connections:
Then you will place a battery on the workplane and use the inspector panel to change it. To create a two battery case: > Find the 1.5V Battery in the components library and drag and drop it into the workplane. ① > Use the Inspector panel. 2 > Change Count to 2 batteries. 3 > Change Type to AAA. 4 1.5V Battery Name 2 Count 1 battery Type AA Built-in Switch no وزارة التعليم Ministry of Education 218 2024-1446 > Change Built-in Switch to yes. 5 8: 2 3V GN GND 1 AA 1.5V Start Simulation Send To < Code Components Basic Search 9V Battery Coin Cell 3V Battery 1.5V Battery Breadboard Small micro:bit Arduino Uno R3 2 1.5V Battery Name 2 3 Count 2 batteries 4 Type AAA 5 Built-in Switch yes Built-in switch Figure 5.50: Create a two battery case AAA 15V 2xAAA + OFF ON A 1.5V
Create a two battery case:
Place an NPN Transistor into the workplane. The transistor will be used to transfer the amount of voltage that is applied by the potentiometer and regulate it using the resistor. The transistor has three ends. The collector will be connected to a battery power source, Terminal 1 will be connected via the resistor to the micro:bit pin P2, which will take as input the voltage applied by the potentiometer to the pin PO, and the emitter will transfer the voltage to the DC motor. To add the transistor and the resistor: > Find the NPN Transistor in the components library, drag and drop it into the workplane and rotate it so the pins point towards the micro:bit. ① > Find the Resistor in the components library and drag and drop it into the workpane to connect one leg of the resistor to Terminal 1 of the transistor. > Connect the open end of the resistor to pin P2 of the micro:bit and change the wire color to green. 3 وزارة التعليم Ministry of Education 2024-1446 :0 3 Basic Search micro:bit Arduino Uno R3 GND Vibretion Motor DC Motor 1 N 2 AAA 1.5V 2 x AAA OFF ON 415V Figure 5.51: Add the transistor and the resistor Micro Servo Hobby Gearmotor NPN Transistor (BJT) LED ROB Dioow Photoresistor Soil Moisture Sensor Ultrasonic Distance Sensor PIR Sensor Piezo TMP 125.0 mA 715 Temperature Sensor TMP36 Multimeter 219
Add the transistor and the resistor:
Now, you will add a DC motor to the workplane and connect Terminal 2 to the transistor emitter and Terminal 1 to the micro:bit GND. To add the DC motor and make the connections: > Find the DC Motor in the components library, 1 drag and drop it into the workplane and rotate it so the pins point towards the transistor. 2 > Connect Terminal 1 of the DC Motor to the micro:bit GND and change the wire color to black. 3 > Connect Terminal 2 of the DC Motor to the Emitter of the transistor and change the wire color to green. 4 2 وزارة التعليم Ministry of Education 220 2024-1446 44 :0 3V 4 Terminal 1 Terminal 2 Figure 5.52: The terminals of a DC motor K Code Start Simulation Send To Components Basic Search 1 Vibration Motor DC Motor GND 3 N AAA 15V 2x AAA OFF ON 1.5V Micro Servo Hobby Gearmotor > N Figure 5.53: Add the DC motor and make the connections NPN Transistor (BJT) LED RGB w Diode Photoresistor
Add the DC motor and make the connections:
Next, you will add the battery to the workplane, connect its negative pin to the micro:bit ground and connect its positive pin to the transistor collector pin. To connect the battery: > Connect the negative pin of the Battery case to micro:bit GND and change the wire color to black. 1 > Connect the positive pin of the Battery case to the Collector pin of the transistor and change the wire color to red. 2 وزارة التعليم Ministry of Education 2024-1446 II B 3V GN GND N Figure 5.54: Connect the battery 2 1 AAA 1.5V 2 x AAA + OFF ON A 15V 221
Connect the battery:
وزارة التعليم Ministry of Education 222 2024-1446 DC Motor AD Finally, write the code below and start the simulation. 0:. 2xAAA OFF ON Simulator time: 00:00:41 All changes saved 0 K7 Code Stop Simulation Send To 1 (micro:bit) : def on forever (): 2 pins.analog_write_pin (AnalogPin. P2, pins.analog_read pin (AnalogPin.PO)) basic. forever (on_forever) Figure 5.55: Test code def on forever(): pins. analog_write_pin (Analog Pin. P2, pins.analog_read_pin (Analog Pin.PO)) basic.forever (on_forever) Notice how the DC Motor rotates when the voltage applied is adjusted by the potentiometer. 4865 rpm 1859 rpm Figure 5.56: Adjusting voltage with the potentiometer 119 rpm
Finally, write the code below and start the simulation.
Exercises 1 What is a linear potentiometer? What is the main difference between a linear and a rotary potentiometer? 2 Find the most common example of a device with linear potentiometers. Why do you think we use this type of potentiometer for this device? وزارة التعليم Ministry of Education 2024-1446 223
What is a linear potentiometer?
Find the most common example of a device with linear potentiometers. Why do you think we use this type of potentiometer for this device?
وزارة التعليم Ministry of Education 224 2024-1446 3 Examine the following circuit and its code carefully and find the problem. What do you need to do to fix it? def on_forever (): pins.analog_write_pin (Analog Pin. Pl, pins. analog_read_pin (Analog Pin. P0)) basic. forever (on_forever) P 0: 3V GND AAA 1.5V N 2x AAA OFF ON
What do you need to do to fix it?
4 In the previous circuit, why do we use the functions pins. analog_write_pin and pins. analog_read_pin instead of pins.digital_write_pin and pins.digital_read_pin? 5 How are NPN transistors used in an electronic circuit? Describe how the NPN transistor works. وزارة التعليم Ministry of Education 2024-1446 225
why do we use the functions pins.analog_write_pin
How are NPN transistors used in an electronic circuit?
6 In the last project of the lesson, change the resistor value to 100k and then to 200k 2. How does this change affect the DC Motor? وزارة التعليم Ministry of Education 2024-1446 Resistor Resistor Name 1 Name 1 Resistance 100 ΚΩ Resistance 200 kQ ▼ :0 3V GND AAA 1.5V N 2 x AAA OFF ON