So my Sparki's ultra-sonic range finder is still broke unfortunately but I have purchased an infrared sensor that can be used for object detection.
This brings back a sense of autonomy for Sparki as he can now navigate the rooms, making decisions about turns.
The following code allows Sparki to turn Right at very short intervals if his way forward is blocked:
#include <Sparki.h> // include the sparki library
void setup() {
pinMode (3, INPUT); //Sensor output
}
void loop() {
sparki.clearLCD();
sparki.print ("Sensor: ");
sparki.println (digitalRead(3)); //print the sensor output
sparki.updateLCD();
delay (1500);
while (digitalRead(3) <0 )
{
sparki.moveForward();
}
while (digitalRead(3) >1 )
{
sparki.moveRight(10);
}
}
Like this:
Like Loading...
Related
How does this compare to the ultrasonic sensor? More accurate? Different sensing range?
LikeLiked by 1 person
well with the ultrasonic range finder Sparki was able to measure distances to obstacles (and then choose the “path of least resistance”) but the infrared range finder only provides a 1 or a 0 to the presence of an object; if an object is in the way it reads 1, if not 0 so Sparki cannot make intelligent decisions about which direction will be obstacle free for the furthest period. Having said that I think the sensing range on the infrared sensor is better than the ultrasonic range finder in that it can be altered to smaller or larger distances depending on your area and program, which means less for the atmega to process and less bytes in the program. I think the ultrasonic range finder is better overall and I would love to get my three pin one working but I cant so as an alternative the infrared sensor is my best bet 🙂
LikeLike