0% found this document useful (0 votes)
28 views

answer key

Uploaded by

nithishvb15
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

answer key

Uploaded by

nithishvb15
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

1) Controlling of DC motor for direction control

Aim:
To design, implement, and test a DC motor direction control system using the ATMEGA328
microcontroller and a motor driver, enabling precise and real-time directional control for robotic
navigation.

Apparatus Required:

Hardware Required:
1. DC Motor
2. L293D driver IC
3. Power Supply
4. ATMEGA328P Microcontroller
5. Push Buttons or Switches
6. Diodes
7. Resistors
8. Breadboard or PCB
9. Jumper Wires and Connectors

Software Required:
1. Arduino IDE

Procedure :

1. Connect the ATMEGA328 microcontroller to the DC motor through a motor driver (e.g.,
L293D).
2. Ensure proper wiring for motor power supply, control signals, and microcontroller I/O pins.
3. Write a program to generate PWM signals and control motor direction by setting specific digital
pins high or low.
4. Use a programmer or debugger to upload the code to the ATMEGA328 microcontroller.
5. Power on the circuit and test the motor in forward, reverse, and stop states using the
microcontroller’s control signals.
6. Adjust the PWM frequency and test different duty cycles to ensure smooth and precise motor
control.
Circuit Diagram:

Code:

// Motor A pins
const int ENA = 10; // Enable pin for Motor A
const int IN1 = 9; // Control pin 1 for Motor A
const int IN2 = 8; // Control pin 2 for Motor A

// Motor B pins
const int ENB = 5; // Enable pin for Motor B
const int IN3 = 7; // Control pin 1 for Motor B
const int IN4 = 6; // Control pin 2 for Motor B

void setup() {
// Set all the motor control pins as outputs
pinMode(ENA, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

// Initialize motors to off


stopMotors();
}

void loop() {
// Move both motors forward
moveForward();
delay(2000); // Run forward for 2 seconds

// Move both motors backward


moveBackward();
delay(2000); // Run backward for 2 seconds

// Stop motors
stopMotors();
delay(2000); // Stop for 2 seconds
}

void moveForward() {
// Motor A forward
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);

// Motor B forward
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);

// Enable motors at full speed


analogWrite(ENA, 255); // Full speed (0-255)
analogWrite(ENB, 255); // Full speed (0-255)
}

void moveBackward() {
// Motor A backward
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);

// Motor B backward
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);

// Enable motors at full speed


analogWrite(ENA, 255); // Full speed (0-255)
analogWrite(ENB, 255); // Full speed (0-255)
}

void stopMotors() {
// Disable both motors
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);

// Turn off PWM


analogWrite(ENA, 0);
analogWrite(ENB, 0);
}

Result:

The DC motor's direction was successfully controlled using the ATMEGA328 microcontroller
and a motor driver.

2. Interfacing IR Sensors

Aim:
To interface an IR sensor with a microcontroller (e.g., ATMEGA328) for object detection,
enabling accurate signal reading and reliable interpretation of the sensor’s output.

Apparatus Required:

Hardware Required:
1. IR Sensor
2. Power Supply
3. ATMEGA328P Microcontroller
4. Resistor and Capacitors
5. Jumper Wires and Connectors

Software Required:
1. Arduino IDE
Procedure:

1. Connect the IR sensor to the ATMEGA328 microcontroller, ensuring proper alignment of power,
ground, and signal pins.
2. Add resistors or capacitors to stabilize the IR sensor signal and reduce noise.
3. Write a program to read the IR sensor’s analog or digital signal and interpret object detection
based on threshold values.
4. Test the sensor by placing objects at different distances and verifying the signal consistency.
5. Adjust the sensor's placement and sensitivity, calibrating detection thresholds for optimal
performance.

Circuit Diagram:
Code:
// Pin definitions
#define L_IR A1 // Left IR sensor connected to analog pin A1
#define R_IR A0 // Right IR sensor connected to analog pin A0

