You are on page 1of 33

HIMALAYA ROBOTICS CLUB

PRESENTS

HARDWARE
FELLOWSHIP
Arduino

Ultrasound
Sensor

Remote
Bot
DAY 1
Bread Board
LM7805 Voltage Regulator

The LM7805 is a voltage


regulator that outputs +5 volts.
Input voltage can range from 7 –
35 V DC and it outputs a fixed 5V
at over 1A of current and up to
2.2A of surge current.
Circuit diagram 02
Schematic diagram 02
Transistor
A transistor is a
semiconductor device
used to amplify or
switch electrical
signals and power
Circuit diagram 03
Schematic diagram 03
Relay
Single Pole Single Throw relays provide the most straight
forward approach to isolation. A single stationary contact
and a moveable contact furnish a simple on-off
configuration. Forms include normally open, NO, and
normally closed, NC.
Schematic diagram 04
Arduino (UNO)
• Microcontroller
• Microprocessor vs microcontroller
• ATmega328
• Analog Pins (10 bits)
• Digital Pins
• PWM pins (8 bits)
• Power Pins
• Crystal oscillator (16 MHz)
• USB type B
• EEPROM
• Serial Communication (URAT)
• Reset button
• TTL logic (3 to 5 : High | 0 to 1.5 : Low)
Arduino (UNO)
Analog pins (10 bits)
-> 2^10 = 1024
(0 - 1023) read/write

PWM Pins (8 bits) [tilde ~]


-> 2^8 = 256
(0 - 2553) read/write

DC current for I/O pins = 20mA


DC current for 3.3 V pin = 50mA

32 KB flash memory
Arduino Programming

Structure:
• Sketch (Language)
• Syntax -> Termination with semicolon(;)
• Control structure ->if, if else, else, for, while etc.
• Operators -> Arithmetic, Comparison
• Casing -> camel Casing

Functions: Data types:


• Digital I/O • Int
• Analog I/O • Float
• Time • Char
• Boolean
• Static
• volatile
Arduino Programming

Digital I/O functions:


digitalWrite( pin, status ) [status = HIGH or LOW ]
digitalRead(pin)

Analog I/O functions:


analogRead(pin) [ i/p value ranges from 0 to 1023 ]
analogWrite(pin, value) [value ranges from 0 to 255]

Note: Analog pins can only used for reading analog values (0 - 1023). For
writing analog values, PWM pin are used (so value ranges from 0 to 255)
Arduino Programming
Code Structure

//header file declaration if required


//global variable declaration

