Cum activezi autentificarea în doi pași (2FA) pentru Google
Vrei să îți securizezi contul Google, dar nu știi cum se activează 2FA.
[mai mult...]Soluții pentru problemele tale IT
Vrei să îți securizezi contul Google, dar nu știi cum se activează 2FA.
[mai mult...]The sensor sends out an ultrasonic sound wave from the TRIG pin. When the sound wave hits an object, it reflects back and is detected by the ECHO pin.
The Arduino measures the time it takes for the signal to return and uses that to calculate the distance.
Distance (cm) = (Time in microseconds × 0.034) / 2
The speed of sound is 0.034 cm/µs. We divide by 2 because the sound travels to the object and back.
Required Components
| Component | Quantity | Purpose |
|---|---|---|
| Arduino Uno / Nano / Mega | 1 | Main microcontroller |
| HC-SR04 Ultrasonic Sensor | 1 | Measures distance |
| Jumper Wires | 4 | Connections |
| Breadboard (optional) | 1 | Easy wiring |
| USB Cable | 1 | Power & programming |
Pin Connections
Connect the HC-SR04 sensor to the Arduino as shown below:
| HC-SR04 Pin | Arduino Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| TRIG | Digital Pin 9 |
| ECHO | Digital Pin 10 |
Note: The ECHO pin outputs 5V, which is safe for Arduino Uno/Nano/Mega.
Arduino Code
Upload the following code to your Arduino:
#define TRIG_PIN 9
#define ECHO_PIN 10
void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}
void loop() {
long duration;
float distance;
// Clear trigger
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
// Trigger ultrasonic burst
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Measure echo time
duration = pulseIn(ECHO_PIN, HIGH);
// Convert time to distance
distance = (duration * 0.034) / 2;
// Output result
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(500);
}
Code Explanation
Testing the Sensor
You should see something like:
Distance: 15.4 cm
Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Always reads 0 cm | Incorrect pin wiring | Check TRIG and ECHO |
| Values jump around | Object surface curved or too small | Use a flat object |
| No Serial output | Wrong baud rate | Set Serial Monitor to 9600 |
| Sensor not working | No power | Ensure 5V and GND connected properly |
[mai mult...]
When your screen colors shift and distort, your work can turn into a kaleidoscope of chaos. Frustration can set in quickly, so before you start seeing red (or green or blue), let’s delve into the causes and symptoms that could distort your LCD monitor’s colors.
[mai mult...]A corrupted file is a file that has been damaged so that Windows 11 or the program associated with it can no longer read it correctly. Instead of opening as expected, the file may trigger errors, freeze the application, or appear blank or incomplete.
[mai mult...]Your iPhone can read texts and other notifications in circumstances where you’re unable to see your screen. This can be useful when you’re listening to music on your AirPods or Beats headphones, but it can be annoying. You can stop AirPods from reading texts completely, but you also have a few other options to make Siri less noisy. You can instead reduce the number of texts (and other notifications) your iPhone reads or have it only read texts while you’re driving.
[mai mult...]