Vit Skvara
Published © CC BY

Smart delivery robot

Smart environmentally friendly Raspberry Pi-powered robot used to deliver small packages

AdvancedWork in progress2 days1,606
Smart delivery robot

Things used in this project

Hardware components

Raspberry Pi 4 Model B
Raspberry Pi 4 Model B
I used 4GB ram that is enough
×1
Arduino Nano Every
Arduino Nano Every
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×2
HMC5883L
×1
MPU6050
×1
HX711
×1
weight sensor 5 kg
×1
5 mm LED: Yellow
5 mm LED: Yellow
×8
5 mm LED: Red
5 mm LED: Red
×10
Adafruit LED 5mm white
×10
3 mm LED: Green
3 mm LED: Green
×3
Adafruit 3mm LED blue
not sixpacks, but six LEDS
×6
Through Hole Resistor, 200 ohm
Through Hole Resistor, 200 ohm
×9
Resistor 330 ohm
Resistor 330 ohm
×28
cd4017
×1
18650 Battery
×6
18650 holder x2
×3
Camera Module
Raspberry Pi Camera Module
×1
USB webcam
Czech web, because I didn't find it on us web. You can use any webcam that fits
×1
Solar panel
×1
DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
TaydaElectronics DC POWER JACK 2.1MM BARREL-TYPE PCB MOUNT
×1
Step up module
×1
switch
×1
l298N
×2
25GA-370 6V 620RPM
×6
5v 30x30x8 fan
×2
6-24 v to USB
×1
BMS module 2s 20A
×1
5v one channel relay
×1
electromagnetic lock 12v
×1
Adafruit 3x4 keypad
×1
SparkFun IR line sensor
×1

Software apps and online services

Fusion
Autodesk Fusion
Prusaslicer
Raspbian
Raspberry Pi Raspbian
thonny
OpenCV
OpenCV

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot Air Station, Industrial
Hot Air Station, Industrial
Torque, Control Screwdriver
Torque, Control Screwdriver
Drill / Driver, Cordless
Drill / Driver, Cordless
knife with snap off blades
3D Printer (generic)
3D Printer (generic)
I use Prusa MINI+
dremel tool
Tape, Double Sided
Tape, Double Sided
shrink insulation tubes
wires

Story

Read more

Custom parts and enclosures

Robot F3D

You must rearrange objects

Robot STL

Robot 3MF

Schematics

Power

Power management system

HCSR04

Hc-sr 04 connections to Arduino

Base

Connect Raspberry Pi 4 and L298N modules as in this diagram

MPU6050

Gyroscope accelerometer connection

Load cell

Load cell and HX711 connection

Keypad

I connected keypad to RPi like this

Analog sensors

Connect thermistor and LDR this way

Lights

Headlights of vehicle

Leypad lights

Lights for indicating keypad pin code

GPS

Optional installation of GPS

Motors

Connect motors like this

Power 2

Solar panel connection

Indicator

Lock indicator connection

Relay

Connect relay to Arduino

Lock

Connect lock to relay with this diagram

HMC5883L

Connection of magnetometer

Code

Arduino code

