Topic outline

  • What is infra red?

    Light comes from the sun to us in a spectrum. We see a very small part of this and call it the visible spectrum.

    Some animals see outside this spectrum and can detect ultra violet and infra red. In space, many bodies give off other forms including radio waves. 

    We can detect parts of the spectrum using sensors.
    • Types of sensors

      Single detector

      Reflective

      Encoder


      • Topic 3

        IR detector : TCRT500

        IR sensors are used extensively in many applications. They are the sensors that tell you when the paper in your printer has been used, whether your car door is closed or if a machine is too close to a job.

         Optoelectronic transmitters and receivers are used in pairs and linked together optically. Manufacturers fabricate them in suitable forms. They are available for a wide range of applications as ready-to-use components known as couplers, transmissive sensors (or interrupters), reflex couplers and reflex sensors. Increased automation in industry in particular has heightened the demand for these components and stimulated the development of new types.

        This IR reflective sensor utilizes a TCRT5000 to detect color and distance. It emits IR and then detects if it receives the echo. This sensor is often used in line following robots, auto data logging on utility meters, because this module can sense if a surface is white or black.

        The measuring distance range from 1mm to 8mm, and the central point is about 2.5mm. There is also an on-board potentiometer to adjust the sensitivity.

        The infrared diode will emmitting the infrared continutelly when the module connect to the power, when the emitted infrared light has not been reflected or the strength is not big enough,the triode will in the off state, at this time, D0 output logic LOW and the signal indicate LED off.

        Note : they do not detect color or light intensity.

        TCRT5000


        tcrt5000

        //this is a program to test if we can read a sensor
        //we used a tcrt5000 sensor i bought off alibaba
        //in a set with an ir led
        //the key to the exercise was the balance between the two resistors in the circuit diagram

        int sensor; // use an integer and read it continually

        void setup()
        {
        Serial.begin(9600); //read serial port
        }

        void loop()
        {
        sensor=analogRead (A0); // note use of Arduino analog port
        Serial.println(sensor);
        delay(1000);

        if (sensor < 500)
        {
        Serial.println("hello less than 500, it must be light");
        }
        else
        {
        Serial.println("we are in the dark, greater than 500");
        }
        }

        Data sheet
        • Topic 4

          Line following robot

           If you are using 1 sensor, then your code should be something like:
          Void loop {
              If(sensorvalue  < threshold){
                  Turn left
              };
              If(sensorvalue > threshold){
                  Turn right
              };
          }
          This will cause your robot to wiggle side to side while riding the edge of the line.
          Line following robot
          • Topic 5

            • Topic 6

              Sample code for line following robot

               

              /*
              marks little line follower

              with a little bit of mucking around. this code will balance robot speed
              and the speed of turn to follow a line.

              the problem comes when it reaches the end and turns around.

              the next step is to investigate Proportional-Integral-Derivative Control (PID).
              PID is a feedback loop that adjest a process around a set condition.

              */

              int left_motor_1 = 5;
              int left_motor_2 = 6; // these pins support pwm

              int right_motor_1 = 9;
              int right_motor_2 = 10;

              int analogPinx = A0;
              int digiPin = 13;
              int val = 100; // variable to store the value read

              int threshhold = 500; // between 0 - 1024

              boolean run = true;


              void setup(){
              pinMode (right_motor_1,OUTPUT);
              pinMode (right_motor_2,OUTPUT);
              pinMode (left_motor_1,OUTPUT);
              pinMode (left_motor_2,OUTPUT);

              pinMode (digiPin,OUTPUT);

              Serial.begin(9600); // setup serial

              }

              void loop()
              {
              val = analogRead(analogPinx); // read the input pin
              Serial.println(val); // debug value
              delay(1000);
              digitalWrite(digiPin,HIGH);

              forward();
              delay(500);
              while (run == true) // uses == the equality evaluator
              { // run is never set to false so is infinite
              if (val > threshhold) // wiggle left
              {
              left();
              delay (20);
              forward();
              delay(20);
              val = analogRead(analogPinx);
              } // the use of 'x' in case
              // analogPin is reserved word
              else
              {
              right(); // wiggle right
              delay (20);
              forward();
              delay(20);
              val = analogRead(analogPinx);
              }
              }
              }


              void halt()
              {
              digitalWrite(left_motor_1,LOW);
              digitalWrite(left_motor_2,LOW);

              digitalWrite(right_motor_1,LOW);
              digitalWrite(right_motor_2,LOW);

              }

              void back()
              {

              digitalWrite(left_motor_1,LOW);
              digitalWrite(left_motor_2,HIGH);

              digitalWrite(left_motor_1,LOW);
              digitalWrite(right_motor_2,HIGH);

              }

              void left()
              {

              digitalWrite(left_motor_1,LOW);
              analogWrite(left_motor_2,125); // uses an analog signal to control speed

              digitalWrite(right_motor_1,HIGH);
              analogWrite(right_motor_2,125); // better andled with a variable

              }

              void right()
              {
              analogWrite(left_motor_1,125);
              digitalWrite(left_motor_2,LOW);

              digitalWrite(right_motor_1,LOW);
              analogWrite(right_motor_2,125);

              }

              void forward()
              {
              analogWrite(left_motor_1,125);
              digitalWrite(left_motor_2,LOW);

              analogWrite(right_motor_1,125);
              digitalWrite(right_motor_2,LOW);

              }

              • Topic 7

                • Topic 8

                  • Topic 9

                    • Topic 10

                      • Topic 11

                        • Topic 12

                          • Topic 13

                            • Topic 14

                              • Topic 15

                                • Topic 16

                                  • Topic 17

                                    • Topic 18

                                      • Topic 19

                                        • Topic 20

                                          • Topic 21

                                            • Topic 22

                                              • Topic 23

                                                Using an infra red remote

                                                  Instructable IR Remote
                                                • Topic 24

                                                  Code alert : global variables

                                                   

                                                  /*
                                                  This piece of code demonstrates the use of global variables. Global variables maintain their assigned value anywhere in the code. If it changes in a function, it retains its value.

                                                  Some things to be concidered

                                                  1. arduino deals with functions not subprocedures
                                                  2. a global variable is any variable declared *outside* a function
                                                  3. a counter can increment to keep track of the number of times code runs.
                                                  4. a sentinal value can be used to a switch between code fragments

                                                  mrweber
                                                  261115
                                                  */

                                                  int count = 0 ;  // declared outside function
                                                  int sentinal = 1;

                                                  void setup() {
                                                  // put your setup code here, to run once:
                                                  Serial.begin(9600);
                                                  }

                                                  void loop() {
                                                  sg90();
                                                  Serial.print(count);
                                                  Serial.print(" ");
                                                  Serial.println(sentinal);
                                                  delay(2000);
                                                  }

                                                  void sg90(){
                                                  count = count + 1; // increments here
                                                  if (count <= 10){
                                                  sentinal = 1; // sentinal
                                                  }

                                                  if (count > 10){
                                                  sentinal = -1;// sentinal changes
                                                  }

                                                  if (count > 20){ // all is reset
                                                  count = 0;
                                                  sentinal = 1;
                                                  }
                                                  }