This circuit is designed to control two DC motors using a Raspberry Pi 5 microcontroller and an L298N motor driver. The motors are activated based on input from two PIR motion sensors. Additionally, a 7-inch WaveShare display is connected to the Raspberry Pi for visual output, and a Huskylens camera module is used for additional sensing capabilities.
Raspberry Pi 5
DC Motor
Motor Driver (L298N)
12v5ah Battery
PIR/Motion Sensor
7 inch WaveShare (H)
5v Battery
Micro USB to Cable (2 Pin)
Huskylense
/*
* This Arduino Sketch is designed for a Raspberry Pi 5 microcontroller.
* The circuit includes two DC motors controlled via an L298N motor driver.
* The motors are controlled based on input from two PIR motion sensors.
* The code initializes the GPIO pins and sets up the motor control logic.
* The motors will run when motion is detected by the sensors.
*/
// Define motor driver pins
#define IN1 1
#define IN2 2
#define IN3 3
#define IN4 4
// Define PIR sensor pin
#define PIR_SENSOR 14
void setup() {
// Initialize motor driver pins as outputs
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
// Initialize PIR sensor pin as input
pinMode(PIR_SENSOR, INPUT);
}
void loop() {
// Read PIR sensor value
int pirValue = digitalRead(PIR_SENSOR);
// If motion is detected, run the motors
if (pirValue == HIGH) {
// Motor 1 forward
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
// Motor 2 forward
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
} else {
// Stop motors
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
// Small delay to debounce PIR sensor
delay(100);
}
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
This documentation provides a comprehensive overview of the circuit, including a summary, detailed component list, wiring details, and the code used in the microcontroller.