void setup() {
// Initialize the serial monitor for debugging
Serial.begin(9600);

// Set IR sensor pins as inputs


pinMode(L_IR, INPUT);
pinMode(R_IR, INPUT);
}

void loop() {
// Read the digital values from the IR sensors
int leftIRValue = digitalRead(L_IR);
int rightIRValue = digitalRead(R_IR);

// Check the Left IR sensor


if (leftIRValue == 0) {
Serial.println("Left IR: Object Detected");
} else {
Serial.println("Left IR: No Object Detected");
}

// Check the Right IR sensor


if (rightIRValue == 0) {
Serial.println("Right IR: Object Detected");
} else {
Serial.println("Right IR: No Object Detected");
}

// Add a small delay to avoid overwhelming the serial monitor


delay(200);
}

Result:

The IR sensor was successfully interfaced with the ATMEGA328 microcontroller, enabling
reliable object detection and signal processing.
3. Obstacle Sensing and avoidance

Aim:

To design and implement an obstacle sensing and avoidance system using sensors and a
microcontroller, enabling a robot to detect and navigate around obstacles in real time

Apparatus Required:

Hardware Required:
1. Ultrasonic sensor or IR sensor
2. DC Motor
3. H-Bridge Circuit
4. Power Supply
5. ATMEGA328P Microcontroller
6. Chassis
7. Breadboard or PCB
8. Jumper Wires and Connectors

Software Required:
1. Arduino IDE

Procedure:

1. Choose appropriate sensors (IR or ultrasonic) and connect them to the microcontroller, ensuring
proper alignment for obstacle detection.
2. Design the circuit to interface the sensors with the microcontroller, ensuring stable signal
readings and correct power distribution.
3. Write code to read sensor data, processing inputs to detect obstacles based on predefined distance
thresholds.
4. Develop algorithms for obstacle avoidance, such as stopping, turning, or following walls when an
obstacle is detected.
5. Test the robot's obstacle detection and avoidance capabilities in various environments, adjusting
sensor placement and algorithm parameters as needed.
Circuit Diagram:

Code:

#define L_IR A1
#define R_IR A0

#define ENA 10
#define IN_1 9
#define IN_2 8
#define IN_3 7
#define IN_4 6
#define ENB 5

void setup() {
Serial.begin(9600);
pinMode(L_IR , INPUT);
pinMode(R_IR , INPUT);

pinMode(ENA, OUTPUT);
pinMode(IN_1, OUTPUT);
pinMode(IN_2, OUTPUT);
pinMode(IN_3, OUTPUT);
pinMode(IN_4, OUTPUT);
pinMode(ENB, OUTPUT);

analogWrite(ENA, 100);
analogWrite(ENB, 100);

Serial.println("Robot is Ready");
Stop();

void loop() {

int left= digitalRead(L_IR);


int right= digitalRead(R_IR);
if( (left ==1) && (right ==1)){ // forwared
Move_Forwared();
}
else if((left == 0) && (right == 1)) {

Move_Right();
}
else if((left ==1 ) && (right == 0)) {
Move_Left();
}
else{
Stop();
}
Serial.print("left value: " +String(left));
Serial.println(" || right value: " +String(right));
}
void Move_Forwared(){
Serial.println(" Move Forwared");
digitalWrite(IN_1, LOW) ;
analogWrite(IN_2, 100);

digitalWrite(IN_3, LOW) ;
digitalWrite(IN_4, HIGH);
}

void Move_Left(){
Serial.println(" Move Left");

digitalWrite(IN_1, HIGH) ;
digitalWrite(IN_2, LOW);

digitalWrite(IN_3, LOW);
digitalWrite(IN_4, HIGH) ;
}

void Move_Right(){
Serial.println(" Move Right");

digitalWrite(IN_1, LOW);
digitalWrite(IN_2, HIGH);

digitalWrite(IN_3, HIGH);
digitalWrite(IN_4, LOW);
}

void Stop(){
Serial.println(" Stop ");

digitalWrite(IN_1, LOW);
digitalWrite(IN_2, LOW);
digitalWrite(IN_3, LOW);
digitalWrite(IN_4, LOW);
}
Result:

The obstacle sensing and avoidance system successfully enabled the robot to detect and navigate
around obstacles in real-time, utilizing sensor data and dynamic avoidance algorithms.

4. Design of power Supply for Microcontroller

Aim:

To design a stable and efficient power supply for a microcontroller, ensuring proper voltage
regulation, protection against overvoltage and overcurrent, and compatibility with the microcontroller’s
power requirements.

Apparatus Required:

Hardware Components

1. Voltage Regulator
2. Capacitors
3. Protection Diodes
4. Power Source
5. Multimeter
6. Breadboard or PCB
7. Jumper Wires and Connectors
Procedure:

1. Identify the required output voltage and current for the system components, ensuring it meets the
peak and idle demands.
2. Choose a voltage regulator (linear or switching), capacitors for filtering, and protection diodes for
the required voltage and current specifications.
3. Connect the chosen voltage regulator to the power source, adding capacitors to stabilize the
output and ensure smooth voltage regulation.
4. Test the power supply using a multimeter to verify stable output voltage, current limits, and
proper operation under load conditions.

Circuit Diagram:

Result:

The power supply was successfully designed to deliver stable voltage, efficient current regulation,
and protection against overcurrent and reverse polarity.
5) Identifying Two Colors

