Hello!
My matter is that I desire put on work the HC-SR04 just by using an Atmega328p standalone, but when I do that nothing happens, I proved using my arduino, the same code and the same components and in this case it works excellent, then I tried to use the stand-alone and a LED with the example Blink and it worked very well too, so I need some help , maybe I need to create another circuit or connect it in a different way, I don't know.... I attach here my code and the circuit that I'm using, thanks by reading this post and I expect to get a great answer, thanks again!.
#define trigPin 7
#define echoPin 8
#define zumbador 10
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(zumbador,OUTPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/58);
if(distance < 30){
digitalWrite(zumbador,HIGH);
}
else if(distance > 30){
digitalWrite(zumbador,LOW);
}
{
Serial.print(distance);
Serial.println("cm");
}
delay(200);
}
