Evan Rust
Published © GPL3+

Raspberry Spy Robot

Use a DFRobot MiniQ chassis to create a robot that streams video over WiFi. It can be used to move around your house and spy on anything.

IntermediateFull instructions provided3 hours4,481

Things used in this project

Hardware components

DFRobot MiniQ Chassis
×1
Dual H-Bridge motor drivers L293D
Texas Instruments Dual H-Bridge motor drivers L293D
×1
Jumper wires (generic)
Jumper wires (generic)
×1
5v Regulator
×1
1800 mAh 11.7V LiPo Battery
×1
SparkFun ESP8266 Thing - Dev Board
SparkFun ESP8266 Thing - Dev Board
×1
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×3
DFRobot Raspberry Pi 3
×1
DFRobot Raspberry Pi Camera Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

Battery Platform

Schematics

Schematic of Robot

Code

Controller Good

C/C++
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

ESP8266WiFiMulti WiFiMulti;

#define SSID "SSID"
#define PSSWD "PASSWORD"

int pins[3] = {12,13,4};

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  for(int i=0; i<3;i++){
    pinMode(pins[i], INPUT_PULLUP);
  }
  WiFiMulti.addAP(SSID, PSSWD);
}

void loop() {
  // put your main code here, to run repeatedly:
  int motor1, motor2;
  if(digitalRead(pins[0])==0){ //Turn left
    Serial.println("left");
    motor1 = 50;
    motor2 = 50;
  }
  else if(digitalRead(pins[1])==0){ //Go forward
    Serial.println("forward");
    motor1 = 50;
    motor2 = -50;
  }
  else if(digitalRead(pins[2])==0){ //Turn right
    Serial.println("right");
    motor1 = -50;
    motor2 = -50;
  }
  else{
    motor1 = 0;
    motor2 = 0;
  }
  
  if(WiFiMulti.run() == WL_CONNECTED){
    HTTPClient http;
    http.begin("http://<RaspberryPiIP:5000/control/");
    http.addHeader("Content-Type", "application/json");
    int httpCode = http.POST("{\"motor1\":"+String(motor1)+", \"motor2\":"+String(motor2)+"}");
    String payload = http.getString();
    Serial.print('\t');
    Serial.println(httpCode);
    Serial.println(payload);
  }
  delay(40);
}

Robot Code

Python
from flask import *
import RPi.GPIO as GPIO
import subprocess
import shlex

p=subprocess.Popen(shlex.split('./mjpg_streamer -o "output_http.so -w ./www" -i "input_raspicam.so"'))

app=Flask(__name__)
GPIO.setmode(GPIO.BCM)
motor_array = [6,5,19,13]
for pin in motor_array:
    GPIO.setup(pin, GPIO.OUT)
motorL1_pwm = GPIO.PWM(6, 100)
motorL2_pwm = GPIO.PWM(5, 100)
motorR1_pwm = GPIO.PWM(19, 100)
motorR2_pwm = GPIO.PWM(13, 100)
motorL1_pwm.start(0)
motorL2_pwm.start(0)
motorR1_pwm.start(0)
motorR2_pwm.start(0)

def turn_wheel(motor1, motor2):
    motor1 = motor1 / 2
    motor2 = motor2 / 2
    
    if motor1<0:
        motorL2_pwm.ChangeDutyCycle(motor1*-1)
        motorL1_pwm.ChangeDutyCycle(0)#make positive if negative
    else:
        motorL1_pwm.ChangeDutyCycle(motor1)
        motorL2_pwm.ChangeDutyCycle(0)
        
    if motor2<0:
        motorR2_pwm.ChangeDutyCycle(motor2*-1)
        motorR1_pwm.ChangeDutyCycle(0)#make positive if negative
    else:
        motorR1_pwm.ChangeDutyCycle(motor2)
        motorR2_pwm.ChangeDutyCycle(0)

@app.route("/control/", methods=['GET','POST'])
def control():
    data = request.get_json()
    motor1 = data['motor1']
    motor2 = data['motor2']
    turn_wheel(motor1, motor2)
    print("Motor 1 value is: "+str(motor1)+", motor 2 value is: "+str(motor2))
    return "ACK"
if __name__=="__main__":
    try:
        app.run(host='0.0.0.0')
    except KeyboardInterrupt: 
        p.terminate()
        pass

Credits

Evan Rust

Evan Rust

122 projects • 1091 followers
IoT, web, and embedded systems enthusiast. Contact me for product reviews or custom project requests.

Comments