Arduino6 Condicionales if else programación bloques arduino Tinkercad ultrasonidos tercera parte 😎
Introduction to Ultrasonic Sensors in Arduino
Overview of the Ultrasonic Sensor
- The tutorial introduces an ultrasonic sensor that emits waves to measure distance, demonstrating its application with a virtual traffic light system.
- The traffic light changes color based on proximity: red when over 200 cm away and green when within 200 cm.
Setting Up the Project
- The instructor begins from scratch, explaining how to set up the Arduino starter kit and remove existing code for clarity.
- A default code is reviewed, which measures distance in both centimeters and inches using variables defined in the program.
Building the Circuit
Components Used
- Three LEDs (red, yellow, green) are introduced along with resistors; connections are made according to standard practices.
- The instructor emphasizes proper wiring techniques for testing both the ultrasonic sensor and LEDs effectively.
Initial Testing
- Initial tests confirm that all components function correctly before proceeding with coding.
Programming Logic for Distance Measurement
Defining Variables and Inputs
- The ultrasonic sensor is assigned to digital input pin 7; variables are established for measuring distance.
- Code snippets demonstrate how to print measured distances via serial output, ensuring accurate readings from the sensor.
Conditional Statements for LED Control
- Programming logic is developed where if distance exceeds 200 cm, the red LED lights up; if less than or equal to 200 cm, the green LED activates.
Debugging and Enhancements
Troubleshooting LED Behavior
- Issues arise where both LEDs illuminate simultaneously; adjustments are made in code logic to ensure only one LED lights at a time based on proximity.
Finalizing Code Structure
- A delay mechanism is implemented between state changes of LEDs (100 ms), enhancing responsiveness without flickering.
Challenges and Conclusion
Proposed Challenges
- Two challenges are presented: changing yellow when between 200 cm and 100 cm, and making it blink instead of staying solid during this range.
Wrap-Up
- The tutorial concludes with encouragement for students to subscribe for more content as they continue learning about Arduino programming.