Security
Secure data upload to openSenseMap
Information on connecting and programming the sensors, Bees and other components
The HC-SR04 measures distances using ultrasound and outputs them in centimeters (cm).
int trig = 1; // Trig-Pin des Sensors ist an Pin 1 angeschlossen.
int echo = 2; // Echo-Pin des Sensors ist an Pin 2 angeschlossen.
// Definieren der Variablen
unsigned int time = 0;
unsigned int distance = 0;
void setup() {
Serial.begin(9600); // Startet den Seriellen Monitor
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
}
void loop() {
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
distance = time / 58;
Serial.println(distance);
}
In Blockly the sensor can be read out via the following block:
Select the port where you have connected the sensor from the drop-down menu. Trigger and echo pin will be adjusted automatically.