Arduino Bootcamp
Arduino Bootcamp
Arduino Bootcamp
to Arduino!
What is a Microcontroller?
Memory
● Memory chip stores all the program and data
● Microcontrollers are built in with certain amount of RAM or ROM
Timers and Counters
Interrupt mechanism
● Interrupts are basically mechanisms to make the CPU stop
processing one task and temporarily switch to another
● They are typically used for time critical applications where
immediate response to changing condition is required.
ADC and DAC
Void loop(){
…..
}
1 - USB CONNECTOR
2 - POWER JACK
3 - GROUND PINS
4 - 5V PINS
5 - 3.3V PINS
6 - ANALOG INPUT PINS
7/8 - DIGITAL PINS
Out of the 14 Pins, 6 can be used
for PWM (denoted by ~)
9- ANALOG REFERENCE//
10 - RESET BUTTON
11 - POWER LED
WHAT’S ON THE BOARD?
12 - TX/RX LEDS
13 - ATMEGA328P
14 - VOLTAGE
REGULATOR
Pins, On-board LEDs!!
DIGITAL PINS ● Digital Input/Output
pins(0,1 are serial in/out) are
numbered from 2-13
● PWM enabled
pins(3,5,6,9,10,11) can also be
used as Analog Outputs
digitalRead(Pin_no);
Gives the reading of the digital input pin as a high or a
low.
TIME
delay(T), delayMicroseconds(T):
Used to pause the program for certain amount of time.
(where T is in milliseconds & microseconds respectively)
micros(), millis():
Returns the time since the Arduino board began running
the current program.This value can overflow.
BLINKING LED
● The part before the setup() has the LED pin number and
delay initiated
● The single line in setup() specifies LED pin as an output pin
● In loop() digitalWrite makes the value of pin HIGH, delay
pauses execution for given time then pin is switched to
LOW and the delay function is called once more.
Time to Code!
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
// initialize digital pin LED_BUILTIN as an output.
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED
on (HIGH is the voltage level)
delay(1000);
// wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off
by making the voltage LOW
delay(1000); //
wait for a second
}
ANALOG
analogWrite(Pin_no, Value):
Value (the duty cycle) is a 8 bit number (0-255) where 255 represents
5V and the intermediate value represents a corresponding voltage
<5V.
This is implemented by PWM. Only some pins are PWM enabled,
marked with ~ symbol before the pin no.
analogRead(Pin_no);
Reads the input from the analog pins marked as A0,A1...A5 on the
arduino board. This reading is a 10 bit value (0-1023).
Pulse Width Modulation(PWM)
Example Code!
int ledPin = 9; // LED connected to digital pin 9
void setup() { }
void loop() {
// fade in from min to max in increments of 5 points:
for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
// sets the value (range from 0 to 255):
analogWrite(ledPin, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}
[Get Code]
Ultrasonic Sensor
How does an Ultrasonic sensor work?
● This sensor sends out pulses from T, which bounce off
from the object and R receives them.
// defines variables
long duration;
int distance;
void setup() {
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
distance= duration*0.034/2;
Serial.print("Distance: ");
Serial.println(distance);
}
int trigPin =9;
int echoPin = 10;
void setup(){
Serial.begin(9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
void loop(){
long duration, distance;
digitalWrite(trigPin,HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin,LOW);
duration=pulseIn(echoPin,HIGH);
distance=(duration/2)/29.1;
Serial.println(distance);
}
https://create.arduino.cc/projecthub/will-su/touchless-automatic-motion-senso
r-trash-can-bbeed1?ref=tag&ref_id=ultrasonic&offset=2
https://create.arduino.cc/projecthub/straylight-burn-10/animated-pumpkin-a31
5ef?ref=tag&ref_id=ultrasonic&offset=11
https://create.arduino.cc/projecthub/walid-mafuj/android-motion-detector-ca
mera-with-arduino-mcu-306789?ref=tag&ref_id=ultrasonic&offset=7
INFRARED SENSOR
● I.R. sensor is used as a proximity sensor or collision sensor (not exact
distance).
● TX which emits IR light continuously.
● So, when an object is near the sensor light is reflected into the RX
which creates a voltage difference.
● The generation of this voltage difference depends on the intensity of
IR light received by the RX
● Note: You cannot use IR sensors outdoors or in bright lights
because the IR light of sun or from the bulb interacts with the RX.
Use US sensors instead.
void setup() {
pinMode(LED, OUTPUT);
pinMode(isObstaclePin, INPUT);
Serial.begin(9600);
}
void loop() {
isObstacle = digitalRead (isObstaclePin);
if (isObstacle == LOW)
{
Serial.println("OBSTACLE!!, OBSTACLE!!" );
digitalWrite (LED, HIGH);
Write for analog!
}
else
{
Serial.println("clear");
digitalWrite (LED, LOW);
}
delay(200);
}
void setup(){
pinMode(7,INPUT);
Serial.begin(9600);
pinMode(13,OUTPUT);
}
void loop(){
Serial.println(digitalRead(7));
if(digitalRead(7)==0)
{
digitalWrite(13,HIGH);
}
else{
digitalWrite(13,LOW);
}
}