Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By angelvargas
#47588 I have that code to recive the signal from the HC-SR04 ultrasonic sensor, and I need that when recive the correct signal the ESP8266 conects to a website (only go to a web adress).
I don't know if I can use this code: wiki/doku.php?id=arduino-docs
I have this code:
Code: Select all#define ECHOPIN 3        // Pin to receive echo pulse
#define TRIGPIN 2        // Pin to send trigger pulse
int RedLED = 13;
int GreenLED = 12;
 
void setup()
{
  pinMode(RedLED, OUTPUT);
  pinMode(GreenLED, OUTPUT);
  Serial.begin(9600);
  pinMode(ECHOPIN, INPUT);
  pinMode(TRIGPIN, OUTPUT);
}

void loop()
{
  // Start Ranging -Generating a trigger of 10us burst
  digitalWrite(TRIGPIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIGPIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIGPIN, LOW);

  // Distance Calculation

 
  float distance = pulseIn(ECHOPIN, HIGH);
  distance= distance/58;

if(distance < 7) {
    digitalWrite(RedLED, HIGH);
    digitalWrite(GreenLED, LOW);
  }
else {
    digitalWrite(GreenLED, HIGH);
    digitalWrite(RedLED, LOW);
  }
 
/* The speed of sound is 340 m/s or 29 us per cm.The Ultrasonic burst travels out & back.So to find the distance of object we divide by 58  */

  Serial.print(distance);
  Serial.println(" cm");

  delay(200);
}