Hi guys
So today I got my new ultrasonic range finder for Sparki-one with 3 pins instead of 4.
My poor soldering skills had meant that although I had fixed Sparki (here) he soon broke again.
The 4 pin ultrasonic range finder did not connect to the expansion port as there was not enough ports for one of the pins, so I opted for a 3 pin replacement to connect to the expansion port, instead of the board itself which is how Sparki was originally set up.
So he’s now set up and all ready to go!
Although I now have to re-code everything I have ever worked on…
So I began, but now I’m awfully stuck.
Using the digital pin 1 (TX) does not seem to make a change to the reading given on the screen , it simply remains at 1….although this is the code I ahve found for a 3 pin sensor online…
so I hooked it up to the Analogue pin 8 instead (and moved the touch sensor that was there to the digital pin RX which works great) but on there it flickers between 383/384/385 and 0. To test it I edited a previous code:
#include <Sparki.h> void setup() { } void loop() { sparki.servo(0); float distance=analogRead(8); sparki.clearLCD(); sparki.print(distance); sparki.updateLCD(); delay(2000); if((distance<380)) { delay(1000); sparki.RGB(0,255,0); sparki.moveForward(10); sparki.beep(540, 1000); } sparki.servo(0); if((distance>0)) { delay(1000); sparki.moveRight(10); } }
But it appears that the 0 is random, and not connected to the distance measured at all….
So now I’m feeling frustrated 😦 😦
any help???
My Roaming robot uses a 3 pin Ultrasonic sensor, the code is available here:
http://killerrobotics.me/2015/07/27/roaming-robot-update/
This is the function you want to focus on:
long ping()
{
// Send Ping pulse
pinMode(PING_PIN, OUTPUT);
digitalWrite(PING_PIN, LOW);
delayMicroseconds(2);
digitalWrite(PING_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(PING_PIN, LOW);
//Get duration it takes to receive echo of Ping sent
pinMode(PING_PIN, INPUT);
duration = pulseIn(PING_PIN, HIGH);
//Convert duration into distance (cm)
return duration / 29 / 2;
}
Let me know if you need any more assistance.
LikeLiked by 1 person
That’s awesome thank you so much 🙂
LikeLike
So I am using this code: and all I get us 12 and no change…I’m sure I am missing something 😦
#include
void setup()
{}
void loop()
{
sparki.clearLCD();
// Send Ping pulse
const int PING_PIN= 0;
pinMode(PING_PIN, OUTPUT);
digitalWrite(PING_PIN, LOW);
delayMicroseconds(2);
digitalWrite(PING_PIN, HIGH);
delayMicroseconds(5);
digitalWrite(PING_PIN, LOW);
//Get duration it takes to receive echo of Ping sent
pinMode(PING_PIN, INPUT);
int duration = pulseIn(PING_PIN, HIGH);
//Convert duration into distance (cm)
sparki.print(duration/29/2);
sparki.updateLCD();
delay(2000);
}
LikeLike
Your code looks correct, maybe just try and connect it to another Pin to test (Disconnect something else for now and just uncomment any code relevant to it). There is a chance that the sensor is not functioning correctly, if possible you can also test it on another Arduino, just to make sure it is working.
LikeLiked by 1 person
And just to Verify you connected the signal pin to Digital pin 0, the the 2 power terminals to ground and 5V pins?
LikeLiked by 1 person
yep exactly that …
LikeLike
[…] around the room. As some of you may know, my ultrasonic range finder is currently not working (https://ashbotandsparki.wordpress.com/2015/08/18/sparkis-new-eyes/) so for the time being Sparki has been unable to be autonomous in his movements…until […]
LikeLike