Arduino Project Tutorial for Controlling Motors Using L298N Driver

slide1 n.w
1 / 9
Embed
Share

Explore this detailed tutorial on creating an Arduino project to control motors with an L298N driver. Learn about setup, coding, and testing, all explained with images and code snippets.

  • Arduino
  • Motor Control
  • L298N Driver
  • Tutorial
  • Robotics

Uploaded on | 2 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. 8

  2. Arduino*1 *4 *1 *8+4 *1 *4 18650 *2 *1 18650 *1 *14 L298N*1 *2 *2 *2 *4 *1

  3. void setup() { // pinMode(ENA, OUTPUT); pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(ENB, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); // const int Vcc = 11; const int trigPin = 12; const int echoPin = 13; // pinMode(Vcc, OUTPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); Serial.begin(9600); // Initialize serial communication } #define ENA 5 // (PWM) #define IN1 6 // #define IN2 7 // #define ENB 10 // (PWM) #define IN3 8 // #define IN4 9 //

  4. // if (distance > 20) { // digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); analogWrite(ENA, 200); // Adjust the PWM value as needed void loop() { digitalWrite(Vcc, HIGH); // long duration, distance; digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); analogWrite(ENB, 200); // Adjust the PWM value as needed } else { // digitalWrite(IN1, LOW); digitalWrite(IN2, LOW); analogWrite(ENA, 0); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); digitalWrite(IN3, LOW); digitalWrite(IN4, LOW); analogWrite(ENB, 0); delay(400); // 0.5 digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); analogWrite(ENA, 200); // Adjust the PWM value as needed duration = pulseIn(echoPin, HIGH); distance = (duration / 2) / 29.1; delay(25); // Serial.print("Distance: "); digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); analogWrite(ENB, 200); delay(500); Serial.print(distance); Serial.println(" cm");

  5. // Randomly choose left or right if (random(2) == 0) { // digitalWrite(IN1, LOW); digitalWrite(IN2, HIGH); analogWrite(ENA, 200); // Adjust the PWM value as needed digitalWrite(IN3, HIGH); digitalWrite(IN4, LOW); analogWrite(ENB, 200); // Adjust the PWM value as needed delay(random(200, 501)); // Random duration between 200 and 500 milliseconds } else { // digitalWrite(IN1, HIGH); digitalWrite(IN2, LOW); analogWrite(ENA, 200); // Adjust the PWM value as needed digitalWrite(IN3, LOW); digitalWrite(IN4, HIGH); analogWrite(ENB, 200); // Adjust the PWM value as needed delay(random(200, 501)); // Random duration between 200 and 500 milliseconds } } }

Related


More Related Content