// Copyright 2007, Sandeep Gangadharan // For more free scripts go to http://www.sivamdesign.com/scripts/

Brakelight Blink with Code Car

Blink Hookup: 1 LED in pin 13. Remember shorter leg of LED is ground.

Flash the brake light on Code Car like the 'hazard flashers' on a real car. Learn about loops and delays along the way! 


The code below already works and is ready to upload! Upload the code to Code Car and see what happens. Then, you'll 'take apart' the code to learn what each piece of the program does.

/* * Blink the tail light on and off once per second */ void setup() { pinMode(7,OUTPUT); //set your tail light LED as an OUTPUT } void loop() { digitalWrite(7,HIGH); //Send power to pin 7 delay(1000); //wait 1000 milliseconds (1 second) with the tail light on digitalWrite(7,LOW); //Turn off the power to pin 7 delay(1000); //wait 1000 milliseconds with the tail light off } // (c) 2017 Let's Start Coding. License: www.letsstartcoding.com/bsdlicense

Walkthrough Videos

Watch the videos for line-by-line explanation of how the example program works. Then you'll be ready to make some changes of your own!


How many can you complete? Change the code according to the challenges below. Upload your code to see the effect when you're finished. Complete a challenge? Check it off the list!


These are the new code concepts covered in this example program. To become a great coder, read through these concepts to learn new vocabulary.

New Concept: Code Loops

You may have noticed that this example program runs again and again- that's a code loop in action. Computers don't get tired and they don't get bored, so it's very easy to program a computer to do the same thing over and over. When your blinking LED code reaches the closing curly brace of void loop(), it jumps back to the top of the void loop and starts running again, line by line. The loop here doesn't change each time it is run and it never stops. Later, you'll learn about loops that change as they run and that stop once they reach a certain goal. 


New Concept: It's All In the Details

If you worked on the challenges in this program, you may have noticed how a small change in the code can have a big effect on how it works- or stop it from working at all! Computers are very precise, so make sure you're carefully looking over all of the parts of your program as you make changes. A misplaced comma or forgetting to change a number in the void setup() can make a big difference in how your program works!


New Concept: Speed!

When you worked on the challenge about changing the code's delay, you may have tried a really, really small number for the delay and noticed that you couldn't see the blink at all! Because computers are so precise, you can be certain that the computer ran the blink commands, even if they were too quick for you to see. Sometimes, you want a computer to run at lightning speed. Other times, you need to slow it down so that you can observe what's happening at human-speed. Use delay(); as a tool in your programs to slow things down.



If you're having trouble, try to run an experimental program or look at the example code to help you find the answer.

The delay function measures time in_________________.

If you make both of the delay values smaller, what will happen?