I'm working on Arduino Uno.
I combine GPS module with ultrasonic sensor.
I use Beitian BN-880 as the GPS, and US-100 Ultrasonic sensor.
Inside the attachement below is the code.
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#define echo 2
#define trigger 9
const int RXPin = 6, TXPin = 5;
const uint32_t GPSBaud = 9600;
int Data_US=0;
TinyGPSPlus gps;
SoftwareSerial ss(RXPin,TXPin);
void setup() {
Serial.begin(9600);
delay(500);
ss.begin(9600);
delay(1000);
pinMode(echo, INPUT);
pinMode(trigger, OUTPUT);
delay(1000);
}
void loop() {
show_distance();
delay(1000);
}
void show_distance(){
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(5);
digitalWrite(trigger, LOW);
Data_US = 0;
while (digitalRead(echo) == LOW){}
while (digitalRead(echo) == HIGH){
Data_US++;
if (Data_US > 1000)
break;
}
Serial.println(Data_US/10);
delay(10);
}
The ultrasonic sensor somehow results incorrect distance value when combined with GPS module.
If i remove the line below in the setup function,
ss.begin(9600);
the ultrasonic sensor results correct distance value.
I have assumptions that the current of the electricity is not enough to power up the ultrasonic sensor as I use the power from my laptop, but I haven't found any logical proof/documentation about this. Or there is another trouble inside the micro controller that causes conflicts between SoftwareSerial used in GPS and pinMode.
Is there any solution for this problem?
testing_compass_gps.ino (817 Bytes)