Line follower Arduino Alvik robot

Simple black line follower code for Arduino Alvik

This entry is part 5 of 6 in the series Arduino Alvik

Arduino Alvik was launched on May 14, 2024, there are lots of search going on to find the correct codes for it. Arduino Alvik is a robot designed for STEM education and is intended to be a tool for hands-on learning, creativity, and critical thinking. It's suitable for users of all ages and skill levels.

At Vidyasagar Academy we have written different interesting codes for Arduino Alvik and teaching them practically to our students. All these codes are successfully tested in our lab.

Arduino Alvik is a unique and innovative development platform, designed to expand the capabilities of the Arduino ecosystem by incorporating MicroPython as its primary programming language. AlvikArduino Alvik Arduino Alvik is a unique and innovative development platform, designed to expand the capabilities of the Arduino ecosystem by incorporating MicroPython as its primary programming language. Alvik focuses on offering a versatile environment for building projects that require advanced features such as real-time control, robotic automation, and sensor-based systems. focuses on offering a versatile environment for building projects that require advanced features such as real-time control, robotic automation, and sensor-based systems. This makes it particularly appealing to hobbyists, educators, and professionals alike, who want to leverage the power of both the hardware flexibility of Arduino and the ease-of-use that MicroPython provides.

With Alvik, users can easily integrate sensors, motors, LEDs, and other actuators into their projects while using high-level Pythonic constructs to write clean and efficient code. This platform retains the simplicity that Arduino is known for, but offers more advanced features typically seen in MicroPython-based environments, such as asynchronous programming, native handling of complex data structures, and fast prototyping for IoT applications.

Alvik also comes equipped with its own specialized modules and libraries that make it easier to control different hardware components like motors, sensors, and buzzers. It supports various robotic applications, including line-following robots, making it ideal for robotics enthusiasts.

About Multicolor LEDs of Alvik

You might have noticed that there are two multicolor LEDs on the top of the Arduino Alvik known as DL1 and DL2. These LEDs can be controlled with following built-in functions:

alvik.left_led.set_color(1, 0, 0) 
alvik.right_led.set_color(1, 0, 0)

In the above code note that there are three parameters inside these functions. They are used to emit Red, Green or Blue light from the LEDs.

Arduino Alvik

To emit red light from these LEDs use following piece of code:

alvik.left_led.set_color (1, 0, 0) # red light is emitted
alvik.right_led.set_color(1, 0, 0) # red light is emitted

To emit green light from these LEDs use following piece of code:

alvik.left_led.set_color(0, 1, 0) # green light is emitted
alvik.right_led.set_color(0, 1, 0) # green light is emitted

To emit blue light from these LEDs use following piece of code:

alvik.left_led.set_color(0, 0, 1) # blue light is emitted
alvik.right_led.set_color(0, 0, 1) # blue light is emitted

In this way you can emit multiple shades of colors by using different combination of the parameters of these functions.

About Motors

The motors of Arduino Alvik are controlled using different built-in functions. These functions are the default functionsMeaning of function in coding A function in any programming language is defined as the group of commands to carry out a particular task. It is necessary to note that all the commands in a function will execute a particular task, together. of Arduino Alvik. Let us see how to use them!

Move forward

alvik.set_wheels_speed(50, 50) # move forward at speed 50

In above piece of code you can change the value of both parameters from minimum 10 to maximum 100.

Here remember that the first parameter in the above function is for right motor and next parameter is for left motor.

Move backward

To move the Alvik backward, just change the sign of the speed parameters. When you make them negative, the Alvik moves backward.

alvik.set_wheels_speed(-50, -50) # move backward at speed 50

How to turn Alvik?

pivot turns to Arduino Alvik

Turning the Alvik is very simple. It is called pivot turn. There are four possible ways in which we can give turns to the Alvik robot. Note that the following piece of codes are given as per the modules that you import in your code.

from arduino_alvik import ArduinoAlvik
from time import sleep_ms

Start your code with above two lines to use the following piece of codes to turn the Arduino Alvik.

Soft left turn

To turn the Alvik with soft left turn, just make the right motor parameter as 0 and set the left motor parameter as per your choice of speed.

Here note that you will have to give delay also below the command of soft left turn, as follows:

alvik.set_wheels_speed(0, 50) # turn left at angular speed 50
sleep_ms(2600) # this delay will turn Arduino Alvik almost in 90 degrees

Soft right turn

For soft right turn, just make the left motor parameter as 0 and set the right motor parameter as per your choice of speed.

Here note that you will have to give delay also below the command of soft right turn, as follows:

alvik.set_wheels_speed(50, 0) # turn right at angular speed 50
sleep_ms(2600) # this delay will turn Arduino Alvik almost in 90 degrees

If your Arduino Alvik is running on some soft or slippery surface, you may have to slightly adjust the delay parameter.

Power left turn

The trick behind giving a power turn to Arduino Alvik, just change the sign of speed parameter of any one motor. Let us see how to give power left turn to the Arduino Alvik. There should be some delay to get proper turn to Arduino Alvik.

alvik.set_wheels_speed(-50, 50) # power left turn at angular speed 50
sleep_ms(800) # this delay will turn Arduino Alvik almost in 90 degrees

Power right turn

To give power right turn, use following piece of code. There should be some delay to get proper turn to Arduino Alvik.

alvik.set_wheels_speed(50, -50) # power right turn at angular speed 50
sleep_ms(800) # this delay will turn Arduino Alvik almost in 90 degrees

Stop motors

To stop the motors of Arduino Alvik, just use the following default functionMeaning of function in coding A function in any programming language is defined as the group of commands to carry out a particular task. It is necessary to note that all the commands in a function will execute a particular task, together..

alvik.brake()
sleep_ms(1000) # some delay to stop it

The line follower code

Now let us see how to write the code of line follower robot using these piece of codes for Arduino Alvik.

Signup or Login to view remaining content. It's Completely Free!
Share on your network!
Dattaraj Vidyasagar
Dattaraj Vidyasagar

Author on this website. He is veteran of Core Electronics since last 36+ years. ATL Mentor of Change, Niti Ayog, Govt. of India, Google Certified Educator, International Robotics Trainer and author of 18 books on electronics, robotics, programming languages and web designing... ➤➤

Leave a Reply

Your email address will not be published. Required fields are marked *