How to make an IR remote control car with Raspberry Pi Pico board

How to make an IR remote control car with Raspberry Pi Pico board

Hello and welcome back. In this project, we will learn how to make an IR remote control car with a Raspberry Pico board. For that, I used the IR receiver and remote. But, you can use any other IR remote. They are TV remotes, air conditioner remotes, DVD player remotes, etc. The process is the same. Also, I used two gear motors, and the L298N motor driver board was used to power up these motors.

You can use a car chassis for this project. But I built this car with a low budget. Therefore, I have used a piece of Rigiform board for this car.

  • If you want to do this project with Arduino, please use this link.

OK, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, cut the piece of Regiform board to the size below.

Step 3

Thirdly, glue the gear motors and caster wheel to the car chassis. And then, connect the robot wheels to the motors.

Step 4

Next, install the motor driver board and breadboard on the car chassis.

Step 5

Now, connect the motors to the motor driver board. And then, place the Raspberry Pi Pico board on the breadboard.

Step 6

Next, connect the motor driver board to the Raspberry Pi Pico board. For that, use the circuit diagram below.

How to make an IR remote control car with Raspberry Pi Pico board

Step 7

And then, place the IR receiver as you like. After, connect it to the Raspberry Pi Pico board.

Step 8

Finally, attach the battery holder to the car chassis and connect it to the motor driver board. Use the circuit diagram above for that.

Step 9

Ok now connect the Raspberry Pi Pico board to the computer. Then, follow the steps below.

  • First, include the library files on the Pico board. For that, use the pictures below.
  • Project script — Download
  • IR library — Download
#Include the library files
import time
from machine import Pin, freq, PWM
from ir_rx.print_error import print_error
from ir_rx.nec import NEC_8

#Define the IR receiver pin and motor pins
pin_ir = Pin(8, Pin.IN)
ENA = PWM(Pin(2))
IN1 = Pin(3,Pin.OUT)
IN2 = Pin(4,Pin.OUT)
IN3 = Pin(5,Pin.OUT)
IN4 = Pin(6,Pin.OUT)
ENB = PWM(Pin(7))

# speed of this car
speed = 60000 # 0 - 65025
ENA.duty_u16(speed)
ENB.duty_u16(speed)

Up = 0
Down = 0
Left = 0
Right = 0
Stop = 0

def decodeKeyValue(data):
    return data
    
# User callback
def callback(data, addr, ctrl):
    if data < 0:  # NEC protocol sends repeat codes.
        pass
    else:
        print(data)
        if data == Up:
            forward()
        elif data == Down:
            backward()
        elif data == Left:
            left()
        elif data == Right:
            right()
        elif data == Stop:
            stop()

def forward():
    IN1.on()
    IN2.off()
    IN3.on()
    IN4.off()
    
def backward():
    IN1.off()
    IN2.on()
    IN3.off()
    IN4.on()
    
def left():
    IN1.on()
    IN2.off()
    IN3.off()
    IN4.on()
    
def right():
    IN1.off()
    IN2.on()
    IN3.on()
    IN4.off()
    
def stop():
    IN1.off()
    IN2.off()
    IN3.off()
    IN4.off()
        

ir = NEC_8(pin_ir, callback)  # Instantiate receiver
ir.error_function(print_error)  # Show debug information

try:
    while True:
        pass
except KeyboardInterrupt:
    ir.close()


  • Now, click the run button and get the IR remote button values. For that, you can use any button. I used buttons 2,4,5,6 and 8. It depends on your requirement.

  • Now, you can see these values in the shell. Then, copy and paste these values into the main script. Use the following images for that.

  • Next, save this script as “main.py” on the Raspberry Pi Pico board. And then, click the run button.

Step 10

Now, put the batteries to the battery holder and enjoy this project.

How to make an IR remote control car with Raspberry Pi Pico board

Similar Posts

Leave a Reply

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