The ultrasonic sensor i have is given in link below
using aurdino uno r3
i want to read and compare the received data with a constant number.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX
void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {;
// wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Serial Ultrasonic Distance Measure");
Serial.println(" Distance Measure in cm");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
if (mySerial.available())
Serial.write(mySerial.read());
}
By using above code am getting distance in cm in my serial monitor but i am not able to compare the same with a constant value.
I am new to coding hence any help would be great.
thank you.
This may have been better for the UNO, there is a library for using the unit for distance measuring.
Without all the hardware just to go from TTL to RS232 to TTL to the arduino.
Thank you ,but the problem is ttl is fixed and not able to remove it.
and do i need to change my tx,rx pin of sensor to 11,10 pin of aurdino respectively?
and if pins need to b changed then what is the syntax to read and store the data in a variable and then compare it using if statement???
thanks a lot
below code is not working,led does not turn on,can someone help me out please.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10,11); // RX, TX
int sv=0; //sensor value
#define sp 10 //sensor input to uno
void setup()
{
pinMode(sp,INPUT);
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {;
// wait for serial port to connect. Needed for Leonardo only
}
Serial.println("Serial Ultrasonic Distance Measure");
Serial.println(" Distance Measure in cm");
// set the data rate for the SoftwareSerial port
mySerial.begin(9600);
}
void loop() // run over and over
{
int sv=mySerial.read();
if (mySerial.available())
Serial.write(mySerial.read());
if (sv<50)
{
digitalWrite(13,HIGH); // led at pin 13
}
else
{
digitalWrite(13,LOW);
}
}
There is an error on the product page. The picture with the labelled pinouts is wrong, according to the labels on the actual PCB.
I've highlighted the errors in the attached pics.
This shows the actual pinouts:-
This shows the wrong labelling:-
Small wonder the LED isn't lighting up.
(There's a good chance that the red PCB is cactus if it's wired according to the erroneous pic.)