Вы находитесь на странице: 1из 33

Arduino and Microcontrollers

Topic-flow
★ Microcontroller VS Microprocessor
★ Why you should study this?
★ What is Arduino?
★ Why Arduino?
★ Components of Arduino
★ Arduino IDE
★ Lets play ==> Your first hardware project!
Exploring the Basics

What is a microcontroller and microprocessor?


Exploring the Basics
Why you should study this?
Why you should study this?
Why you should study this?
What is Arduino?

Arduino is an open-source platform used for building


electronics projects. Arduino consists of both a physical
programmable circuit board (often referred to as a
microcontroller) and a piece of software, or IDE (Integrated
Development Environment) that runs on your computer, used
to write and upload computer code to the physical board.
Why Arduino?
1-Inexpensive

2-Cross-platform

3-Simple, clear programming environment

4-Open source and extensible


Components of Arduino
Arduino Pin Configuration
➔ VCC

➔ GND

➔ Analog Pins

➔ Digital Pins

➔ PWM pins ( ~ )

➔ Mystery of Tx and Rx

➔ A special Digital Pin 13!


Arduino IDE
Basic Code Elements and Components

★ Just like C language.

★ setup()

★ loop()

★ Functions

★ Component Libraries
Most needed Code elements
1. pinMode
2. digitalWrite
3. Serial.print() / Serial.println()
4. HIGH and LOW
5. OUTPUT and INPUT
6. delay()
7. MACROS
Breadboard
Connections-:
Blink - The hello world of Arduino
➔ Setup the pin - we’ll use digital pin 7.
➔ Under loop :
1) Give the HIGH OUTPUT to the pin 7.
2) Give a delay of a few milliseconds on your choice.
3) Give the LOW OUTPUT to the pin 7.
4) Again, another delay of any number of milliseconds
➔ The loop will run that part repeatedly
Blinking Of LED code-:
Blinking of LED-:Series connection
Blinking of LED-:parallel connection
Blinking of LED using Switch
LED Using Switch - Code(1)
LED Using Switch-Code(2)
Automatic LED ON and OFF
HARDWARE REQUIRED

1. ARDUINO UNO
2. LED
3. LDR(PhotoResistor)
4. 220 and 10k ohm Resistors
5. Jumper wires
6. Breadboard
WHAT IS LDR AND HOW IT WORKS ?

● Light Dependent Resistor(PhotoResistor)


● Semiconductor Material
● Light Falls Resistance Changes
● No Cathode and Anode
APPLICATION
CIRCUIT DESIGN
CODE
void setup() {

pinMode(A0,INPUT); //initialise LDR pin as INPUT

pinMode(8,OUTPUT); //initialise LED pin as OUTPUT

Serial.begin(9600);

void loop() {

int ldr=analogRead(A0); //read status of LDR value

Serial.println(ldr);

//check if ldr value is >=300

//Make Led on else Off


if(ldr>=300)

digitalWrite(8,HIGH); //Turn LED ON

else

digitalWrite(8,LOW); //TURN LED OFF

}
Fading of LED
BASICS REQUIRED

PWM :- Pulse Width Modulation (“~”)

● What is it ?
● How does it work ?
● Where can we use this ?
Continued….
analogWrite(pin, Value) :-

● What is it?
● What does it do?
Let’s Try it out…..
int led=7; // The pin where the LED is attached
int brightness = 0; // Value of this variable will change the brightness of LED
int fadeAmount = 5; // This variable is used to change LED brightness
void setup()
{
pinMode(led, OUTPUT);
}
void loop()
{
analogWrite(led, brightness); //
brightness = brightness + fadeAmount; //Updates brightness
if (brightness == 0 || brightness == 255)
{
fadeAmount = -fadeAmount ; // Helps in fading and then glowing of LED repeatedly
}
delay(30);
}
Thank You

By :- Anshit Gupta

Dhruva Gupta

Karan Thakur

Anmol Tiwari

Вам также может понравиться