Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
Paul Binary
Published

Phobot: Basic Obstacle Avoidance

Using a Particle Photon, Phobot, and a Ultrasonic Sensor for basic Obstacle Avoidance.

BeginnerFull instructions provided2,667

Things used in this project

Hardware components

Photon
Particle Photon
×1
Phobot
×1
4xAA battery holder
4xAA battery holder
×1
Sprout Runt Rover
×1
AA Batteries
AA Batteries
×4
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Story

Read more

Schematics

Github

Code

Basic Obstacle Avoidance

C/C++
#include "HC_SR04/HC_SR04.h"
#include "PhoBot/PhoBot.h"


PhoBot p = PhoBot(9.0, 6.0);
HC_SR04 rangefinder = HC_SR04(p.trigPin, p.echoPin);
double distance = 0.0;

void setup() {
}

void loop() {

    distance = rangefinder.getDistanceCM();
    if (distance < 20){
        pause();
        rotateRight();
        delay(100);
    } else {
        forward();
    }
    delay(100);
}

void forward(){
    p.setMotors("M3-F-50");
    p.setMotors("M4-F-50");  
}

void backward(){
    p.setMotors("M3-B-50");
    p.setMotors("M4-B-50");  
}

void rotateRight(){
    p.setMotors("M3-F-100");
    p.setMotors("M4-B-100");  
}

void rotateLeft(){
    p.setMotors("M3-B-100");
    p.setMotors("M4-F-100");  
}

void pause() {
    p.setMotors("M3-S");
    p.setMotors("M4-S");
    delay(100);
}

Credits

Paul Binary
7 projects • 51 followers

Comments