Sparki’s new eyes

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!

DSC_0031

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???

Advertisements

7 thoughts on “Sparki’s new eyes

  1. 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.

    Liked by 1 person

    • 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);
      }

      Like

  2. 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.

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s