Arduino
Upload to Nano Every
int incomingByte = 0;
int thermistorPin = A0;
int thermistorVal = 0;
int ldrPin = A1;
int ldrVal = 0;
int trigPin = 2;
int echoPin = 3;
int trigPin2 = 4;
int echoPin2 = 5;
int relay = 6;
int green = 11;
int count = 12;
int resetcounter = 13;
long response1, range1, response2, range2;
void setup() {
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  pinMode(relay, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(count, OUTPUT);
  pinMode(resetcounter, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  digitalWrite(green, HIGH);
  delay(1000);
  digitalWrite(green, LOW);
}

void loop() {

  if (Serial.available() > 0) {
  incomingByte = Serial.read(); // read the incoming byte:
  Serial.println(incomingByte);
  if(incomingByte == 82){ //send char R to turn relay off (unlock the robot)
    Serial.println("Relay ON");
    digitalWrite(relay, HIGH);
    digitalWrite(green, HIGH);
    }
  else if(incomingByte == 114){ //send char r to turn relay off (lock the robot)
    Serial.println("Relay OFF");
    digitalWrite(relay, LOW);
    digitalWrite(green, LOW);
    }
  else if(incomingByte == 84) //count +1 to written chars
  {
  Serial.println("Keypad button pressed");
  digitalWrite(count, HIGH);
  delay(100);
  digitalWrite(count, LOW);
  }
  else if(incomingByte == 116)//reset counter
  {
    digitalWrite(count, LOW);
    digitalWrite(resetcounter, HIGH);
    delay(100);
    digitalWrite(resetcounter, LOW);
    Serial.println("Counter IC resetted");
    
  }
  }
   thermistorVal = analogRead(thermistorPin);
   if (thermistorVal < 350)
   {
    Serial.println("BatteriesAreGettingHot"); //hot battery warning
   }
   ldrVal = analogRead(ldrPin); //LED intensity adjustment
   if(ldrVal > 800)
   {
      Serial.println("Lights3");
   }
   else if(ldrVal > 600)
   {
      Serial.println("Lights2");
   }
   else
   {
      Serial.println("Ligths1");
   }
  digitalWrite(trigPin, LOW); //reading data from front sensor
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPin, LOW);
  response1 = pulseIn(echoPin, HIGH);
  range1 = response1 / 58.31;
  Serial.print("Range1");
  Serial.println(range1);
 
  digitalWrite(trigPin2, LOW); //reading data from back sensor
  delayMicroseconds(2);
  digitalWrite(trigPin2, HIGH);
  delayMicroseconds(5);
  digitalWrite(trigPin2, LOW);
  response2 = pulseIn(echoPin2, HIGH);
  range2 = response2 / 58.31;
  Serial.print("Range2");
  Serial.println(range2);
  delay(500); //delay for controller pause
}

CodeforRPi

Python
Use this code for RPi, it's only a draft, only basic driving and QR, you must change code for your own purpose
import cv2
import serial
import RPi.GPIO as gpio
import numpy as np
from gpiozero import Robot, LineSensor
from signal import pause
from time import sleep
correctqrpin = "123-456" #write your own correct qr code for recieving (change after delivery), must be string - 3 numbers, semicolon and 3 more numbers
cap = cv2.VideoCapture(0)
qcd = cv2.QRCodeDetector()
ser = serial.Serial('dev/tty/your-port name', 9600)
ser.bytesize = 8
ser.parity  ='N'
ser.stopbits = 1
gpio.setwarnings(False)
gpio.setmode(GPIO.BCM)
robot = Robot(left=(14, 15), right=(4, 18))#you must change pin numbers like your main L298N
left_sensor = LineSensor(4)
right_sensor = LineSensor(5)
writtenqrpin == ""
firstrun = True
while True:
    ret, frame = cap.read()
    qretval, decoded_info, points. straight_qrcode = qcd.detectAndDecodeMulti(frame)
    data = ser.readline().decode('utf-8').strip()
    if firstrun == True:
        #show QR code with number of unloading spot to go
        if decoded_info != "":
            place_to_go = decoded_info
    if data == "BatteriesAreGettingHot":
        print("Batteries extremely overheated, quitting")
        break
    elif data.startswith("Range1"):
        substring1 == "Range1"
        range1 = data.replace(substring1, "")
    elif data.startswith("Range2"):
        substring2 == "Range2"
        range2 = data.replace(substring2, "")
    if delivered == True:
        if qretval == True:
            writtenqrpin = decoded_info
        if writtenqrpin == correctqrpin:
            print("Correct QR")
            for indicator in range(6):
                ser.write(b'R')
                sleep(0.5)
            sleep(5)
            ser.write(b'r')
            delivered = False
        elif writtenqrpin == "":
            print("No QR")
        else:
            print("QR is incorrect")
            ser.write(b'r')
            ser.write(b't')
    else:
        left_detect  = int(left_sensor.value)
        right_detect = int(right_sensor.value)
        if left_detect == 0 and right_detect == 0:
            left_mot = 1
            right_mot = 1
        if left_detect == 0 and right_detect == 1:
            left_mot = -1
        if left_detect == 1 and right_detect == 0:
            right_mot = -1
        yield (right_mot * speed, left_mot * speed)
        robot.source = motor_speed()
        if decoded_info != "":
            if decoded_info.startswith("place-"):
                placesubstring="place-"
                placeinfo = decoded_info.replace(placesubstring, "")
                if placeinfo.trim() == settedplace:
                    delivered = True
            elif decoded_info.startswith("left-"):
                left_part, right_part = input_string.split(';')
                left_numbers = [int(num) for num in left_part.split('-')[1].split(',')]
                right_numbers = [int(num) for num in right_part.split('-')[1].split(',')]
                place_to_go_int = int(place_to_go)
                if place_to_go_int in left_numbers:
                    #go left
                    robot.forward(0.5)
                    sleep(1)
                    robot.left(0.5)
                    sleep(0.5) #you must adjust timing with experiments of turning time of your robot
                    robot.forward(0.5)
                    sleep(1)
                elif place_to_go_int in right_numbers:
                    #go right
                    robot.forward(0.5)
                    sleep(1)
                    robot.right(0.5)
                    sleep(0.5) #you must adjust timing with experiments of turning time of your robot
                    robot.forward(0.5)
                    sleep(1)
robot.stop()
robot.source = None
robot.close()
left_sensor.close()
cap.close()
right_sensor.close() 

Credits

Vit Skvara

Vit Skvara

1 project • 1 follower
I'm young student that is interested in technology.

Comments