Nothing Special   »   [go: up one dir, main page]

Book Overview

Download as pdf or txt
Download as pdf or txt
You are on page 1of 266

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.

The Arduino platform has become quite popular with


people just starting out with electronics, and for good
reason. Unlike most previous programmable circuit
boards, the Arduino does not need a separate piece of
hardware (called a programmer) in order to load new code
onto the board -- you can simply use a USB cable.
Additionally, the Arduino IDE uses a simplified version
of C++, making it easier to learn to program. Finally,
Arduino provides a standard form factor that breaks out
the functions of the micro-controller into a more
accessible package.
Power (USB / Barrel Jack)
Every Arduino board needs a way to be connected to a
power source. The Arduino UNO can be powered from a
USB cable coming from your computer or a wall power
supply (like this) that is terminated in a barrel jack. In the
picture above the USB connection is labeled (1) and the
barrel jack is labeled (2).
The USB connection is also how you will load code onto
your Arduino board. More on how to program with
Arduino can be found in our Installing and Programming
Arduino tutorial.
NOTE: Do NOT use a power supply greater than 20 Volts
as you will overpower (and thereby destroy) your
Arduino. The recommended voltage for most Arduino
models is between 6 and 12 Volts.
Pins (5V, 3.3V, GND, Analog, Digital, PWM, AREF)

The pins on your Arduino are the places where you


connect wires to construct a circuit (probably in
conjuction with a breadboard and some wire. They
usually have black plastic ‘headers’ that allow you to just
plug a wire right into the board. The Arduino has several
different kinds of pins, each of which is labeled on the
board and used for different functions.
• GND (3): Short for ‘Ground’. There are several GND
pins on the Arduino, any of which can be used to
ground your circuit.
• 5V (4) & 3.3V (5): As you might guess, the 5V pin
supplies 5 volts of power, and the 3.3V pin supplies
3.3 volts of power. Most of the simple components
used with the Arduino run happily off of 5 or 3.3
volts.
• Analog (6): The area of pins under the ‘Analog In’
label (A0 through A5 on the UNO) are Analog In
pins. These pins can read the signal from an analog
sensor (like a temperature sensor) and convert it into
a digital value that we can read.
• Digital (7): Across from the analog pins are the
digital pins (0 through 13 on the UNO). These pins
can be used for both digital input (like telling if a
button is pushed) and digital output (like powering an
LED).
• PWM (8): You may have noticed the tilde (~) next to
some of the digital pins (3, 5, 6, 9, 10, and 11 on the
UNO). These pins act as normal digital pins, but can
also be used for something called Pulse-Width

Modulation (PWM). We have a tutorial on PWM, but


for now, think of these pins as being able to simulate
analog output (like fading an LED in and out).
• AREF (9): Stands for Analog Reference. Most of the
time you can leave this pin alone. It is sometimes
used to set an external reference voltage (between 0
and 5 Volts) as the upper limit for the analog input
pins.
Reset Button
Just like the original Nintendo, the Arduino has a reset
button (10). Pushing it will temporarily connect the reset
pin to ground and restart any code that is loaded on the
Arduino. This can be very useful if your code doesn’t
repeat, but you want to test it multiple times. Unlike the
original Nintendo however, blowing on the Arduino
doesn't usually fix any problems.
Power LED Indicator
Just beneath and to the right of the word “UNO” on your
circuit board, there’s a tiny LED next to the word
‘ON’ (11). This LED should light up whenever you plug
your Arduino into a power source. If this light doesn’t
turn on, there’s a good chance something is wrong. Time
to re-check your circuit!
TX RX LEDs
TX is short for transmit, RX is short for receive. These
markings appear quite a bit in electronics to indicate the
pins responsible for serial communication. In our case,

there are two places on the Arduino UNO where TX and


RX appear -- once by digital pins 0 and 1, and a second
time next to the TX and RX indicator LEDs (12). These
LEDs will give us some nice visual indications whenever
our Arduino is receiving or transmitting data (like when
we’re loading a new program onto the board).
Main IC
The black thing with all the metal legs is an IC, or
Integrated Circuit (13). Think of it as the brains of our
Arduino. The main IC on the Arduino is slightly different
from board type to board type, but is usually from the
ATmega line of IC’s from the ATMEL company. This can
be important, as you may need to know the IC type (along
with your board type) before loading up a new program
from the Arduino software. This information can usually
be found in writing on the top side of the IC. If you want
to know more about the difference between various IC's,
reading the datasheets is often a good idea.
Voltage Regulator
The voltage regulator (14) is not actually something you
can (or should) interact with on the Arduino. But it is
potentially useful to know that it is there and what it’s for.
The voltage regulator does exactly what it says -- it
controls the amount of voltage that is let into the Arduino
board. Think of it as a kind of gatekeeper; it will turn
away an extra voltage that might harm the circuit. Of
course, it has its limits, so don’t hook up your Arduino to
anything greater than 20 volts.

The Arduino Family


Arduino makes several different boards, each with
different capabilities. In addition, part of being open
source hardware means that others can modify and
produce derivatives of Arduino boards that provide even
more form factors and functionality. If you’re not sure
which one is right for your project, check this guide for
some helpful hints. Here are a few options that are well-
suited to someone new to the world of Arduino:
Arduino Uno (R3)
The Uno is a great choice for your first Arduino. It's got
everything you need to get started, and nothing you don't.
It has 14 digital input/output pins (of which 6 can be used
as PWM outputs), 6 analog inputs, a USB connection, a
power jack, a reset button and more. It contains
everything needed to support the microcontroller; simply
connect it to a computer with a USB cable or power it
with a AC-to-DC adapter or battery to get started.

LilyPad Arduino
This is LilyPad Arduino main board! LilyPad is a
wearable e-textile technology developed by Leah
Buechley and cooperatively designed by Leah and
SparkFun. Each LilyPad was creatively designed with
large connecting pads and a flat back to allow them to
be sewn into clothing with conductive thread. The
LilyPad also has its own family of input, output, power,

and sensor boards that are also built specifically for e-


textiles. They're even washable!

RedBoard
At SparkFun we use many Arduinos and we're always
looking for the simplest, most stable one. Each board is a
bit different and no one board has everything we want --
so we decided to make our own version that combines all
our favorite features.
The RedBoard can be programmed over a USB Mini-B
cable using the Arduino IDE. It'll work on Windows 8
without having to change your security settings (we used
signed drivers, unlike the UNO). It's more stable due to
the USB/FTDI chip we used, plus it's completely flat on

the back, making it easier to embed in your projects. Just


plug in the board, select "Arduino UNO" from the board
menu and you're ready to upload code. You can power the
RedBoard over USB or through the barrel jack. The on-
board power regulator can handle anything from 7 to
15VDC.

Arduino Mega (R3)


The Arduino Mega is like the UNO's big brother. It has
lots (54!) of digital input/output pins (14 can be used as
PWM outputs), 16 analog inputs, a USB connection, a
power jack, and a reset button. It contains everything
needed to support the microcontroller; simply connect it

to a computer with a USB cable or power it with a AC-to-


DC adapter or battery to get started. The large number of
pins make this board very handy for projects that require a
bunch of digital inputs or outputs (like lots of LEDs or
buttons).

Arduino Leonardo
The Leonardo is Arduino's first development board to use
one microcontroller with built-in USB. This means that it
can be cheaper and simpler. Also, because the board is
handling USB directly, code libraries are available which
allow the board to emulate a computer keyboard, mouse,
and more!

Motor driver
Motor drivers acts as an interface between the motors and

the control circuits. Motor require high amount of current

whereas the controller circuit works on low current

signals. So the function of motor drivers is to take a low-

current control signal and then turn it into a higher-current

signal that can drive a motor.

Different motor drivers for Remote Controlled Robots

To control the robot wirelessly through a remote

controller we need to interface the motors with the

wireless systems such as Bluetooth, 2.4 GHz Rf modules,

etc.

Here is the detailed comparision between the suggested

motor drivers which will help you to select the

combination of motor and motor driver

Motor drivers acts as an interface between the motors and

the control circuits. Motor require high amount of current

whereas the controller circuit works on low current

signals. So the function of motor drivers is to take a low-

current control signal and then turn it into a higher-current

signal that can drive a motor.

Different motor drivers for Remote Controlled Robots

To control the robot wirelessly through a remote

controller we need to interface the motors with the

wireless systems such as Bluetooth, 2.4 GHz Rf modules,

etc.

Here is the detailed comparision between the suggested

motor drivers which will help you to select the

combination of motor and motor driver

Different Types of Sensors

In daily life, it has become our habit to implement various


types of sensors frequently in the power systems
comprising of load control systems, electrical and
electronics appliances, and industrial and home
automation. All types of sensors are further divided into
analog and digital sensors.

However, there are few types of sensors that are used in


electronic applications such as pressure sensors, touch
sensors, IR sensors, ultrasonic sensors, temperature
sensors, proximity sensors, and so on.
Temperature Sensors:

Temperature is the commonly measured environmental


quantity for various reasons. There are different types of
temperature sensors that are used for measuring
temperature such as thermistors, resistance temperature
detectors, thermocouples, semiconductor temperature
sensors, and so on.

On the basis of requirements, various types of sensors are


used for the purpose of measuring temperature in different
applications. A simple temperature sensor with a circuit
may be used for switching the load on and off at a specific
temperature.

This temperature is detected by the temperature sensor, in


these cases, a thermistor is put to use. The temperature

sensor circuit comprises a thermistor, transistor, relay, and


battery. The temperature sensor activates the relay by
detecting the required temperature.

The relay switches on the load that is connected to it


which can be AC or DC. This circuit may be further
utilized for the purpose of controlling the fan on the basis
of temperature. Primarily, this type of sensor may be
further classified into various other types such as digital
temperature sensors, thermistors, and so on.
IR Sensors:

The small photo chips comprising of photocells that are


used for detecting and emitting infrared light are termed
IR sensors. These sensors are most commonly used for
the purpose of designing remote-control technology.

These sensors may be used for detecting various obstacles


of the robotic vehicle and controlling the direction of the
same. There are different types of sensors that might be
used for the detection of infrared lights.

A simple example of an IR sensor circuit that we use in


our day-to-day life is a TV remote control. It comprises
IR receiver circuits and IR emitter circuits that may be
designed. The IR emitter circuit is used as a remote by the
user for the purpose of emitting infrared light.

This infrared light is transmitted or sent to the IR receiver


circuit which interfaces to the devices such as IR remote-

controlled robots or a TV. These sensors are further used


for designing television remote controls.

A TV remote is an example of a simple IR sensor-based


electronics project which is used for the purpose of
controlling a robotic vehicle in remote areas by using IR
or TV remote. This type of TV remote is being utilized for
sending commands to the robotic vehicle.
Ultrasonic Sensor:

An ultrasonic sensor or transceiver is a transducer that


works on the principle alike radar or sonar and is known
for estimating the attributes of the target by interpreting.
These sensors are classified as active and passive
ultrasonic sensors and maybe differentiated on their
working.

The active ultrasonic sensors are known for generating


high-frequency sound waves that are received back by the
ultrasonic sensor for the evaluation of echo. The time
interval taken for receiving and transmitting the echo
helps in the determination of the distance to an object.

However, the passive ultrasonic sensors are merely used


for the detection of ultrasonic noise whose presence can
be found in specific conditions. When it comes to the
practical application of an ultrasonic sensor with a circuit,
it may also be used as an ultrasonic distance sensor
circuit.

Touch Sensor:

The switches that are activated by touch may be said to


have touch sensors. These sensors are classified into
different types on the basis of their touch-type such as
piezo touch switch, capacitance touch switch, and
resistance touch switch.

For the purpose of controlling the load, a touch-sensitive


load is designed. The touch-controlled load switch which
is touch sensor principle-based comprises various blocks
such as touch sensor plate, load, relay, and power supply
block.
Proximity Sensor:

The proximity sensor is a type of IoT sensor in which the


existence and non-existence of the surrounding objects
are identified. After this, the detected signal is converted
into a form that the user understands.

This type of sensor is mainly applied in the retail domain


where any movement is found out and an association is
present between the consumer and product. The users are
provided with quick notifications related to exclusive
offers and discount updates of the products in which they
are interested.
Chemical Sensor:

A chemical sensor helps in determining various kinds of


changes in liquid and for detecting the air chemical
variations. These are mainly put to use in bigger cities and
towns as it is important to look after the changes for
providing safety to the people.

This type of sensor is essentially implemented in


commercially atmospheric observation. It is used for
processing management which may comprise of
fortuitously or intentionally evolved chemicals,
radioactive exposure, pharmaceutical industries, and
reusable operations in space stations.

The most commonly used chemical sensors include


chemical FET, electrochemical gas type, chemi resistor,
non-dispersive IR, zinc oxide nanorod, and fluorescent
chloride type.
Gas Sensor:

Gas sensors are similar to chemical sensors but are


specially implemented for observing modifications in the
quality of air. This is done to find out which types of
gases are present in it. This sensor is being used in
multiple domains such as health, manufacturing,
agriculture, for supervision of gas in coal industries,
chemical laboratory investigations, etc.

Some of the gas sensors that have been put to use include
hydrogen type, hygrometer, carbon-dioxide sensor, ozone

monitoring type, air pollution type, gas detection type,


etc.
Humidity Sensors:

Humidity is used for defining the vapor present in the


atmosphere or in gaseous substances. Humidity sensors
are used as temperature sensors as the manufacturing
operations require similar operating conditions. By
measuring humidity, it can be ensured that the complete
procedure will pass away easily.

In case of modification, immediate action can be taken as


these sensors are known for quickly identifying the
variations. There are numerous domains in which these
are used such as ventilators, residential and commercial
use for heating purposes, etc. Some other domains include
meteorology, greenhouses, automobile, painting, coating
industries, and hospitals.
Accelera on Sensor:

An acceleration sensor is used for calculating the


acceleration and angular values. The accelerometer is
primarily used for calculating acceleration. There are two
types of forces that create an impact on the accelerometer;
these are static force and dynamic force.

These sensors are present in numerous configurations and


their type of selection is dependent on the industry’s
requirement. There are few parameters that are required to

ti

be checked before selecting the sensors such as total


number of axes, bandwidth, sensitivity, type of outputs,
etc.
Sound Sensor:

Sound sensors can generally be identified as the


microphone devices that are used for delivering the
corresponding level of voltage and sound on the basis of
the sound level detection. By implementing the sound
sensor, a small robot may be manufactured for navigation
on the basis of sound received.

In comparison to light sensors, the design process of


sound sensors is complicated. The reason being the
delivery of minimal voltage difference by them. This is
further to be amplified for providing voltage variation that
is measurable.

Various other sensors include a light sensor, tactile


sensors, force sensors, etc. The types of sensors used in
building include motion detection sensors, camera
sensors, gas sensors, smoke and fire detection sensors,
electric voltage and current sensors, and temperature
sensors.

Uses of Sensors

If we look around carefully, sensors are used in many


products that we use in our day-to-day life. Sensors are

used in various industries comprising automotive,


medical, aerospace, defense, and agriculture.

You can read also: What are Resistors: Classification,


Types, Uses, and Details

Position sensors are used for the purpose of measuring


movement, displacement, and position and maybe rotary
or linear. These are used for controlling the throttle,
measuring wind direction, positioning the ramp and
bridge, simulating flights, and steering angle
measurement.

Pressure sensors are being used for measuring pressure


and can be a differential, gauge, or absolute. The most
common types of pressure sensors that are used comprise
transducers which are also known as pressure switches or
pressure transmitters.

Some of the areas of pressure sensor application are oil


pressure, tire pressure, vehicle braking systems, oil
pressure, fans, filters, and diesel and engines applications.
The force sensors also known as load cells or weight
sensors are used for weighing applications in scales.

The weight sensors are known for giving the exact weight
measurement by measuring the amount of force that is
being applied. The load sensors are used in counting
scales, hopper scales, platform scales, tank weighing, and
on-boarding weighing.

Temperature sensors are put to use when it comes to


monitoring and measuring the temperature of liquid,
solid, and gas. It is the most commonly used sensor in
homes and it is used in various shapes and sizes for
serving different purposes.

This type of sensor is used in motors, surface plates,


computers, industrial equipment, electrical radiators,
exhaust gas monitoring, and home appliances. Sensors are
highly beneficial and are used in various equipment used
in our daily lives.

Applications of Digital Sensors

Digital sensors are the electrochemical sensors or


electronic sensors in which the transmission and
conversion of data take place. Digital sensors are known
to have overcome the drawbacks present in analog sensors
and have slowly begun to replace them.

Digital sensors are of different types such as digital


accelerometers and digital temperature sensors. A digital
accelerometer is known for generating variable frequency
square wave output termed pulse-width modulation. In
this, the readings are taken at a fixed rate by the pulse
width modulated accelerometer.

A digital temperature sensor is known for providing


device temperature with 9-bit temperature readings. It is
known for acting as a thermostat with the presence of
three thermal alarm outputs. It is being considered as a

digital temperature control system that uses digital


temperature sensors.

This control system has various advantages and provides


accurate results in comparison to the analog temperature
control system. A digital temperature control system is
capable of providing a temperature display and switches
off when the temperature exceeds a set point.

How do Sensors work?

Sensors are known to react as per the changing physical


conditions by bringing a change in their electrical
properties. It has been observed that artificial sensors in
most cases rely on electronic systems for analyzing,
capturing, and relaying environment information.

In simple words, it can be said that a sensor converts the


stimuli such as sound, motion, heat, and light into
electrical signals. These signals are passed through an
interface that further converts these into a binary code
passing them on to a computer to get processed.

Mostly, the sensors act as a switch and are used for


controlling the flow of electric charges passing via the
circuit. Switches form an important part of electronics as
these are known for changing the state of the circuit.

The components present in sensors such as transistors,


diodes, and integrated circuits or chips consist of

semiconducting material. These materials are included in


the sensor circuits so that they can be used as switches.

Mostly, sensors use radiation such as laser or light,


infrared radio waves, or other waves such as ultrasonic
ones for detecting the changes and objects present in the
environment. This is possible if they have an energy
source that assists them in emitting radiation in the
direction of their target object.

This radiation is reflected back by the object and gets


detected by the sensor; it is termed an active sensor.
Passive sensors don’t send radiation or waves that are
their own and detect what is being emitted by the target
objects such as thermal infrared radiation, heat, or
radiation from external sources like Sun reflected off the
objects.

Pros and Cons of Different Sensors

Now let’s go through the pros of di erent sensors. When


it comes to a touch sensor, the axle hole present in the
sensor area may be used for creating its own bumper. The
color sensor is known for detecting color, avoiding
ambient light, and following lines.

The gyro sensor can be used for accurately turning and


measuring the robot turning. An infrared sensor helps in
finding the beacon and remote receiver. It is known for
working and helping in measuring the proximity
accurately.

ff

An ultrasonic sensor measures in and cm and provides


accurate distance measurement and wall following. These
were the pros of di erent sensors, let’s know the cons of
di erent sensors. The con in the case of a touch sensor is
that the object must touch the sensor’s red part and its
sensor area is small.

The color sensor is known to be reliable only when it is at


a close range and the light color that it detects is white. In
the case of a gyro sensor, the robot is required to be still
when it is plugged. It can be unreliable and touch many
times.

The other cons of di erent sensors include the sound of


ultrasonic which may interfere with the sensor.

EDGE AVOIDER BLUETOOTH CAR

Components:
● Arduino uno
● Motor driver shield(L293D)
● Ir sensor -2
● Bluetooth module (hc-05)
● Jumper wires
● Bo motor-4
● Tyre-4
ff

ff

ff

● A car body
● Bluetooth rc controller (phone app)

Circuit Diagram:

Code in c language:
//Arduino Table edge Avoidance Robot
//Created By Janta Group
//You need to include the AFMotor.h library before
uploading the sketch, otherwise you'll get a compilation
error message.

#include <AFMotor.h>

#define IR1 A0
#define IR2 A1

AF_DCMotor motor1(1, MOTOR12_1KHZ);


AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

char command;

void setup()
{
Serial.begin(9600); //Set the baud rate to your Bluetooth
module.

pinMode(IR1, INPUT);
pinMode(IR2, INPUT);

void loop(){

/*Serial.print("Right");
Serial.println(Right);
Serial.print("Left");
Serial.println(Left);*/

if(Serial.available() > 0){


command = Serial.read();
Stop();

Serial.println(command);

switch(command){
case 'F':
forward();

break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}

int Right = digitalRead(IR1);


int Left = digitalRead(IR2);

if(Right == 1 || Left == 1) {
motor1.setSpeed(255);
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);

motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);

}else if(Right == 0 || Left == 0) {


command = Serial.read();
}
}
}

