Motion Sensor LED

}

Here for simplicity are the OP's pics:

Ok first things first...

Does the sensor work properly? Are you seeing the inch and centimetre distance displaying when you open the serial monitor (ctrl shift M) ?

Second, there's nothing in your code that uses the sensor reading to do anything other than display it, far as I can see any road. So you will need to describe in words first, what you expect the value to mean in terms of the lights.

Your heading says "motion sensor", yet the sensor you have is a distance sensor; it does not detect motion. So you'll need to describe how you want that to work. Say a person comes within range of the sensor from out of rang, that would be "motion" I guess, so lights on? But then they stop... the sensor value will no longer change and your code would need to continually monitor for the value to change, and turn the lights off if it doesn't change for a few seconds?

That's quite tricky (ie non beginner) coding I'd say.

You might be better with a PIR sensor, which does detect motion.

Third: looks like a relay wired in there somehow: you'll need to provide a circuit diagram of how that's been done. Can't tell much from the photos :wink:

Also, you're using the code for a PING))), which uses the same pin to trigger the device and receive the echo pulse, but you don't have a PING)))....you have an HC-SR04, which uses one pin to trigger and another to receive (in normal use).

Suggest using the NewPing library with your HC-SR04. And since inevitably the sensor will return erroneous values occasionally (such as zero), you should use NewPing's median method to help eliminate outliers. Or roll your own code to test for outliers.

Also, the photos don't show a connection between the HC-SR04 and the jumpers that plug into the breadboard (maybe they're hidden behind the HC?)

And, some of those jumpers aren't plugged all the way in. Plug 'em all the way in.