- Make sure nothing on Sparki is getting in its way, like a connector or wire. Tilt it up above the board, and face it forward.
- Try the test code below. It doesn’t use any Sparki library code at all, so it will make sure no other parts are interfering. Once it’s uploaded, you should be able to see the output in the serial port monitor (the little icon in the upper-right hand corner of SparkiDuino).
#define ULTRASONIC_ECHO 5 // PC6 #define ULTRASONIC_TRIG 10 // PB6 void setup() { Serial.begin (9600); pinMode(ULTRASONIC_TRIG, OUTPUT); pinMode(ULTRASONIC_ECHO, INPUT); } void loop() { int duration, cm; digitalWrite(ULTRASONIC_TRIG, LOW); delayMicroseconds(2); digitalWrite(ULTRASONIC_TRIG, HIGH); delayMicroseconds(10); digitalWrite(ULTRASONIC_TRIG, LOW); duration = pulseIn(ULTRASONIC_ECHO, HIGH); cm = duration / 29 / 2; Serial.print(cm); Serial.println(" cm"); delay(100); }
Sparki's ultrasonic range finder is giving me a really small distance every time.
Have more questions? Submit a request
0 Comments