0% found this document useful (0 votes)
35 views13 pages

REPORT

Uploaded by

Sivakumar Siva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views13 pages

REPORT

Uploaded by

Sivakumar Siva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1.

Description:
This experiment demonstrates how to control a servo motor using an Arduino. It involves
programming the servo to sweep back and forth between 0 and 180 degrees. The servo
moves in increments of 30 degrees, pausing for 2 seconds at each step, showcasing basic
servo motor operation and control via incremental positioning.

CIRCUIT DIAGRAM:

SCHEMATIC CIRCUIT DIAGRAM :


CODE:
#include <Servo.h>

int pos = 0;

Servo servo_9;

void setup()
{
servo_9.attach(9, 500, 2500);
}

void loop()
{

int pos =0;


while(pos <=180){
pos+=30;
servo_9.write(pos);
delay(2000);
}
pos=180;
while(pos>=0){
pos-=30;
servo_9.write(pos);
delay(2000);
}
}
2.
Description:
This experiment demonstrates how to use an Arduino to control an LED based on the input
from a Light Dependent Resistor (LDR). The LDR measures the ambient light level and sends
a corresponding analog value to the Arduino. If this value is above a certain threshold (100 in
this case), the LED is turned on; otherwise, it is turned off. The program also outputs the LDR
readings to the serial monitor for real-time monitoring of the light levels.

CIRCUIT DIAGRAM:

SCHEMATIC CIRCUIT DIAGRAM :


CODE:
const int led = 5;
const int ldr = A1;
void setup()
{
pinMode(led, OUTPUT);
pinMode(ldr, INPUT);
Serial.begin(9600);
}
void helper(int n){
if(n >=100)digitalWrite(led,HIGH);
else digitalWrite(led,LOW);
}

void loop()
{
int val = analogRead(ldr);
Serial.print("Serial Values of LDR : ");
Serial.println(val);
helper(val);
}
3.
Description:
This experiment demonstrates how to control a robot's movement using an
Arduino. The robot has two motors, each with two control pins, allowing for
forward, backward, left, and right movements. The Arduino reads commands
from the serial input, where specific characters ('f', 'b', 'l', 'r', 's') are used to
move the robot forward, backward, left, right, or stop, respectively. This setup
showcases basic motor control and serial communication with an Arduino.

CIRCUIT DIAGRAM:

SCHEMATIC CIRCUIT DIAGRAM :


CODE:
int leftMotorPin1 = 13; // Left motor pins
int leftMotorPin2 = 12;

int rightMotorPin1 = 11; // Right motor pins


int rightMotorPin2 = 10;

void setup()
{
pinMode(leftMotorPin1, OUTPUT);
pinMode(leftMotorPin2, OUTPUT);
pinMode(rightMotorPin1, OUTPUT);
pinMode(rightMotorPin2, OUTPUT);

Serial.begin(9600);
}

void moveForward()
{
digitalWrite(leftMotorPin1, HIGH);
digitalWrite(leftMotorPin2, LOW);
digitalWrite(rightMotorPin1, HIGH);
digitalWrite(rightMotorPin2, LOW);
}

void moveBackward()
{
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, HIGH);
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, HIGH);
}

void moveLeft()
{
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, HIGH);
digitalWrite(rightMotorPin1, HIGH);
digitalWrite(rightMotorPin2, LOW);
}

void moveRight()
{
digitalWrite(leftMotorPin1, HIGH);
digitalWrite(leftMotorPin2, LOW);
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, HIGH);
}

void stopMotors()
{
digitalWrite(leftMotorPin1, LOW);
digitalWrite(leftMotorPin2, LOW);
digitalWrite(rightMotorPin1, LOW);
digitalWrite(rightMotorPin2, LOW);
}

void loop()
{
if (Serial.available() > 0)
{
char incomingByte = Serial.read();

switch (incomingByte)
{
case 'f':
moveForward();
break;

case 'b':
moveBackward();
break;

case 'l':
moveLeft();
break;

case 'r':
moveRight();
break;

case 's':
stopMotors();
break;
}
}
}
4.
Description:
This sketch demonstrates basic usage of an ultrasonic sensor with Arduino to
measure distance and control an LED based on that distance. It's a simple
example of how to integrate sensor data with output control in an Arduino
project.
CIRCUIT DIAGRAM:

SCHEMATIC CIRCUIT DIAGRAM :


CODE:
#define ech 9
#define tri 10

long dur;
int dis;
void setup(){
pinMode(ech,INPUT);
pinMode(tri,OUTPUT);
pinMode(7,OUTPUT);
Serial.begin(9600);

}
int calDur(){
return pulseIn(ech,HIGH);
}
int calDis(int s){
return s*0.03437/2;
}

void loop(){
digitalWrite(tri,LOW);
delayMicroseconds(2);
digitalWrite(tri,HIGH);
delayMicroseconds(10);
digitalWrite(tri,LOW);
dur = calDur();
if(calDis(dur) <=60)digitalWrite(7,HIGH);
else digitalWrite(7,LOW);
Serial.print(calDis(dur)/2.54);
Serial.print("inch");
Serial.print(" ");
Serial.print(calDis(dur));
Serial.println("inch");
}
5.
Description:
This experiment demonstrates how to use an Arduino to control the movement
of a motor based on distance measurements from an ultrasonic sensor. The
ultrasonic sensor sends out a pulse and measures the time it takes to return,
calculating the distance to an object. Depending on the distance, the Arduino
controls the motor to move forward, move backward, or stop. The distance
values are also printed to the serial monitor for real-time monitoring. This
setup showcases the integration of sensor data with motor control in an
Arduino project.
CIRCUIT DIAGRAM:

SCHEMATIC CIRCUIT DIAGRAM :


CODE:
#define ech 2
#define tri 3
#define sw A0
int leftm1 = 9;
int leftm2 = 10;
void setup()
{
pinMode(tri, OUTPUT);
pinMode(ech, INPUT);
pinMode(leftm1, OUTPUT);
pinMode(leftm2, OUTPUT);
Serial.begin(9600);
}
void moveForward()
{
digitalWrite(leftm1, LOW);
digitalWrite(leftm2, HIGH);
}

void moveBackward()
{
digitalWrite(leftm1, HIGH);
digitalWrite(leftm2, LOW);
}
void stop(){
digitalWrite(leftm1, LOW);
digitalWrite(leftm2, LOW);
}
int calDis(int n){
return n*0.034/2;
}

void loop()
{
digitalWrite(tri,LOW);
delayMicroseconds(2);
digitalWrite(tri, HIGH);
delayMicroseconds(10);
digitalWrite(tri, LOW);
long dur = pulseIn(ech,HIGH);
float dis = calDis(dur);
Serial.println(dis);
if(dis >100){
moveForward();

}else if(dis >30 && dis <=100){


moveBackward();
}else if(dis <=30){

stop();
}
}

You might also like