Aim:

To design and implement a color detection system capable of reliably identifying and
distinguishing between two specific colors using a color sensor and microcontroller, ensuring real-time
operation and high accuracy under varying lighting conditions.

Apparatus Required:

Hardware Required:

1. Color Sensor
2. Microcontroller
3. Power Supply
4. Resistors and Capacitors
5. LEDs or Colored Objects
6. Breadboard or PCB
7. Jumper Wires and Connectors

Software Required:
1. Arduino IDE
Procedure:

1. Select the appropriate color sensor (e.g., TCS3200 or TCS34725) and connect it to the
microcontroller, ensuring stable wiring and proper signal connections.
2. Define the RGB or HSV values for the two target colors, experimenting with different shades and
lighting conditions to determine acceptable tolerance ranges.
3. Write code to read data from the color sensor and convert the readings to RGB or HSV values.
4. Develop an algorithm to compare the sensor readings against predefined color ranges for each
target color and determine if a match is detected.
5. Test the system with various colored objects under different lighting conditions, adjusting the
algorithm and sensor parameters for optimal performance and accuracy.
Circuit Diagram:

Code:

// Pin definitions for TCS3200


const int S0 = 4; // Frequency scaling
const int S1 = 5; // Frequency scaling
const int S2 = 6; // Color selection
const int S3 = 7; // Color selection
const int OUT = 8; // Output (frequency)

int redValue, greenValue, blueValue;

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

// Set TCS3200 control pins as outputs


pinMode(S0, OUTPUT);
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(OUT, INPUT);

// Set frequency scaling to 100% (S0 and S1 both HIGH)


digitalWrite(S0, HIGH);
digitalWrite(S1, HIGH);
}

void loop() {
// Read red color
digitalWrite(S2, LOW);
digitalWrite(S3, LOW);
redValue = pulseIn(OUT, digitalRead(OUT) == HIGH ? HIGH : LOW);

// Read green color


digitalWrite(S2, HIGH);
digitalWrite(S3, HIGH);
greenValue = pulseIn(OUT, digitalRead(OUT) == HIGH ? HIGH : LOW);

// Read blue color


digitalWrite(S2, LOW);
digitalWrite(S3, HIGH);
blueValue = pulseIn(OUT, digitalRead(OUT) == HIGH ? HIGH : LOW);

// Print RGB values to serial monitor


Serial.print("Red: ");
Serial.print(redValue);
Serial.print("\tGreen: ");
Serial.print(greenValue);
Serial.print("\tBlue: ");
Serial.println(blueValue);

delay(500); // Wait for 500ms before next reading


}

Result :
The color detection system successfully identified and distinguished between two specific colors
with real-time accuracy under varying lighting conditions.

You might also like