Build Your Own AI Assistant Part 1 - Creating the Assistant
115007 Views
Is the new Raspberry Pi AI Kit better than Google Coral?
103855 Views
Control Arduino with Python using Firmata / PyFirmata
86426 Views
How to Map with LiDAR - using a Raspberry Pi Zero 2W, RPLidar and Rviz
55270 Views
Node-Red Automation, MQTT, NodeMCU & MicroPython
51306 Views
Creating a Supercomputer with a Raspberry Pi 5 Cluster and Docker Swarm!
50568 Views
Installing and Using DeepSeek-R1:1.5 on a Raspberry Pi with Docker
Gamepad & BurgerBot
Level Up your CAD Skills
Operation Pico
Raspberry Pi Home Hub
Hacky Temperature and Humidity Sensor
Using the Raspberry Pi Pico's Built-in Temperature Sensor
0h 24m
Getting Started with SQL
0h 32m
Introduction to the Linux Command Line on Raspberry Pi OS
0h 42m
How to install MicroPython
0h 8m
Wall Drawing Robot Tutorial
0h 22m
BrachioGraph Tutorial
0h 16m
Learn Linux from the basics to advanced topics.
Learn how to use a Raspberry Pi Pico
Learn MicroPython the best language for MicroControllers
Learn Docker, the leading containerization platform. Docker is used to build, ship, and run applications in a consistent and reliable manner, making it a popular choice for DevOps and cloud-native development.
Learn how to build SMARS robots, starting with the 3D Printing the model, Designing SMARS and Programming SMARS
Learn how to build robots, starting with the basics, then move on to learning Python and MicroPython for microcontrollers, finally learn how to make things with Fusion 360.
Learn Python, the most popular programming language in the world. Python is used in many different areas, including Web Development, Data Science, Machine Learning, Robotics and more.
Learn how to create robots in 3D, using Fusion 360 and FreeCAD. The models can be printed out using a 3d printer and then assembled into a physical robot.
Learn how to create Databases in Python, with SQLite3 and Redis.
KevsRobots Learning Platform
100% Percent Complete
By Kevin McAleer, 3 Minutes
In this lesson you will learn how to use the line follow module to make the robot follow along a line, or stay within a marked area.
Download the PDFs here:
New Sketch
You can download the code below from GitHub, but its better to type it in yourself line by line, as you will get to understand what each line means.
/* * Kevin McAleer * 24 July 2020 * * Line Following Code * See Lesson 07 for the full tutorial * https://www.smarsfan.com/play/lessons/lesson_07_linefollow * Watch the livestream video: * https://youtu.be/u9VT32q7ero * * */ // set the line sensor thresholds int light_threshold = 650; int dark_threshold = 300; int lineNumber; // stores the line sensor value int lineSensorPin = 4; // set Motor A to Arduino Pins int motor_A = 12; // official Arduino Motor Shield uses D12 int motor_B = 13; // official Arduino Motor Shield uses D13 int buzzer = 4; // set the Motor Speed using the Arduino Pins int motor_A_speed = 10; // official Arduino Motor Shield uses D3 int motor_B_speed = 11; // official Arduino Motor Shield uses D11 // set the time between motor on and motor off int wait_in_milliseconds = 10; ///////////////////////////////////// /* * Movement block of code, from the movement lessons * https://www.smarsfan.com/play/lessons/lesson_01_movement * https://www.smarsfan.com/play/lessons/lesson_02_turning * */ // move forward void forward() { // set the direction to forward digitalWrite(motor_A, LOW); digitalWrite(motor_B, HIGH); // set to full speed analogWrite(motor_A_speed, 255); analogWrite(motor_B_speed, 255); // wait delay(wait_in_milliseconds); // stop analogWrite(motor_A_speed, 0); analogWrite(motor_B_speed, 0); } void backward(){ // set the direction to forward digitalWrite(motor_A, HIGH); digitalWrite(motor_B, LOW); // set to full speed analogWrite(motor_A_speed, 255); analogWrite(motor_B_speed, 255); // wait delay(wait_in_milliseconds); // stop analogWrite(motor_A_speed, 0); analogWrite(motor_B_speed, 0); } void turnRight(){ // set the direction to forward digitalWrite(motor_A, HIGH); digitalWrite(motor_B, HIGH); // set to full speed analogWrite(motor_A_speed, 255); analogWrite(motor_B_speed, 255); // wait delay(wait_in_milliseconds); // stop analogWrite(motor_A_speed, 0); analogWrite(motor_B_speed, 0); } void turnLeft(){ // set the direction to forward digitalWrite(motor_A, LOW); digitalWrite(motor_B, LOW); // set to full speed analogWrite(motor_A_speed, 255); analogWrite(motor_B_speed, 255); // wait delay(wait_in_milliseconds); // stop analogWrite(motor_A_speed, 0); analogWrite(motor_B_speed, 0); } ///////////////////////////////////// int readLineSensor() { return analogRead(lineSensorPin); } void setup() { // set the Serial to 9600 baud and open it for comms Serial.begin(9600); // set the Arduino pin to OUTPUT mode pinMode(motor_A, OUTPUT); pinMode(motor_B, OUTPUT); pinMode(buzzer, OUTPUT); } void loop() { // Read the value from the line sensor (connected to the line sensor pin) lineNumber = readLineSensor(); // move forward while the line sensor is white while(lineNumber > light_threshold) { Serial.println("move forward"); // move forward forward(); Serial.println(lineNumber); lineNumber = readLineSensor(); } Serial.println(lineNumber); if(lineNumber < light_threshold){ turnLeft(); } else { Serial.println(lineNumber); backward(); backward(); turnLeft(); } Serial.println(lineNumber); }
< Previous