Hi, currently i want to try to build an ultrasonic data communication. I tried one sample project from this website, https://hackaday.com/2018/06/01/dead-simple-ultrasonic-data-communication/#comments but i cannot get data transmitted.
I used Arduino nano in this project.
On the transmitter side, i got PWM waveform with much noises but on the receiver side i got straight line waveforms throughout the circuit.
How do i reduce the noise in the transmitter? How to i make sure whether the data from transmitter is transit or not? Is it possible transmitter transmitted data, but receiver cannot receive it? Any solution? Thank you
These coding is given in the website.
Transmitter Coding:
void setup()
{
Serial.begin(115200);
pinMode(3,OUTPUT);
}
void loop()
{
send("Ultrasonic communication by Zola Lab\n");
send("Hello World\n\n");
}
void send(String msg)
{
byte ch;
unsigned int pos = 0;
unsigned int sz = msg.length();
while(pos<sz)
{
ch = msg.charAt(pos);
Serial.print((char)ch);
tone(3,40000);
delay(10);
noTone(3);
for(int i=0;i<8;i++)
{
boolean b;
b = bitRead(ch,7-i);
// Serial.print (b);
if(b)
{
tone(3,40000);
delay(2);
}
else
{
tone(3,40000);
delay(4);
}
noTone(3);
delay(11);
}
pos++;
}
}
Receiver Coding :
int pos = 0;
unsigned char CH = 0;
unsigned int bits1 = 0;
boolean capture = false;
void setup()
{
Serial.begin(115200);
pinMode(5,INPUT_PULLUP);
}
void loop()
{
if(digitalRead(5))
{
bits1 = 0;
unsigned long deltaT = millis();
while(millis()-deltaT <= 10) if(digitalRead(5)) bits1 ++;
Serial.println(bits1);
if(capture)
{
boolean b = 0;
if(bits1 > 290 && bits1 < 600) b = 0;
if(bits1 > 20 && bits1 < 290) b = 1;
if(b) bitSet(CH,7-pos); else bitClear(CH,7-pos);
Serial.print(b);
pos++;
if(pos == 8)
{
Serial.print((char)CH);
pos = 0;
capture = false;
}
}
if(bits1 > 600)
{
capture = true;
pos = 0;
}
}
}