Scratch Game:Pathways

Scratch is a programming language by The MIT University. It uses blocks that connect together like Lego to code sprites(characters) and create programs,games and animations. I made a game in Scratch. It is called Pathways. It uses the Arrow keys to go through a path. Touch the purple line and you’ll lose. After you get out press the space key to start again. I have only made 2 levels. You can build on it. The only hard thing is that at level 2, if you lose and press the space key, you have to start from level 1! Click here to see my game.

Advertisements

How to make a Line following robot

A line following robot follows a line using two sensors called IR sensors. The robots are used in hotels for serving food, at factories for taking material in and out of the warehouse, or for just playing around with it.

How does an IR sensor work?

Slide2The IR LED reflects infrared light onto the surface. If the light reflects back to the Photo Diode, there is no white line and the motors will go everywhere trying to find a line. If it doesn’t reflect back, that means there is a line and the motors move forward and the whole process starts again (quickly, not slowly).

Ingredients for the robot

  • L293D Motor driver Shield
  • An Arduino UNO
  • 6 male to female wires
  • 2 IR proximity sensors
  • Power source. Not 9v batteries. (A power bank should do)
  • 2wd chassis (if you have two caster wheels, use just one at the back).

Building the Robot

  1. Build the chassis. There should be instructions in the box. If not, screw all the parts. The top of the gear motor is negative and the bottom positive. If it doesn’t work, turn the wires the other way round.
  2. Copy the schematics as given here. 

However, you need not connect the LEDs as shown in the diagram.

3. Copy the code to the Arduino web editor or download Arduino IDE. You will need to sign up if you are using the web editor. After you have uploaded to the Arduino, test it on a white line on a black surface and if it works, you’ve finished!

    int dataPin = 8;         
    int latchPin = 12;
    int clockPin = 4;
    int en = 7;
    
    int LeftSensor = A1;
    int RightSensor = A0; 
    int L_sensor_val = 0;  
    int R_sensor_val = 0; 
    
    int threshold = 300;  
    
    void setup()
    {    
        pinMode(dataPin, OUTPUT);      
        pinMode(latchPin, OUTPUT);
        pinMode(clockPin, OUTPUT);
        pinMode(en, OUTPUT);    
        digitalWrite(en, LOW);   
    
    }
    
    void loop()
    {
    L_sensor_val =  analogRead(LeftSensor); 
    R_sensor_val =  analogRead(RightSensor);  
    
    
      if(L_sensor_valthreshold) {   
        while (L_sensor_valthreshold){
          turn_right();  
          L_sensor_val =  analogRead(LeftSensor);
          R_sensor_val =  analogRead(RightSensor);
        }
      }
      else if(L_sensor_val>threshold && R_sensor_val<threshold){ 
    
    while (L_sensor_val>threshold && R_sensor_val<threshold){
          turn_left();
          L_sensor_val =  analogRead(LeftSensor);
          R_sensor_val =  analogRead(RightSensor);
        }
     }
    forward(); 
    }
    
    void forward(void){  
            digitalWrite(latchPin, LOW);            
            shiftOut(dataPin, clockPin, LSBFIRST, 3);
            digitalWrite(latchPin, HIGH);  
    
    }
    
    void backward(void){   
            digitalWrite(latchPin, LOW);            
            shiftOut(dataPin, clockPin, LSBFIRST, 164);
            digitalWrite(latchPin, HIGH);  
    }
    
    void turn_left(void){   
            digitalWrite(latchPin, LOW);            
            shiftOut(dataPin, clockPin, LSBFIRST, 161);
            digitalWrite(latchPin, HIGH);  
    }
    
    void turn_right(void){    
            digitalWrite(latchPin, LOW);            
            shiftOut(dataPin, clockPin, LSBFIRST, 38);
            digitalWrite(latchPin, HIGH);  
    }
    
    void halt(void){       
            digitalWrite(latchPin, LOW);             
            shiftOut(dataPin, clockPin, LSBFIRST, 32);
            digitalWrite(latchPin, HIGH);  
    }