InfinityX - Electronics Assignment 30.6 Answers-1
InfinityX - Electronics Assignment 30.6 Answers-1
Answers
Q1. For a simple circuit that consists of 2 switches and 1 dc motor connected to Arduino UNO write a code for the below set of actions
1. If Switch 1 is pressed once the motor should run clockwise direction at 50% of its max speed and if Switch 1 is pressed again it should run at 100% of its
max speed
2. If Switch 2 is pressed once the motor should stop for a time of 3 seconds and must start running anti-clockwise direction at 50% of its max speed and if
Switch 2 is pressed again it should run at 100% of its max speed
Answer :
➢ Connect the motor enable pin (ENABLE A) of the motor driver to the pin no. 9 (PWM pin) on the Arduino.
➢ Connect the motor direction control pins “INPUT 1” and “INPUT 2” of the motor driver to two digital pins 7 and 8 on the Arduino(What we set for
motor direction pin).
➢ We may provide separate power supply to the motor driver or we may provide power supply to both Arduino and Motor driver from a power bank
or a power source of 5 ~ 12 V.
➢ Connect the two terminals of the DC motor to the output terminals “OUT 1” and “OUT 2”(As Enable pin “ENABLE A” is selected) of the motor driver
as per the required direction of the rotation.
➢ Connect one terminal of the push button (Switch 1) to 5V pin of the Arduino and another terminal to the GND pin using a resistor (Avoid current
overload and damage). Also connect the “switch1Pin” or digital pin “2” to that pin (which is connected to resistance and ground).
➢ Connect one terminal of the push button (Switch 2) to 5V pin of the Arduino and another terminal to the GND pin using a resistor. Also connect the
“switch2Pin” or digital pin “3” to that pin (which is connected to resistance and ground).
Schematic Diagram :
2
3
// Switch pins
const int switch1Pin = 2; // Connect Switch 1 to digital pin 2
const int switch2Pin = 3; // Connect Switch 2 to digital pin 3
// Variables
int switch1Count = 0; // Number of times Switch 1 is pressed
int switch2Count = 0;
void setup() {
// Motor control pins as outputs
pinMode(motorEnablePin, OUTPUT);
pinMode(motorDirectionPin1, OUTPUT);
pinMode(motorDirectionPin2, OUTPUT);
void loop() {
// Check if Switch 1 is pressed to control motor speed
4
if (digitalRead(switch1Pin) == HIGH) {
switch1Count++;
if (switch2Count == 1){
stopMotor();
delay(3000);
rotateHalfPowerCounterclockwise();
} else if (switch2Count == 2) {
rotateFullPowerCounterclockwise();
}
if (switch2Count >= 2) {
switch2Count = 0;
}
}
5
void rotateHalfPowerClockwise() {
digitalWrite(motorDirectionPin1, HIGH); // Set motor direction
digitalWrite(motorDirectionPin2, LOW);
analogWrite(motorEnablePin, 128); // Half power (128 out of 255)
}
void rotateFullPowerClockwise() {
digitalWrite(motorDirectionPin1, HIGH);
digitalWrite(motorDirectionPin2, LOW);
analogWrite(motorEnablePin, 255); // Full power (255 out of 255)
}
void rotateHalfPowerCounterclockwise() {
digitalWrite(motorDirectionPin1, LOW); // Change motor direction (counterclockwise)
digitalWrite(motorDirectionPin2, HIGH);
analogWrite(motorEnablePin, 128); // Half power (128 out of 255)
}
void rotateFullPowerCounterclockwise() {
digitalWrite(motorDirectionPin1, LOW);
digitalWrite(motorDirectionPin2, HIGH);
analogWrite(motorEnablePin, 255); // Full Power 255
}
void stopMotor() {
digitalWrite(motorDirectionPin1, LOW); // Set motor direction to stop
digitalWrite(motorDirectionPin2, LOW);
analogWrite(motorEnablePin, 0); // Disable the motor
}
6
*Q2. The Arduino NANO is one of the most widely used microcontroller boards. Redesign the PCB of the Arduino NANO in the shape of an Infinity with the
following dimensions.
25mm
50mm
Answer :
➢ Here, I have not included the ICSP pins. I have attached a micro USB for uploading Arduino sketch code. I have used CH340 USB to Serial data
converter.
➢ The size of the Arduino PCB is shaped like an infinity with 50mm length and 25mm height as given.
8
9