亚洲精品不卡AV在线播放|国产性爱无码高清视频|国产成人 ,97人人色,国产免费一区二区三区,日本一区二区在线

內(nèi)容中心

返回列表
2026年質(zhì)量好的寧波節(jié)能干燥注塑輔機/塑料粉碎注塑輔機高評價品牌廠家推薦哪家權(quán)威
2026-02-10 08:00:04

To help you build a simple, beginner-friendly robot, let’s create a line-following robot (one of the most common and educational projects). It uses basic components and is easy to program with Arduino.

Materials You’ll Need

Gather these affordable parts (most are available online or at electronics stores):

  1. Arduino Uno (or compatible board like Nano)
  2. L298N Motor Driver Module (controls DC motors)
  3. 2 DC Motors (with wheels attached)
  4. 1 Caster Wheel (for front/back support)
  5. 2 IR Reflective Sensors (detects line contrast)
  6. Battery Pack (4xAA = 6V, ideal for motors; or 9V with a barrel jack for Arduino)
  7. Chassis (plastic base, foam board, or cardboard box for DIY)
  8. Jumper Wires (male-to-male, male-to-female)
  9. Optional: Breadboard (simplifies sensor wiring)

Step-by-Step Assembly


1. Build the Chassis

  • Attach the two DC motors to the sides of your chassis (left/right).
  • Fix wheels to the motor shafts.
  • Add the caster wheel to the opposite end of the motors (to balance the robot).

2. Connect Motors to the L298N Driver

The L298N handles high current for motors (Arduino can’t drive motors directly):

  • Connect left motor wires to OUT1 and OUT2 of the L298N.
  • Connect right motor wires to OUT3 and OUT4 of the L298N.
  • Link L298N’s GND to Arduino’s GND (critical for signal stability).
  • Connect L298N’s 5V pin to Arduino’s 5V (powers the driver’s logic).

3. Wire IR Sensors

IR sensors detect contrast (black line on white surface):

  • Each sensor has 3 pins: VCC (5V), GND, OUT (digital signal).
  • Connect both sensors’ VCC to Arduino’s 5V, GND to Arduino’s GND.
  • Connect left sensor’s OUT to Arduino pin 2, right sensor’s OUT to pin3.

4. Link Motor Driver to Arduino

Control motor direction with Arduino pins:

  • L298N’s IN1 → Arduino pin8, IN2 → pin9 (left motor).
  • L298N’s IN3 → Arduino pin10, IN4 → pin11 (right motor).

5. Power the Robot

  • Connect the 4xAA battery pack to the L298N’s 12V input (it works with 6V too).
  • Power Arduino via the same battery pack (use L298N’s 5V output or a separate 9V battery).

6. Program the Arduino

Upload this code to your Arduino (uses the Arduino IDE):

// Define pins
int leftSensor = 2;
int rightSensor = 3;
int in1 = 8, in2 =9, in3=10, in4=11;

void setup() {
  pinMode(leftSensor, INPUT);
  pinMode(rightSensor, INPUT);
  pinMode(in1, OUTPUT); pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT); pinMode(in4, OUTPUT);
}

void loop() {
  int leftVal = digitalRead(leftSensor);
  int rightVal = digitalRead(rightSensor);

  // IR sensor outputs LOW when on a black line (adjust if needed)
  if(leftVal == LOW && rightVal == LOW) {
    forward(); // Both sensors on line → go straight
  } else if(leftVal == HIGH && rightVal == LOW) {
    turnLeft(); // Left sensor off line → turn left
  } else if(leftVal == LOW && rightVal == HIGH) {
    turnRight(); // Right sensor off line → turn right
  } else {
    stopRobot(); // No line detected → stop
  }
}

// Helper functions for motor movement
void forward() {
  digitalWrite(in1, HIGH); digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH); digitalWrite(in4, LOW);
}

void turnLeft() {
  digitalWrite(in1, LOW); digitalWrite(in2, HIGH); // Left motor reverse
  digitalWrite(in3, HIGH); digitalWrite(in4, LOW); // Right motor forward
}

void turnRight() {
  digitalWrite(in1, HIGH); digitalWrite(in2, LOW); // Left motor forward
  digitalWrite(in3, LOW); digitalWrite(in4, HIGH); // Right motor reverse
}

void stopRobot() {
  digitalWrite(in1, LOW); digitalWrite(in2, LOW);
  digitalWrite(in3, LOW); digitalWrite(in4, LOW);
}

7. Test & Adjust

  1. Draw a thick black line on a white surface (use tape or marker).
  2. Place the robot on the line and turn it on.
  3. Tweak:
    • Adjust sensor height (1-2 cm above the surface).
    • Use the sensor’s potentiometer to change sensitivity (if it misses the line).
    • Reposition sensors to align with the line.

Key Tips for Success

  • DIY Chassis: Use a foam board or cardboard box if you don’t have a plastic base.
  • Safety: Avoid short circuits (don’t cross positive/negative wires).
  • Learn: Arduino’s official website has tutorials for each component (e.g., IR sensors, motor drivers).

This robot will follow any black line you draw—perfect for learning basic robotics and coding!

(免責聲明:本文為本網(wǎng)站出于傳播商業(yè)信息之目的進行轉(zhuǎn)載發(fā)布,不代表本網(wǎng)站的觀點及立場。本文所涉文、圖、音視頻等資料的一切權(quán)利和法律責任歸材料提供方所有和承擔。本網(wǎng)站對此資訊文字、圖片等所有信息的真實性不作任何保證或承諾,亦不構(gòu)成任何購買、投資等建議,據(jù)此操作者風險自擔。) 本文為轉(zhuǎn)載內(nèi)容,授權(quán)事宜請聯(lián)系原著作權(quán)人,如有侵權(quán),請聯(lián)系本網(wǎng)進行刪除。

點擊呼叫(詳情介紹)
在線客服

在線留言
您好,很高興為您服務(wù),可以留下您的電話或微信嗎?