I am beginner in arduino and i want to make a stick for blind person which gives sound from buzzer when something is there in front of
Ultrasonic sensor
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;
// defines variables
long duration;
int distance;
int safetyDistance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
safetyDistance = distance;
if (safetyDistance <= 5){
digitalWrite(buzzer, HIGH);
digitalWrite(ledPin, HIGH);
}
else{
digitalWrite(buzzer, LOW);
digitalWrite(ledPin, LOW);
}
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
}
code as ------^
error=====
Variables and constants in RAM (global, static), used 28176 / 80192 bytes (35%)
║ SEGMENT BYTES DESCRIPTION
╠══ DATA 1496 initialized variables
╠══ RODATA 936 constants
╚══ BSS 25744 zeroed variables
. Instruction RAM (IRAM_ATTR, ICACHE_RAM_ATTR), used 60363 / 65536 bytes (92%)
║ SEGMENT BYTES DESCRIPTION
╠══ ICACHE 32768 reserved space for flash instruction cache
╚══ IRAM 27595 code in IRAM
. Code in flash (default, ICACHE_FLASH_ATTR), used 236388 / 1048576 bytes (22%)
║ SEGMENT BYTES DESCRIPTION
╚══ IROM 236388 code in flash
esptool.py v3.0
Serial port COM12
Connecting......................................____
A fatal esptool.py error occurred: Failed to connect to ESP8266: Timed out waiting for packet header_