In the last couple of units you have learned how to make a motor go and how to read a sensor. Now you are going to read a light sensor and use this information to control a motor. This is what you need to do if you want to make a robot follow a line marked on the ground.
Set up this circuit:
Then type in this code:
If you get error messages when you compile the code, it is usually missed semi-colons, or brackets, or commas, or not having capital letters where they are needed. Just check that your code is exactly the same as the example above.
Can you see how to modify this program so that the motor will go when the LDR has light shining on it
Challenge: Can you set up two motors with two sensors connected to two different pins on the Arduino and control both motors at the same time? You might want a bigger breadboard to set up you circuit.