void forward()
{
motor1.setSpeed(150); //Define maximum Speed
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(150); //Define maximum Speed
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(150);//Define maximum Speed
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(150);//Define maximum Speed
motor4.run(FORWARD); //rotate the motor clockwise
}

void back()
{
motor1.setSpeed(150); //Define maximum Speed
motor1.run(BACKWARD); //rotate the motor anti-
clockwise
motor2.setSpeed(150); //Define maximum Speed
motor2.run(BACKWARD); //rotate the motor anti-
clockwise
motor3.setSpeed(150); //Define maximum Speed
motor3.run(BACKWARD); //rotate the motor anti-
clockwise
motor4.setSpeed(150); //Define maximum Speed
motor4.run(BACKWARD); //rotate the motor anti-
clockwise
}

void left()
{
motor1.setSpeed(200); //Define maximum Speed
motor1.run(BACKWARD); //rotate the motor anti-
clockwise
motor2.setSpeed(200); //Define maximum Speed
motor2.run(BACKWARD); //rotate the motor anti-
clockwise
motor3.setSpeed(200); //Define maximum Speed
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(200); //Define maximum Speed
motor4.run(FORWARD); //rotate the motor clockwise
}

void right()
{
motor1.setSpeed(200); //Define maximum Speed
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(200); //Define maximum Speed
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(200); //Define maximum Speed

motor3.run(BACKWARD); //rotate the motor anti-


clockwise
motor4.setSpeed(200); //Define maximum Speed
motor4.run(BACKWARD); //rotate the motor anti-
clockwise
}

void Stop()
{
motor1.setSpeed(0); //Define minimum Speed
motor1.run(RELEASE); //stop the motor when release the
button
motor2.setSpeed(0); //Define minimum Speed
motor2.run(RELEASE); //rotate the motor clockwise
motor3.setSpeed(0); //Define minimum Speed
motor3.run(RELEASE); //stop the motor when release the
button
motor4.setSpeed(0); //Define minimum Speed
motor4.run(RELEASE); //stop the motor when release the
button
}

3-LED and push button control with arduino uno

Diagram:

Code:

// constants won't change. They're used here to set pin


numbers:

const int buttonPin = 4; // the number of the


pushbutton pin

const int ledPin = 13; // the number of the LED


pin
const int ledPin1 = 12;
const int ledPin2 = 11;

// variables will change:


int initial = 0; //hold current initial
int oldstate = 0; //hold last initial
int buttonstate = 0; // variable for reading the
pushbutton status

void setup() {
pinMode(ledPin, OUTPUT); // initialize the LED pin
as an output:
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(buttonPin, INPUT); // initialize the
pushbutton pin as an input:
}

void loop(){
//debouncing routine to read button
buttonstate = digitalRead(buttonPin); //state the
initial of button
if(buttonstate == HIGH){ //check if it has been
pressed
delay(50);
buttonstate = digitalRead(buttonPin);//state button
again
if(buttonstate == LOW){ //if it is 0 considered
one press
initial = oldstate + 1; //increase initial by 1
}
}else{ //check if it has been NOT pressed
delay(100);
}

switch (initial){ //react to button press a initial


case 1: //if initial is 1
digitalWrite(ledPin, HIGH);//on
digitalWrite(ledPin1, LOW);//off
digitalWrite(ledPin2, LOW);//off
oldstate = initial; //set oldstate initial as
current initial
break;
case 2:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, HIGH);
digitalWrite(ledPin2, LOW);
oldstate = initial;
break;
case 3:
digitalWrite(ledPin, LOW);
digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, HIGH);
oldstate = initial;
break;
default: //if initial is not 1 2 3

digitalWrite(ledPin, LOW); //off


digitalWrite(ledPin1, LOW);
digitalWrite(ledPin2, LOW);
oldstate = 0; //reset to all off/initial 0
break;
}
}

Arduino obstacle avoiding + voice control + Bluetooth


control Robot

Diagram:

Code:
/*obstacle avoiding, Bluetooth control, voice control
robot car.
*/
#include <Servo.h>
#include <AFMotor.h>
#define Echo A0
#define Trig A1

#define motor 10
#define Speed 170
#define spoint 103
char value;
int distance;
int Left;
int Right;
int L = 0;
int R = 0;
int L1 = 0;
int R1 = 0;
Servo servo;
AF_DCMotor M1(1);
AF_DCMotor M2(2);
AF_DCMotor M3(3);
AF_DCMotor M4(4);
void setup() {
Serial.begin(9600);

pinMode(Trig, OUTPUT);
pinMode(Echo, INPUT);
servo.attach(motor);
M1.setSpeed(Speed);
M2.setSpeed(Speed);
M3.setSpeed(Speed);
M4.setSpeed(Speed);
}
void loop() {
//Obstacle();
//Bluetoothcontrol();
//voicecontrol();
}
void Bluetoothcontrol() {
if (Serial.available() > 0) {
value = Serial.read();
Serial.println(value);
}

if (value == 'F') {
forward();
} else if (value == 'B') {
backward();
} else if (value == 'L') {
left();
} else if (value == 'R') {
right();
} else if (value == 'S') {
Stop();
}
}
void Obstacle() {
distance = ultrasonic();
if (distance <= 12) {

Stop();
backward();

delay(100);
Stop();
L = leftsee();
servo.write(spoint);
delay(800);
R = rightsee();
servo.write(spoint);
if (L < R) {
right();
delay(500);
Stop();
delay(200);
} else if (L > R) {
left();
delay(500);
Stop();
delay(200);
}

} else {
forward();
}
}
void voicecontrol() {
if (Serial.available() > 0) {
value = Serial.read();
Serial.println(value);
if (value == '^') {
forward();
} else if (value == '-') {
backward();
} else if (value == '<') {
L = leftsee();
servo.write(spoint);
if (L >= 10 ) {
left();
delay(500);

Stop();
} else if (L < 10) {
Stop();
}
} else if (value == '>') {
R = rightsee();

servo.write(spoint);
if (R >= 10 ) {
right();
delay(500);
Stop();
} else if (R < 10) {
Stop();
}
} else if (value == '*') {
Stop();
}

}
}
// Ultrasonic sensor distance reading function
int ultrasonic() {
digitalWrite(Trig, LOW);
delayMicroseconds(4);
digitalWrite(Trig, HIGH);
delayMicroseconds(10);
digitalWrite(Trig, LOW);
long t = pulseIn(Echo, HIGH);
long cm = t / 29 / 2; //time convert distance
return cm;
}
void forward() {
M1.run(FORWARD);
M2.run(FORWARD);
M3.run(FORWARD);
M4.run(FORWARD);

}
void backward() {
M1.run(BACKWARD);
M2.run(BACKWARD);
M3.run(BACKWARD);
M4.run(BACKWARD);
}
void right() {
M1.run(BACKWARD);
M2.run(BACKWARD);
M3.run(FORWARD);
M4.run(FORWARD);
}
void left() {
M1.run(FORWARD);
M2.run(FORWARD);

M3.run(BACKWARD);

M4.run(BACKWARD);
}
void Stop() {
M1.run(RELEASE);
M2.run(RELEASE);
M3.run(RELEASE);
M4.run(RELEASE);
}
int rightsee() {
servo.write(20);
delay(800);
Left = ultrasonic();
return Left;
}
int leftsee() {
servo.write(180);
delay(800);
Right = ultrasonic();

return Right;
}

Arduino and a Laser


Diagram:

Code:

