{"id":355,"date":"2025-08-12T08:41:05","date_gmt":"2025-08-12T08:41:05","guid":{"rendered":"http:\/\/www.amartkh.com\/store\/?p=355"},"modified":"2025-08-12T09:44:41","modified_gmt":"2025-08-12T09:44:41","slug":"arduino-servo-motor-7-segment-display-counting-from-0-to-9","status":"publish","type":"post","link":"http:\/\/www.amartkh.com\/store\/2025\/08\/12\/arduino-servo-motor-7-segment-display-counting-from-0-to-9\/","title":{"rendered":"Arduino Servo Motor 7-Segment Display | Counting from 0 to 9"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong>Arduino project<\/strong> that uses a <strong>servo motor<\/strong> and a <strong>7-segment display<\/strong> to count from <strong>0 to 9<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s a complete breakdown so you can both understand it and build it.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. Project Overview<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In this project:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The <strong>Arduino<\/strong> will count from <strong>0 to 9<\/strong>.<\/li>\n\n\n\n<li>The <strong>7-segment display<\/strong> will show the number.<\/li>\n\n\n\n<li>The <strong>servo motor<\/strong> will move to a specific position for each number.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">For example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When the display shows <code>0<\/code>, the servo is at 0\u00b0.<\/li>\n\n\n\n<li>When the display shows <code>5<\/code>, the servo is at 90\u00b0.<\/li>\n\n\n\n<li>When the display shows <code>9<\/code>, the servo is at 180\u00b0.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Components Needed<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Arduino Uno (or compatible)<\/li>\n\n\n\n<li>SG90 or MG90S Servo motor<\/li>\n\n\n\n<li>Common cathode or common anode 7-segment display<\/li>\n\n\n\n<li>220\u03a9 resistors (x7)<\/li>\n\n\n\n<li>Breadboard + jumper wires<\/li>\n\n\n\n<li>USB cable for Arduino<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. Circuit Wiring<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>7-Segment Display (Common Cathode example)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s assign Arduino pins for each segment:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Segment<\/th><th>Arduino Pin<\/th><\/tr><\/thead><tbody><tr><td>A<\/td><td>2<\/td><\/tr><tr><td>B<\/td><td>3<\/td><\/tr><tr><td>C<\/td><td>4<\/td><\/tr><tr><td>D<\/td><td>5<\/td><\/tr><tr><td>E<\/td><td>6<\/td><\/tr><tr><td>F<\/td><td>7<\/td><\/tr><tr><td>G<\/td><td>8<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Common cathode pin<\/strong> \u2192 GND.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Servo Motor<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Signal pin \u2192 Arduino pin 9<\/li>\n\n\n\n<li>Vcc \u2192 5V<\/li>\n\n\n\n<li>GND \u2192 GND<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4. Arduino Code<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-preformatted\">cppCopyEdit<code>#include &lt;Servo.h&gt;\n\nServo myServo;\n\n\/\/ Segment pin order: A, B, C, D, E, F, G\nint segmentPins[] = {2, 3, 4, 5, 6, 7, 8};\n\n\/\/ Number patterns for 0\u20139 (common cathode)\nbyte numbers[10][7] = {\n  {1, 1, 1, 1, 1, 1, 0}, \/\/ 0\n  {0, 1, 1, 0, 0, 0, 0}, \/\/ 1\n  {1, 1, 0, 1, 1, 0, 1}, \/\/ 2\n  {1, 1, 1, 1, 0, 0, 1}, \/\/ 3\n  {0, 1, 1, 0, 0, 1, 1}, \/\/ 4\n  {1, 0, 1, 1, 0, 1, 1}, \/\/ 5\n  {1, 0, 1, 1, 1, 1, 1}, \/\/ 6\n  {1, 1, 1, 0, 0, 0, 0}, \/\/ 7\n  {1, 1, 1, 1, 1, 1, 1}, \/\/ 8\n  {1, 1, 1, 1, 0, 1, 1}  \/\/ 9\n};\n\nvoid setup() {\n  \/\/ Set all segment pins as output\n  for (int i = 0; i &lt; 7; i++) {\n    pinMode(segmentPins[i], OUTPUT);\n  }\n  \n  myServo.attach(9); \/\/ Servo signal pin\n}\n\nvoid loop() {\n  for (int num = 0; num &lt;= 9; num++) {\n    displayNumber(num);\n    \n    \/\/ Map number 0\u20139 to servo angle 0\u2013180\n    int angle = map(num, 0, 9, 0, 180);\n    myServo.write(angle);\n\n    delay(1000); \/\/ Wait 1 second before next number\n  }\n}\n\nvoid displayNumber(int num) {\n  for (int seg = 0; seg &lt; 7; seg++) {\n    digitalWrite(segmentPins[seg], numbers[num][seg]);\n  }\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5. How It Works<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The <code>numbers<\/code> array defines which segments light up for each digit.<\/li>\n\n\n\n<li>In the <code>loop()<\/code>, the Arduino counts from <code>0<\/code> to <code>9<\/code>.<\/li>\n\n\n\n<li>For each number:\n<ul class=\"wp-block-list\">\n<li><code>displayNumber(num)<\/code> lights up the correct segments.<\/li>\n\n\n\n<li>The servo moves to a mapped position based on the number.<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>After a short delay, it moves to the next number.<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"444\" height=\"546\" src=\"http:\/\/www.amartkh.com\/store\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-12-153304-1.png\" alt=\"\" class=\"wp-image-363\" srcset=\"http:\/\/www.amartkh.com\/store\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-12-153304-1.png 444w, http:\/\/www.amartkh.com\/store\/wp-content\/uploads\/2025\/08\/Screenshot-2025-08-12-153304-1-244x300.png 244w\" sizes=\"(max-width: 444px) 100vw, 444px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">source by <a href=\"https:\/\/www.youtube.com\/shorts\/aSGwVuYEXBg\">https:\/\/www.youtube.com\/shorts\/aSGwVuYEXBg<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Arduino project that uses a servo motor and a 7-segment display to count from 0 to 9. Here\u2019s a complete breakdown so you can both understand it and build it. 1. Project Overview In this&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-355","post","type-post","status-publish","format-standard","hentry","category-projects"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/355","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/comments?post=355"}],"version-history":[{"count":4,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/355\/revisions"}],"predecessor-version":[{"id":366,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/355\/revisions\/366"}],"wp:attachment":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/media?parent=355"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/categories?post=355"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/tags?post=355"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}