Using LEGO WeDo kits with Scratch Before you begin: 1. Download and install Scratch from h:p://scratch.mit.edu 2. Connect WeDo s USB hub to your computer s USB port. 3. Connect the WeDo motor to the USB hub. Scratch Vocabulary Script: A series of icons strung together to perform a task. Sprite: An on- screen character or item that you can manipulate through a script. You can have mulnple sprites within a program and they can interact with one another. Costume: A sprite can have different visual representanons, or costumes. During a program, you can make a sprite switch to a different costume to change its appearance. menu Use this space to display variables and sprites Icons for each menu Click and drag icons from le1 and drop it here to make a program. Click on script to run the program. This will turn on the motor for 1 second. You may also click on commands directly on the le1 pane.
WeDo Motor When you plug the WeDO USB hub into your computer, the motor control icons will appear under MoNon menu. To turn on the motor use one of the following icons: motor on to turn motor on motor power # to turn motor on at a specific power seung motor on for # seconds to run the motor for a specific Nme To turn off the motor use the following icon: Motor DirecCons To specify the motor direcnon use this icon: The motor direcnon icon does NOT turn the motor on. It must be used in combinanon with one of the motor on icons. this way turns the motor clockwise. that way turns the motor counter- clockwise. reverse reverses the motor direcnon from the current seung. that way this way
WeDo Sensors Distance sensor gives you a number between zero and 100 from about 3 to 12. 2 4 1 3 Tilt sensor gives you a number between 0 to 4 depending on orientanon of the sensor. Some possible use for sensors: Using sensor as a switch: Start motor when distance is greater than 10. Start motor when Nlt is 1. Stop when distance is 0 (to prevent running into something) Using sensor as a variable: Set motor speed to the value of distance sensor. Motor moves forward if Nlt is 1; reverse if Nlt is 3. Choose distance or Nlt. Use in combinanon with other icons. Using WeDo along with Scratch screen Control the Sprite s movement using distance or Nlt sensor Count up or down when Nlt sensor is triggered (i.e, a:ach Nlt sensor to a door, count how many Nmes the door has been opened)
Wait Wait block pauses the script for a specified amount of Nme. This script turns on the motor, waits 3 sec, and stops. Wait uncl Turn on the motor when distance sensor reads greater than 30. Forever The Forever block repeats a script indefinitely. The example below connnuously runs the motor with power seung corresponding to the distance sensor value. Add a forever block for a more useful code. Turn on the motor when distance sensor reads greater than 50, off when sensor reads less than 50, and repeat. Note: The motor power block just sets the motor power; it does not turn the motor on. Repeat (#) Repeat block will repeat a script for a specified number of Nmes. This code turns on the motor for 1 sec, then stops for 1 sec, and repeats the process 10 Nmes (total of 20 seconds).
If else If the Nlt sensor is 1 turn the motor on. If it is in any other posinon, turn the motor off. Sprites On- screen characters and items in Scratch are called sprites. The default Sprite is a cat but it can be changed to a different picture. You can also create one yourself. Sprites can be manipulated using the various scripts: Change costume of physical appearance Change posinons, orientanon, or size Interact with other Sprites (i.e., if Sprite A touches Sprite B, do this) and much more. This script connnuously sets the y- posinon of the Sprite to the distance sensor value. You can nest mulnple if- else blocks to create more complex scripts. If Nlt sensor is 1 turn motor on in one direcnon; if 3 turn the motor on in opposite direcnon; if all other values then stop. This script is a varianon of the script above. By numerically manipulanng the distance sensor value, it increases the range of monon of the Sprite to cover the ennre screen. This script moves the Sprite forward when Nlt sensor is Nlt forward, and backwards when the sensor is Nlted backward.
Using Variables Variables lets you see and/or manipulate numbers in your program. You can make mulnple variables in a program. This program connnuously displays the value of the distance sensor on the right side screen. This program adds 1 to the variable counter every Nme the distance reads 0. This allows us to use the distance like a counter bu:on. Wait unnl distance sensor value > 30 is added to ensure that each touch is only counted once. Click on Make a variable to create a variable. Once created, the variable and its value are shown on the screen.
WeDo/Scratch Challenges Build a motorized crane or li1- arm using the WeDo kit. The crane must be motorized and must have a Nlt sensor a:ached to the arm. Program with Scratch so that the motor turns on and stops a1er the the crane is up (according to the Nlt sensor value). Build a game controller with a Nlt sensor so that you can control an on- screen Sprite to go right, le1, up and down as you Nlt the controller. In Scratch, create a maze using a ball (Sprite 1) and walls (Sprite 2). Use the controller to travel through the maze. Bonus: Reverse the motor and lower the crane unnl the arm is down again. Build a rocker switch with a Nlt sensor. The switch should return to zero posinon automancally. Program with Scratch to count how many Nmes the switch has been pressed on each side. This device can be used as a vonng machine for two- choice quesnons.
Motion Looks Sound Pen MoNon icons are used to control the monon and posinon of Sprites. Motor icons also appear here. Use these icons to change the appearance of a Sprite color, size, etc. Sound icons allow you to incorporate sound into your program. Use the Pen to draw lines on the screen during your program. Puzzle piece icons are commands or steps in the program. They snap together to form a program. Rounded rectangular icons are numbers. Hexagonal icons are booleans (True/False or Yes/No).
Control Sensing Operators Variables Control icons introduce flow & structure into your program. Use these icons to detect various acnons such as key input or Sprite interacnons. Use operators to calculate or compare values. Use the Variable icons to store and manipulate numbers. These icons appear once you create a variable. Puzzle piece icons are commands or steps in the program. They snap together to form a program. Rounded rectangular icons are numbers. Hexagonal icons are booleans (True/False or Yes/No).