Well for one thing you only ever switch the LED on. You don't switch it off again when the distance isn't <15.But if it is very dim then what value resistor do you have in series with it? What Arduino are you using?Steve
And how is the LED wired?GND -- 220 -- LED -- Arduinoor+5V -- 220 -- LED -- Arduino
And by the way can two brushed dc motors be controlled by an Arduino Mega along with a HC-Sr04 without an H-bridge
If you need to control both speed and direction of the motors then you need an H-bridge. If you only need to control speed then a couple of MOSFETs will do it. But you will need something. Basically the motors and HC-SR04 can easily be CONTROLLED by a Mega. But motors must be POWERED separately. The Arduino pins can only safely provide tiny currents.Steve
Ok apparently my led was the culprit, now once I swapped the led, the led emits a light of regular intensity. However, the led just stays alight for the entire time, instead of changing depending on the distance between it and the object.