void setup() {

pinMode(12,OUTPUT); // relay on digital pin 12


/*
Don't use the relay directly to the arduino board as
shown in my video.
it may be harmful for your arduino board.Use a 1
channel relay module for that.
a circuit diagram is given with this.
*/

boolean laser_beam_cut=false;

void loop() {
int LDR_read=analogRead(A0); // LDR on analog pin
A0

if(LDR_read<700){
laser_beam_cut=true;
}else{

if(laser_beam_cut==true){
changeledstate();
laser_beam_cut=false;
}
}
}

void changeledstate(){
if(digitalRead(12)==HIGH){
digitalWrite(12,LOW);
}else{
digitalWrite(12,HIGH);
}
}

ARDUINO LINE FOLLOWER CAR

Components:
● Arduino uno
● Motor driver shield(L293D)
● Ir sensor -2
● Jumper wires
● Bo motor-4
● Tyre-4
● A car body

Circuit Diagram:

Code in c language:
//ARDUINO LINE FOLLOWING CAR//
// YOU HAVE TO INSTALL THE AFMOTOR
LIBRARY BEFORE UPLOAD THE CODE//

// GO TO SKETCH >> INCLUDE LIBRARY >>


ADD .ZIP LIBRARY >> SELECT AF MOTOR ZIP FILE
//

//including the libraries


#include <AFMotor.h>

//defining pins and variables


#define left A0
#define right A1

//defining motors
AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

void setup() {
//declaring pin types
pinMode(left,INPUT);
pinMode(right,INPUT);

//begin serial communication


Serial.begin(9600);

void loop(){
//printing values of the sensors to the serial monitor
Serial.println(digitalRead(left));

Serial.println(digitalRead(right));

//line detected by both


if(digitalRead(left)==0 && digitalRead(right)==0){
//Forward
motor1.run(FORWARD);
motor1.setSpeed(150);
motor2.run(FORWARD);
motor2.setSpeed(150);
motor3.run(FORWARD);
motor3.setSpeed(150);
motor4.run(FORWARD);

motor4.setSpeed(150);
}
//line detected by left sensor
else if(digitalRead(left)==0 && !analogRead(right)==0){
//turn left
motor1.run(FORWARD);
motor1.setSpeed(200);
motor2.run(FORWARD);
motor2.setSpeed(200);
motor3.run(BACKWARD);
motor3.setSpeed(200);
motor4.run(BACKWARD);
motor4.setSpeed(200);

}
//line detected by right sensor
else if(!digitalRead(left)==0 && digitalRead(right)==0){
//turn right
motor1.run(BACKWARD);
motor1.setSpeed(200);
motor2.run(BACKWARD);

motor2.setSpeed(200);
motor3.run(FORWARD);
motor3.setSpeed(200);
motor4.run(FORWARD);
motor4.setSpeed(200);

}
//line detected by none
else if(!digitalRead(left)==0 && !digitalRead(right)==0){
//stop
motor1.run(RELEASE);
motor1.setSpeed(0);
motor2.run(RELEASE);
motor2.setSpeed(0);
motor3.run(RELEASE);
motor3.setSpeed(0);
motor4.run(RELEASE);
motor4.setSpeed(0);

Arduino with Fire Sensor, LED and Buzzer


Component:
● An arduino and its adapter
● Few jumper Wires
● A fire sensor
● A led
● A breadboard
● A buzzer
● A lighter
Circuit diagram:

Code:

const int ledpin=13; // ledpin,flamepin and buzpin are


not changed throughout the process
const int flamepin=A2;
const int buzpin=11;
const int threshold=200;// sets threshold value for
flame sensor
int flamesensvalue=0; // initialise flame sensor reading
void setup() {
Serial.begin(9600);
pinMode(ledpin,OUTPUT);
pinMode(flamepin,INPUT);

pinMode(buzpin,OUTPUT);
}
void loop() {
flamesensvalue=analogRead(flamepin); // reads analog
data from flame sensor
if (flamesensvalue<=threshold) { // compares reading
from flame sensor with the threshold value
digitalWrite(ledpin,HIGH); //turns on led and buzzer

tone(buzpin,100);
delay(1000); //stops program for 1 second
}
else{
digitalWrite(ledpin,LOW); //turns led off led and
buzzer
noTone(buzpin);
}
}

BLUETOOTH CONTROLLED CAR


Uses component
● Arduino UNO
● Motor Driver Shield(L293D).
● Bluetooth module(HC-05).
● Jumper Wire
● 4 VO Motor
● 4 Tyre

● A car body
● Circuit diagram
● Code in C language
● Bluetooth RC Controller phone App

ARDUINO UNO
The Arduino Uno is an open-source microcontroller
board based on the Microchip ATmega328P
microcontroller and developed by Arduino.cc and initially
released in 2010. The board is equipped with sets of
digital and analog input/output (I/O) pins that may be
interfaced to various expansion boards (shields) and other
circuits. The board has 14 digital I/O pins (six capable of
PWM output), 6 analog I/O pins, and is programmable
with the Arduino IDE (Integrated Development
Environment), via a type B USB cable. It can be powered
by the USB cable or by an external 9-volt battery, though
it accepts voltages between 7 and 20 volts. It is similar to
the Arduino Nano and Leonardo. The hardware reference
design is distributed under a Creative Commons
Attribution Share-Alike 2.5 licence and is available on the
Arduino website. Layout and production files for some
versions of the hardware are also available.
The word "uno" means "one" in Italian and was chosen to
mark the initial release of Arduino Software. The Uno

board is the first in a series of USB-based Arduino boards;


it and version 1.0 of the Arduino IDE were the reference
versions of Arduino, which have now evolved to newer
releases. The ATmega328 on the board comes
preprogrammed with a bootloader that allows uploading
new code to it without the use of an external hardware
programmer.
While the Uno communicates using the original STK500
protocol, it differs from all preceding boards in that it
does not use the FTDI USB-to-serial driver chip. Instead,
it uses the Atmega16U2 (Atmega8U2 up to version R2)
programmed as a USB-to-serial converter.

Technical specification
● Microcontroller: Microchip ATmega328P[7]
● Operating Voltage: 5 Volts
● Input Voltage: 7 to 20 Volts
● Digital I/O Pins: 14
● PWM Pins: 6 (Pin # 3, 5, 6, 9, 10 and 11)[9]
● UART: 1
● I2C: 1
● SPI: 1
● Analog Input Pins: 6
● DC Current per I/O Pin: 20 mA
● DC Current for 3.3V Pin: 50 mA

● Flash Memory: 32 KB of which 0.5 KB used by


bootloader
● SRAM: 2 KB
● EEPROM: 1 KB
● Clock Speed: 16 MHz
● Length: 68.6 mm
● Width: 53.4 mm
● Weight: 25 g
● ICSP Header: Yes
● Power Sources: DC Power Jack, USB Port and the VIN
pin (+5 volt only)

General pin functions


● LED: There is a built-in LED driven by digital pin 13.
When the pin is high value, the LED is on, when the pin
is low, it is off.
● VIN: The input voltage to the Arduino/Genuino board
when it is using an external power source (as opposed
to 5 volts from the USB connection or other regulated
power source). You can supply voltage through this pin,
or, if supplying voltage via the power jack, access it
through this pin.
● 5V: This pin outputs a regulated 5V from the regulator
on the board. The board can be supplied with power
either from the DC power jack (7 - 20V), the USB

connector (5V), or the VIN pin of the board (7-20V).


Supplying voltage via the 5V or 3.3V pins bypasses the
regulator, and can damage the board.
● 3V3: A 3.3 volt supply generated by the on-board
regulator. Maximum current draw is 50 mA.
● GND: Ground pins.
● IOREF: This pin on the Arduino/Genuino board
provides the voltage reference with which the
microcontroller operates. A properly configured shield
can read the IOREF pin voltage and select the
appropriate power source, or enable voltage translators
on the outputs to work with the 5V or 3.3V.
● Reset: Typically used to add a reset button to shields
that block the one on the board.
Special pin functions

Each of the 14 digital pins and 6 analog pins on the Uno


can be used as an input or output, under software control
(using pinMode(), digitalWrite(), and digitalRead()
functions). They operate at 5 volts. Each pin can provide
or receive 20 mA as the recommended operating
condition and has an internal pull-up resistor
(disconnected by default) of 20-50K ohm. A maximum of
40mA must not be exceeded on any I/O pin to avoid
permanent damage to the microcontroller. The Uno has 6
analog inputs, labelled A0 through A5; each provides 10
bits of resolution (i.e. 1024 different values). By default,

they measure from ground to 5 volts, though it is possible


to change the upper end of the range using the AREF pin
and the analogReference() function.[7]
In addition, some pins have specialised functions:
● Serial / UART: pins 0 (RX) and 1 (TX). Used to
receive (RX) and transmit (TX) TTL serial data. These
pins are connected to the corresponding pins of the
ATmega8U2 USB-to-TTL serial chip.
● External interrupts: pins 2 and 3. These pins can be
configured to trigger an interrupt on a low value, a
rising or falling edge, or a change in value.
● PWM (pulse-width modulation): pins 3, 5, 6, 9, 10, and
11. Can provide 8-bit PWM output with the
analogWrite() function.
● SPI (Serial Peripheral Interface): pins 10 (SS), 11
(MOSI), 12 (MISO), and 13 (SCK). These pins support
SPI communication using the SPI library.
● TWI (two-wire interface) / I²C: pin SDA (A4) and pin
SCL (A5). Support TWI communication using the Wire
library.
● AREF (analog reference): Reference voltage for the
analog inputs.

Motor Driver Shield(L293D)


Motors used in academic robots normally operate at 5, 6,


9, 12 or 24 volts. Depending on the model, the
manufacturing method, price, etc., their current is about
100 mA to 5A. You can use motors in several ways. One
method is to connect it directly to a battery, then it spins
at its maximum speed in a particular direction, but in
practice, we need to control the motors (on and off, speed
control, direction control, and position control).
Therefore, we must control motors using controllers
(logic circuits or microcontrollers or PCs or computers).
But as you know, the output of microcontrollers are 5V
and 200mA and can not spin the motor. So we need
intermediate circuits to connect the controller to the
motor, called drivers. L293D is one of the most popular
drivers in the market. There are several reasons which
make L293D the preferred driver to the users, such as,
cheap price (compared to other drivers), proper shape and
size, easy control, no need for protective circuit and
diodes, no need for heat sinks and good resistance to
temperature and high-speed variations. This IC can set up
motors with a voltage between 5V to 36V and a current of
up to 600 mA. However, it can withstand a current up to
1200 mA in 100
microseconds and is non-repetitive. The frequency of this
IC is 5 kHz. If your motor matches these specifications,
do not hesitate to use L293D.

L293D Features and Specifications

The L293 and L293D devices are quadruple high current


half-H drivers. The L293 is designed to provide
bidirectional drive currents of up to 1 A at voltages from
4.5 V to 36 V. The L293D is designed to provide
bidirectional drive currents of up to 600-mA at voltages
from 4.5 V to 36 V. Both devices are designed to drive
inductive loads such as relays, solenoids, DC and bipolar
stepping motors, as well as other high current / high
voltage loads in positive supply applications.
Each output is a complete totem-pole drive circuit, with a
Darlington transistor sink and a pseudo- Darlington
source. Drivers are enabled in pairs, with drivers 1 and 2

enabled by 1,2EN and drivers 3 and 4 enabled by 3,4EN.


L293 and L293D are characterised for operation from 0°C
to 70°C.
Other important L293D features are:
● Wide Supply-Voltage Range: 4.5 V to 36 V

● Separate Input-Logic Supply

● Internal ESD Protection

● High-Noise-Immunity Inputs

● Output Current 1 A Per Channel (600 mA for L293D)

● Peak Output Current 2 A Per Channel (1.2 A for

L293D)

● Output Clamp Diodes for Inductive Transient

Suppression (L293D)

Bluetooth module(HC-05)

Ever wanted to control your Mechanical Bots with


an Android Phone or design the robots with a
custom remote, here in this tutorial we will learn
about a Bluetooth Module HC-05 used for the
above mentioned and many other cases. Here we
will be understanding the connection and working
of a HC-05 module and also its interfacing with a
custom android app.

Basics
Wireless communication is swiftly replacing the
wired connection when it comes to electronics and
communication. Designed to replace cable
connections, HC-05 uses serial communication to
communicate with the electronics. Usually, it is used
to connect small devices like mobile phones using a
short-range wireless connection to exchange files. It
uses the 2.45GHz frequency band. The transfer rate
of the data can vary up to 1Mbps and is in range of
10 metres.
The HC-05 module can be operated within 4-6V of
power supply. It supports baud rate of 9600, 19200,
38400, 57600, etc. Most importantly it can be

operated in Master-Slave mode which means it will


neither send or receive data from external sources.

Description of pins

Enable - This pin is used to set the Data Mode or and


AT command mode (set high).
VCC - This is connected to +5V power supply.
Ground - Connected to ground of the powering
system.
Tx (Transmitter) - This pin transmits the received data
Serially.
Rx (Receiver) - Used for broadcasting data serially
over bluetooth.
State -Used to check if the bluetooth is working
properly.

Programming HC-05 with Microcontroller

Technical specs of the code:


● Arduino-Uno is used as the microcontroller.

● Name: HC-05

● Password: 1234 (or 0000)

● Type: Slave

● Mode: Data




● Baud Rate: 9600 with 8 data bits, no parity and 1 stop


bit

Jumper Wire
jumper wires are easy and inexpensive to purchase, it
can also be a fun task to challenge students to make
their own. Doing so requires insulated wire and wire
strippers. However, beware that it is important not to
nick the wire when stripping off the insulation.

BO Motor with tyre


A DC motor is any of a class of rotary electrical motors
that converts direct current (DC) electrical energy into
mechanical energy. The most common types rely on the
forces produced by induced magnetic fields due to
flowing current in the coil. Nearly all types of DC motors
have some internal mechanism, either electromechanical
or electronic, to periodically change the direction of
current in part of the motor.
DC motors were the first form of motors widely used, as
they could be powered from existing direct-current
lighting power distribution systems. A DC motor's speed
can be controlled over a wide range, using either a
variable supply voltage or by changing the strength of
current in its field windings. Small DC motors are used in
tools, toys, and appliances. The universal motor, a
lightweight brushed motor used for portable power tools
and appliances can operate on direct current and
alternating current. Larger DC motors are currently used

in propulsion of electric vehicles, elevators and hoists,


and in drives for steel rolling mills. The advent of power
electronics has made replacement of DC motors with AC
motors possible in many applications.

Car body

Code in C language

//Arduino Bluetooth Controlled Car


//Before uploading the code you have to install the
necessary library

//Note - Disconnect the Bluetooth Module before hiting


the upload button otherwise you'll get a compilation error
message.
//AFMotor Library https://learn.adafruit.com/adafruit-
motor-shield/library-install
//After downloading the library open Arduino IDE >> go
to sketch >> Include Library >> ADD. ZIP Library >>
Select the downloaded
//ZIP File >> Open it >> Done
//Now You Can Upload the Code without any problem but
make sure the bt module isn't connected with Arduino
while uploading code

#include <AFMotor.h>

//initial motors pin


AF_DCMotor motor1(1, MOTOR12_1KHZ);
AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

char command;

void setup()
{
Serial.begin(9600); //Set the baud rate to your Bluetooth
module.
}

void loop(){
if(Serial.available() > 0){
command = Serial.read();
Stop(); //initialise with motors stoped
//Change pin mode only if new command is different from
previous.
//Serial.println(command);
switch(command){
case 'F':
forward();

break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
}
}

void forward()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise

motor2.setSpeed(255); //Define maximum velocity


motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255);//Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255);//Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}

void back()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-
clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-
clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-
clockwise

motor4.setSpeed(255); //Define maximum velocity


motor4.run(BACKWARD); //rotate the motor anti-
clockwise
}

void left()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(BACKWARD); //rotate the motor anti-
clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(BACKWARD); //rotate the motor anti-
clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(FORWARD); //rotate the motor clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(FORWARD); //rotate the motor clockwise
}

void right()
{
motor1.setSpeed(255); //Define maximum velocity
motor1.run(FORWARD); //rotate the motor clockwise
motor2.setSpeed(255); //Define maximum velocity
motor2.run(FORWARD); //rotate the motor clockwise
motor3.setSpeed(255); //Define maximum velocity
motor3.run(BACKWARD); //rotate the motor anti-
clockwise
motor4.setSpeed(255); //Define maximum velocity
motor4.run(BACKWARD); //rotate the motor anti-
clockwise
}

void Stop()
{
motor1.setSpeed(0); //Define minimum velocity
motor1.run(RELEASE); //stop the motor when release the
button

motor2.setSpeed(0); //Define minimum velocity


motor2.run(RELEASE); //rotate the motor clockwise
motor3.setSpeed(0); //Define minimum velocity
motor3.run(RELEASE); //stop the motor when release the
button
motor4.setSpeed(0); //Define minimum velocity
motor4.run(RELEASE); //stop the motor when release the
button
}

Circuit diagram

Bluetooth RC Controller phone App


● Search HC-05 Bluetooth module and drive the car

www.jantagroup.org

Brightness Controller with Push Button

Diagram:

Code:
int pinIncrease = 9; //Button for increase the
brightness.
int pinDecrease = 10; //Button for decrease the
brightness.
int pinLED = 3; // LED pin D3.
int steps = 10; // Enter number of steps here.
int brightness = 0;
void setup()
{
pinMode(pinIncrease, INPUT);
pinMode(pinDecrease, INPUT);
pinMode(pinLED, OUTPUT);
digitalWrite(pinIncrease, HIGH);
digitalWrite(pinDecrease, HIGH);
}

void loop() {
brightness = constrain(brightness, 0, 255);
analogWrite(pinLED, brightness);
if (digitalRead(pinIncrease) == LOW)
{
brightness = brightness + (256/steps);
} else if (digitalRead(pinDecrease) == LOW)
{
brightness = brightness - (256/steps);
}
delay(100);
}

CLAPPING LIGHT WITH ARDUINO


COMPONENTS:
● Microphone module
● 5V relay module
● Arduino UNO
● Jumper wire
Diagram:

Code:
int mic = 2; // microphone module

int indicLED = 13; // indication pin

int lightPin = 9; // relay (lights control)

bool lightState = true;

bool ignoreInt = false;

bool ClapDetected = false;

uint32_t ClapDetetedTime [3] {};

void setup() {

Serial.begin(115200);

pinMode(indicLED, OUTPUT);

pinMode(lightPin, OUTPUT);

digitalWrite(lightPin, lightState);

attachInterrupt(digitalPinToInterrupt(mic),
ISR_ClapDetected, FALLING);

void loop() {

delay(2);

if(millis() - ClapDetetedTime[2] >= 800)

digitalWrite(indicLED, LOW);

if(millis() - ClapDetetedTime[2] < 800 && millis() -


ClapDetetedTime[1] < 800 && ClapDetected &&
ClapDetetedTime[1] - ClapDetetedTime[0]>=800)

Serial.println("double clap detected");

digitalWrite(indicLED, LOW);

Serial.print("Setting light to ");

Serial.println(String(!lightState));

digitalWrite(lightPin, lightState);

lightState=!lightState;

ClapDetected = false;

void ISR_ClapDetected()

if(millis() - ClapDetetedTime[2] > 200){ // debounce

for (int i = 0; i != 2; i++) {

ClapDetetedTime[i] = ClapDetetedTime[i + 1];

ClapDetetedTime[2] = millis();

ClapDetected = true;

Serial.println("clap detected");

digitalWrite(indicLED, HIGH);

Arduino Ultrasonic Sensor and LCD Display Example

example: how to use the ultrasonic sensor with Arduino


and display the results on an LCD.

You can connect the ultrasonic sensor and the LDC as


following:

The code measuring the distance is pretty much the same


as the basic example. Here, instead of printing the results
on the serial monitor we print them on the LCD. If you
need more details on how to use and connect an LCD
with an Arduino you can check my particular tutorial for
it.

/*
Ultrasonic Sensor HC-SR04 and Arduino Tutorial

by Janta group,
www.jantagroup.org

*/
#include <LiquidCrystal.h> // includes the
LiquidCrystal Library
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LCD
object. Parameters: (rs, enable, d4, d5, d6, d7)
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distanceCm, distanceInch;
void setup() {
lcd.begin(16, 2); // Initializes the interface to the LCD
screen, and specifies the dimensions (width and height) of
the display
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm = duration * 0.034 / 2;
distanceInch = duration * 0.0133 / 2;
lcd.setCursor(0, 0); // Sets the location at which
subsequent text written to the LCD will be displayed
lcd.print("Distance: "); // Prints string "Distance" on the
LCD
lcd.print(distanceCm); // Prints the distance value from
the sensor
lcd.print(" cm");
delay(10);
lcd.setCursor(0, 1);
lcd.print("Distance: ");
lcd.print(distanceInch);
lcd.print(" inch");
delay(10);

Fingerprint Door Lock system using Arduino


Components:
● Arduino Uno
● Fingerprint Scanner (FPM10A DY50)
● 5V relay
● Solenoid 12V lock
● 12 V AC-DC Adapter (We can use 12V battery as
well)
● Jumper wires

Diagram:

Code:

#include <Adafruit_Fingerprint.h>

SoftwareSerial mySerial(2, 3);


Adafruit_Fingerprint finger =
Adafruit_Fingerprint(&mySerial);

#define RELAY_PIN 4
#define ACCESS_DELAY 3000 // Keep lock
unlocked for 3 seconds

void setup()
{
// set the data rate for the sensor serial port
finger.begin(57600);
delay(5);
if (finger.verifyPassword())
{
}
else
{

while (1) { delay(1); }


}

pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, HIGH); //Switch off relay
initially. Relay is LOW level triggered relay so we need
to write HIGH.
}

void loop()
{
if ( getFingerPrint() != -1)
{
digitalWrite(RELAY_PIN, LOW);
delay(ACCESS_DELAY);
digitalWrite(RELAY_PIN, HIGH);
}
delay(50); //Add some delay before next scan.
}

// returns -1 if failed, otherwise returns ID #


int getFingerPrint()
{
int p = finger.getImage();
if (p != FINGERPRINT_OK) return -1;

p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;

p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;

// found a match!
return finger.fingerID;
}

FingerPrint Enrol code:

#include <Adafruit_Fingerprint.h>

SoftwareSerial mySerial(2, 3);


Adafruit_Fingerprint finger =
Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup()
{
Serial.begin(9600);
while (!Serial);
delay(100);

// set the data rate for the sensor serial port


finger.begin(57600);
if (finger.verifyPassword())
{
Serial.println("Found fingerprint sensor!");
}
else
{

Serial.println("Did not find fingerprint sensor :(");


while (1) { delay(1); }
}

Serial.println(F("Reading sensor parameters"));


finger.getParameters();
finger.getTemplateCount();
Serial.print(F("Status: 0x"));
Serial.println(finger.status_reg, HEX);
Serial.print(F("Sys ID: 0x"));
Serial.println(finger.system_id, HEX);
Serial.print(F("Capacity: "));
Serial.println(finger.capacity);
Serial.print(F("Security level: "));
Serial.println(finger.security_level);
Serial.print(F("Device address: "));
Serial.println(finger.device_addr, HEX);
Serial.print(F("Packet len: "));
Serial.println(finger.packet_len);
Serial.print(F("Baud rate: "));
Serial.println(finger.baud_rate);
Serial.print(F("Total finger prints stored: "));
Serial.println(finger.templateCount);

uint8_t readnumber(void)
{
uint8_t num = 0;

while (num == 0)
{
while (! Serial.available());
num = Serial.parseInt();
}
return num;
}

void loop()
{
Serial.println("\n\nReady to enroll a fingerprint!");
Serial.println("Please type in -1 to delete all the stored
finger prints...");
Serial.println("Please type in the ID # (from 1 to 127) you
want to save the finger as...");
id = readnumber();

if (id == 0) // ID #0 not allowed, try again!


{
return;
}

if (id == uint8_t(-1))
{
Serial.print("Cleared all finger prints from database");
finger.emptyDatabase();
return;
}

Serial.print("Enrolling ID #");
Serial.println(id);
while (! getFingerprintEnroll() );
}

uint8_t getFingerprintEnroll()
{

int p = -1;

Serial.print("Waiting for valid finger to enroll as #");


Serial.println(id);
while (p != FINGERPRINT_OK)
{
p = finger.getImage();
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
break;
default:
Serial.println("Unknown error");
break;

}
}

// OK success!

p = finger.image2Tz(1);
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:
Serial.println("Image too messy");
return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");

return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;

case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");
return p;
}

Serial.println("Remove finger");
delay(2000);
p = 0;
while (p != FINGERPRINT_NOFINGER)
{
p = finger.getImage();
}
Serial.print("ID "); Serial.println(id);
p = -1;
Serial.println("Place same finger again");
while (p != FINGERPRINT_OK)
{
p = finger.getImage();

switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image taken");
break;
case FINGERPRINT_NOFINGER:
break;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
break;
case FINGERPRINT_IMAGEFAIL:
Serial.println("Imaging error");
break;
default:
Serial.println("Unknown error");
break;
}
}

// OK success!

p = finger.image2Tz(2);
switch (p)
{
case FINGERPRINT_OK:
Serial.println("Image converted");
break;
case FINGERPRINT_IMAGEMESS:

Serial.println("Image too messy");


return p;
case FINGERPRINT_PACKETRECIEVEERR:
Serial.println("Communication error");
return p;
case FINGERPRINT_FEATUREFAIL:
Serial.println("Could not find fingerprint features");
return p;
case FINGERPRINT_INVALIDIMAGE:
Serial.println("Could not find fingerprint features");
return p;
default:
Serial.println("Unknown error");

return p;
}

// OK converted!
Serial.print("Creating model for #"); Serial.println(id);

p = finger.createModel();
if (p == FINGERPRINT_OK) {
Serial.println("Prints matched!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR)
{
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_ENROLLMISMATCH) {
Serial.println("Fingerprints did not match");
return p;
} else {
Serial.println("Unknown error");
return p;
}

Serial.print("ID "); Serial.println(id);


p = finger.storeModel(id);
if (p == FINGERPRINT_OK) {
Serial.println("Stored!");
} else if (p == FINGERPRINT_PACKETRECIEVEERR)
{
Serial.println("Communication error");
return p;
} else if (p == FINGERPRINT_BADLOCATION) {
Serial.println("Could not store in that location");
return p;
} else if (p == FINGERPRINT_FLASHERR) {
Serial.println("Error writing to flash");
return p;
} else {
Serial.println("Unknown error");
return p;
}

return true;
}

Flowing LED Lights with a Potentiometer

COMPONENTS:
1. Arduino Uno
2. Breadboard
3. 8 LEDs with 8 X 330 ohm Resistors
4. 10K Potentiometer
5. Jumper Wires

PROGRAM:
*/Created by janta group

www.jantagroup.org/*

int ledNum = 8; // define the number of


the LEDs
int ledPin[] = {2, 3, 4, 5, 6, 7, 8, 9}; // create array for
LED pins
int delayTime; // define a variable for the
value of delay
int potPin = A0; // define the
potentiometer pin

void setup() {
for (int x = 0; x < ledNum; x++) { // setting all LEDs
as OUTPUT
pinMode(ledPin[x], OUTPUT);
}
}

void loop() {
for (int i = 0; i < 8; i++) {
delayTime = analogRead(potPin); //getting the time
delay from the potentiometer

digitalWrite(ledPin[i], HIGH); //turn on LEDs


delay(delayTime); //time interval
digitalWrite(ledPin[i], LOW); //turn off LEDs
}
for (int i = 7; i >= 0; i--) {
delayTime = analogRead(potPin); //getting the time
delay from the potentiometer
digitalWrite(ledPin[i], HIGH); //turn on LEDs
delay(delayTime); //time interval
digitalWrite(ledPin[i], LOW); //turn off leds
}
}

Flowing LED Lights without a Potentiometer

COMPONENTS:
● Arduino Uno
● Breadboard
● 8 LEDs with 8 X 330 ohm Resistors
● Jumper Wires

PROGRAM:
*/Created by janta group
www.jantagroup.org/*

int ledNum = 8; // define the number of


the LEDs
int ledPin[] = {2, 3, 4, 5, 6, 7, 8, 9}; // create array for
LED pins
int delayTime = 1000; // define a variable for
the value of delay

void setup() {
for (int x = 0; x < ledNum; x++) { // setting all LEDs
as OUTPUT
pinMode(ledPin[x], OUTPUT);
}
}

void loop() {
for (int i = 0; i < 8; i++) {
digitalWrite(ledPin[i], HIGH); //turn on LEDs
delay(delayTime); //time interval
digitalWrite(ledPin[i], LOW); //turn off LEDs
}
for (int i = 7; i >= 0; i--) {
digitalWrite(ledPin[i], HIGH); //turn on LEDs
delay(delayTime); //time interval
digitalWrite(ledPin[i], LOW); //turn off leds
}
}

Follow Me Car Robot Using Ultrasonic Sensor

Uses component
● Arduino UNO
● Motor Driver Shield(L293D).
● Ultrasonic Sensor(HC-SR04)
● Jumper Wire
● 4 BO Motor
● 4 Tyre
● A car body
● IR sensor-2
● Circuit diagram
● Code in C language

ARDUINO UNO
The Arduino Uno is an open-source
microcontroller board based on the
Microchip ATmega328P microcontroller
and developed by Arduino.cc and initially
released in 2010. The board is equipped

with sets of digital and analog input/output


(I/O) pins that may be interfaced to various
expansion boards (shields) and other
circuits. The board has 14 digital I/O pins
(six capable of PWM output), 6 analog I/O
pins, and is programmable with the
Arduino IDE (Integrated Development
Environment), via a type B USB cable. It
can be powered by the USB cable or by an
external 9-volt battery, though it accepts
voltages between 7 and 20 volts. It is
similar to the Arduino Nano and Leonardo.
The hardware reference design is
distributed under a Creative Commons
Attribution Share-Alike 2.5 licence and is
available on the Arduino website. Layout
and production files for some versions of
the hardware are also available.
The word "uno" means "one" in Italian and
was chosen to mark the initial release of
Arduino Software. The Uno board is the
first in a series of USB-based Arduino
boards; it and version 1.0 of the Arduino
IDE were the reference versions of
Arduino, which have now evolved to
newer releases. The ATmega328 on the
board comes preprogrammed with a
bootloader that allows uploading new code

to it without the use of an external


hardware programmer.
While the Uno communicates using the
original STK500 protocol, it differs from
all preceding boards in that it does not use
the FTDI USB-to-serial driver chip.
Instead, it uses the Atmega16U2
(Atmega8U2 up to version R2)
programmed as a USB-to-serial converter.
Technical specification
Microcontroller: Microchip ATmega328POperating
Voltage: 5 Volts
● Input Voltage: 7 to 20 Volts
● Digital I/O Pins: 14
● PWM Pins: 6 (Pin # 3, 5, 6, 9, 10 and 11)
● UART: 1
● I2C: 1
● SPI: 1
● Analog Input Pins: 6
● DC Current per I/O Pin: 20 mA
● DC Current for 3.3V Pin: 50 mA
● Flash Memory: 32 KB of which 0.5 KB used by
bootloader
● SRAM: 2 KB
● EEPROM: 1 KB
● Clock Speed: 16 MHz

● Length: 68.6 mm
● Width: 53.4 mm
● Weight: 25 g
● ICSP Header: Yes
● Power Sources: DC Power Jack, USB Port and the VIN
pin (+5 volt only)

General pin functions


● LED: There is a built-in LED driven by digital pin 13.
When the pin is high value, the LED is on, when the pin
is low, it is off.
● VIN: The input voltage to the Arduino/Genuino board
when it is using an external power source (as opposed
to 5 volts from the USB connection or other regulated
power source). You can supply voltage through this pin,
or, if supplying voltage via the power jack, access it
through this pin.
● 5V: This pin outputs a regulated 5V from the regulator
on the board. The board can be supplied with power
either from the DC power jack (7 - 20V), the USB
connector (5V), or the VIN pin of the board (7-20V).
Supplying voltage via the 5V or 3.3V pins bypasses the
regulator, and can damage the board.
● 3V3: A 3.3 volt supply generated by the on-board
regulator. Maximum current draw is 50 mA.

● GND: Ground pins.


● IOREF: This pin on the Arduino/Genuino board
provides the voltage reference with which the
microcontroller operates. A properly configured shield
can read the IOREF pin voltage and select the
appropriate power source, or enable voltage translators
on the outputs to work with the 5V or 3.3V.
● Reset: Typically used to add a reset button to shields
that block the one on the board.
Special pin functions

Each of the 14 digital pins and 6 analog pins on the Uno


can be used as an input or output, under software control
(using pinMode(), digitalWrite(), and digitalRead()
functions). They operate at 5 volts. Each pin can provide
or receive 20 mA as the recommended operating
condition and has an internal pull-up resistor
(disconnected by default) of 20-50K ohm. A maximum of
40mA must not be exceeded on any I/O pin to avoid
permanent damage to the microcontroller. The Uno has 6
analog inputs, labelled A0 through A5; each provides 10
bits of resolution (i.e. 1024 different values). By default,
they measure from ground to 5 volts, though it is possible
to change the upper end of the range using the AREF pin
and the analogReference() function.[7]
In addition, some pins have specialised functions:

● Serial / UART: pins 0 (RX) and 1 (TX). Used to


receive (RX) and transmit (TX) TTL serial data. These
pins are connected to the corresponding pins of the
ATmega8U2 USB-to-TTL serial chip.
● External interrupts: pins 2 and 3. These pins can be
configured to trigger an interrupt on a low value, a
rising or falling edge, or a change in value.
● PWM (pulse-width modulation): pins 3, 5, 6, 9, 10, and
11. Can provide 8-bit PWM output with the
analogWrite() function.
● SPI (Serial Peripheral Interface): pins 10 (SS), 11
(MOSI), 12 (MISO), and 13 (SCK). These pins support
SPI communication using the SPI library.
● TWI (two-wire interface) / I²C: pin SDA (A4) and pin
SCL (A5). Support TWI communication using the Wire
library.
● AREF (analog reference): Reference voltage for the
analog inputs.

Motor Driver Shield(L293D)

Motors used in academic robots normally operate at 5, 6,


9, 12 or 24 volts. Depending on the model, the
manufacturing method, price, etc., their current is about
100 mA to 5A. You can use motors in several ways. One
method is to connect it directly to a battery, then it spins
at its maximum speed in a particular direction, but in
practice, we need to control the motors (on and off, speed
control, direction control, and position control).
Therefore, we must control motors using controllers
(logic circuits or microcontrollers or PCs or computers).
But as you know, the output of microcontrollers are 5V
and 200mA and can not spin the motor. So we need
intermediate circuits to connect the controller to the
motor, called drivers. L293D is one of the most popular
drivers in the market. There are several reasons which
make L293D the preferred driver to the users, such as,
cheap price (compared to other drivers), proper shape and
size, easy control, no need for protective circuit and
diodes, no need for heat sinks and good resistance to
temperature and high-speed

variations. This IC can set up motors with a voltage


between 5V to 36V and a current of up to 600 mA.
However, it can withstand a current up to 1200 mA in 100
microseconds and is non-repetitive. The frequency of this
IC is 5 kHz. If your motor matches these specifications,
do not hesitate to use L293D.

L293D Features and Specifications

The L293 and L293D devices are quadruple high current


half-H drivers. The L293 is designed to provide
bidirectional drive currents of up to 1 A at voltages from
4.5 V to 36 V. The L293D is designed to provide
bidirectional drive currents of up to 600-mA at voltages
from 4.5 V to 36 V. Both devices are designed to drive
inductive loads such as
relays, solenoids, DC and bipolar stepping motors, as well
as other high current / high voltage loads in positive
supply applications.

Each output is a complete totem-pole drive circuit, with a


Darlington transistor sink and a pseudo- Darlington
source. Drivers are enabled in pairs, with drivers 1 and 2
enabled by 1,2EN and drivers 3 and 4 enabled by 3,4EN.
L293 and L293D are characterised for operation from 0°C
to 70°C.
Other important L293D features are:
● Wide Supply-Voltage Range: 4.5 V to 36 V
● Separate Input-Logic Supply
● Internal ESD Protection
● High-Noise-Immunity Inputs
● Output Current 1 A Per Channel (600 mA for L293D)
● Peak Output Current 2 A Per Channel (1.2 A for
L293D)
● Output Clamp Diodes for Inductive Transient
Suppression (L293D)
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. Ultrasonic waves travel faster than the speed of
audible sound (i.e. the sound that humans can hear).
Ultrasonic sensors have two main components: the
transmitter (which emits the sound using piezoelectric

crystals) and the receiver (which encounters the sound


after it has travelled to and from the target).

In order to calculate the distance between the sensor and


the object, the sensor measures the time it takes between
the emission of the sound by the transmitter to its contact
with the receiver. The formula for this calculation is D =
½ T x C (where D is the distance, T is the time, and C is

the speed of sound ~ 343 metres/second). For example, if


a scientist set up an ultrasonic sensor aimed at a box and it
took 0.025 seconds for the sound to bounce back, the
distance between the ultrasonic sensor and the box would
be:

D = 0.5 x 0.025 x 343


or about 4.2875
metres.

Jumper Wire
jumper wires are easy and inexpensive to purchase, it can
also be a fun task to challenge students to make their own.
Doing so requires insulated wire and wire strippers.
However, beware that it is important not to nick the wire
when stripping off the insulation.

BO Motor with tyre


A DC motor is any of a class of rotary electrical motors
that converts direct current (DC) electrical energy into
mechanical energy. The most common types rely on the
forces produced by induced magnetic fields due to
flowing current in the coil. Nearly all types of DC motors
have some internal mechanism, either electromechanical
or electronic, to periodically change the direction of
current in part of the motor.
DC motors were the first form of motors widely used, as
they could be powered from existing direct-current
lighting power distribution systems. A DC motor's speed
can be controlled over a wide range, using either a
variable supply

voltage or by changing the strength of current in its field


windings. Small DC motors are used in tools, toys, and
appliances. The universal motor, a lightweight brushed
motor used for portable power tools and appliances can
operate on direct current and alternating current. Larger
DC motors are currently used in propulsion of electric
vehicles, elevators and hoists, and in drives for steel

rolling mills. The advent of power electronics has made


replacement of DC motors with AC motors possible in
many applications.

Car body

IR Sensor

IR sensor is an electronic device that emits light in order


to sense some object of the surroundings. An IR sensor
can measure the heat of an object as well as detect the
motion. Usually, in the infrared spectrum, all the objects

radiate some form of thermal radiation. These types of


radiation are invisible to our eyes, but infrared sensors can
detect these radiations.

The emitter is simply an IR LED (Light Emitting Diode)


and the detector is simply an IR photodiode . Photodiodes
are sensitive to IR light of the same wavelength which is
emitted by the IR LED. When IR light falls on the
photodiode, the resistances and the output voltages will
change in proportion to the magnitude of the IR light
received.

There are five basic elements used in a typical infrared


detection system: an infrared source, a transmission
medium, optical component, infrared detectors or
receivers and signal processing. Infrared lasers and
Infrared LED’s of specific wavelength used as infrared
sources.

Circuit diagram

Code in C language

//Arduino Human Following Robot


// Created By Janta Group
// You have to install the AFMotor and NewPing library
Before Uploading the sketch
// You can find all the required libraris from arduino
library manager.

// Contact me on instagram for any query(Insta Id :


diy.builder)
// Modified 7 Mar 2022
// Version 1.1

//include the library code:


#include<NewPing.h>
#include<Servo.h>
#include<AFMotor.h>

#define RIGHT A2 // Right IR sensor connected


to analog pin A2 of Arduino Uno:
#define LEFT A3 // Left IR sensor connected to
analog pin A3 of Arduino Uno:
#define TRIGGER_PIN A1 // Trigger pin connected
to analog pin A1 of Arduino Uno:
#define ECHO_PIN A0 // Echo pin connected to
analog pin A0 of Arduino Uno:

#define MAX_DISTANCE 200 // Maximum ping


distance:

unsigned int distance = 0; //Variable to store ultrasonic


sensor distance:
unsigned int Right_Value = 0; //Variable to store Right IR
sensor value:
unsigned int Left_Value = 0; //Variable to store Left IR
sensor value:

NewPing sonar(TRIGGER_PIN, ECHO_PIN,


MAX_DISTANCE); //NewPing setup of pins and
maximum distance:

//create motor objects


AF_DCMotor Motor1(1,MOTOR12_1KHZ);
AF_DCMotor Motor2(2,MOTOR12_1KHZ);
AF_DCMotor Motor3(3,MOTOR34_1KHZ);
AF_DCMotor Motor4(4,MOTOR34_1KHZ);

Servo myservo; //create servo object to control the servo:


int pos=0; //variable to store the servo position:

void setup() { // the setup function runs only once when


power on the board or reset the board:

Serial.begin(9600); //initialise serial communication at


9600 bits per second:
myservo.attach(10); // servo attached to pin 10 of Arduino
UNO
{
for(pos = 90; pos <= 180; pos += 1){ // goes from 90
degrees to 180 degrees:
myservo.write(pos); //tell servo to move
according to the value of 'pos' variable:
delay(15); //wait 15ms for the servo to
reach the position:
}

for(pos = 180; pos >= 0; pos-= 1) { // goes from 180


degrees to 0 degrees:
myservo.write(pos); //tell servo to move
according to the value of 'pos' variable:
delay(15); //wait 15ms for the servo to
reach the position:
}
for(pos = 0; pos<=90; pos += 1) { //goes from 180
degrees to 0 degrees:
myservo.write(pos); //tell servo to move
according to the value of 'pos' variable:
delay(15); //wait 15ms for the servo to
reach the position:
}
}
pinMode(RIGHT, INPUT); //set analog pin RIGHT as an
input:
pinMode(LEFT, INPUT); //set analog pin RIGHT as an
input:
}

// the lope function runs forever


void loop() {

delay(50); //wait 50ms between


pings:
distance = sonar.ping_cm(); //send ping, get
distance in cm and store it in 'distance' variable:
Serial.print("distance");
Serial.println(distance); // print the
distance in serial monitor:

Right_Value = digitalRead(RIGHT); // read the


value from Right IR sensor:
Left_Value = digitalRead(LEFT); // read the
value from Left IR sensor:

Serial.print("RIGHT");

Serial.println(Right_Value); // print the right


IR sensor value in serial monitor:
Serial.print("LEFT");
Serial.println(Left_Value); //print the left IR
sensor value in serial monitor:

if((distance > 1) && (distance < 15)){ //check


wheather the ultrasonic sensor's value stays between
1 to 15.
//If the condition is 'true' then the statement below will
execute:
//Move Forward:
Motor1.setSpeed(130); //define motor1 speed:
Motor1.run(FORWARD); //rotate motor1 clockwise:
Motor2.setSpeed(130); //define motor2 speed:
Motor2.run(FORWARD); //rotate motor2 clockwise:
Motor3.setSpeed(130); //define motor3 speed:
Motor3.run(FORWARD); //rotate motor3 clockwise:
Motor4.setSpeed(130); //define motor4 speed:
Motor4.run(FORWARD); //rotate motor4 clockwise:

}else if((Right_Value==0) && (Left_Value==1)) { //If


the condition is 'true' then the statement below will
execute:

//Turn Left
Motor1.setSpeed(150); //define motor1 speed:
Motor1.run(FORWARD); //rotate motor1 cloclwise:
Motor2.setSpeed(150); //define motor2 speed:
Motor2.run(FORWARD); //rotate motor2 clockwise:
Motor3.setSpeed(150); //define motor3 speed:
Motor3.run(BACKWARD); //rotate motor3
anticlockwise:
Motor4.setSpeed(150); //define motor4 speed:
Motor4.run(BACKWARD); //rotate motor4
anticlockwise:
delay(150);

}else if((Right_Value==1)&&(Left_Value==0)) { //If


the condition is 'true' then the statement below will
execute:

//Turn Right
Motor1.setSpeed(150); //define motor1 speed:
Motor1.run(BACKWARD); //rotate motor1
anticlockwise:
Motor2.setSpeed(150); //define motor2 speed:
Motor2.run(BACKWARD); //rotate motor2
anticlockwise:
Motor3.setSpeed(150); //define motor3 speed:
Motor3.run(FORWARD); //rotate motor3 clockwise:
Motor4.setSpeed(150); //define motor4 speed:
Motor4.run(FORWARD); //rotate motor4 clockwise:
delay(150);

}else if(distance > 15) { //If the condition


is 'true' then the statement below will execute:

//Stop
Motor1.setSpeed(0); //define motor1 speed:
Motor1.run(RELEASE); //stop motor1:
Motor2.setSpeed(0); //define motor2 speed:
Motor2.run(RELEASE); //stop motor2:
Motor3.setSpeed(0); //define motor3 speed:
Motor3.run(RELEASE); //stop motor3:
Motor4.setSpeed(0); //define motor4 speed:
Motor4.run(RELEASE); //stop motor4:
}
}

Gas detector sensor

Code:

void setup() {
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop(){
if (digitalRead(2)==LOW){
digitalWrite(5,HIGH);
delay(1000);

}
else
{
digitalWrite(5,LOW);
}
}

Wireless Robot circuit

GESTURE CONTROL ROBOT


● RX CIRCUIT

● TR CIRCUIT


CODE FOR GESTURE CONTROLE ROBOT

#include <MPU6050_tockn.h>
#include <Wire.h>

MPU6050 mpu6050(Wire);

long timer = 0;

void setup() {

pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);

Serial.begin(9600);
Wire.begin();
mpu6050.begin();

void loop() {
mpu6050.update();

Serial.print("accX :
");Serial.print(mpu6050.getAccX());
Serial.print("\taccY :
");Serial.print(mpu6050.getAccY());

Serial.print("\taccZ :
");Serial.println(mpu6050.getAccZ());

if (mpu6050.getAccX() >= 0.70)


{ //FORWARD
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, HIGH);
}
else if(mpu6050.getAccX() <= -0.60)
{ //BACKWARD
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);
}
else if(mpu6050.getAccY() >= 0.60)
{ //LEFT
digitalWrite(4, LOW);
digitalWrite(5, HIGH);

digitalWrite(6, LOW);
digitalWrite(7, HIGH);

}
else if(mpu6050.getAccY() <= -0.60)
{ //RIGHT

digitalWrite(4, HIGH);
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7, LOW);

else{
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
}
}

Hand sanitizer robot

Component:
● Arduino uno/nano
● Ultrasonic sensor
● Pump with pipe

● Jumper wires
● Bread board

Code:
#define echoPin 2
#define trigPin 3

long duration;
int distance;

void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(5, OUTPUT);
Serial.begin(9600);
}
void loop() {

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

distance = duration * 0.034 / 2;


Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance<=3)
{
digitalWrite(5, HIGH);
Serial.print("Pump On");
delay(150);
digitalWrite(5, LOW);
Serial.print("Pump OFF");

delay(2000);
}
else
{
digitalWrite(5, LOW);
Serial.print("Pump OFF");

}
delay(50);

How to use the heart pulse sensor with Arduino | Heart


pulse monitoring system

The PIN diagram of this sensor

● Arduino UNO board x1


● Heart pulse sensor x 1
● OLED display x 1
● Jumper wires x 1

Circuit diagram:

● BusIO library — Download


● SSD1306 — Download
● GFX-library — Download
● The complete program of this project — Download

Code:

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 srituhobby =
Adafruit_SSD1306(128, 64, &Wire);

#define sensor A0
#define Highpulse 540

int sX = 0;
int sY = 60;

int x = 0;
int Svalue;
int value;
long Stime = 0;
long Ltime = 0;
int count = 0;
int Bpm = 0;

void setup() {
Serial.begin(9600);
srituhobby.begin(SSD1306_SWITCHCAPVCC,
0x3C);// Address 0x3C for 128x32
delay(1000);
srituhobby.clearDisplay();
}

void loop() {
Svalue = analogRead(sensor);

Serial.println(Svalue);
value = map(Svalue, 0, 1024, 0, 45);

int y = 60 - value;

if (x > 128) {
x = 0;
sX = 0;
srituhobby.clearDisplay();
}

srituhobby.drawLine(sX, sY, x, y, WHITE);


sX = x;

sY = y;
x ++;

BPM();

srituhobby.setCursor(0, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print("BPM :");
srituhobby.display();

void BPM() {

if (Svalue > Highpulse) {


Stime = millis() - Ltime;
count++;

if (Stime / 1000 >= 60) {


Ltime = millis();
Serial.println(count);

srituhobby.setCursor(60, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print(count);
srituhobby.print(" ");
srituhobby.display();
count = 0;
}
}
}

Code explanation:

Firstly, library files are included.

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

Secondly, an object is created for the OLED display

Adafruit_SSD1306 srituhobby =
Adafruit_SSD1306(128, 64, &Wire);

Thirdly, the sensor pin and the high pulse value are
defined. After, variables are created to help the
program.

#define sensor A0
#define Highpulse 540

int sX = 0;
int sY = 60;
int x = 0;
int Svalue;
int value;
long Stime = 0;
long Ltime = 0;
int count = 0;
int Bpm = 0;

In the setup function,


void setup() {

Serial.begin(9600);
srituhobby.begin(SSD1306_SWITCHCAPVCC,
0x3C);// Address 0x3C for 128x32
delay(1000);
srituhobby.clearDisplay();
}

In the loop function,

void loop() {
Svalue = analogRead(sensor);
Serial.println(Svalue);

value = map(Svalue, 0, 1024, 0, 45);

int y = 60 - value;

if (x > 128) {

x = 0;
sX = 0;
srituhobby.clearDisplay();
}

srituhobby.drawLine(sX, sY, x, y, WHITE);


sX = x;

sY = y;
x ++;

BPM();

srituhobby.setCursor(0, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print("BPM :");
srituhobby.display();

This is the heart pulse calculation function.

void BPM() {

if (Svalue > Highpulse) {


Stime = millis() - Ltime;
count++;

if (Stime / 1000 >= 60) {


Ltime = millis();
Serial.println(count);
srituhobby.setCursor(60, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);

srituhobby.print(count);
srituhobby.print(" ");
srituhobby.display();
count = 0;
}
}
}

home automation with esp8266 - Esp8266 projects

ESP8266 Home Automation with new Blynk 2.0

Component requirements:

1. NodeMCU ESP8266 board.


2. 4 Channel Relay.
3. Light Bulb x 4.
4. Bulb holder x 4.
5. Breadboard.
6. Jumper wire.
7. AC plug.

Circuit Diagram:

Pin connection:

1. First take a breadboard and attach the esp8266


board to it.
2. Now, take a four-channel relay module.

● Connect Relay IN1 Pin to esp8266 D1 pin.


● Connect Relay IN2 Pin to esp8266 D2 pin.
● Connect Relay IN3 Pin to esp8266 D5 pin.

● Connect Relay IN4 Pin to esp8266 D6 pin.

3. Esp8266 VIN pin is connected to breadboard


positive side.

4. Esp8266 GND pin is connected to breadboard GND


side.

5. Connect Relay VCC Pin to breadboard positive side


and Connect Relay GND Pin to breadboard GND side.

6. Now, take a bulb holder and connect a yellow


electric wire to holder pin and secure it with the help
of secure.

7. Take a red electric wire and connect it with the


holder another pin.

8. Bulb holder connection to the relay module.

● Connect the yellow wire to relay NO pin and


secure it with the screw.

● Connect the green wire to relay the COM pin.

9. Take another bulb holder and connect the yellow


wire to relay NO pin.

10. Take a red wire and attach it to the first holders


red wire.

11. Now, connect the red wire to second bulb holder


pin.

12. Take another green wire and attach it to the relay


green wire and then connect it to the second relay
COM pin.

13. Follow the same process for other bulb holder and
relays.

14. Now, Provide the AC power supply to the bulb. AC


plug wire is connected to red wire and another one to
green Wire.

15. Now, Circuit is completed, after that attach the


bulb to the bulb holder.

16. Upload the code and setup the new blynk 2.0 Iot
platform.

Code:
#define BLYNK_FIRMWARE_VERSION "0.1.0"

#define BLYNK_PRINT Serial


//#define BLYNK_DEBUG

#define APP_DEBUG

// Uncomment your board, or configure a custom board


in Settings.h
//#define USE_SPARKFUN_BLYNK_BOARD
//#define USE_NODE_MCU_BOARD
//#define USE_WITTY_CLOUD_BOARD
//#define USE_WEMOS_D1_MINI

#include "BlynkEdgent.h"

int RelayPin1 = 5;

int RelayPin2 = 4;
int RelayPin3 = 14;
int RelayPin4 = 12;

BLYNK_WRITE(V0) { //Button Widget is writing to pin


V0
int pinValue = param.asInt();
digitalWrite(RelayPin1, pinValue);
}

BLYNK_WRITE(V1) { //Button Widget is writing to pin


V1
int pinValue = param.asInt();
digitalWrite(RelayPin2, pinValue);
}
BLYNK_WRITE(V2) { //Button Widget is writing to pin
V2
int pinValue = param.asInt();
digitalWrite(RelayPin3, pinValue);
}
BLYNK_WRITE(V3) { //Button Widget is writing to pin
V3

int pinValue = param.asInt();


digitalWrite(RelayPin4, pinValue);
}

void setup()
{
Serial.begin(115200);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);

//TURN OFF all Relays on Start

digitalWrite(RelayPin1, HIGH);
digitalWrite(RelayPin2, HIGH);
digitalWrite(RelayPin3, HIGH);
digitalWrite(RelayPin4, HIGH);

delay(100);
BlynkEdgent.begin();
}

void loop() {
BlynkEdgent.run();
}

How to make an obstacle avoiding robot with three


ultrasonic sensors

components:

● Arduino UNO board x 1


● Ultrasonic sensor x 3
● L293D motor driver x 1
● Gear motor x 4
● Robot wheel x 4

● Li-ion battery x 2
● Battery holder x1 Jumper wires
● Foam board / Cardboard / Rigifoam

Code:

#include <AFMotor.h>

//Define the sensor pins


#define S1Trig A0
#define S2Trig A1
#define S3Trig A2
#define S1Echo A3
#define S2Echo A4
#define S3Echo A5

//Set the speed of the motors

#define Speed 160

//Create objects for the motors


AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

void setup() {
Serial.begin(9600);
//Set the Trig pins as output pins
pinMode(S1Trig, OUTPUT);
pinMode(S2Trig, OUTPUT);
pinMode(S3Trig, OUTPUT);
//Set the Echo pins as input pins
pinMode(S1Echo, INPUT);
pinMode(S2Echo, INPUT);
pinMode(S3Echo, INPUT);
//Set the speed of the motors
motor1.setSpeed(Speed);

motor2.setSpeed(Speed);
motor3.setSpeed(Speed);
motor4.setSpeed(Speed);
}

void loop() {

int centerSensor = sensorTwo();


int leftSensor = sensorOne();
int rightSensor = sensorThree();
// Check the distance using the IF condition

if (8 >= centerSensor) {

Stop();
Serial.println("Stop");
delay(1000);
if (leftSensor > rightSensor) {

left();

Serial.println("Left");
delay(500);
} else {

right();
Serial.println("Right");
delay(500);
}

Serial.println("Forward");

forward();

//Get the sensor values


int sensorOne() {
//pulse output
digitalWrite(S1Trig, LOW);
delayMicroseconds(4);
digitalWrite(S1Trig, HIGH);
delayMicroseconds(10);
digitalWrite(S1Trig, LOW);

long t = pulseIn(S1Echo, HIGH);//Get the pulse


int cm = t / 29 / 2; //Convert time to the distance
return cm; // Return the values from the sensor
}

//Get the sensor values

int sensorTwo() {
//pulse output
digitalWrite(S2Trig, LOW);
delayMicroseconds(4);
digitalWrite(S2Trig, HIGH);
delayMicroseconds(10);
digitalWrite(S2Trig, LOW);

long t = pulseIn(S2Echo, HIGH);//Get the pulse


int cm = t / 29 / 2; //Convert time to the distance
return cm; // Return the values from the sensor
}

//Get the sensor values

int sensorThree() {
//pulse output

digitalWrite(S3Trig, LOW);
delayMicroseconds(4);
digitalWrite(S3Trig, HIGH);
delayMicroseconds(10);
digitalWrite(S3Trig, LOW);

long t = pulseIn(S3Echo, HIGH);//Get the pulse


int cm = t / 29 / 2; //Convert time to the distance
return cm; // Return the values from the sensor
}

/*******************Motor
functions**********************/

void forward() {

motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
void left() {

motor1.run(BACKWARD);
motor2.run(BACKWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);
}
void right() {

motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);

}
void Stop() {

motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}

Interfacing SGP30 CO2 & TVOC Sensor with Arduino

Overview

In this post, we will be interfacing SGP30 CO2 & TVOC


Sensor with Arduino and display the value on an OLED
Screen. The SGP30 Sensor is capable of detecting

equivalent Carbon dioxide & Total Volatile Organic


Compounds from the atmosphere. In an earlier project, we
measured CO2 & TVOC using CCS811 Gas Sensor &
also BME680 integrated environmental sensor.

But SGP30 is a completely different sensor and has the


ability to give proper reading quickly. While the CCS811
requires a burn-in of 48 hours and a run-in of 20 minutes
the SGP30 is ready to go after just 15 seconds.

In this project, we will first read the CO2 & TVOC value
from SGP30 Sensor using the Arduino Sparkfun library &
display their value on Serial Monitor. The sensor can also
measure the ethanol and Hydrogen (H2) values in raw
values. Later we will display the sensor reading on a
0.96″ I2C OLED Display and test the sensor by
introducing some perfume near the sensor.

Bill of Materials

You can purchase the following components from

Amazon.

COMPONENTS QUANTI PURCHASE


S.N.
NAME TY LINKS
1 Arduino Nano 1 Amazon |
Board AliExpress
2 SGP30 Air Quality 1 Amazon |
Sensor AliExpress
3 0.96" I2C OLED 1 Amazon |
Display AliExpress
4 Connecting Wires 20 Amazon |
AliExpress
5 Breadboard 1 Amazon |
AliExpress

SGP30 Air Quality Sensor


The SGP30 Gas Sensor is an air quality sensor used to
measure VOC and eCO2. This is a very fine air quality

sensor from the sensor experts at Sensirion. The sensor


has an I2C interface. It gives fully calibrated output
signals with a typical accuracy of 15% within measured
values. The SGP combines multiple metal-oxide sensing
elements on one chip to provide more detailed air quality
signals. This module provides TVOC(Total Volatile
Organic Compounds) and CO2eq output with outstanding
long-term stability and low power consumption. This
makes it a perfect choice for indoor air quality detection
using Arduino or any other microcontroller.

The Sensirion SGP30 is a digital multi-pixel gas sensor


that can easily integrate with air purifiers or demand-

controlled ventilation. The sensor is powered by


Sensirion’s CMOSens®technology that integrates a
complete sensor system on a

single chip featuring a temperature-controlled micro


hotplate, and two preprocessed indoor air quality signals.
As the first metal-oxide gas sensor featuring multiple
sensing elements on one chip, the SGP30 provides more
detailed information. Check SGP30 Datasheet for more
information.

It outputs equivalent CO2 in ppm and Total Volatile


Organic Compounds (TVOC) in ppb. The sensor also
gives access to its raw measurement values of Ethanol
and H2. The SGP30 boasts high stability with low long-
term drift. With its continuous baseline compensation
algorithm, readings stay accurate over time. You can even

fine-tune your readings by interfacing with an external


humidity sensor to add humidity compensation.

Features & Specifications


● Sensirion SGP30 TVOC and eCO2 sensor
● TVOC sensing from 0-60,000 ppb (parts per
billion)
● CO2 sensing from 400 to 60,000 ppm (parts per
million)
● 1Hz sampling rate
● I2C interface(address 0x58)
● 3.3V or 5V compatible
● Raspberry Pi-compatible pinout (pins 1, 3, 5, 7, 9)
● Compatible with all models of Raspberry Pi, and
Arduino

Displaying CO2 & TVOC value on OLED Display

Now lets display the CO2 & TVOC value on some


display modules instead of displaying on Serial Monitor.
The best module for that is 0.96″ I2C OLED Display.

The OLED display is also an I2C Module. Therefore


connect it directly with the I2C Pin of the Arduino Board

Source Code/Program for OLED Display


The SSD1306 OLED Display requires two libraries for
compilation. Download the following libraries and add
them to the library folder.

1. Adafruit SSD1306 Library: https://github.com/


adafruit/Adafruit_SSD1306
2. Adafruit GFX Library: https://github.com/adafruit/
Adafruit-GFX-Library

Copy the following code and upload it to the Arduino


Board.

#include "SparkFun_SGP30_Arduino_Library.h" // Click


here to get the library: http://librarymanager/
All#SparkFun_SGP30
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 // OLED display width,


in pixels
#define SCREEN_HEIGHT 64 // OLED display height,
in pixels
#define OLED_RESET 4 // Reset pin # (or -1 if
sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C // 0x3D for 128x64,
0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH,
SCREEN_HEIGHT, &Wire, OLED_RESET);

SGP30 mySensor; //create an object of the SGP30 class

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

if (!display.begin(SSD1306_SWITCHCAPVCC,
SCREEN_ADDRESS))
{
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
display.clearDisplay();

//Initialize sensor
if (mySensor.begin() == false)
{
Serial.println("No SGP30 Detected. Check
connections.");
while (1);
}

//Initializes sensor for air quality readings


//measureAirQuality should be called in one second
increments after a call to initAirQuality
mySensor.initAirQuality();
}

void loop()
{
//First fifteen readings will be
//CO2: 400 ppm TVOC: 0 ppb
delay(1000); //Wait 1 second
//measure CO2 and TVOC levels
mySensor.measureAirQuality();
Serial.print("CO2: ");

Serial.print(mySensor.CO2);
Serial.print(" ppm\tTVOC: ");
Serial.print(mySensor.TVOC);
Serial.println(" ppb");

display.setCursor(0, 10); //oled display


display.setTextSize(2);
display.setTextColor(WHITE);
display.print("CO2:");
display.print(mySensor.CO2);
display.setTextSize(1);
display.print("ppm");

display.setCursor(0, 40); //oled display


display.setTextSize(2);
display.setTextColor(WHITE);
display.print("TVOC:");
display.print(mySensor.TVOC);
display.setTextSize(1);
display.print("ppb");

display.display();
display.clearDisplay();

Ir sensor based light

Components:
● 5v relay module
● Ir sensor

● Ac lamp
● 5v 200mA adapter

Laser security system using with arduino


Components:
● Arduino UNO
● Arduino UNO Cable
● LASER
● Jumper Wire (M To M ) and (M TO F)
● Resistor
● Breadboard
● LDR
● Buzzer

Circuit diagram:

Code:
void setup() {
// put your setup code here, to run once:
pinMode(11,OUTPUT); //Buzzer Pin
pinMode(7,INPUT); // Light Sensor
delay(500);
}

void loop() {
// put your main code here, to run repeatedly:
int i=0;
if(digitalRead(7)==HIGH)
{
a:

digitalWrite(11,HIGH);
delay(100);
digitalWrite(11,LOW);
delay(100);
i++;
if(i<50){
goto a;
}

Ldr , relay module with arduino

Diagram:

Code:
int sensorPin = A0;
int relayPin = 8;

void setup()
{
Serial.begin(9600);
pinMode(sensorPin, INPUT);
pinMode(relayPin, OUTPUT);
}
void loop()
{
int sensorValue = analogRead(sensorPin);

if( sensorValue <= 25 ) // Change the value as per your


requirement
{
digitalWrite(relayPin, LOW);
Serial.println(sensorValue);
delay(100);
}
else
{
digitalWrite(relayPin, HIGH);
Serial.println(sensorValue);
}
}

OBSTACLE AVOIDER CAR

COMPONENTS:
● ARDUINO
● MOTOR DRIVER SHIELD(L293D)
● 1-SERVO MOTOR
● 1-ULTRASONIC SENSOR(HC-SR04)

● 4-BO MOTOR WITH TYRE


● JUMPER WIRES
● A CAR BODY

CIRCUIT DIAGRAM:

CODE:

#include <AFMotor.h> //Import library


to control motor shield
#include <Servo.h> //Import library to
control the servo

AF_DCMotor rightBack(1); //Create an


object to control each motor
AF_DCMotor rightFront(2);
AF_DCMotor leftFront(3);
AF_DCMotor leftBack(4);
Servo servoLook; //Create an object
to control the servo

byte trig = 0; //Assign the ultrasonic


sensor pins
byte echo = 1;
byte maxDist = 150; //Maximum
sensing distance (Objects further than this distance are
ignored)
byte stopDist = 50; //Minimum
distance from an object to stop in cm

float timeOut = 2*(maxDist+10)/100/340*1000000; //


Maximum time to wait for a return signal

byte motorSpeed = 55; //The maximum


motor speed
int motorOffset = 10; //Factor to account
for one side being more powerful
int turnSpeed = 50; //Amount to add to
motor speed when turning

void setup()
{
rightBack.setSpeed(motorSpeed); //Set the
motors to the motor speed
rightFront.setSpeed(motorSpeed);
leftFront.setSpeed(motorSpeed+motorOffset);
leftBack.setSpeed(motorSpeed+motorOffset);

rightBack.run(RELEASE); //Ensure all


motors are stopped
rightFront.run(RELEASE);
leftFront.run(RELEASE);
leftBack.run(RELEASE);
servoLook.attach(10); //Assign the servo
pin
pinMode(trig,OUTPUT); //Assign
ultrasonic sensor pin modes
pinMode(echo,INPUT);
}

void loop()
{
servoLook.write(90); //Set the servo to
look straight ahead
delay(750);
int distance = getDistance(); //Check that there
are no objects ahead

if(distance >= stopDist) //If there are no


objects within the stopping distance, move forward
{
moveForward();
}
while(distance >= stopDist) //Keep checking
the object distance until it is within the minimum stopping
distance
{
distance = getDistance();
delay(250);
}
stopMove(); //Stop the motors
int turnDir = checkDirection(); //Check the left
and right object distances and get the turning instruction
Serial.print(turnDir);
switch (turnDir) //Turn left, turn
around or turn right depending on the instruction
{

case 0: //Turn left


turnLeft (400);
break;
case 1: //Turn around
turnLeft (700);
break;
case 2: //Turn right
turnRight (400);
break;
}
}

void accelerate() //Function to


accelerate the motors from 0 to full speed
{
for (int i=0; i<motorSpeed; i++) //Loop from 0
to full speed
{

rightBack.setSpeed(i); //Set the motors to


the current loop speed
rightFront.setSpeed(i);
leftFront.setSpeed(i+motorOffset);
leftBack.setSpeed(i+motorOffset);
delay(10);
}
}

void decelerate() //Function to


decelerate the motors from full speed to zero
{
for (int i=motorSpeed; i!=0; i--) //Loop from full
speed to 0
{
rightBack.setSpeed(i); //Set the motors to
the current loop speed
rightFront.setSpeed(i);
leftFront.setSpeed(i+motorOffset);

leftBack.setSpeed(i+motorOffset);
delay(10);
}
}

void moveForward() //Set all motors


to run forward
{
rightBack.run(FORWARD);
rightFront.run(FORWARD);
leftFront.run(FORWARD);
leftBack.run(FORWARD);
}

void stopMove() //Set all motors to


stop
{
rightBack.run(RELEASE);

rightFront.run(RELEASE);
leftFront.run(RELEASE);
leftBack.run(RELEASE);
}

void turnLeft(int duration) //Set


motors to turn left for the specified duration then stop
{
rightBack.setSpeed(motorSpeed+turnSpeed); //
Set the motors to the motor speed
rightFront.setSpeed(motorSpeed+turnSpeed);
leftFront.setSpeed(motorSpeed+motorOffset+turnSpeed);
leftBack.setSpeed(motorSpeed+motorOffset+turnSpeed);
rightBack.run(FORWARD);
rightFront.run(FORWARD);
leftFront.run(BACKWARD);
leftBack.run(BACKWARD);
delay(duration);

rightBack.setSpeed(motorSpeed); //Set
the motors to the motor speed
rightFront.setSpeed(motorSpeed);
leftFront.setSpeed(motorSpeed+motorOffset);
leftBack.setSpeed(motorSpeed+motorOffset);
rightBack.run(RELEASE);
rightFront.run(RELEASE);
leftFront.run(RELEASE);
leftBack.run(RELEASE);

void turnRight(int duration) //Set


motors to turn right for the specified duration then stop
{
rightBack.setSpeed(motorSpeed+turnSpeed); //
Set the motors to the motor speed
rightFront.setSpeed(motorSpeed+turnSpeed);
leftFront.setSpeed(motorSpeed+motorOffset+turnSpeed);

leftBack.setSpeed(motorSpeed+motorOffset+turnSpeed);
rightBack.run(BACKWARD);
rightFront.run(BACKWARD);
leftFront.run(FORWARD);
leftBack.run(FORWARD);
delay(duration);
rightBack.setSpeed(motorSpeed); //Set
the motors to the motor speed
rightFront.setSpeed(motorSpeed);
leftFront.setSpeed(motorSpeed+motorOffset);
leftBack.setSpeed(motorSpeed+motorOffset);
rightBack.run(RELEASE);
rightFront.run(RELEASE);
leftFront.run(RELEASE);
leftBack.run(RELEASE);
}

int getDistance() //Measure the


distance to an object
{
unsigned long pulseTime; //Create a
variable to store the pulse travel time
int distance; //Create a variable to
store the calculated distance
digitalWrite(trig, HIGH); //Generate a 10
microsecond pulse
delayMicroseconds(10);
digitalWrite(trig, LOW);
pulseTime = pulseIn(echo, HIGH, timeOut); //
Measure the time for the pulse to return
distance = (float)pulseTime * 340 / 2 / 10000; //
Calculate the object distance based on the pulse time
return distance;
}

int checkDirection() //Check


the left and right directions and decide which way to turn
{
int distances [2] = {0,0}; //Left and
right distances
int turnDir = 1; //Direction to
turn, 0 left, 1 reverse, 2 right
servoLook.write(180); //Turn
servo to look left
delay(500);
distances [0] = getDistance(); //Get the
left object distance
servoLook.write(0); //Turn
servo to look right
delay(1000);
distances [1] = getDistance(); //Get the
right object distance
if (distances[0]>=200 &&
distances[1]>=200) //If both directions are
clear, turn left

turnDir = 0;
else if (distances[0]<=stopDist &&
distances[1]<=stopDist) //If both directions are blocked,
turn around
turnDir = 1;
else if (distances[0]>=distances[1]) //If
left has more space, turn left
turnDir = 0;
else if (distances[0]<distances[1]) //If
right has more space, turn right
turnDir = 2;
return turnDir;
}

Pir sensor light with arduino


Components Required:

● Arduino,
● Relay module,
● PIR sensor (HC-SR501),

● Breadboard & Jumper Wire,


● 240V/120V light bulb ,
● Bulb holder, wire and plug.

Diagram:

Code:

int Bulb = 8;

int PIR = 3;

int val = 0;

void setup() {

pinMode(Bulb, OUTPUT);

pinMode(PIR, INPUT);

void loop(){

val = digitalRead(PIR);

if (val == HIGH) {

digitalWrite(Bulb, HIGH);

delay(200);

else

digitalWrite(Bulb, LOW);

delay(200);

SMART DUSTBIN
COMPONENT:
● ARDUINO
● ULTRASONIC SENSOR
● SERVO MOTOR
● JUMPER WIRES

CIRCUIT DIAGRAM:

CODE:

#include <Servo.h> //servo library


Servo servo;
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver[3]; //array for average

void setup() {
Serial.begin(9600);
servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}

void measure() {
digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);

delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}
void loop() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;

if ( dist<50 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}

SMART DUSTBIN
COMPONENT:
● ARDUINO
● ULTRASONIC SENSOR
● SERVO MOTOR
● JUMPER WIRES

CIRCUIT DIAGRAM:

CODE:

#include <Servo.h> //servo library


Servo servo;
int trigPin = 5;
int echoPin = 6;
int servoPin = 7;
int led= 10;
long duration, dist, average;
long aver[3]; //array for average

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

servo.attach(servoPin);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
servo.write(0); //close cap on power on
delay(100);
servo.detach();
}

void measure() {
digitalWrite(10,HIGH);
digitalWrite(trigPin, LOW);
delayMicroseconds(5);
digitalWrite(trigPin, HIGH);

delayMicroseconds(15);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
dist = (duration/2) / 29.1; //obtain distance
}

void loop() {
for (int i=0;i<=2;i++) { //average distance
measure();
aver[i]=dist;
delay(10); //delay between measurements
}
dist=(aver[0]+aver[1]+aver[2])/3;

if ( dist<50 ) {
//Change distance as per your need
servo.attach(servoPin);
delay(1);
servo.write(0);
delay(3000);
servo.write(150);
delay(1000);
servo.detach();
}
Serial.print(dist);
}

Temperature and Humidity Sensor DHT11 with arduino


Tutorial – Make OLED Termometer

DHT11 is the cheapest temperature and humidity sensor


compared to other sensors. It has 3 pins that we can easily
interface with the arduino. It uses single-bus operation.

DHT11 Temperature and


Humidity Sensor

DHT11 Wiring Diagram with arduino


Connect your DHT11 Sensor with arduino as follow

Arduino Code
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#include <Fonts/FreeMonoBold18pt7b.h>
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
int h;
int t;
#define SCREEN_WIDTH 128 // OLED display width, in
pixels
#define SCREEN_HEIGHT 64 // OLED display height,
in pixels

// Declaration for an SSD1306 display connected to I2C


(SDA, SCL pins)
#define OLED_RESET 4 // Reset pin # (or -1 if sharing
Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH,
SCREEN_HEIGHT, &Wire, OLED_RESET);
#define bitmap_height 128
#define bitmap_width 64
static const unsigned char PROGMEM logo_bmp[] =
{ 0x00, 0x00, 0x00, 0x00, 0xFF, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x3F, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x1F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x0F, 0x8F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x00, 0x00, 0x08, 0x0F, 0xC0, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x78, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x08, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0x08, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x80, 0x78, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x80, 0x08, 0x03, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xC0, 0x08, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xC0, 0x78, 0x03, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0xC0, 0x78, 0x07, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x03, 0xC0, 0x08, 0x0F, 0xC0, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x03, 0xE0, 0x08, 0x03, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xE0, 0x78, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x07, 0xF0, 0x08, 0x03, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0F, 0xF0, 0x08, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0F, 0xF8, 0x78, 0x00, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0xF8, 0x08, 0x03, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0xF8, 0x08, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3F, 0xFC, 0x78, 0x03, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x3F, 0xFE, 0x08, 0x03, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x7F, 0xFE, 0x0F, 0x8F, 0xC0, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0xFF, 0x7F, 0x83, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0x0F, 0x83, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0x0F, 0x83, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0xFF, 0xFF, 0x7F, 0x80, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xFF, 0xFF, 0x0F, 0x8F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xFF, 0xFF, 0x0F, 0x87, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xFF, 0xFF, 0x1F, 0x8F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x07, 0xFF, 0xFF, 0x7F, 0x83, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0xFF, 0xFF, 0x0F, 0x83, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x0F, 0xFF, 0xFF, 0x0F, 0x8F, 0xC0, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, 0xFF, 0xFF, 0x7F, 0x83, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x1F, 0xFF, 0xFF, 0x0F, 0x8F, 0xC0, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, 0x0F, 0xF3, 0xEF, 0x83, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x03, 0xE7, 0xCF, 0xC0, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3C, 0x61, 0xC7, 0x9F, 0xE0, 0x40, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7C, 0x71, 0xCF, 0xBF, 0xE3, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7C, 0x71, 0xCF, 0xBF, 0xF3, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7C, 0x71, 0x9F, 0xBF, 0xE3, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0xFC, 0x71, 0x3F, 0xBF, 0xE3, 0xC0, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFC, 0x71, 0x38, 0x1F, 0xE7, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFC, 0x02, 0x20, 0x0F, 0x87, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFE, 0x06, 0x46, 0x03, 0x0F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0x8C, 0xC7, 0x18, 0x1F, 0xC0, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xFC, 0xC7, 0x1C, 0x7F, 0x80, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xF9, 0xC7, 0x1C, 0x7F, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xFF, 0xF9, 0xC7, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7F, 0xF3, 0xC6, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x7F, 0xE3, 0xC0, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x7F, 0xE7, 0xE0, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x3F, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, 0xFF, 0xFF, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, 0xFF, 0xFF, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0F, 0xFF, 0xFF, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x07, 0xFF, 0xFF, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xFF, 0xFF, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x7F, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x1F, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

0x00, 0x03, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,


0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
void setup() {
Serial.begin(9600);
dht.begin();
// SSD1306_SWITCHCAPVCC = generate display
voltage from 3.3V internally
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
// Address 0x3D for 128x64
Serial.println(F("SSD1306 allocation failed"));
for (;;); // Don't proceed, loop forever
}
// Clear the buffer
display.clearDisplay();
printText();
delay(1500);
}
void loop() {

h = dht.readHumidity();
t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
showBitmap();
printText();
display.display();
delay(500);
display.clearDisplay();
}
void printText() {
display.setFont(&FreeMonoBold18pt7b);
display.setTextColor(WHITE); // Draw white text
display.setCursor(45, 28); // Start at top-left corner
display.print(t);
display.drawCircle(92, 8, 3, WHITE);

display.setCursor(100, 27);
display.print("C");
display.setCursor(45, 62);
display.print(h);
display.print("%");
}
void showBitmap(void) {
display.drawBitmap(0, 0, logo_bmp, bitmap_height,
bitmap_width, WHITE);
//display.display();
}

TILT sensor with LED, BUZZER and ARDUINO

Circuit diagram:

Code:

#define TILT 2
#define LED 4

#define BUZZER 3

void setup() {
Serial.begin(9600);
pinMode(TILT, INPUT);
pinMode(LED, OUTPUT);
pinMode(BUZZER, OUTPUT);

void loop() {
int TILT_VALUE = digitalRead(TILT);
if (TILT_VALUE == LOW){
digitalWrite(LED,HIGH);
digitalWrite(BUZZER, HIGH);
delay(1000);
}
else {
digitalWrite(LED,LOW);
digitalWrite(BUZZER, LOW);

TRAFFIC LIGHTS
COMPONENTS:
● Arduino Uno Board and USB Cable
● Bread Board
● 3 LEDs and 3 Resistors (330 Ohms)
● Jumper wires

CODE:
/*

Traffic Lights By janta group


Turns LEDs ON for 3 seconds, then OFF for 1 second in
sequence repeatedly.
*/

int LedRed= 8; // define Red LED pin


int LedYellow= 9; // define Yellow LED pin
int LedGreen= 10; // define Green LED pin
// the setup function runs once when you press reset or
power the board
void setup() {
// initialise digital pin LED_BUILTIN as an output.
pinMode(LedRed, OUTPUT);
pinMode(LedYellow, OUTPUT);
pinMode(LedGreen, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LedRed, HIGH); // turn the LED on (HIGH
is the voltage level)
delay(3000); // wait for 3 seconds

digitalWrite(LedRed, LOW); // turn the LED off by


making the voltage LOW
delay(1000); // wait for a second
digitalWrite(LedGreen, HIGH); // turn the LED on (HIGH
is the voltage level)
delay(3000); // wait for 3 seconds
digitalWrite(LedGreen, LOW); // turn the LED off by
making the voltage LOW
delay(1000); // wait for a second
digitalWrite(LedYellow, HIGH); // turn the LED on
(HIGH is the voltage level)
delay(3000); // wait for 3 seconds
digitalWrite(LedYellow, LOW); // turn the LED off by
making the voltage LOW
delay(1000); // wait for a second
}
USING LDR SENSORS LIGHT ON

COMPONENTS:
● Arduino
● Breadboard
● LDR sensor
● 1 led with 330 ohm resistor

● Jumper wire

Code: int LDR = 2;


int LED = 3;

void setup()
{
pinMode(LDR,INPUT);
pinMode(LED,OUTPUT);

}
void loop(){
if(digitalRead(LDR)==LOW)
{
digitalWrite(LED,LOW);
}
else
{
digitalWrite(LED,HIGH);
}
}

Vibration sensor with light, buzzer

Component:
● Arduino
● Led
● buzzer
● Jumper wires
● Vibration sensor

Circuit diagram:

Code:
int LED_Pin = 13;
int vibr_Pin =A5;

void setup(){
pinMode(LED_Pin, OUTPUT);
pinMode(vibr_Pin, INPUT); //set vibr_Pin input for
measurement
Serial.begin(9600); //init serial 9600
// Serial.println("----------------------Vibration
demo------------------------");
}
void loop(){

long measurement =TP_init();


delay(50);
// Serial.print("measurement = ");
Serial.println(measurement);
if (measurement > 1000){
digitalWrite(LED_Pin, HIGH);
}
else{
digitalWrite(LED_Pin, LOW);
}
}

long TP_init(){
delay(10);
long measurement=pulseIn (vibr_Pin, HIGH); //wait
for the pin to get HIGH and returns measurement
return measurement;
}

Voice control robot


Components:

● ARDUINO
● MOTOR DRIVER SHIELD(L293D)
● BLUETOOTH MODULE
● 4-BO MOTOR WITH TYRE
● JUMPER WIRES
● A CAR BODY

Diagram:

CODE:

#include <AFMotor.h>
#include <Servo.h>

String command;

AF_DCMotor motor1(1, MOTOR12_1KHZ);


AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

Servo myservo;

void setup() {

Serial.begin(9600);
myservo.attach(10);
myservo.write(90);

void loop() {

delay(10);
while(Serial.available()) {
command = "";
command = Serial.readString();

Serial.print(command);
}
if(command == "*move forward#"){
forward();
}else if(command == "*move backward#"){
backward();
}else if(command == "*turn left#"){
left();
}else if(command == "*turn right#"){
right();
}else if(command == "*stop#") {
Stop();

}
command = "";
}

void forward() {
motor1.setSpeed(255);
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
delay(1500);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);

void backward() {
motor1.setSpeed(255);
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
delay(1500);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}

void left() {

myservo.write(180);
delay(500);
myservo.write(90);
delay(500);
motor1.setSpeed(255);
motor1.run(FORWARD);
motor2.setSpeed(255);
motor2.run(BACKWARD);
motor3.setSpeed(255);
motor3.run(FORWARD);
motor4.setSpeed(255);
motor4.run(BACKWARD);
delay(500);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}

void right() {
myservo.write(0);

delay(500);
myservo.write(90);
delay(500);
motor1.setSpeed(255);
motor1.run(BACKWARD);
motor2.setSpeed(255);
motor2.run(FORWARD);
motor3.setSpeed(255);
motor3.run(BACKWARD);
motor4.setSpeed(255);
motor4.run(FORWARD);
delay(500);
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
}

void Stop() {
motor1.run(RELEASE);
motor2.run(RELEASE);

motor3.run(RELEASE);
motor4.run(RELEASE);
}

EDGE ARDUINO LINE FOLLOWER CAR

Components:
● Arduino uno
● Motor driver shield(L293D)
● Ir sensor
● Jumper wires
● Bo motor-4
● Tyre-4
● A car body

Circuit Diagram:

Code in c language:
//Arduino Table edge Avoidance Robot
//Created By Janta Group
//You need to include the AFMotor.h library before
uploading the sketch, otherwise you'll get a compilation
error message.
#include <AFMotor.h>

//defining pins and variables


#define lefts A0

//defining motors

AF_DCMotor motor1(1, MOTOR12_1KHZ);


AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

void setup() {
//setting the speed of motors
motor1.setSpeed(100);
motor2.setSpeed(100);
motor3.setSpeed(100);
motor4.setSpeed(100);
//declaring pin types
pinMode(lefts, INPUT);
//begin serial communication
Serial.begin(9600);

void loop() {
//printing values of the sensors to the serial monitor
Serial.println(analogRead(lefts));

//
if (analogRead(lefts) <= 350) {
//Forward
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);

}
//
else if (!analogRead(lefts) <= 350) {
//stop-turn-forward
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(500); //
//backward
motor1.run(BACKWARD);
motor2.run(BACKWARD);

motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(500); //
//turn left
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(500); //
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(500); //
}

EDGE ARDUINO LINE FOLLOWER CAR

Components:
● Arduino uno
● Motor driver shield(L293D)
● Ir sensor
● Jumper wires
● Bo motor-4
● Tyre-4
● A car body

Circuit Diagram:

Code in c language:
//Arduino Table edge Avoidance Robot
//Created By Janta Group
//You need to include the AFMotor.h library before
uploading the sketch, otherwise you'll get a compilation
error message.
#include <AFMotor.h>

//defining pins and variables


#define lefts A0

//defining motors

AF_DCMotor motor1(1, MOTOR12_1KHZ);


AF_DCMotor motor2(2, MOTOR12_1KHZ);
AF_DCMotor motor3(3, MOTOR34_1KHZ);
AF_DCMotor motor4(4, MOTOR34_1KHZ);

void setup() {
//setting the speed of motors
motor1.setSpeed(100);
motor2.setSpeed(100);
motor3.setSpeed(100);
motor4.setSpeed(100);
//declaring pin types
pinMode(lefts, INPUT);
//begin serial communication
Serial.begin(9600);

void loop() {
//printing values of the sensors to the serial monitor
Serial.println(analogRead(lefts));

//
if (analogRead(lefts) <= 350) {
//Forward
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(FORWARD);
motor4.run(FORWARD);

}
//
else if (!analogRead(lefts) <= 350) {
//stop-turn-forward
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(500); //
//backward
motor1.run(BACKWARD);
motor2.run(BACKWARD);

motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(500); //
//turn left
motor1.run(FORWARD);
motor2.run(FORWARD);
motor3.run(BACKWARD);
motor4.run(BACKWARD);
delay(500); //
//stop
motor1.run(RELEASE);
motor2.run(RELEASE);
motor3.run(RELEASE);
motor4.run(RELEASE);
delay(500); //
}

You might also like