Book Overview
Book Overview
Book Overview
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,
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
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
etc.
etc.
Touch Sensor:
Some of the gas sensors that have been put to use include
hydrogen type, hygrometer, carbon-dioxide sensor, ozone
ti
Uses of Sensors
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.
ff
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
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);*/
Serial.println(command);
switch(command){
case 'F':
forward();
break;
case 'B':
back();
break;
case 'L':
left();
break;
case 'R':
right();
break;
}
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);
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
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
}
Diagram:
Code:
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);
}
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;
}
Code:
void setup() {
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);
}
}
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//
//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);
void loop(){
//printing values of the sensors to the serial monitor
Serial.println(digitalRead(left));
Serial.println(digitalRead(right));
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);
Code:
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);
}
}
● 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
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
● High-Noise-Immunity Inputs
L293D)
Suppression (L293D)
Bluetooth module(HC-05)
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
Description of pins
● Name: HC-05
● Type: Slave
● Mode: Data
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.
Car body
Code in C language
#include <AFMotor.h>
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
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
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
Circuit diagram
www.jantagroup.org
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);
}
Code:
int mic = 2; // microphone module
void setup() {
Serial.begin(115200);
pinMode(indicLED, OUTPUT);
pinMode(lightPin, OUTPUT);
digitalWrite(lightPin, lightState);
attachInterrupt(digitalPinToInterrupt(mic),
ISR_ClapDetected, FALLING);
void loop() {
delay(2);
digitalWrite(indicLED, LOW);
digitalWrite(indicLED, LOW);
Serial.println(String(!lightState));
digitalWrite(lightPin, lightState);
lightState=!lightState;
ClapDetected = false;
void ISR_ClapDetected()
ClapDetetedTime[2] = millis();
ClapDetected = true;
Serial.println("clap detected");
digitalWrite(indicLED, HIGH);
/*
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);
Diagram:
Code:
#include <Adafruit_Fingerprint.h>
#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
{
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.
}
p = finger.image2Tz();
if (p != FINGERPRINT_OK) return -1;
p = finger.fingerFastSearch();
if (p != FINGERPRINT_OK) return -1;
// found a match!
return finger.fingerID;
}
#include <Adafruit_Fingerprint.h>
uint8_t id;
void setup()
{
Serial.begin(9600);
while (!Serial);
delay(100);
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 == 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;
}
}
// 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:
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;
}
return true;
}
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/*
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
COMPONENTS:
● Arduino Uno
● Breadboard
● 8 LEDs with 8 X 330 ohm Resistors
● Jumper Wires
PROGRAM:
*/Created by janta group
www.jantagroup.org/*
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
}
}
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
● 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)
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.
Car body
IR Sensor
Circuit diagram
Code in C language
Serial.print("RIGHT");
//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);
//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);
//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:
}
}
Code:
void setup() {
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop(){
if (digitalRead(2)==LOW){
digitalWrite(5,HIGH);
delay(1000);
}
else
{
digitalWrite(5,LOW);
}
}
● 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());
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);
}
}
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);
delay(2000);
}
else
{
digitalWrite(5, LOW);
Serial.print("Pump OFF");
}
delay(50);
Circuit diagram:
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();
}
sY = y;
x ++;
BPM();
srituhobby.setCursor(0, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print("BPM :");
srituhobby.display();
void BPM() {
srituhobby.setCursor(60, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print(count);
srituhobby.print(" ");
srituhobby.display();
count = 0;
}
}
}
Code explanation:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
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;
Serial.begin(9600);
srituhobby.begin(SSD1306_SWITCHCAPVCC,
0x3C);// Address 0x3C for 128x32
delay(1000);
srituhobby.clearDisplay();
}
void loop() {
Svalue = analogRead(sensor);
Serial.println(Svalue);
int y = 60 - value;
if (x > 128) {
x = 0;
sX = 0;
srituhobby.clearDisplay();
}
sY = y;
x ++;
BPM();
srituhobby.setCursor(0, 0);
srituhobby.setTextSize(2);
srituhobby.setTextColor(SSD1306_WHITE);
srituhobby.print("BPM :");
srituhobby.display();
void BPM() {
srituhobby.print(count);
srituhobby.print(" ");
srituhobby.display();
count = 0;
}
}
}
Component requirements:
Circuit Diagram:
Pin connection:
13. Follow the same process for other bulb holder and
relays.
16. Upload the code and setup the new blynk 2.0 Iot
platform.
Code:
#define BLYNK_FIRMWARE_VERSION "0.1.0"
#define APP_DEBUG
#include "BlynkEdgent.h"
int RelayPin1 = 5;
int RelayPin2 = 4;
int RelayPin3 = 14;
int RelayPin4 = 12;
void setup()
{
Serial.begin(115200);
pinMode(RelayPin1, OUTPUT);
pinMode(RelayPin2, OUTPUT);
pinMode(RelayPin3, OUTPUT);
pinMode(RelayPin4, OUTPUT);
digitalWrite(RelayPin1, HIGH);
digitalWrite(RelayPin2, HIGH);
digitalWrite(RelayPin3, HIGH);
digitalWrite(RelayPin4, HIGH);
delay(100);
BlynkEdgent.begin();
}
void loop() {
BlynkEdgent.run();
}
components:
● Li-ion battery x 2
● Battery holder x1 Jumper wires
● Foam board / Cardboard / Rigifoam
Code:
#include <AFMotor.h>
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() {
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();
int sensorTwo() {
//pulse output
digitalWrite(S2Trig, LOW);
delayMicroseconds(4);
digitalWrite(S2Trig, HIGH);
delayMicroseconds(10);
digitalWrite(S2Trig, LOW);
int sensorThree() {
//pulse output
digitalWrite(S3Trig, LOW);
delayMicroseconds(4);
digitalWrite(S3Trig, HIGH);
delayMicroseconds(10);
digitalWrite(S3Trig, LOW);
/*******************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);
}
Overview
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
Amazon.
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);
}
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.display();
display.clearDisplay();
Components:
● 5v relay module
● Ir sensor
● Ac lamp
● 5v 200mA adapter
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;
}
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);
COMPONENTS:
● ARDUINO
● MOTOR DRIVER SHIELD(L293D)
● 1-SERVO MOTOR
● 1-ULTRASONIC SENSOR(HC-SR04)
CIRCUIT DIAGRAM:
CODE:
void setup()
{
rightBack.setSpeed(motorSpeed); //Set the
motors to the motor speed
rightFront.setSpeed(motorSpeed);
leftFront.setSpeed(motorSpeed+motorOffset);
leftBack.setSpeed(motorSpeed+motorOffset);
void loop()
{
servoLook.write(90); //Set the servo to
look straight ahead
delay(750);
int distance = getDistance(); //Check that there
are no objects ahead
leftBack.setSpeed(i+motorOffset);
delay(10);
}
}
rightFront.run(RELEASE);
leftFront.run(RELEASE);
leftBack.run(RELEASE);
}
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);
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);
}
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;
}
● Arduino,
● Relay module,
● PIR sensor (HC-SR501),
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:
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:
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);
}
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
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();
}
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:
/*
COMPONENTS:
● Arduino
● Breadboard
● LDR sensor
● 1 led with 330 ohm resistor
● Jumper wire
void setup()
{
pinMode(LDR,INPUT);
pinMode(LED,OUTPUT);
}
void loop(){
if(digitalRead(LDR)==LOW)
{
digitalWrite(LED,LOW);
}
else
{
digitalWrite(LED,HIGH);
}
}
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 TP_init(){
delay(10);
long measurement=pulseIn (vibr_Pin, HIGH); //wait
for the pin to get HIGH and returns measurement
return measurement;
}
● 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;
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);
}
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 motors
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); //
}
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 motors
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); //
}