RoboPet
Arduino code used:
//Download and Install the variable speed servo library for arduino //https://github.com/netlabtoolkit/VarSpeedServo //Download and Install HCSR04 Distance sensor library with median filter //Also availalbe as a zip file in the same folder of this script HCSR04-master.zip //https://github.com/enjoyneering/HCSR04 //Below Instructions how to install arduino libraries //https://www.arduino.cc/en/guide/libraries //Basically after downloading VarSpeedServo zip file, go to sketch > include library > Add zip library // maximum distance you want the servo to read (can go up to 200cm); int servoSpeed = 100; // 50 means 50% of it's maximum speed, sometimes if it's too fast it won't work properly with your bot #include <VarSpeedServo.h> // load servo variable speed library // #include <HCSR04.h> //load distance sensor hcsr04 library //declare variable distance with a 0 value VarSpeedServo myservo; // create servo object to control a servoHCSR04 ultrasonicSensor(12, 13, 22, maxSensorDistance); //set pins of distance sensor (trigger, echo, room temperature, maximum distance) const int power = 11; //declare variable power with value 11 (to be used as pin) int previousangle; void setup() { myservo.attach(10); // attaches the servo on pin 10 to the servo object myservo.write(0, servoSpeed, true); //set servo to 180 degrees at the speed of 50 pinMode(power, OUTPUT); //set pin 11 as an output (so we power our sensor) } void loop() { digitalWrite(power, HIGH); myservo.attach(10); // attaches the servo on pin 10 to the servo object myservo.write(180, servoSpeed, true); myservo.write(0, servoSpeed, true); //write angle value to previous angle }













