Bolt receiving wrong data from arduino

iam trying to do a obstacle detector project with ultra sonic sensor by interfacing BOLT with Arduino everything is good till now but my BOLT wifi module receiving incorrect data

samples of my code


arduino code is working fine

OUTPUTS


as you can see arduino is givingoutput 6 while bolt receiving 60+
this is ciruit

one more thing iam some time getting this error i dont know how to ressolve

Can you share the Arduino code you’re trying to implement?

const int trig = 12;
const int echo = 13;

const int LED1 = 8;
const int LED2 = 7;
const int LED3 = 6;
const int LED4 = 5;
const int LED5 = 4;
const int LED6 = 3;
const int BUZ = 2;

int duration = 0;
int distance = 0;

void setup()
{
pinMode(trig , OUTPUT);
pinMode(echo , INPUT);

pinMode(LED1 , OUTPUT);
pinMode(LED2 , OUTPUT);
pinMode(LED3 , OUTPUT);
pinMode(LED4 , OUTPUT);
pinMode(LED5 , OUTPUT);
pinMode(LED6 , OUTPUT);
pinMode(BUZ , OUTPUT);

Serial.begin(9600);

}

void loop()
{
digitalWrite(trig , HIGH);
delayMicroseconds(1000);
digitalWrite(trig , LOW);

duration = pulseIn(echo , HIGH);
distance = (duration/2) / 28.5 ;
Serial.println(distance);

if(distance<=7)
{
digitalWrite(LED6,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED1,HIGH);
tone(BUZ,3000);
}
else if(7<distance && distance<=14)
{
digitalWrite(LED6,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED2,HIGH);
digitalWrite(LED1,LOW);
tone(BUZ,3000);
delay(100);
noTone(BUZ);
delay(100);
}
else if(14<distance && distance<=21)
{
digitalWrite(LED6,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED3,HIGH);
digitalWrite(LED2,LOW);
digitalWrite(LED1,LOW);
tone(BUZ,3000);
delay(200);
noTone(BUZ);
delay(200);
}
else if(21<distance && distance<=28)
{
digitalWrite(LED6,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED4,HIGH);
digitalWrite(LED3,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED1,LOW);
tone(BUZ,3000);
delay(300);
noTone(BUZ);
delay(300);
}
else if(28<distance && distance<=35)
{
digitalWrite(LED6,HIGH);
digitalWrite(LED5,HIGH);
digitalWrite(LED4,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED1,LOW);
tone(BUZ,3000);
delay(400);
noTone(BUZ);
delay(400);
}
else if(35<distance && distance<=42)
{
digitalWrite(LED6,HIGH);
digitalWrite(LED5,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED1,LOW);
tone(BUZ,3000);
delay(500);
noTone(BUZ);
delay(500);
}

 else 

{
digitalWrite(LED6,LOW);
digitalWrite(LED5,LOW);
digitalWrite(LED4,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED1,LOW);
noTone(BUZ);
}
}

‘\n’ is not an integer, so it is not able to read it as one.

You have to make your arduino push only the data that can be read as integer.

For that, you can use software serial to push the data to Bolt, and use hardware serial to view whatever you wish, on the serial monitor.

You can refer to this arduino code for some idea of it - https://gist.github.com/hippyaki/12be46e5cca4cc3a78e6b938145ebb6a

In python script, make sure you have an interval of 5 seconds for the loop to reset.

actually iam new to this i know little bit about serial communication so can you suggest what changes should i make on my code or can you suggest any reference about serial communications

Can you first change time.sleep(0.2) --> time.sleep(5)
And send a screenshot of your python output?

I’ll surely help you with the serial communication part.

done! i changed not much difference

Put mybolt.serialBegin(9600) before the while loop. And check the output.

You mean in python script?

Yes, in python script.


and one more thing when i try to re upload arduino code its not uploading i mean it just showing uploading but upload not finishing

Correction - serialRead(‘9600’)

My bad

Arduino: 1.8.14 (Windows 10), Board: “Arduino Uno”

Sketch uses 1538 bytes (4%) of program storage space. Maximum is 32256 bytes.

Global variables use 28 bytes (1%) of dynamic memory, leaving 2020 bytes for local variables. Maximum is 2048 bytes.

An error occurred while uploading the sketch

This report would have more information with
“Show verbose output during compilation”
option enabled in File -> Preferences.

im getting this error message

For Arduino, It could be anything.

Go to File > Preferences > Show verbose output - Tick for ‘upload’

Press reset button on arduino. And press upload again.

You’ll see some errors if any on the message box

Sketch uses 1538 bytes (4%) of program storage space. Maximum is 32256 bytes.
Global variables use 28 bytes (1%) of dynamic memory, leaving 2020 bytes for local variables. Maximum is 2048 bytes.
C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM3 -b115200 -D -Uflash:w:C:\Users\kondr\AppData\Local\Temp\arduino_build_392135/buzzer_tone.ino.hex:i

avrdude: Version 6.3-20190619
Copyright © 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright © 2007-2014 Joerg Wunsch

     System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

     Using Port                    : COM3
     Using Programmer              : arduino
     Overriding Baud Rate          : 115200

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

Reconnect your USB, Arduino, check port, click reset button.

Try again.

hey iam getting that error when i reupload my code with bolt iot connected to arduino
when i remove rx and tx wire then it is uploading fine