void setup() {
// one time call/run
//all the pins functions/modes are defined here

void loop() {
//continuous run until power off or reset
//codes that should be run continuously are written
.here
}
Arduino Programming

Demo Program : Serial.begin(9600)


void setup() { The value 9600 is called the
// put your setup code here, to run once: 'baud rate' of the connection.
pinMode(5,OUTPUT); This is how fast the data is to
pinMode(6,INPUT); be sent.
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int a = digitalRead(6);
Serial.println(a);
digitalWrite(5,HIGH);
}
Arduino Programming

Led Blink
//blink led
void setup() {
// put your setup code here, to run once:
pinMode(7,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(7,HIGH);
delay(100);
digitalWrite(7,LOW);
delay(100);
}
Arduino Programming
Millis Function
• Inbuilt function
• Count from 0 t0 49.7 days

Q. Blink LED using millis function.


Arduino Programming
Millis Function
volatile boolean toggle = false;
unsigned long previous = 0;
void setup() {
// put your setup code here, to run once:
pinMode(10,OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
unsigned long current = millis();
if((current - previous) == 500)
{
toggle = !toggle;
digitalWrite(10,toggle);
previous = current;
Serial.println(toggle);
}
}
Sensors

Sensors
1. LDR sensor

2. IR sensor

3. PIR sensor

4. Ultrasonic sensor

5. Condenser mic
LDR sensor
An LDR is a component that
has a (variable) resistance
that changes with the light
intensity that falls upon it.
This allows them to be used in
light sensing circuit.

• It works on analog signal.


• Luminance inversely proportional to
resistance.
LDR sensor
void setup() { // 3 M-M
// put your setup code here, to run once: // resistor - 2k
pinMode(A0,INPUT);
pinMode(13,OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int var = analogRead(A0);
Serial.println(var);
if(var > 800){
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}
}
IR sensor
A passive infrared sensor is an
electronic sensor that measures
infrared light radiating from
objects in its field of view.

• Works on digital signal


• Transmitter
• Receiver
IR sensor
void setup() {
// put your setup code here, to run once:
pinMode(8, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int var = digitalRead(8);
Serial.println(var);
if(var == 0){
digitalWrite(13,HIGH);
}
else{
digitalWrite(13,LOW);
}
}
//3 M -F
PIR Sensor
Passive infrared (PIR) sensors
use a pair of pyroelectric
sensors to detect heat energy
in the surrounding
environment. These two
sensors sit beside each other,
and when the signal differential
between the two sensors
changes (if a person enters the
room, for example), the sensor
will engage

• It works on digital signal


PIR Sensor
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(2,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
int data = digitalRead(2);
Serial.println(data);
if(data == 1)
{
tog = !tog;
digitalWrite(13,tog);
}

}
Ultrasonic sensor
An ultrasonic sensor is an electronic device that
measures the distance of a target object by
emitting ultrasonic sound waves, and converts the
reflected sound into an electrical signal.

components: 
the transmitter - which emits the ultrasonic sound

receiver - which encounters the sound after it has


travelled to and from the target.
Ultrasonic sensor
int trig = 8;
int echo = 9; if (d < 15) {
digitalWrite(13, HIGH);
void setup() { }
// put your setup code here, to run once: else
pinMode(trig, OUTPUT); {
pinMode(echo, INPUT); digitalWrite(13,LOW);
pinMode(13, OUTPUT); }
Serial.begin(9600); }
} //3 - M-M
//3 - led
void loop() { //4 M-F
// put your main code here, to run repeatedly:
digitalWrite(trig, LOW);
delayMicroseconds(5);
digitalWrite(trig, HIGH);
delayMicroseconds(5);
digitalWrite(trig, LOW);
delayMicroseconds(5);
long t = pulseIn(echo, HIGH);
int d = (0.032 * t) / 2;
Serial.println(d);
Ultrasonic sensor
Task:
Using an ultrasonic sensor and 3 LEDs create a circuit that gives us output in
such a way that when distance is less than 10 cm, glow 1 LED , when
distance is between 10 cm to 20 cm, glow 2 LED and finally when distance
is 20 cm to 30 cm, glow three LEDs.
Ultrasonic sensor
int trig = 8; if (d < 10) {
int echo = 9; digitalWrite(13, HIGH);
}
void setup() { else if (d > 10 and d < 20)
// put your setup code here, to run once: {
pinMode(trig, OUTPUT); digitalWrite(13, HIGH);
pinMode(echo, INPUT);
pinMode(13, OUTPUT); digitalWrite(2, HIGH);
pinMode(2, OUTPUT); }
pinMode(4, OUTPUT); else if (d > 20 and d < 50)
Serial.begin(9600); {
} digitalWrite(13, HIGH);
digitalWrite(2, HIGH);
void loop() { digitalWrite(4, HIGH);
// put your main code here, to run repeatedly: }
digitalWrite(trig, LOW); else
delayMicroseconds(5); {
digitalWrite(trig, HIGH); digitalWrite(13, LOW);
delayMicroseconds(5); digitalWrite(2, LOW);
digitalWrite(trig, LOW); digitalWrite(4, LOW);
delayMicroseconds(5); }
long t = pulseIn(echo, HIGH); Serial.println(d);
int d = (0.032 * t) / 2; }
//3 - M-M //3 – led //4 M-F
Condenser Mic
A condenser mic is a type of sensor
that reacts on the change in intensity
of sound around it

• Works on both analog and digital


signal
Condenser Mic
Clap Switch:
static boolean tog = false;
void setup() {
// put your setup code here, to run once:
pinMode(13,OUTPUT);
pinMode(A1,INPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
int data = analogRead(A1);
Serial.println(data);
if(data > 70){
tog = !tog;
digitalWrite(13,tog);
delay(50);
}
}

You might also like