You are on page 1of 40

ARDUINO PROGRAMMING FOR

AUTOMATION USING TINKERCAD

By
Institute of Computer Science and Digital Innovation
(ICSDI)
Content
• Introduction to Arduino
• What is Microcontroller?
• What is development board?
• What is Arduino?
• Types of Arduino
• What is Tinkercad ?
• Activities
• LED Blinking
• Traffic Light Controller
• Automated LED Switching based on Light Intensity
• Kahoot!
• Ultrasonic Distance Sensor with Piezo (Demo only)
Introduction to Arduino
What is a Microcontroller

• A small computer on a single chip


• containing a processor, memory, and input/output
• Typically "embedded" inside some device that they control
• A microcontroller is often small and low cost
What is a Development Board

• A printed circuit board


designed to facilitate work
with a particular
microcontroller.

• Typical components include:


• power circuit
• programming interface
• basic input; usually buttons and LEDs
• I/O pins
The Arduino Development Board
The Arduino on breadboard
The Arduino Microcontroller: Atmel ARV
Atmega 328
What is the Arduino
What is the Arduino?

• Single-board microcontroller, intended to make the application of


interactive objects or environments more accessible.
• Designed to make the process of using electronics multidisciplinary
projects more accessible
• Open Source Hardware, you can make your own board.
• Cheap, easily available
• Open source Software
• Very widespread, many projects openly available
Types of Arduino

Arduino Uno

Arduino Nano

Arduino Mega 2560


Arduino UNO
Connect the USB Cable
What is Tinkercad ?
Tinkercad is a free, easy-to-use app for 3D
design, electronics, and coding. 
Practical Session
Activity 1
LED Blink
Arduino UNO

1 x LED (Red/ Yellow/Green)


Components
Jumper wires

1 x Resistors (200Ω)
Light Emitting Diode (LEDs)
Building the circuit in Tinkercad

• In the Tinkercad Circuits components panel, drag a resistor and LED onto the
workplane.
• Edit the resistor's value by adjusting it to 200Ω in the component inspector which
appears when the resistor is selected.
• Back in the components panel, find and bring over an Arduino Uno board.
• Click once to connect a wire to a component or pin, and click again to connect the
other end.
• Connect your resistor to the LED's anode (positive, longer), connect the resistor's
other leg to Arduino's digital pin 13.
• Create another wire between the unconnected LED leg to ground.
Coding in Tinkercad

• Open the code editor (button labeled "Code"), click Text.


Programming Code
// C++ code
//
void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(10000); // Wait for 10000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
Activity 2
Traffic Light Control
Arduino UNO

3 x LEDs (Red, Yellow, Green)


Components
Jumper wires

3 x Resistors (200Ω)
Connection of Arduino with LEDs
Programming Code (1/2)
int red = 13;
int yellow = 12;
int green = 11;

void setup()
{
// configured red, yellow and green LEDs to be outputs.
pinMode (red, OUTPUT);
pinMode (yellow, OUTPUT);
pinMode (green, OUTPUT);

}
Programming Code (2/2)
void loop()
{
// green off, yellow on for 3 seconds
digitalWrite(green, LOW);
digitalWrite(yellow, HIGH);
delay(3000);
// turn off yellow, then turn red on for 5 seconds
digitalWrite(yellow, LOW);
digitalWrite(red, HIGH);
delay(5000);
// turn off red and yellow, then turn on green
digitalWrite(yellow, LOW);
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
delay(6000);
}
Activity 3
Automated LED switching based on light
intensity
Arduino Uno

1 LED (Yellow)

Components 2 Resistors (200Ω and 10kΩ)

1 Photoresistor

Jumper Wires
Connection of Arduino with LED and
Photoresistor
Programming Code
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop()
{
if(analogRead(A0)>=903)
{
digitalWrite(13,LOW);
}
else
{
digitalWrite(13,HIGH);
}
}
Let’s Kahoot!

• Scan the QR code.

• Type a team name.


Activity 4
Ultrasonic Distance Sensor with Piezo
Arduino Uno

1 Piezo

Components 1 Resistor(330Ω)

1 Ultrasonic Distance Sensor

Jumper Wires
Connection of Arduino with Buzzer and
Ultrasonic Sensor
Programming Code
const int buzzer = 8;

int echopin = 6;
int trigpin = 7;

int mesafe;
int sure;

void setup()
{
Serial.begin(9600);

pinMode(buzzer, OUTPUT);
pinMode(trigpin, OUTPUT);
pinMode(echopin, INPUT);
}
Programming Code
void loop()
{
digitalWrite(trigpin,LOW);
delayMicroseconds(2);
digitalWrite(trigpin,HIGH);
delayMicroseconds(10);
digitalWrite(trigpin,LOW);
sure = pulseIn(echopin,HIGH);
mesafe = (sure/2)/29.0;
if(mesafe <= 15)
{
digitalWrite(buzzer,HIGH);
delay(250);
digitalWrite(buzzer,LOW);
delay(125);
}
Programming Code
else if(mesafe <= 20)
{
digitalWrite(buzzer,HIGH);
delay(500);
digitalWrite(buzzer,LOW);
delay(250);
}
else if(mesafe <= 30)
{
digitalWrite(buzzer,HIGH);
delay(1000);
digitalWrite(buzzer,LOW);
delay(1000);
}
Programming Code
else
{
digitalWrite(buzzer,LOW);
}
Serial.print("uzaklik = ");
Serial.print(mesafe);
Serial.println("cm");
delay(500);
}

You might also like