{"id":13,"date":"2025-02-01T06:20:37","date_gmt":"2025-02-01T06:20:37","guid":{"rendered":"https:\/\/samerli.com\/en\/lessons\/?p=13"},"modified":"2025-05-08T16:17:04","modified_gmt":"2025-05-08T16:17:04","slug":"lesson-2-making-a-traffic-light-project-with-arduino","status":"publish","type":"post","link":"https:\/\/samerli.com\/en\/lessons\/?p=13","title":{"rendered":"Lesson 2: Making a Traffic Light Project With Arduino"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">One of the first things you can start doing with Arduino after learning how to light an LED and<a href=\"https:\/\/samerli.com\/en\/lessons\/?p=59\" title=\"Lesson 1: Simple Blinking LED Project With Arduino\"> blink it<\/a> is to make a <strong>traffic light project with Arduino<\/strong>. This lesson goes through the basic steps using two different connection methods.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">List of content<\/h3>\n\n\n\n<div class=\"wp-block-aioseo-table-of-contents\"><ul><li><a href=\"#aioseo-1-needed-components\">1. Needed Components<\/a><\/li><li><a href=\"#aioseo-2-connecting-your-traffic-light-circuit\">2. Connecting Your Traffic Light Circuit<\/a><\/li><li><a href=\"#aioseo-3-code\">3. Code<\/a><\/li><li><a href=\"#aioseo-4-advanced-tips-for-modification\">4. Advanced Tips for Modification<\/a><\/li><\/ul><\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"aioseo-1-needed-components\">1. Needed Components<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Arduino Board<\/strong> (Arduino Uno or another type)<\/li>\n\n\n\n<li><strong>LEDs<\/strong> (Red, Green)<\/li>\n\n\n\n<li><strong>Resistors<\/strong> (330 ohm for each LED)<\/li>\n\n\n\n<li><strong>Breadboard<\/strong><\/li>\n\n\n\n<li><strong>Jumper Wires<\/strong><\/li>\n\n\n\n<li><strong>Power Supply<\/strong> (USB cable or battery pack)<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"aioseo-2-connecting-your-traffic-light-circuit\">2. Connecting Your Traffic Light Circuit<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Set Up the Breadboard:<\/strong>\n<ul class=\"wp-block-list\">\n<li>Place the LEDs on the breadboard. The longer leg (anode) is the positive side, and the shorter leg (cathode) is the negative side.<\/li>\n\n\n\n<li>Connect the anode of each LED to a digital pin on the Arduino (e.g., Red to pin 12, Green to pin 13).<\/li>\n\n\n\n<li>Connect one leg of the 330-ohm resistor to the cathode of each LED, and connect the other leg of the resistor to the ground <strong>(GND)<\/strong> on the Arduino.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><strong>Schematics and Pictures<\/strong><br><br><\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-f56f613f wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"625\" height=\"235\" src=\"https:\/\/samerli.com\/en\/lessons\/wp-content\/uploads\/2025\/02\/image.png\" alt=\"\" class=\"wp-image-15\" srcset=\"https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image.png 625w, https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-300x113.png 300w\" sizes=\"(max-width: 625px) 100vw, 625px\" \/><figcaption class=\"wp-element-caption\">First connection option<\/figcaption><\/figure>\n<\/div>\n<\/div>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"498\" height=\"497\" src=\"https:\/\/samerli.com\/en\/lessons\/wp-content\/uploads\/2025\/02\/image-3-edited.png\" alt=\"\" class=\"wp-image-20\" srcset=\"https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-3-edited.png 498w, https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-3-edited-300x300.png 300w, https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-3-edited-150x150.png 150w\" sizes=\"(max-width: 498px) 100vw, 498px\" \/><\/figure>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-f56f613f wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:100%\">\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"737\" height=\"456\" src=\"https:\/\/samerli.com\/en\/lessons\/wp-content\/uploads\/2025\/02\/image-1.png\" alt=\"\" class=\"wp-image-16\" srcset=\"https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-1.png 737w, https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-1-300x186.png 300w\" sizes=\"(max-width: 737px) 100vw, 737px\" \/><figcaption class=\"wp-element-caption\">Second connection option (common resistor)<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"490\" height=\"489\" src=\"https:\/\/samerli.com\/en\/lessons\/wp-content\/uploads\/2025\/02\/image-4-edited.png\" alt=\"\" class=\"wp-image-22\" srcset=\"https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-4-edited.png 490w, https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-4-edited-300x300.png 300w, https:\/\/samerli.com\/en\/lessons\/..\/..\/wp-uploads\/2025\/02\/image-4-edited-150x150.png 150w\" sizes=\"(max-width: 490px) 100vw, 490px\" \/><\/figure>\n<\/div>\n<\/div>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"aioseo-3-code\">3. Code<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s a simple Arduino code for the traffic light system:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><em>\/\/ Define pin numbers<\/em>\nconst int redPin = 12;\nconst int greenPin = 13;\n\nvoid setup() {\n  <em>\/\/ Set pin modes<\/em>\n  pinMode(redPin, OUTPUT);\n  pinMode(greenPin, OUTPUT);\n}\n\nvoid loop() {\n  <em>\/\/ Red light<\/em>\n  digitalWrite(redPin, HIGH);\n  delay(5000); <em>\/\/ Red for 5 seconds<\/em>\n  digitalWrite(redPin, LOW);\n\n  <em>\/\/ Green light<\/em>\n  digitalWrite(greenPin, HIGH);\n  delay(5000); <em>\/\/ Green for 5 seconds<\/em>\n  digitalWrite(greenPin, LOW);\n}\n<\/code><\/pre>\n\n\n\n<pre id=\"block-963cebf7-ebd3-43b6-8c63-4cb17ea471b3\" class=\"wp-block-preformatted\"><strong>How this code words<\/strong>:\n<strong>Variable declaration<\/strong>\nat the beginning, we stored the numbers 12 and 13 into variables (redPin, GreenPin)\n<strong>Setup<\/strong>\nThe <em>pinMode()<\/em> Command determines the type of pin (input or output) and therefore its function and internal connections.\n<strong>Loop<\/strong>\nThe <em>digitalWrite() <\/em>Command turns a pin on (HIGH) or off (LOW). The <em>delay()<\/em> Command pauses the program from running according to the milliseconds number given.\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"aioseo-4-advanced-tips-for-modification\">4. Advanced Tips for Modification<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Multiple Traffic Lights:<\/strong> In the next lesson, we will expand the project to control multiple sets of traffic lights for intersections.<\/li>\n\n\n\n<li><strong>Pedestrian Crossing:<\/strong> Add a push button to allow pedestrians to request a crossing. When pressed, the traffic light can switch to red, and a buzzer can sound to indicate it&#8217;s safe to cross.<\/li>\n\n\n\n<li><strong>Timing Adjustments:<\/strong> Modify the delay times for each light to simulate different traffic conditions (e.g., rush hour vs. off-peak).<\/li>\n\n\n\n<li><strong>Traffic Sensors:<\/strong> Integrate infrared or ultrasonic sensors to detect vehicles and adjust the light timing based on traffic flow.<\/li>\n\n\n\n<li><strong>LED Matrix Display:<\/strong> Use an LED matrix to display additional information, such as countdown timers for each light.<\/li>\n\n\n\n<li><strong>Remote Control:<\/strong> Implement a remote control feature using an IR remote to manually change the lights or override the automatic sequence.<\/li>\n\n\n\n<li><strong>Mobile App Control:<\/strong> Use Bluetooth or Wi-Fi modules (like HC-05 or ESP8266) to control the traffic lights via a mobile app.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">This project can be as simple or complex as you want, depending on your interests and skills. Enjoy building your traffic light system!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the first things you can start doing with Arduino after learning how to light an LED and blink it is to make a traffic light project with Arduino. This lesson goes through the basic steps using two different connection methods. List of content 1. Needed Components 2. Connecting Your Traffic Light Circuit 3. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":22,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[9],"class_list":["post-13","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","tag-arduino"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":4,"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":184,"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/184"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=\/wp\/v2\/media\/22"}],"wp:attachment":[{"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/samerli.com\/en\/lessons\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}