Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Raspberry Pi Embedded Projects Hotshot
  • Toc
  • feedback
Raspberry Pi Embedded Projects Hotshot

Raspberry Pi Embedded Projects Hotshot

By : Sai Yamanoor, Srihari Yamanoor
close
Raspberry Pi Embedded Projects Hotshot

Raspberry Pi Embedded Projects Hotshot

By: Sai Yamanoor, Srihari Yamanoor

Overview of this book

This book is targeted towards beginners and intermediate designers of mechatronic systems and embedded system design. Some familiarity with the Raspberry Pi and Python programming is preferred but not required.
Table of Contents (15 chapters)
close
14
Index

Implementation of line following logic based on sensor data


In this task, we will implement a simple line following technique using the infrared sensor. We will make use of a pair of infrared sensors to track a black line on a white surface. The robot will move forward if both the sensors are on a white surface. The robot turns left if the left sensor is on the black line and vice versa.

Prepare for lift off

The sensor needs to be soldered and connected to the Raspberry Pi (something like the one shown in the preceding schematic). Alternatively, you may use a sensor of your choice.

Engage thrusters

  1. As always, we will get started by importing the required modules, especially Rpi.GPIO:

    import RPi.GPIO as GPIO
    from time import sleep
  2. We will set the pin configuration that we will use in this program:

    GPIO.setwarnings(False)
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(18,GPIO.IN)
    GPIO.setup(25,GPIO.IN)
  3. The control logic explained earlier is implemented as follows:

    state = 1
    prev_state = 0
    while True:
      #both sensors...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete