Soluții
Arduino Ultrasonic Sensor
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
- pulseIn() measures the duration of the ECHO signal.
- The sensor sends a 40 kHz ultrasonic burst using the TRIG pin.
- Arduino calculates the distance based on the speed of sound.
- Distance is printed in centimeters to the Serial Monitor.
Testing the Sensor
- Upload the code to your Arduino
- Open the Serial Monitor
- Set the baud rate to 9600
- Move your hand in front of the sensor
- Watch the distance update live
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...]
iPhone 17: Disable Center Stage Camera Auto-Zoom
On the iPhone 17 series and iPhone Air, the new 18-megapixel Center Stage front camera features a square sensor that offers more flexibility in framing and composition. Center Stage will also auto-zoom to include everyone in a group selfie, but if you don’t like it, you can turn it off.
The Center Stage camera automatically adjusts its view depending on what’s happening in front of it. If you’re the only person in the shot, it keeps the frame tight for a more personal feel. As others join, the view zooms out to fit everyone in, with no need to adjust it yourself.
This dynamic feature reduces the chance of friends being cropped out in group photos. However, you may find that Center Stage is not zooming adequately for your particular needs, in which case you can disable the auto-zoom feature.
[mai mult...]Use this little-known PowerPoint feature to make pictures stand out
For far too long, I struggled to find the perfect image without a distracting background for my PowerPoint slides. I used to think I needed complicated software to fix it, but I eventually discovered a tool that’s built into the software itself: Remove Background.
[mai mult...]Cum navigam fara sa pierdem timp din cauza reclamelor
Slimjet combina mai multe functii inteligente si convenabile pentru a realiza mai multe in mult mai putin timp, fara a epuiza timp pentru cautarea de pluginuri externe. De asemenea, putem adauga multe optiuni si setari pentru a personaliza aspectul si comportamentul browserului, astfel incat sa se potriveasca cel mai bine preferintelor noastre personale.
[mai mult...]Cum adaugam butonul Focused Inbox in Outlook
Focused Inbox in Outlook sorteaza automat e-mailurile in doua categorii: Prioritare si Altele, bazandu-se pe inteligenta artificiala pentru a identifica mesajele importante. Aceasta functionalitate ajuta utilizatorii sa se concentreze mai usor pe e-mailurile cu prioritate, lasand celelalte mesaje, cum ar fi notificari sau newslettere, intr-o fila separata, pentru a evita supraincarcarea inbox-ului.
- De exemplu: fila Prioritare: Contine e-mailurile considerate cele mai importante de catre Outlook, pe baza inteligentei artificiale.
- Fila Altele: Contine restul mesajelor, care sunt la fel de accesibile, dar nu se afla in calea vizuala a mesajelor prioritare.
Putem ajuta Outlook sa invete ce este important pentru noi, mutand manual e-mailuri intre cele doua file. De exemplu, putem muta un e-mail din fila “Altele” in “Prioritare” sau putem alege sa mutam intotdeauna mesajele de la un anumit expeditor in fila “Prioritare“.
[mai mult...]