Hi,
I would like to ask if anyone could help me edit the code for Arduino. My project is about motion detection with HC-SR04 sensor.
I found this code from Mr. Wolfgang Ewald:
int triggerPin = 12;
int echoPin = 11;
int ledPin = 13;
int cmDistancePrevious, cmDistanceCurrent;
const int sensitivity = 20;
void setup () {
pinMode (triggerPin, OUTPUT);
pinMode (ledPin, OUTPUT);
pinMode (echoPin, INPUT);
cmDistancePrevious = measureDistance ();
}
void loop () {
cmDistanceCurrent = measureDistance ();
if (abs (cmDistanceCurrent - cmDistancePrevious)> sensitivity) {
digitalWrite (ledPin, HIGH);
delay (1000);
digitalWrite (ledPin, LOW);
cmDistanceCurrent = measureDistance ();
}
cmDistancePrevious = cmDistanceCurrent;
delay (50);
}
int measureDistance () {
unsigned long duration = 0;
digitalWrite (triggerPin, HIGH);
delayMicroseconds (10);
digitalWrite (triggerPin, LOW);
duration = pulseIn (echoPin, HIGH);
int cmDis = duration * 0.03432 / 2;
if (cmDis> 400) {
cmDis = 400;
}
return cmDis;
}
I would like to insert a 433 Mhz transmitter into this code (I have Transmitter STX882 + Receiver SRX882) so that it can do this:
After detecting movement by the sensor, the transmitter sends a character such as "1".
Wait for 10 seconds, for example.
Thats all
I tried to program this, but I'm not a programmer so the code doesn't work at all. Would anyone help with that?