[SOLVED]Led dimmed when used as output with HC-SR04 ultrasonic sensor
hello,
i'm new here.
i made project hc-sr04.
basically, when object close, arduino light red led , if not close, green one.
it work leds aren't glowing should. if connect led directly grd , 5v work fine. (220 ohm resistor).
when output pin dimmed.
i not know can come. ?
thanks in advance.
my code:
i'm new here.
i made project hc-sr04.
basically, when object close, arduino light red led , if not close, green one.
it work leds aren't glowing should. if connect led directly grd , 5v work fine. (220 ohm resistor).
when output pin dimmed.
i not know can come. ?
thanks in advance.
my code:
code: [select]
int led_r = 6;
int led_g = 8;
int distance, duree;
void setup() {
serial.begin(9600); // open serial monitor @ 115200 baud see ping results.
pinmode (trigger_pin, output);
pinmode (echo_pin, input);
pinmode (led_r, output);
pinmode (led_g, output);
}
void loop() {
digitalwrite(led_r, low);
digitalwrite(led_g, low);
digitalwrite(trigger_pin, low);
delaymicroseconds(500);
digitalwrite(trigger_pin, high);
delaymicroseconds(10);
digitalwrite(trigger_pin, low);
duree = pulsein(echo_pin, high);
distance = (duree/2) / 29.3;
if (distance >= 15 || distance <= 0)
{
serial.println(" loin \n");
serial.print("distance= ");
serial.print(distance);
digitalwrite(led_g, high);
}
else
{
serial.println(" cm proche \n");
serial.print("distance= ");
serial.print(distance);
digitalwrite(led_r,high);
}
}
your sketch turning leds off each time loop starts, causing pwm effect dims leds. try qualifying turn off sr04 output setting flag when condition calling led turned on , leave on until condition no longer exists.
Arduino Forum > Using Arduino > Project Guidance > [SOLVED]Led dimmed when used as output with HC-SR04 ultrasonic sensor
arduino
Comments
Post a Comment