0% found this document useful (0 votes)
92 views6 pages

Myrc 2025

The document contains code for a 2025 Autonomous Microbot that implements line following and obstacle avoidance functionalities. It initializes sensors and motors, reads line sensor values, and controls motor speed based on sensor input. The main loop continuously checks for obstacles and adjusts the robot's movement accordingly.

Uploaded by

KUGAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views6 pages

Myrc 2025

The document contains code for a 2025 Autonomous Microbot that implements line following and obstacle avoidance functionalities. It initializes sensors and motors, reads line sensor values, and controls motor speed based on sensor input. The main loop continuously checks for obstacles and adjusts the robot's movement accordingly.

Uploaded by

KUGAN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

# MYRC 2025 Autonomous Microbot Code

# Basic framework for line following and obstacle avoidance

from microbit import *

import neopixel

import utime

# Initialize sensors and motors

np = neopixel.NeoPixel(pin0, 8) # Neopixel for status indication

left_motor = pin1

right_motor = pin2

ir_sensor_left = pin3

ir_sensor_right = pin4

ultrasonic = pin5

def setup():

# Initialize all components

display.show(Image.HAPPY)

np.clear()

np[0] = (0, 255, 0) # Green LED indicates ready

np.show()

sleep(1000)

def read_line_sensors():

left_val = ir_sensor_left.read_digital()

right_val = ir_sensor_right.read_digital()

return left_val, right_val

def read_distance():

# Simple ultrasonic distance reading

return ultrasonic.read_analog()

def motor_control(left_speed, right_speed):

# Control motors with PWM

left_motor.write_analog(left_speed)

right_motor.write_analog(right_speed)
def line_following():

left, right = read_line_sensors()

if left == 1 and right == 1:

# On track, move forward

motor_control(800, 800)

elif left == 0 and right == 1:

# Left sensor off track, turn right

motor_control(600, 400)

elif left == 1 and right == 0:

# Right sensor off track, turn left

motor_control(400, 600)

else:

# Both sensors off track - stop or search

motor_control(0, 0)

def obstacle_avoidance():

dist = read_distance()

if dist < 200: # Obstacle detected

# Back up and turn

motor_control(-400, -400)

sleep(500)

motor_control(-400, 400)

sleep(300)

return True

return False

def main_loop():

setup()

if not ob while True:

stacle_avoidance():

line_following()

sleep(50)

# Start the program


if name == "main":

main_loop()

You might also like