Paso 1: Lista de Partes
- Arduino UNO R3
- Un (1) HC-SR04 Sensor Ultrasonio
- Un (1) LED Rojo
- Un (1) LED Verde
- Dos (2) Resistencias de 560 ohm (Verde, Azul, Cafe, Dorado)
- Placa de prototipado
- Ocho (8) Cables Macho a Macho
- Una regla que mida centimetros (o el monitor serial del IDE de Arduino.
Paso 3: Cargar el sketch
/*
HC-SR04 Ping distance sensor]
VCC to arduino 5v GND to arduino GND
Echo to Arduino pin 13 Trig to Arduino pin 12
Red POS to Arduino pin 11
Green POS to Arduino pin 10
560 ohm resistor to both LED NEG and GRD power rail
More info at: http://goo.gl/kJ8Gl
Original code improvements to the Ping sketch sourced from Trollmaker.com
Some code and wiring inspired by http://en.wikiversity.org/wiki/User:Dstaub/robotcar
*/
#define trigPin 13
#define echoPin 12
#define led 11
#define led2 10
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW); // Added this line
delayMicroseconds(2); // Added this line
digitalWrite(trigPin, HIGH);
// delayMicroseconds(1000); - Removed this line
delayMicroseconds(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance < 4) { // This is where the LED On/Off happens
digitalWrite(led,HIGH); // When the Red condition is met, the Green LED should turn off
digitalWrite(led2,LOW);
}
else {
digitalWrite(led,LOW);
digitalWrite(led2,HIGH);
}
if (distance >= 200 || distance <= 0){
Serial.println("Out of range");
}
else {
Serial.print(distance);
Serial.println(" cm");
}
delay(500);
}
Fuente: Instructables
Comentarios
Tarjeta Visual Duino
Estimados "Arduineros":
Pongan en YouTube VisualDuino y vean 3 videos acerca de la tarjeta Visual Duino
1) Ejemplo 1 - Hola Mundo
2) Ejemplo 2 - Semaforo A
3) Ejemplo 3 - Semaforo B