Loading ...
Sorry, an error occurred while loading the content.

Re: [Electronics_101] Ardunino Code

Expand Messages
  • mark hubrich
    Try this... http://bildr.org/2011/03/various-proximity-sensors-arduino/ ... [Non-text portions of this message have been removed]
    Message 1 of 10 , Mar 24, 2013
    • 0 Attachment
      Try this...
      http://bildr.org/2011/03/various-proximity-sensors-arduino/
      On Mar 24, 2013 10:50 AM, "sprodanuk" <sprodanuk@...> wrote:

      > **
      >
      >
      > I am trying to build a sensor for using an Arduino and I was hoping
      > someone could help me with the code for the QRD1113/1114 sensor. I wired
      > according to the A0 pin, which from my understanding can also behave as a
      > digital pin. I found some examples of code for this sensor however, I am
      > confused as to what I need this code to do. I think it must interpret the
      > interruption on the beam of the sensor by sending the Arduino a signal.
      > However, I am not sure how to write this code, I found a few examples
      > online but they did not make allot of sense and when I tried upload it to
      > the Arduino I could not get anything to happen. I think the sensor is
      > getting power, measured with a voltmeter but I see nothing on the sensor.
      > Online on one site I saw a picture of the sensor lighting up online
      > however, mine does not light up.
      >
      > Anyone out there able to help?
      >
      >
      >


      [Non-text portions of this message have been removed]
    • rtstofer
      Since you don t know whether the sensor is working, there is no point in connecting it to the Arduino until you do.
      Message 2 of 10 , Mar 24, 2013
      • 0 Attachment
        Since you don't know whether the sensor is working, there is no point in connecting it to the Arduino until you do.

        http://www.fairchildsemi.com/ds/QR/QRD1114.pdf

        Look at Figure 5. You will see that the optimum sensing distance is 35 mils or 0.035". That's about 10 sheets of standard printer paper - more or less.

        So, let's start at the beginning. I have you some low value resistor to put in series with the emitter. The cathode side of the emitter diode goes to ground, the anode side connects through the resistor to +5V. Once you have that set up, measure the emitter current with your DVM (or whatever). You should have about 20 mA. If you don't have emitter current, you have a bigger problem.

        Next, I gave you a value for the sensor resistor - somewhere around 10k, IIRC. Connect the collector of the sensor to +5V through the resistor. Connect the emitter of the sensor to ground. Take something shiny (paper MIGHT work) and make a solid black line. Figure out some way to get the sensor within 0.035" and slide the paper back and forth. Monitor the collector voltage of the sensor with respect to ground (where the resistor is connected). The meter should read 0V when over the white area and +5V when over the black area.

        If you don't get these results, there is no point in connecting to the Arduino.

        Personally, I would stay away from the analog pins for now. The sensor is essentially a digital device - it's either on (reflecting) or off (non-reflecting). Yes, I know the Ax pins can be used for digital IO but I'm going to use pin 8.

        Something like this:

        int sensor = 8; // use IO pin 8
        int value = 0; // result of digitalRead(sensor)
        int LED = 13; // LED is on pin 13

        void setup() {
        pinMode(sensor, INPUT);
        pinMode(LED, OUTPUT);
        }

        void loop() {
        value = digitalRead(sensor);
        digitalWrite(LED,value);
        }

        I haven't tested the code but it does compile.

        Richard
      • mark hubrich
        I just thought of something. You said you seen a pic of one of these lighting up. You will only see it light up through the eye of a camera. It can t be seen
        Message 3 of 10 , Mar 25, 2013
        • 0 Attachment
          I just thought of something. You said you seen a pic of one of these
          lighting up.

          You will only see it light up through the eye of a camera. It can't be seen
          with the naked eye.

          Try this.. break out your cell phone and make like your gonna take a
          picture. Grab your remote for your TV and push some buttons while you're
          looking at the transmitting end through your camera.

          You should be a little amazed as you witness the light flashing from your
          remote.

          Now power your sensor and look at it through your camera. If powered
          properly, you should some signs of life through your camera. If not, maybe
          the cathode and anode connection are reversed?
          On Mar 24, 2013 1:49 PM, "rtstofer" <rstofer@...> wrote:

          > **
          >
          >
          > Since you don't know whether the sensor is working, there is no point in
          > connecting it to the Arduino until you do.
          >
          > http://www.fairchildsemi.com/ds/QR/QRD1114.pdf
          >
          > Look at Figure 5. You will see that the optimum sensing distance is 35
          > mils or 0.035". That's about 10 sheets of standard printer paper - more or
          > less.
          >
          > So, let's start at the beginning. I have you some low value resistor to
          > put in series with the emitter. The cathode side of the emitter diode goes
          > to ground, the anode side connects through the resistor to +5V. Once you
          > have that set up, measure the emitter current with your DVM (or whatever).
          > You should have about 20 mA. If you don't have emitter current, you have a
          > bigger problem.
          >
          > Next, I gave you a value for the sensor resistor - somewhere around 10k,
          > IIRC. Connect the collector of the sensor to +5V through the resistor.
          > Connect the emitter of the sensor to ground. Take something shiny (paper
          > MIGHT work) and make a solid black line. Figure out some way to get the
          > sensor within 0.035" and slide the paper back and forth. Monitor the
          > collector voltage of the sensor with respect to ground (where the resistor
          > is connected). The meter should read 0V when over the white area and +5V
          > when over the black area.
          >
          > If you don't get these results, there is no point in connecting to the
          > Arduino.
          >
          > Personally, I would stay away from the analog pins for now. The sensor is
          > essentially a digital device - it's either on (reflecting) or off
          > (non-reflecting). Yes, I know the Ax pins can be used for digital IO but
          > I'm going to use pin 8.
          >
          > Something like this:
          >
          > int sensor = 8; // use IO pin 8
          > int value = 0; // result of digitalRead(sensor)
          > int LED = 13; // LED is on pin 13
          >
          > void setup() {
          > pinMode(sensor, INPUT);
          > pinMode(LED, OUTPUT);
          > }
          >
          > void loop() {
          > value = digitalRead(sensor);
          > digitalWrite(LED,value);
          > }
          >
          > I haven't tested the code but it does compile.
          >
          > Richard
          >
          >
          >


          [Non-text portions of this message have been removed]
        • mark hubrich
          I just thought of something. You said you seen a pic of one of these lighting up. You will only see it light up through the eye of a camera. It can t be seen
          Message 4 of 10 , Mar 25, 2013
          • 0 Attachment
            I just thought of something. You said you seen a pic of one of these
            lighting up.

            You will only see it light up through the eye of a camera. It can't be seen
            with the naked eye.

            Try this.. break out your cell phone and make like your gonna take a
            picture. Grab your remote for your TV and push some buttons while you're
            looking at the transmitting end through your camera.

            You should be a little amazed as you witness the light flashing from your
            remote.

            Now power your sensor and look at it through your camera. If powered
            properly, you should some signs of life through your camera. If not, maybe
            the cathode and anode connection are reversed?
            On Mar 24, 2013 1:49 PM, "rtstofer" <rstofer@...> wrote:

            > **
            >
            >
            > Since you don't know whether the sensor is working, there is no point in
            > connecting it to the Arduino until you do.
            >
            > http://www.fairchildsemi.com/ds/QR/QRD1114.pdf
            >
            > Look at Figure 5. You will see that the optimum sensing distance is 35
            > mils or 0.035". That's about 10 sheets of standard printer paper - more or
            > less.
            >
            > So, let's start at the beginning. I have you some low value resistor to
            > put in series with the emitter. The cathode side of the emitter diode goes
            > to ground, the anode side connects through the resistor to +5V. Once you
            > have that set up, measure the emitter current with your DVM (or whatever).
            > You should have about 20 mA. If you don't have emitter current, you have a
            > bigger problem.
            >
            > Next, I gave you a value for the sensor resistor - somewhere around 10k,
            > IIRC. Connect the collector of the sensor to +5V through the resistor.
            > Connect the emitter of the sensor to ground. Take something shiny (paper
            > MIGHT work) and make a solid black line. Figure out some way to get the
            > sensor within 0.035" and slide the paper back and forth. Monitor the
            > collector voltage of the sensor with respect to ground (where the resistor
            > is connected). The meter should read 0V when over the white area and +5V
            > when over the black area.
            >
            > If you don't get these results, there is no point in connecting to the
            > Arduino.
            >
            > Personally, I would stay away from the analog pins for now. The sensor is
            > essentially a digital device - it's either on (reflecting) or off
            > (non-reflecting). Yes, I know the Ax pins can be used for digital IO but
            > I'm going to use pin 8.
            >
            > Something like this:
            >
            > int sensor = 8; // use IO pin 8
            > int value = 0; // result of digitalRead(sensor)
            > int LED = 13; // LED is on pin 13
            >
            > void setup() {
            > pinMode(sensor, INPUT);
            > pinMode(LED, OUTPUT);
            > }
            >
            > void loop() {
            > value = digitalRead(sensor);
            > digitalWrite(LED,value);
            > }
            >
            > I haven't tested the code but it does compile.
            >
            > Richard
            >
            >
            >


            [Non-text portions of this message have been removed]
          • rtstofer
            ... Using a camera is an excellent idea. Also, since the emitter resistor between the anode and +5V is on the order of 165-180 Ohms, simply measuring the
            Message 5 of 10 , Mar 25, 2013
            • 0 Attachment
              --- In Electronics_101@yahoogroups.com, mark hubrich <meistro57@...> wrote:
              > Now power your sensor and look at it through your camera. If powered
              > properly, you should some signs of life through your camera. If not, maybe
              > the cathode and anode connection are reversed?
              > On Mar 24, 2013 1:49 PM, "rtstofer" <rstofer@...> wrote:
              >

              Using a camera is an excellent idea.

              Also, since the emitter resistor between the anode and +5V is on the order of 165-180 Ohms, simply measuring the voltage drop across the resistor will also prove that the emitter is working.

              For 20mA of current, we can expect 3.3V - 3.6V dropped across the resistor. So, anything in that range will be good enough. There will be some variation due to inexact Vf/If specs.

              Earlier, I mentioned that in testing, the output at the collector of the sensor should be 0V when the detector is seeing a reflection. That would be 'ideal' and the real voltage will probably be 0.2V or so. The 5V measurement may not be perfect either. There could still be some reflection from the black mark. It will be more perfect if the sensor is aimed at a distant dark surface. Still, anything around 4.5V should be fine.

              From Table 29.1 of the ATMega328 datasheet, the low logic level is less than 0.3*Vcc or 1.5V. The logic high level is greater than 0.6*Vcc or 3.0V. So, when the device is sensing a reflection, the collector voltage must be below 1.5V and when it is not sensing a reflection, the voltage must be above 3.0V. I wouldn't want to be within 0.5V of those values so I would hope to achieve 1.0V and 3.5V.

              Richard
            • rtstofer
              Just to be sure we re all on the same page, I posted a schematic QRD1113.pdf in the Files folder. Richard
              Message 6 of 10 , Mar 25, 2013
              • 0 Attachment
                Just to be sure we're all on the same page, I posted a schematic QRD1113.pdf in the Files folder.

                Richard
              • Shaun Prodanuk
                Thank you very much. I was able to turn on an off an LED using this code. You must have some experience coding Arduinos. Now I am trying to get sensors to
                Message 7 of 10 , Mar 29, 2013
                • 0 Attachment
                  Thank you very much. I was able to turn on an off an LED using this code. You must have some experience coding Arduinos. Now I am trying to get sensors to sense then display on the screen using the serial print command. I had it working but now nothing.
                  To: Electronics_101@yahoogroups.com
                  From: rstofer@...
                  Date: Sun, 24 Mar 2013 18:49:15 +0000
                  Subject: [Electronics_101] Re: Ardunino Code


























                  Since you don't know whether the sensor is working, there is no point in connecting it to the Arduino until you do.



                  http://www.fairchildsemi.com/ds/QR/QRD1114.pdf



                  Look at Figure 5. You will see that the optimum sensing distance is 35 mils or 0.035". That's about 10 sheets of standard printer paper - more or less.



                  So, let's start at the beginning. I have you some low value resistor to put in series with the emitter. The cathode side of the emitter diode goes to ground, the anode side connects through the resistor to +5V. Once you have that set up, measure the emitter current with your DVM (or whatever). You should have about 20 mA. If you don't have emitter current, you have a bigger problem.



                  Next, I gave you a value for the sensor resistor - somewhere around 10k, IIRC. Connect the collector of the sensor to +5V through the resistor. Connect the emitter of the sensor to ground. Take something shiny (paper MIGHT work) and make a solid black line. Figure out some way to get the sensor within 0.035" and slide the paper back and forth. Monitor the collector voltage of the sensor with respect to ground (where the resistor is connected). The meter should read 0V when over the white area and +5V when over the black area.



                  If you don't get these results, there is no point in connecting to the Arduino.



                  Personally, I would stay away from the analog pins for now. The sensor is essentially a digital device - it's either on (reflecting) or off (non-reflecting). Yes, I know the Ax pins can be used for digital IO but I'm going to use pin 8.



                  Something like this:



                  int sensor = 8; // use IO pin 8

                  int value = 0; // result of digitalRead(sensor)

                  int LED = 13; // LED is on pin 13



                  void setup() {

                  pinMode(sensor, INPUT);

                  pinMode(LED, OUTPUT);

                  }



                  void loop() {

                  value = digitalRead(sensor);

                  digitalWrite(LED,value);

                  }



                  I haven't tested the code but it does compile.



                  Richard


















                  [Non-text portions of this message have been removed]
                • rtstofer
                  ... Try this: int sensor = 8; // use IO pin 8 int value = 0; // result of digitalRead(sensor) int LED = 13; void setup() { pinMode(sensor, INPUT); pinMode(LED,
                  Message 8 of 10 , Mar 31, 2013
                  • 0 Attachment
                    --- In Electronics_101@yahoogroups.com, Shaun Prodanuk <sprodanuk@...> wrote:
                    >
                    > Thank you very much. I was able to turn on an off an LED using this code. You must have some experience coding Arduinos. Now I am trying to get sensors to sense then display on the screen using the serial print command. I had it working but now nothing.



                    Try this:

                    int sensor = 8; // use IO pin 8
                    int value = 0; // result of digitalRead(sensor)
                    int LED = 13;

                    void setup() {
                    pinMode(sensor, INPUT);
                    pinMode(LED, OUTPUT);
                    Serial.begin(9600); // set serial port to 9600
                    }

                    void loop() {
                    value = digitalRead(sensor);
                    digitalWrite(LED, value);
                    Serial.println(value);
                    }

                    Richard
                  Your message has been successfully submitted and would be delivered to recipients shortly.