Design Workshop
Design Workshop
Dr. Mahendra B M
School of Computational & Data Sciences.
Mail: [email protected]
Course Plan
3
4
5
6
7
8
9
Let us understand Microcontroller and its Architecture
10
What all you must know about VU Building to do so
11
What all you must know to use Arduino Uno effectively
12
Programming for automation
The ability to work with language, and the potential to save human effort through
automation.
13
Experiment Number-1.a
Arduino program to implement LED blinking and Scrolling, to glow even/odd
LED and to simulate using tinkerCAD.
Let's breakdown the problem into small sections.
a. LED→Blinking
b. LED→Scrolling
c. LED→Glow Even/Odd
d. Arduino→Program
e. TinkerCAD
14
LED
What is LED?
15
Do you have LEDs with you?
If No, then use Tinkercad; a free web app for 3D design, electronics, and coding.
16
Task-1
1. Can you identify how many color and type of LEDs are available in
TinkerCAD?
2. Can you bring Green LED on to works Space?
3. Can you identify their structure and polarities?
17
Light up the LED
18
Task-2
1. Are you ready with your TinkerCad login?
If Yes
19
Let us learn how to make connections:
20
Task-3
1. Do you know how to simulate the circuit?
2. Can you change the value of the resistor to Zero-Ohms and check the status
of LED?
3. Can you change the value of the resistor to 1 Giga-Ohms and check the
status of LED?
4. What is the difference you noticed from point 2&3?
5. Did you understand the importance of resistor in the given circuit?
6. Did you find any programmable components in the circuite?
7. Is the LED glowing or blinking?
21
Make LED On and Off
Do you plug and unplug the wire/LED to make LED On & Off?
22
If No: If Yes:
23
Use Switches
24
Task-4
1. Identify those switches and bring Slideswitch on to the workspace.
2. Move your cursor on to the each of three terminals and name it?
3. Do you Know how to use the three terminal Slideswitch to switch On/Off the
LED?
4. If NO, do trial and error method.
25
Did You get it?
If No, Try this.
Or
26
Task-5
1. Can you switch ON and switch OFF the LED every 10 Second for 2 times?
27
Task-6
Can you switch ON and Switch OFF the LED every second Continuously?
28
Think if you can automate the LED Switching process?
29
Here Microcontroller and Programming Comes.
Do you know what is microcontroller?
30
How to find the value of the resistor
31
Some more
32
Let us automate the LED switching/blinking process
With LED and Resistor, we need Microcontroller and Programming Knowledge.
Hope you have all the bellow components with you on TinkerCAD
33
Replace the Battery and Switch by programmed Microcontroller
34
Is the circuit works? I mean LED blinks?
Noooooooooo.
Because we haven't told microcontroller to what to do. We just interconnected and
powered up the microcontroller.
Let us tell the microcontroller to ON the LED for a second and OFF for a second
and repeat infinitely.
How do you talk to microcontroller?
Through Programming. Embedded-C Programming language
35
What is Embedded-C Programming
● In Simple words, it is modified C to program Microcontrollers (Embedded
Systems).
● Embedded System is the combination of hardware and software, designed to
perform very specific functions or tasks. Ex: Washing Machine.
36
Basic Structure of Arduino Programming
Refer: https://docs.arduino.cc/learn/starting-guide/getting-started-arduino/
Note: TinkerCAD doesn't have its own programming structure. It uses same as
Arduino IDE.
37
Lets learn what to put where in the code?
38
//Initialize the pins as INPUT/OUTPUT
INPUT: It means what you send into Microcontroller through its port PINS.
OUTPUT: It means what microcontroller send out through its port PINS.
Pin:- Mention the pin number which one you want to access as input or output.
39
Task-7
1. Can you identify which pins we are used to connect LED?
2. Can you say the pin used must be configured as INPUT or OUTPUT and
why?
3. If you know the answers for the first two questions, can you fill the following
line of code based on the requirements of LED Blinking Project?
pinMode(______, ______);
40
//Make LED ON for 1 Second
Let's split the task into two separate tasks.
Switch ON: It means, send High Voltage (5V/1/High) through the pin where LED is
connected to.
Wait: It means, wait or keep sending 5V to the LED through the pin where it is
connected to.
41
Syntax to Switch ON and Wait
digitalWrite(pin, Voltage Level);
digitalWrite:-It is a function which sets the pin as HIGH or LOW. (Technically
Writing Digital value 1 to the pin)
Pin:- Mention the pin number which one you want to send HIGH voltage or LOW
voltage.
Voltage Level:- Set the voltage level as HIGH to Glow LED else set LOW to OFF
the LED.
Note: We will digitalRead(); later.
42
Task-8
Fill the blanks to do the following:
digitalWrite(______, ______);
digitalWrite(______, ______);
43
Insert a DELAY of 1 Second.
There is an inbuilt function to generate the specific delay in programming Arduino
Uno. i.e.
delay(x);
x can be
44
Task-9
Fill the value of x to get the 10 Seconds delay
delay(______);
45
Task-10
46
It's time to copy the same code on TinkerCAD to Blink LED
DIY
47
It's time to Jump to Hardware and Get Hands on Experience.
48
Task-11
Make Group of 2 (Total 15 Groups)
List the components required to conduct the experiment simulated in tiker CAD
and collect the same from Mr. Chethan.
Write the steps to be followed (Keep it in mind that the circuit may blown if you
don't follow the proper steps)
49
Experiment Number-1.b
Arduino program to implement LED Scrolling and to simulate using
tinkerCAD.
50
Task
1. Can you identify which digital pins are used to control 6 LED’s?
2. Have you understood the placement of LED’s and Resistors on breadboard?
3. Is all the resistors connected to same ground?
4. Can you place the components same as mentioned in the photo?
5. Can you convert the hardware implementation into program? If yes, write the
algorithm first.
51
Code Structure
52
Lets go further
53
The executable code
54
DIY: Can you write a code to glow blink the ODD/EVEN LED’s?
55
Traffic Light Controller: 4 Way
56
Task-12
List the Components and its Quantity required to implement the 4-Way Traffic
Signal.
(Don't Miss anything, Can't go to market again and again or pay high online)
57
Step1: Assign the traffic lights pins to variables
If we use only the pin numbers directly, we may forget or confuse with positions of
lights. So it is better to name them using variables.
Select the readable names and available IO Pin numbers in Arduino bo.
58
Task 13
1. Chose the name and assign the pin number
● Example: East_G oe E_G=2, E_R=3, E_Y=4
2. In Embedded C, Syntax to assign variables to IO Pin is
Int E_G = 2;
59
Step2: Configure the Pins to INPUT/OUTPUT
It is necessary to assign the pins as OUTPUT/INPUT based on our application.
We can set the pin as OUTPUT using the function format as follows
pinMode(pin, OUTPUT)
60
Task-14
Write a code to assign the selected pins as INPUT/OUTPUT based on the requirements.
Hint:
pinMode(2, OUTPUT)
pinMode(pin, OUTPUT)
pinMode(4, OUTPUT)
.
.
.
pinMode(pin, OUTPUT)
61
Step-4: First Let all Yellow lights let Glow to start the day.
I will give u a hint, rest you fill
digitalWrite(E_Y,HIGH);
digitalWrite(_____,______);
digitalWrite(_____,______);
digitalWrite(_____,______);
62
Step-5: Let the East way allow the vehicles first
Make the East_Green LED glow to allow vehicles, before that make East_Yellow
LED go OFF and all other direction Red LED Glow On.
63
Step-6: Now allow vehicles in North direction.
You know that vehicles moving in East direction cannot stop and allow the
vehicles in North direction immediately.
Hope you have understood what you must do before Red signal in East and
Green signal in North direction.
If you have understood this, write the part of code to do the same. Take this as
Task-16.
64
Step-7: Continue the procedure for West Direction.
In East Direction: RED→ON, G,Y→OFF
Take it as Task-17
65
Step-8: Continue the procedure for South Direction.
You know what to do. Take it as Task- 18
66
Step-9: Repeat the procedure infinitely.
It's time to stitch the code pieces and make it runnable.
NO.. Design a Circuit in TinkerCAD and paste the code and run.
67
Is the 4-way traffic signal is working fine?
If Yes, its fine,
68
A BIG Task is HERE:
Optimise the code.
It means Shorten the code, Fasten the code, Make the Traffic Signal more
Smarter and Intelligent.
69
Project 2
Arduino program to demonstrate usage of push button to control the LED and to
simulate using tinkerCAD.
70
Push Button or Momentary Switch
● When the button is pressed, the
spring mechanism compresses,
allowing the contacts to come into
contact with each other and complete
the electrical circuit.
71
Tinker the following
Explore the Contacts which are internally connected and not connected.
72
Let make use of the push button for the more practical requirements.
73
Project-3
Arduino program to demonstrate usage of potentiometer with LED’s and to
simulate using TinkerCAD
74
Potentiometer
75
Task-19
1. Search for potentiometer in TinkerCAD, bring it to workspace.
2. Identify and mention the three terminals of potentiometer.
3. What is the minimum and maximum range of potentiometer resistance is
available in tinkerCAD?
76
Let us understand what is analog and digital signal.
77
Let us see what kind of output a potentiometer produce
Rigup the following circuit and vary the potentiometer wiper position, note down
the values of Voltage for Minimum and Maximum Values of potentiometer.
Notice whether the output values are continuous wrt time or discrete.
78
Task-20
1. Is the signal from potentiometer is continuous or discrete?
79
What is the difference between analog & digital pins?
80
Decode the Behaviour of Analog Pins by Coding. Task-21
1. Is Arduino Uno is digital Device or analog Device?
Ans:___________
2. What about Potentiometer?
Ans:___________
3. Is both Arduino and Potentiometer is compatible wrt to type of signals used?
Ans:___________
4. If not compatible, which is making both compatible to each other?
Ans:___________
81
Before Diving into the code, Lets learn how read/write analog data
82
Here is the coding exercise for you:
Step1: Take Potentiometer of 1k-Ohms.
Step2: Take Arduino Uno
Step3: Connect Potentiometer to Arduino.
Step4: Display the Potentiometer values read by analog pins on serial monitor.
Step5: Note down the values displayed on serial monitor for Minimum and Maximum
potentiometer value (0V-5V).
Step6: Repeat for different positions of potentiometer and note down the values.
Task: What is the relationship b/w voltage varying by potentiometer and values displaying
on serial monitor?
83
Complete the circuit and note down all the pins used for
programming in the next slide
84
Task-22: Complete the code:
// initialise the sensor value to zero in the beginning
void setup() {
Serial.begin(9600);// initialize serial communication at 9600 bits per second:
pinMode(________, _______);// Initialise the analog pin as input
}
void loop() {
int sensorValue = analogRead(_____);// read the input on analog pin 0:
Serial.println(sensorValue);// print out the value you read:
__________ // 10 Sec delay in between reads for stability
} 85
Have you completed the code?
1. If yes, what is the output displaying on the serial monitor?
2. Is it a Voltage between 0 to 5 Volts or a Digital value between 0 to 1023?
86
Yesssssssss, You did it.
Hope you will say Yes to the following
87
Lets control the brightness of the LED based on the value
of the potentiometer
Remember: Brightness of the LED = Strength of the Voltage Applied
Strength of the Voltage Applied = Value of the resistance
Increase in resistance→Increase in Voltage→Increase in Brightness
&
Vice-versa
All the above is because of
Ohm's Law
V=IXR
88
Task-23
1. Interface LED with Arduino Uno
(To Any Digital i/o Pin)
2. Interface Potentiometer with
Arduino Uno (To Any Analog i/o
Pin)
3. Write a code considering the pin
numbers used above.
4. Check the brightness of LED
based the position of the
potentiometer wiper.
89
Here is the code
Why it is analogWrite(), instead
digitalWrite()?
90
Where we can we use this knowledge:
Assume Potentiometer as any Sensors like Ultrasonic, Touch Sensor, Load Cell,
Heartbeat Sensor, Rain detecting sensor, Moisture Sensor, Presion Senor, IR
Sensor and many More.
Assume the LED as any Actuators devices like LCD, Seven Segment Display,
Motors and many more.
The Knowledge what you have learned is applicable to all the above.
Hope you can implement a projects by combining sensors and actuators with
Arduino UNO
91
Project-4
Arduino program to demonstrate usage of potentiometer to control the speed of
servo motor and to simulate using TinkerCAD
92
Servo Motor
93
Applications of Servo Motors
94
Task:24 How it Works:
This is a task for you.
95
Try this code to rotate the Servo Motor
#include <Servo.h>
Servo servoMotor;
void setup()
{
servoMotor.attach(9); // Attach the servo to pin 9 }
void loop()
{
servoMotor.write(90); // Move the servo to 90 degrees
delay(1000); // Wait for 1 second
servoMotor.write(0); // Move the servo back to 0 degrees
delay(1000); // Wait for 1 second
}
96
Project-4
Interfacing servo motor with potentiometer and to simulate using TinkerCAD
97
Implement the following
Perform the following rotation pattern by servo motor in printer application.
It must increase 10 Degree every time (8 Steps). I.e. each 10 Degree rotation
prints next line.
Once it prints 8 lines, the printer takes new page and servo must go back to initial
line.
98
Project-5
Interface 7-Segment Display and Arduino Uno to display the numbers from 0
to 9 and vice versa.
99
7-Segment Display
1. A 7-segment display is used in electronic devices to display decimal numbers
(0-9) and basic characters.
2. LEDs were traditionally used in these displays, but LCDs are now also
common.
3. Applications include devices like microwaves, calculators, washing machines,
radios, and digital clocks.
4. Understanding the pinout of the 7-segment display is important for its effective
use.
100
Understanding the pinout of the 7-segment display
A seven-segment display is made of seven different illuminating segments.
101
Seven Segment Display Types
There are basically 2 types of seven-segment LED displays:
102
Interfacing Diagram for Common Cathode (CC)
103
Task for you
104
Display numbers on a 7-segment display in common cathode configuration
105
Task for you
106
void setup() {
// Set all segment pins as output
Programming 7-Segment Display (CC) pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
Let's learn the things in bits and pieces: pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
Task 1: Display all the segments for ever. pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
}
void loop() {
// Turn on all segments
digitalWrite(2, HIGH);
digitalWrite(3, HIGH);
digitalWrite(4, HIGH);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, HIGH);
digitalWrite(8, HIGH);
}
107
Tinkering the 7-Segment
● All segments have glown, but
why it is blown?
● Anything we missed?
● If got it, rectify it.
108
Use resistors and dont try to imitate my circuit. Rig up your own
109
Try to display each digit at a time on the 7-Segment
Display
110
Display each digit one after the other (0 to 9) continuously
on the 7-Segment Display:
111
void setup() { // Display ONE on 7-Seg Display // Display THREE on 7-Seg Display
// Initialize all the port pins as output digitalWrite(2, LOW); // A digitalWrite(2, HIGH); // A
pinMode(2, OUTPUT); // Segment A digitalWrite(3, HIGH); // B digitalWrite(3, HIGH); // B
pinMode(3, OUTPUT); // Segment B digitalWrite(4, HIGH); // C digitalWrite(4, HIGH); // C
pinMode(4, OUTPUT); // Segment C digitalWrite(5, LOW); // D digitalWrite(5, HIGH); // D
pinMode(5, OUTPUT); // Segment D digitalWrite(6, LOW); // E digitalWrite(6, LOW); // E
pinMode(6, OUTPUT); // Segment E digitalWrite(7, LOW); // F digitalWrite(7, LOW); // F
pinMode(7, OUTPUT); // Segment F digitalWrite(8, LOW); // G digitalWrite(8, HIGH); // G
pinMode(8, OUTPUT); // Segment G delay(1000); delay(1000);
}
112
// Display SEVEN on 7-Seg Display
// Display FIVE on 7-Seg Display
digitalWrite(2, HIGH); // A
digitalWrite(2, HIGH); // A
digitalWrite(3, HIGH); // B
digitalWrite(3, LOW); // B
digitalWrite(4, HIGH); // C
digitalWrite(4, HIGH); // C
digitalWrite(5, LOW); // D
digitalWrite(5, HIGH); // D
digitalWrite(6, LOW); // E
digitalWrite(6, LOW); // E // Display NINE on 7-Seg Display
digitalWrite(7, LOW); // F
digitalWrite(7, HIGH); // F digitalWrite(2, HIGH); // A
digitalWrite(8, LOW); // G
digitalWrite(8, HIGH); // G digitalWrite(3, HIGH); // B
delay(1000);
delay(1000); digitalWrite(4, HIGH); // C
digitalWrite(5, HIGH); // D
// Display EIGHT on 7-Seg Display
// Display SIX on 7-Seg Display digitalWrite(6, LOW); // E
digitalWrite(2, HIGH); // A
digitalWrite(2, HIGH); // A digitalWrite(7, HIGH); // F
digitalWrite(3, HIGH); // B
digitalWrite(3, LOW); // B digitalWrite(8, HIGH); // G
digitalWrite(4, HIGH); // C
digitalWrite(4, HIGH); // C delay(1000);
digitalWrite(5, HIGH); // D
digitalWrite(5, HIGH); // D }
digitalWrite(6, HIGH); // E
digitalWrite(6, HIGH); // E
digitalWrite(7, HIGH); // F
digitalWrite(7, HIGH); // F
digitalWrite(8, HIGH); // G
digitalWrite(8, HIGH); // G
delay(1000);
delay(1000);
113
Try to optimise the previous code
114
Task for you
Assume your potentiometer is connected to a DC fan and you want to display the
fan speed as
1. Pot value (0)= Display 0 on 7-Seg Display and Glow White LED
2. Pot value (1 to 250)= Display 1 on 7-Seg Display
3. Pot value (251 to 500)= Display 2 on 7-Seg Display and glow Green LED
4. Pot value (501 to 750)= Display 3 on 7-Seg Display
5. Pot value (751 to 1023)= Display 4 on 7-Seg Display and Glow Red LED
115
Not able to understand the code in the previous slide?
Reason is we haven't learnt coding still (But some extent we did).
116
Introduction to Arduino Programming
Conducted in dedicated Course
117
Project-6
Arduino program to implement soil moisture detector and to simulate using
tinkerCAD.
118
Soil moisture sensor/detector
The soil moisture sensor is one kind of sensor used to gauge the volumetric
content of water within the soil.
119
Soil Moisture Sensor Pin Configuration
The FC-28 soil moisture sensor includes 4-pins.
120
How Does a Soil Moisture Sensor Work?
The fork-shaped probe with two exposed conductors
acts as a variable resistor (similar to a potentiometer)
whose resistance varies with the soil’s moisture
content.
This resistance varies inversely with soil moisture:
● The more water in the soil, the better the
conductivity and the lower the resistance.
● The less water in the soil, the lower the
conductivity and thus the higher the resistance.
The sensor produces an output voltage according to
the resistance, which by measuring we can determine
the soil moisture level.
121
What AO and DO (Analog & Digital Output Pin’s) do?
The module generates an output voltage based on the resistance of the probe,
which is available at an Analog Output (AO) pin.
The same signal is fed to an LM393 High Precision Comparator, which digitizes
it and makes it available at a Digital Output (DO) pin.
122
What potentiometer do?
The module includes a potentiometer for adjusting the sensitivity of the digital
output (DO).
it set a threshold, so that when the soil moisture level exceeds the threshold, the
module outputs LOW otherwise HIGH.
This setup is very useful for triggering an action when a certain threshold is
reached.
For example, if the moisture level in the soil exceeds a certain threshold, you can
activate a relay to start watering the plant.
123
What LED’s Do?
The module also includes two LEDs.
The Power LED illuminates when the module is turned on, and the Status LED
illuminates when the soil moisture level exceeds the threshold value.
124
Interfacing Diagram
125
Measure soil moisture using Arduino Uno
The analog output of soil moisture sensor is processed using ADC. The moisture
content in terms of percentage is displayed on the serial monitor.
The output of the soil moisture sensor changes in the range of ADC value from 0
to 1023 (May vary based on the input voltage, 9v-1023, 5v-876, 3.3v-523).
For zero moisture, we get maximum value of 10-bit ADC, i.e. 1023. This, in turn,
gives 0% moisture
126
Task25: Implementation
127
Task26: Implement the following
Use Soil Moisture sensor to check the moisture level in three stages
Assume Servo motor is connected to Tap, If RED LED glows, turn the servo by
90-Degree, stay for 10 seconds.
Close the TAP by rotating -90 degree once the Green LED on.
128
Project
Arduino program to control spinning direction and speed of DC motor and to
simulate using tinkerCAD.
129
DC Motor
A direct current, or DC motors normally have two leads, one positive and one
negative (Vice-Versa).
If you connect these two leads directly to a battery, the motor will rotate.
If you switch the leads, the motor will rotate in the opposite direction.
130
Lets Run the Motor in Clockwise direction
void setup()
pinMode(2, OUTPUT);
void loop()
}
131
Lets Run the Motor in Anticlockwise direction
void setup()
pinMode(2, OUTPUT);
void loop()
134
Use Slide Switch to change the polarities
135
Code to run the motor in both the direction using switch
void setup() void loop()
{ {
pinMode(2, OUTPUT); digitalWrite(2, HIGH);//Rotate the motor for 1 second
pinMode(3, OUTPUT); digitalWrite(3, HIGH);
} delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(2, LOW);//Stop the motor for 1 second
digitalWrite(3, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
136
Automate the direction of the spin of DC motor
How can we control the direction of the spin of DC motor by programming?
H Bridge
137
What is H-Bridge?
To control the direction of the spin of DC motor,
without changing the way that the leads are
connected, you can use a circuit called an
H-Bridge.
An H bridge is an electronic circuit that can drive
the motor in both directions. H-bridges are used
in many different applications, one of the most
common being to control motors in robots.
It is called an H-bridge because it uses four
transistors connected in such a way that the
schematic diagram looks like an "H." The switching elements (Q1..Q4) are
usually bi-polar or FET transistors
138
Construction & Working of H-Bridge
139
Off the Shelf Component: L298N H Bridge
140
Let us work with L298N/L293D Motor driver
141
Know the difference between L298N & L293D
The L293D and L298N are both motor drivers, but
they have some key differences, including:
Voltage:The L293D operates at 4.5–36 V, while
the L298N can handle up to 46 V.
Current:The L293D can handle up to 600 mA per
channel, while the L298N can handle up to 2 A per
channel.
Applications:The L293D is suitable for lower
current motors, while the L298N is ideal for
high-torque and high-RPM motors.
142
Note
This module is not available in TinkerCad hence we use L293D IC instead of the
module and it will be explained in the subsequent slides.
143
Changing spinning direction of the motor
The spinning direction of the motor can be controlled by applying logic HIGH or
logic LOW to IN1/IN2 (motor A) and IN3/IN4 (motor B) inputs as shown on table.
144
Interface 5V DC Motor to arduino & control the direction of
the motor using L293D Motor driver in Tinkercad.
145
146
Try connect two motor and change the spinning direction
DIY
147
Speed Controlling using L293D Motor Driver
Till now we learnt to change the direction of the rotation of DC Motor. Now let us
learn to control the speed of DC motor using the same L298D motor driver.
Basically the speed of the DC motor is implemented based on the technique called
Pulse Width Modulation (PWM).
Let us understand how PWM Techniques can control the speed of DC motor.
148
Traditional Method to control the speed of the DC Motor
We control the flow of current through the motor. Well
many people attempt to control the speed of a DC motor
using a large variable resistor (Rheostat) in series with the
motor as shown.
It generates a lot of heat and wasted power in the
resistance.
One simple and easy way to control the speed of a motor
is to regulate the amount of voltage across its terminals
and this can be achieved using “Pulse Width Modulation”
or PWM.
149
Regulate the amount of voltage across its terminals and this can
be achieved using “Pulse Width Modulation” or PWM.
151
How to set different duty cycles in arduino programming?
The Arduino's programming language makes PWM easy to use; simply call
analogWrite(pin, dutyCycle)
where dutyCycle is a value from 0 to 255, and pin is one of the PWM pins (3, 5,
6, 9, 10, or 11).
152
Hope you remember the following line:
analogWrite(enA, 255);
Can you relate the above line of code to the line from the previous slide?
analogWrite(pin, dutyCycle);
Generate the following Duty Cycles: 10%, 22%, 56% & 77%
153
Identify the difference in this code compared to previous one
154
Let us implement it on hardware
The pin design of L293D may vary from one to another based on the
manufacturer. Care must be taken while using your own driver. The below figure is
just for your reference.
155
Project: Interface LCD (I2C) to Arduino Uno
Your task is to interface a 16x2 LCD (Liquid Crystal Display) with an I2C
(Inter-Integrated Circuit) module to the Arduino Uno board. The LCD should
display "Hello, World!".
● Brief explanation of how the I2C protocol works and why it simplifies LCD
interfacing.
● Interface LCD with Arduino Uno.
● Write the code to display "Hello, World!" on the first line of the LCD.
156
I2C Protocol (Inter-Integrated Circuit):
The I2C protocol is a two-wire communication system commonly used to connect
low-speed devices like sensors, displays, and microcontrollers. It uses only two
lines for communication:
157
SDA & SCL
In I2C, one device acts as a master (usually the Arduino in most setups), and the
others are slaves (e.g., an LCD or sensors).
The master controls the communication by sending clock signals on the SCL line
and sending or receiving data on the SDA line.
Each device connected to the I2C bus has a unique address, allowing the master
to communicate with specific devices independently.
158
Why I2C Simplifies LCD Interfacing:
Traditional LCDs require multiple pins for data and control lines (around 6–8 pins).
However, by using an I2C interface module, the LCD can be controlled with just
two pins (SDA and SCL), significantly reducing the wiring complexity and saving
space on the microcontroller.
159
Can you see SDA and SCL on UNO board?
160
16X2 LCD with I2C enabled.
161
Interface the LCD to Arduino Uno
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);// Set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
162
Take care of the following while interfacing LCD
1. If the header files are missing, install them.
2. If the LCD backlight is not working, vary the potentiometer attached to LCD.
163
Project
Interface Ultrasonic Sensor to detect the obstacle:
164
Construction and working principles of Ultrasonic Sensor
165
166
Pin Configuration of Ultrasonic Sensor
167
The working principle of this module is simple.
● It sends an ultrasonic pulse out at 40 kHz,
which travels through the air, and if there
is an obstacle or object, it will bounce
back to the sensor.
● By calculating the travel time and the
speed of sound, the distance can be
calculated.
● We divide the distance formula by 2
because the sound waves travel a round
trip i.e from the sensor and back to the
sensor which doubles the actual distance.
168
Understanding through animation
https://circuitdigest.com/microcontroller-projects/interface-arduino-with-ultrasonic-s
ensor
169
Interfacing Ultrasonic Sensor with Uno
170
Some formulas to remember and convert into standards
To calculate the distance we will use the following formula:
Now we know the speed of sound is 343.2 m/s. To calculate the distance we need
to convert the speed of sound to cm/us which will be 0.03432 cm/uS, and let the
time value received from the ultrasonic sensor which is 500 uS.
171
Can we convert the previous explanation into program?
void loop() {
float duration; digitalWrite(4, LOW);
And
173
Project
Interface Hex Keypad with Arduino Uno to read the each number and display on
serial motor.
174
Hex Keypad or 4x4 Keypad: (Hex=16)
175
Connect Hex Keypad with Uno
176
177
#include <Keypad.h>//Keypad Library void setup(){
Serial.begin(9600);
const byte ROWS = 4; //the four rows of the keypad }
const byte COLS = 4; //the four columns of the keypad
void loop(){
char keys[ROWS][COLS] = { char key = keypad.getKey();// Read the key
{'1','2','3','A'},
{'4','5','6','B'}, // Print the key if pressed
{'7','8','9','C'}, if (key){
Serial.print("Key Pressed : ");
{'*','0','#','D'}
Serial.println(key);
};
}
}
byte rowPins[ROWS] = {9, 8, 7, 6}; //to connect to the row pins of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //to connect to the column pins of the keypad
178
Some of the projects you can implement
1. Calculator
2. Password based locking and unlock
3. ATM
Many More
179
Project
Interface Smoke detector with Arduino Uno to detect smoke and make alarm using
Piezo Buzzer.
180
Smoke Detector (MQ-2 Gas Sensor):
181
Different Gas Sensors
182
Working principle of MQ Series Gas sensor
● The MQ-series of gas sensors use a small heater inside with an
electro-chemical sensor.
● They are sensitive for a range of gasses and are used indoors at room
temperature.
● The output is an analog signal and can be read with an analog input of the
Arduino.
● The MQ-2 Gas Sensor module is useful for gas leakage detecting in home
and industry.
● It can detect LPG, i-butane, propane, methane ,alcohol, hydrogen and smoke.
● Some modules have a built-in variable resistor to adjust the sensitivity of the
sensor.
183
Interfacing Diagram in Tinkercad
184
Hardware Interfacing Diagram
185
Design an Automatic LPG Gas leakage alarm system
Use suitable Gas Sensor to detect the LPG Gas leakage at home and alarm the
user through LCD, Buzzer and LED’s.
186
187
3D Modelling & Printing
Modelling using TinkerCad
&
Printing using 3D printing Machine
Learn 3D Design using TinkerCad
Follow the tutorials link to learn more about 3D Designing:
https://www.tinkercad.com/learn/designs
189
190
3D Printing using Cura
What is Cura?
Ultimaker Cura Slicer is a free, open-source slicing software that allows you to
prepare 3D models for printing.
It’s a powerful tool that lets you customize your print settings, optimize your
models for your specific printer, and preview your prints before sending them to
your 3D printer.
Cura slicer software is easy to use. While the software has many settings, the
interface is user-friendly and easy to navigate.
191
Download CURA for free
Click the link below
https://ultimaker.com/software/ultimaker-cura/#downloads
192
UltiMaker Cura system requirements
UltiMaker Cura is a lightweight application that runs on low-end systems.
The amount of RAM memory, CPU (Central Processing Unit), and GPU (Graphical
Processor Unit) necessary heavily depends on the file size of the loaded 3D
models.
Minimum system requirements
OpenGL 2 compatible graphics card, OpenGL 4.1 for 3D layer view
● Display resolution 1024 x 768
● Intel Core 2 or AMD Athlon 64
● 550 MB available hard disk space
● 4GB RAM memory
193
Before You Open the Cura Software
Set It Up and Hit Print… Wrong
One of the biggest misconceptions about 3D printing is that you can simply load
your model file up in Cura (or another slicer) and hit print. Unfortunately, that’s not
how it works.
First, you will need to learn how to optimize the settings for your printer and the
material you plan to use for your 3D print.
194
Start with Simple Print Models
To avoid frustration (and a failed print), I highly recommend starting off with simple
and less complex models. Once you get comfortable with the software and
understand how the settings work, then you can move on to 3D print more
complex models.
195
Think of these 3D Models
196
The Importance of Using a 3D Slicer
A 3D slicer is a software that converts your 3D model into a series of 2D layers
that your printer can recognize and understand.
197
What is G-Code?
G-Code is the language created by the slicer, in this case, Cura, and acts as a set
of instructions that tells your 3D printer how to create and build the 3D model.
Your printer uses these instructions to understand how to move and extrude the
filament.
The 3D slicer generates this code based on the settings you choose, and it’s sent
to the printer to create your object.
198
How G-Code looks like
This is a very basic explanation of G-Code but there are many other resources to
dive deeper into the more complex nuances such as understanding the basic
syntax, functionality, and commands
199
Ultimaker Cura Slicer Alternatives
While Ultimaker Cura is a great 3D slicer, other options are available. Prusa Slicer
and Simplify3D are two popular alternatives, each with its own strengths and
weaknesses.
PRUSA SLICER
200
Supported File Types in Cura
Cura supports a range of different file types for 3D models, including:
STL is the most commonly used file format for 3D printing and is supported by
most 3D modeling software. It is also the file type I will be using in this tutorial.
201
Where Can I Get 3D Model Files?
There are many websites where you can download 3D models for printing. Some
have free files, while others, you can buy the file from the creator.
You can also create your own 3D models using 3D modeling or free CAD software
like TinkerCAD.
202
Setting up Cura for your 3D printer
203
Adding a Printer
● To set up Cura for your 3D printer,
you’ll need to add your printer to the
software and fill out the machine
settings page. This will allow you to
configure the software to work with
your specific printer.
● You will have the option to choose
either an Ultimaker printer or a
non-Ultimaker printer.
● For this tutorial, I have a
non-Ultimaker printer and will be
setting up my Creality3D Ender 3 Pro.
204
Laser Engraving & CNC Cutting
205
206
CNC Engraving vs Laser Engraving
When deciding which type of engraving to use for a certain project, it's important
to understand the differences between CNC engraving and laser engraving.
While both processes involve engraving a design onto a material, some key
differences exist in how they are achieved and the results they produce.
207
What is CNC Engraving?
● Definition and Purpose: CNC engraving is a computer-controlled process
used to etch or carve intricate designs, letters, or patterns into a surface.
● Computer Numerical Control (CNC): CNC refers to the computer-based
control of the machine’s movements, enabling precise and automated
operations.
● Design Translation: A design is created in specialized software and
converted into G-code, a language that directs the CNC machine’s
movements, speed, and actions.
● Subtractive Process: CNC engraving is a subtractive technique where
rotating cutters or burrs remove material to form the desired shape or pattern
on the surface.
208
CNC Machine
209
CNC engravings are of two types:
CNC milling engraving:
● CNC milling machines are used as CNC engraving machines but they require a high
speed of spindle due to the small size of the tool and the hardness of the material.
● CNC milling engraving is used when our base material to engrave is stainless steel,
mild steel, aluminum, brass, wood, plastics, and some other materials as well.
CNC router engraving:
● CNC routers are used on softer materials such as wood, plastic, and acrylic
because they are less robust than milling machines.
● A CNC router has quite a few applications, like furniture making, signature making,
cabinet making, art and craft, molds, and prototyping.
210
What is Laser Engraving?
● Laser engraving is a CNC technique using a laser beam to create text or
designs on various surfaces.
● It’s versatile, used for customizing items like jewelry, trophies, awards, and
logos with permanent designs.
● As a non-contact process, the laser beam engraves without physically
touching the material.
● The concentrated laser allows for intricate, detailed designs on materials like
metal, plastic, and wood.
211
More Materials & More Creations
212
Computational thinking
What is Computational thinking?
Computational thinking is a problem-solving process that involves breaking
down a problem into manageable parts, recognizing patterns, simplifying
solutions, and creating step-by-step instructions to solve it.
Or
Computational thinking helps break down complex problems, find efficient ways
to solve them, and makes it easier to repeat solutions with similar problems. It's
very useful in many fields, not just programming!
214
Main aspects of computational thinking
1. Decomposition (Breaking Down a Problem)
2. Pattern Recognition (Finding Similarities)
3. Abstraction (Focusing on Important Information)
4. Algorithms (Creating Step-by-Step Solutions)
215
Decomposition (Breaking Down a Problem)
Planning a trip can feel overwhelming, so we start by breaking it down into smaller
tasks:
● Decide on a destination.
● Set a budget.
● Book transportation.
● Reserve accommodation.
● Plan activities and sightseeing.
● Pack essentials.
Each task becomes a manageable piece, making the whole process more
organized and less stressful.
216
Pattern Recognition (Finding Similarities)
As you work through the tasks, you notice some common patterns or needs:
Recognizing these patterns can help streamline the planning, like setting an
overall budget for booking expenses or mapping activities close to each other for
efficiency.
217
Abstraction (Focusing on Important Information)
When researching destinations, you ignore irrelevant details (e.g.,What is the
architecture style of hotel building, How many entries are there in hotel, how many
floors are there).
You focus only on essentials: travel documents, budget limits, weather forecasts,
and must-see sights.
Abstraction helps you avoid unnecessary details that don’t impact your main travel
goals, making decision-making faster and less cluttered.
218
Algorithms (Creating Step-by-Step Solutions)
Finally, you create a clear step-by-step process or “algorithm” for booking and
preparing for the trip:
● Choose a destination and set dates.
● Research and book transportation (flights, train, or car).
● Reserve accommodations close to your planned activities.
● Make a list of activities or sights you want to visit and create a daily schedule.
● Pack essentials, considering weather and planned activities.
● Confirm all bookings and prepare necessary documents (tickets, passports,
etc.).
This algorithm ensures you complete each necessary step in an efficient order and
are well-prepared for the trip.
219
Outcome
Using computational thinking for trip planning helps you organize each aspect,
recognize areas to streamline, focus on important factors, and follow a structured
process, making the entire experience more enjoyable and less stressful.
220
221
222
223
224
225
226
227