0

enter image description hereI am new to programming and would be grateful for any helpful answer...Thank you I used a ping sensor, a piezo buzzer and an RGB strip. I used the Schematic from Adafruit Learning System.. Here is my code:

#define trigPin 5
#define echoPin 6
#define RED_PIN    10
#define GREEN_PIN   11
#define BLUE_PIN  9
int Buzzer = 3;

void setup() {
    //set pinModes for RGB strip
    pinMode(RED_PIN,OUTPUT);
    pinMode(BLUE_PIN,OUTPUT);
    pinMode(GREEN_PIN,OUTPUT);

    pinMode(Buzzer, OUTPUT);

    //reset lights
    analogWrite(RED_PIN,0);
    analogWrite(BLUE_PIN,0);
    analogWrite(RED_PIN,0);

    delay(5000);
    Serial.begin (9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(Buzzer, OUTPUT);
}

void loop() {
    int duration, distance;
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    if (distance >= 80 || distance <= 0){
        Serial.println("No object detected");
        digitalWrite(Buzzer, LOW);
    } else {
        Serial.println("Object Detected");
        tone(Buzzer, 1000); // play 400 Hz tone for 500 ms
        delay(500);
        tone(Buzzer, 10000); // play 800Hz tone for 500ms
        noTone(Buzzer);
    }
    delay(300);
}
7
  • I think you need to be more clear about what you want to do with your RGB lights.
    – deltaray
    Dec 4, 2016 at 1:07
  • @deltaray I would like the rgb led strip to flash when the sensor is triggered, I am a novice at programming..
    – A.Jack
    Dec 4, 2016 at 3:24
  • How do you have the LED strip connected, and what sort is it? A circuit diagram would be useful.
    – Mark Smith
    Dec 4, 2016 at 9:02
  • Would pictures work or do you want schematic
    – A.Jack
    Dec 4, 2016 at 11:56
  • It really matters what type of RGB lights they are. Specifications like brand of lights or the chip that is used on the light strip, whether they are analogue or digitally addressable, how many lights there are on the strip and how many wires the strip has an what the wires are labeled would be a good start. For instance, Neopixels from Adafruit are one type of digitally addressable light strip that uses its own protocol. A 5050 chip represents an analogue strip in which all colors would be the same at the same time.
    – deltaray
    Dec 4, 2016 at 12:25

2 Answers 2

1

An interesting problem with the Arduino paradigm is that not only do you need basic programming knowledge but you also need basic electronics knowledge.

On the plus side, there are plenty of good tutorials where you can over look these issues if you follow the tutorials step by step. That is, get exactly the same parts and wire them up exactly the same way. Later, if you like, you can go over the tutorial, ask questions here and discover how and why what you did works.

In your diagram:

You are implying you are using ordinary Red, Green & Blue LEDs and are going to vary their brightness using the Arduino's Pulse Width Modulation feature.

Possible problems:

You are powering the LEDs from the 9 volt pin of the Arduino. And the LED strip in the diagram is clearly marked 12 volts. This may work. But is out of specification.

Also, this setup makes the assumption you are powering your Arduino with a 9 volt wall power supply. Are you? You could also power the Arduino with 5 volts using only the USB cable. There would then be no 9 volts available at the 9 volt pin. (I would avoid plugging in both power sources at the same time. I think the Arduino design has changed over time.)

You are using a strip of Red, Green & Blue LEDs. Which implies more than 1 of these Red, Green & Blue LEDs. There is an upper current limit on the outputs of the Arduino. More LEDs means more current. Too many LEDs will damage the Arduino. I would stick to 1 LED until you research the amount of current 1 LED takes verses the upper current limit of an Arduino output pin.

0

If you are not sure which LED lights you want to use, take a look at this tutorial and use these LED lights

No, I have no connection to this video or its author.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.