Circuit Documentation
Summary
The circuit in question is designed to interface an Arduino UNO with a pair of IR sensors, a tilt sensor, and a DC motor via an L298N motor driver. The Arduino UNO reads inputs from the IR and tilt sensors to determine environmental conditions and controls the motor accordingly. The IR sensors detect the presence or absence of objects, while the tilt sensor provides positional feedback. The motor driver facilitates the control of the motor's direction and speed.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
L298N DC Motor Driver
- A module that can control up to two DC motors with independent speed and direction control
- It is equipped with two H-bridge circuits capable of driving up to 2A per channel.
Gearmotor DC / Motorreductor
- A DC motor combined with a gearbox to increase torque
- It has two pins for electrical connection.
IR Sensor
- An infrared sensor capable of detecting the presence of objects or changes in a signal reflected from a surface
- It has three pins: VCC, GND, and an output signal pin.
Tilt Sensor
- A sensor that detects orientation or inclination
- It has two pins that change state when tilted.
Wiring Details
Arduino UNO
- 5V: Connected to the VCC pins of both IR sensors and the tilt sensor
- GND: Connected to the GND pins of both IR sensors
- D7: Connected to the output of the first IR sensor
- D6: Connected to the output of the second IR sensor
- D5: Connected to the IN3 pin of the L298N motor driver
- D4: Connected to the IN4 pin of the L298N motor driver
- D3: Connected to the ENB pin of the L298N motor driver
- D2: Connected to pin1 of the tilt sensor
L298N DC Motor Driver
- IN3, IN4: Control pins connected to Arduino UNO for motor direction
- ENB: Enable pin connected to Arduino UNO for motor speed control
- OUT3, OUT4: Output pins connected to the Gearmotor DC
Gearmotor DC / Motorreductor
- Pin1: Connected to OUT4 of the L298N motor driver
- Pin2: Connected to OUT3 of the L298N motor driver
IR Sensor
- VCC: Connected to 5V on the Arduino UNO
- GND: Connected to GND on the Arduino UNO
- OUT: Output signal connected to D7 and D6 on the Arduino UNO for the first and second sensors, respectively
Tilt Sensor
- Pin1: Connected to D2 on the Arduino UNO
- Pin2: Connected to 5V on the Arduino UNO
Documented Code
int irSensor1 = 6;
int irSensor2 = 7;
int tiltSensor = 2;
bool OnlyOneIR = false;
bool IsTilt = false;
void setup() {
pinMode(irSensor1, INPUT);
pinMode(irSensor2, INPUT);
pinMode(tiltSensor, INPUT);
Serial.begin(9600);
}
void loop() {
int irSensor1Value = digitalRead(irSensor1);
int irSensor2Value = digitalRead(irSensor2);
int tiltSensorValue = digitalRead(tiltSensor);
Serial.print("IR Sensor 1: ");
Serial.println(irSensor1Value);
Serial.print("IR Sensor 2: ");
Serial.println(irSensor2Value);
Serial.print("Tilt Sensor: ");
Serial.println(tiltSensorValue);
if (tiltSensorValue == 1) {
IsTilt = true;
} else {
IsTilt = false;
}
if ((irSensor1Value == 1 && irSensor2Value == 0) || (irSensor1Value == 0 && irSensor2Value == 1)) {
OnlyOneIR = true;
} else {
OnlyOneIR = false;
}
Serial.print("IsTilt: ");
Serial.println(IsTilt);
Serial.print("OnlyOneIR: ");
Serial.println(OnlyOneIR);
}
The code is written for the Arduino UNO and is responsible for reading the state of the IR and tilt sensors. It prints the status of each sensor to the serial monitor and determines if only one IR sensor is triggered or if the tilt sensor is activated.
