Auto Detection of Baud Rate

Is there any algorithm that works for auto baud rate detection?
Mine is working fine with GPS but not with echo sounder.

Hayes modems used an approach where the first two characters, the "AT" prefix in the command provided the needed information to determine the baud rates, parity and # of data bits.

A is 0x41 and T is 0x58. one has an even, the other an odd number of 1s allowing parity to be detected. since the LSB is transmitted first, the LSB of A is a 1 and the start bit a zero, the baud rate can be determined by measuring the width of the first zero in what is required to be an 'A'.

can you explain it in an easy way because I am new to programming?

i believe the Hayes modems had hardware to support the processing i described.

Using brute force, try all the baud rates:

baud rate = highest
send "AT, "
read reply
if reply equal to "OK" break
decrement baud rate
while baud rate not less than slowest baud

Actually, I have Mega2560 and I am making data logger. it is connected to 2 GPS and 2 Echo sounder. Everytime, when I put a new echo sounder or GPS module I have to reprogram the arduino. I am searching is there any algorithm which can auto detect the baud rate of equipment.

I don't understand why you need to swap out the devices attached to your Mega or why their baud rates vary.

However, if a device is transmitting you could probably deduce the baud rate by polling the data pin and noting how long it is between high and low transitions. You would need to read for a little while to be sure that you have the time for a single bit and then you can calculate your baud rate.

I found an algorithm which is working fine with gps but not with echo sounder.

if you can send a command using the serial monitor, why not add a command to configure the baud rate?

okay I have one more question, i want to log my data for 15 mins and then stop logging for 15 mins and after that 15 mins I want to log data again.

use millis() to toggle a flag every 15601000 msec

Nice, those italics :grinning_face_with_smiling_eyes:

So it is 15*60*1000 msec :wink:


but by multiplying these it will become 900000.

Fixed :wink:

thank you.