hello
im a biggener doing my first project. Im making distance sensor project.
im using grove ultrasonic sensor.
i want the L led to turn off under certain distance and turn on above that distance.
i manged to programmer it but L led doesn't turn off completely it just emitting
very low light compare to the second state.
onst int pingPin = 13;
unsigned int duration, inches;
void setup() {
Serial.begin(9600);
}
void loop() {
pinMode(pingPin, OUTPUT); // Set pin to OUTPUT
digitalWrite(pingPin, LOW); // Ensure pin is low
delayMicroseconds(2);
digitalWrite(pingPin, HIGH); // Start ranging
delayMicroseconds(5); // with 5 microsecond burst
digitalWrite(pingPin, LOW); // End ranging
pinMode(pingPin, INPUT); // Set pin to INPUT
duration = pulseIn(pingPin, HIGH); // Read echo pulse
inches = duration / 74 / 2; // Convert to inches
Serial.println(inches); // Display result
delay(1000); // Short delay
Hi,
Can you please post a circuit diagram of your project?
A hand drawn schematic would be fine, just make sure you label your components and pin names.
you can in the picture that there are 4 wires going out from the sensor but only 3 going to the arduino
the white is cut
so i plugged pin 13, gnd and 3.3 v
The ultrasonic sensor ONLY provides the signals to detect an object, YOUR code does the calculation.
You might be better off using the "NewPing" libaray to do your range sensing . https://playground.arduino.cc/Code/NewPing/
And look that some of the examples.