I just recently got an arduino robot, and I am trying to setup an ultrasonic sensor. This sensor needs a digital I/O port. With the arduino robot the docs day to change the signal via:
Hi,
I have exactly the same problem: connecting the US sensor to an Arduino UNO using pin 7 everything works fine.
Changing to Arduino Robot using D8 the distance is always 0.
I can post the code, but I think the code is not the problem.
The question is shown above: How to use digital input/output and what is the right connection: where is GND, +5V and Signal on e.g. D8? Link to documentation?
Thank you in advance for help!
Ingeborg
Hello again!
Thank you for the link! This shows me, that the documentation is really poor.
I wonder why noone of the mods is helping us!
In the meantime I tried the following (using a breadboard, a resistor and a LED):
Using Arduino with pin7: blinks!
Connect a LED with a resistor to D8: GND to the GND and the Source to + 5 V: LED is always on (ok).
Connect the Source to the middle pin an uploading the following code:
And Surprise: nothing happend!
I'm really frustrated, because AllIOPorts (the Example of ArduinoRobot) uses the same code.
So what is wrong? Why has nobody else the same problem?
I hope that someone can help us!?
Ingeborg
Below is the code that should make an external led blink. But for some reason all of the Digital I/O pins seem to always be off and never going to low. I have tries the other Digital ports to make sure it wasn't an issue of me assigning the wrong port. Is the problem with the hardware or what?
Hi alexpell00,
how did you connect the LED to port TKD1? Soldering? There are only holes on the board.
Code:
pinMode(TKD1, OUTPUT);
is missing in the setup.
Ingeborg
Hi Uwe,
why can't D8 be used for Digital Output? +5V and GND are set (a connected LED is ON). The middle pin should be the signal pin (as far as I understand TinkerKit connection).
Ingeborg
//Led.ino 14.08.2014
//Connect a LED to D0 middle= +, right= - (GND)
//D0 printed on the board is near to - resp. GND
//It is not recommended to use a LED without a resistor
//but it works for testing purposes
#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>
int led = D0;
void setup() {
//Robot.begin(); // not necessary for this test
pinMode(led, OUTPUT);
}
void loop() {
Robot.digitalWrite(led, HIGH);
delay(500);
Robot.digitalWrite(led, LOW);
delay(500);
}
Ingeborg
Source code (Sensors.cpp) shows that the bottom ports are used for motor purposes.
And here is a working code for the Seeed US distance sensor (digital signal):
/***************************************************************************/
// Function: Measure the distance to obstacles in front and print the distance
// value to the serial terminal.The measured distance is from
// the range 0 to 400cm(157 inches).
// Hardware: Ultrasonic Range sensor
// Arduino IDE: Arduino-1.5.7
// Author: LG
// Date: Jan 17,2013
// Version: v1.0 modified by FrankieChu
// v1.1 modified by Ingeborg 14.08.2014
// by www.seeedstudio.com
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
//
/*****************************************************************************/
#include <ArduinoRobot.h>
#include <Wire.h>
#include <SPI.h>
int pin = D1;
class Ultrasonic
{
public:
Ultrasonic(int pin);
void DistanceMeasure(void);
long microsecondsToCentimeters(void);
long microsecondsToInches(void);
private:
int USpin;//pin number of Arduino connected with SIG pin of US Sensor.
long duration;// the Pulse time received;
};
Ultrasonic::Ultrasonic(int pin)
{
USpin = pin;
}
/*Begin the detection and get the pulse back signal*/
void Ultrasonic::DistanceMeasure(void)
{
pinMode(USpin,OUTPUT);
Robot.digitalWrite(USpin, LOW);
delayMicroseconds(2);
Robot.digitalWrite(USpin, HIGH);
delayMicroseconds(5);
Robot.digitalWrite(USpin,LOW);
pinMode(USpin,INPUT);
duration = pulseIn(USpin,HIGH);
}
/*The measured distance from the range 0 to 400 Centimeters*/
long Ultrasonic::microsecondsToCentimeters(void)
{
return duration/29/2;
}
/*The measured distance from the range 0 to 157 Inches*/
long Ultrasonic::microsecondsToInches(void)
{
return duration/74/2;
}
Ultrasonic ultrasonic(pin);
void setup()
{
Robot.begin();
Serial.begin(9600);
}
void loop()
{
long RangeInInches;
long RangeInCentimeters;
ultrasonic.DistanceMeasure();// get the current signal time;
RangeInInches = ultrasonic.microsecondsToInches();//convert the time to inches;
RangeInCentimeters = ultrasonic.microsecondsToCentimeters();//convert the time to centimeters
Serial.println("The distance to obstacles in front is: ");
Serial.print(RangeInInches);//0~157 inches
Serial.println(" inch");
Serial.print(RangeInCentimeters);//0~400cm
Serial.println(" cm");
delay(1000);
}
So I must buy a soldering iron, because D0 etc are only holes.. :0
Am i doing something wrong with the wiring? I still can't seem to get this light to blink. Here is my code:
#include <ArduinoRobot.h>
//I had to remove the other two imports because it crashed the compile. I am pretty sure arduinorobot.h already includes them
int led = TKD0; //also it said pin D0 was invalid so I had to change it to a valid pin
void setup() {
//Robot.begin(); // not necessary for this test
pinMode(led, OUTPUT);
}
void loop() {
Robot.digitalWrite(led, HIGH);
delay(500);
Robot.digitalWrite(led, LOW);
delay(500);
}
Hi,
I can see from your picture/video that you connect the led to the left and the right "hole". So it should always blink! Take the plus to the middle and see what happens.
I will check if it is really necessary to include Wire.h and SPI.h. But it should be possible to include them because they are needed to start the motors (as far as I know (didn't test it).
Ingeborg