TASK
Using the available Lego Spike Kits and the various outputs (sensors, etc), test some of your ideas to see how you would code them and how they might work.
Add photos as you test ideas with the Spark Robots and include screenshots of code. Explain what is happening and what has changed.
Use the tutorials in the Spike Unit Plans as well as the videos below
TEST & PLAY. TRIAL & ERROR.
COLOURED VEHICLES
For those that wish to utilise the colour sensor, vehicles have been painted different colours so that they may be identified, if needed.
YELLOW: Taxi
RED: Bus
BLUE: Commuter Car
GREEN: Emergency Services
ROAD MAP
Use the simplified, printed map of Dover Road when planning what you will use and where.
You will use this same map when setting up later to prove your concept works.
SENSORS/FUNCTIONS TO AVAILABLE USE
HELPFUL VIDEO TUTORIALS
DISTANCE SENSOR
HUB DISPLAY
FORCE SENSOR
COLOUR SENSOR
MOTORS
SAMPLE CODE PROCESS FOR 'SMART' TRAFFIC LIGHTS
Task: Traffic Light Control at an Intersection
Goal: Control the traffic lights to switch between red, yellow, and green at timed intervals.
Sample Block Code Logic:
Step 1: Set Up Your Workspace
1. Open the Lego Spike software on your computer
2. Create a new project and name it "Smart Traffic System."
Step 2: Connect and Configure the Sensors
1. Connect a Colour Sensor and a Distance Sensor to your Lego Spike hub.
The Colour Sensor will detect emergency vehicles (you can use a specific colour, like red or blue, to represent these).
The Distance Sensor will detect the presence of vehicles or public transport at the intersection.
2. Attach the sensors to your model at the appropriate positions where they can detect traffic.
Step 3: Initialise the Sensors and Variables
1. Drag a ‘When Program Starts’ block from the "Yellow" category to the workspace.
2. Initialise the sensors by dragging and connecting the appropriate blocks:
For the Colour Sensor: Use a block like "Set colour sensor mode" and set it to "Colour."
For the Distance Sensor: Use a block like "Set distance sensor mode" and set it to "Centimetres."
3. Create Variables to track the state of the traffic lights (e.g., `currentLightState`).
Step 4: Continuous Monitoring with a Loop
1. Drag a ‘Forever’ loop from the "Control" category and place it under the "When Program Starts" block.
2. Inside the loop, add a block to continuously check the sensors:
Use a block like "If...then" to create conditions based on what the sensors detect.
tep 5: Detect Traffic Types and Prioritise
1. Detect Emergency Vehicles:
Inside the `If...then` block, add a block to check if the Colour Sensor detects your chosen colour (e.g., red for emergency vehicles).
If it detects the colour, **set the traffic light to green** for the emergency lane by activating a motor connected to the traffic light.
Add a `Wait` block to allow time (e.g., 10 seconds) for the emergency vehicle to pass.
2. Detect Public Transport:
Add an `Else if` block below the first condition.
Inside it, check if the Distance Sensor detects a vehicle within a certain range (e.g., less than 10 cm).
If it does, **set the traffic light to green** for public transport and use a `Wait` block for a shorter time (e.g., 8 seconds).
3. Handle Regular Traffic:
Add another `Else if` block.
Inside it, check if any other vehicles are detected.
If so, set the traffic light to green for regular traffic and use a `Wait` block for 5 seconds.
4. Allow Pedestrians to Cross:
Add an `Else` block at the end.
If no vehicles are detected, set the traffic light to green for pedestrians and allow them to cross for a few seconds (e.g., 7 seconds).
Step 6: Test and Refine
1. Run the program*by pressing the play button.
2. Observe how the traffic lights change based on the sensor inputs.
3. Adjust the timing or sensor thresholds if needed to ensure smooth operation.
Step 7: Save Your Work
1. Save your project by clicking on the save icon in the Lego Spike software.
2. Give it a meaningful name like "Smart Traffic System."
Now, you have a basic smart traffic system that prioritises different types of traffic using Lego Spike. You can expand this by adding more features, such as handling more traffic types or incorporating additional sensors.
BE SURE TO ADD EVIDENCE TO EACH TEAM MEMBER'S PORTFOLIO