I want to get the distance from the HC-Sr04 ultrasonic sensor and the color of the led light displayed on my laptop via PHP can anyone please help i am stuck here.. Thanks in advance
My php code..
<?php
echo "<p>Control Page</p><p>";
$port = fopen("COM4", "w+");
sleep(2);
?>
<br>
</form>
<?php
if ($_GET['distance']<30)
{
$data = $_GET['distance'];
echo '<td bgcolor="#FF0000"> red';
}
else if ($_GET['distance']>35){
$data = $_GET['distance'];
echo '<td bgcolor="#00FF00"> green';
}
else {
echo "Empty";
echo '<td bgcolor="#00FF00"> green';
}
fclose($port);
?>
</body>
</html>
my Arduino code:...
#define trigPin 10
#define echoPin 2
#define led 4
#define led2 6
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(10); // Added this line
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
delay(1000);
distance = (duration/2) / 29.1;
if (distance < 30) { // 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 if(distance >35) {
digitalWrite(led,LOW);
digitalWrite(led2,HIGH);
}
else{
digitalWrite(led,LOW);
digitalWrite(led2,LOW);
}
}