element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • Store
    Store
    • Visit Your Store
    • Choose Another Store
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
The Learning Circuit
  • Challenges & Projects
  • element14 presents
  • The Learning Circuit
  • More
  • Cancel
The Learning Circuit
Documents The Learning Circuit 12: Arduino Starter Kit: Spaceship Interface
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
The Learning Circuit requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Engagement
Author: tariq.ahmad
Date Created: 22 May 2018 8:15 PM
Last Updated: 4 Aug 2018 9:12 PM
Views: 357
Likes: 10
Comments: 2
Related
Recommended

The Learning Circuit 12: Arduino Starter Kit: Spaceship Interface

element14's The Ben Heck Show

Join Karen as she shares her enthusiasm for teaching STEM subjects, gives you what you need to know to get started on electronics projects, and more.

Back to The Ben Heck Show homepage

The Learning Circuit
Featured Bonus Content
See All Episodes

 

You don't have permission to edit metadata of this video.
Edit media
x
Upload Preview

Karen walks you through the Spaceship Interface project which is included in the Arduino Starter Kit book.  For this project you’ll need an Arduino Uno the USB cable to plug into your computer, breadboard, jumpers, a tact switch, two red and one LEDs, three 220 ohm resistors for the LEDs, and one 10 kiloohm resistor. The code you’ll need to do this project is included in the Arduino Starter KitArduino Starter Kit book.

 

The Arduino Starter Kit Arduino Starter Kit book includes circuit diagrams and code which is referred to as sketches.  A sketch includes a set of functions followed by curly brackets, such as void setup () and void loop (). Anything you put in the curly brackets is the code that is executed when the function is called. Sometimes you will need to create what are known as variables for your code. A variable are items that you want your code to remember so that you can reference them later.  One good thing about variables is that if you use the same variable throughout your code and need to adjust the value of the variable, you only need to set the variable to another value at the top of the code.  Karen shows you how to set an integer as a variable for the project.

 

After defining the variable, Karen moves along to the setup code. The setup is where we configure the pins so that the Arduino knows what’s an input, what’s an output, and which pins we’re using. In her code the 3 LED are designated as outputs, for pinMode, and the button is designated as an input for pinMode.

 

int switchState = 0; // Holds the state of the Switch (HIGH - Pressed, LOW - Floating)
void setup(){   // The void setup function runs only once at the beginning. It is the place to define the OUTPUTs and INPUTs
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT); 
// configures pin 3 (digital) as an OUTPUT
  pinMode(5, OUTPUT);
  pinMode(2, INPUT);
}

 

When the code runs it will run once at the beginning to initialize and the loop will run over and over again.  The reason for the loop is to allow the Arduino to keep sensing the inputs and outputs.  Karen enters  the remaining code for the loop and walks you through what it means.

 

int switchState = 0; // Holds the state of the Switch (HIGH - Pressed, LOW - Floating)
void setup(){   // The void setup function runs only once at the beginning. It is the place to define the OUTPUTs and INPUTs
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT); 
// configures pin 3 (digital) as an OUTPUT
  pinMode(5, OUTPUT);
  pinMode(2, INPUT);
}

void loop() { // This function will execute endlessly from the first to the last row
  switchState=digitalRead(2); // reads the digital Value of pin 2
  if (switchState == LOW) { 
// compares if the switchState corresponds to a LOW value. If the statement is true, it executes the orders contained within {}. Otherwise it ignores them. 
    digitalWrite(3, HIGH); // Sets the signal in 3 to HIGH (turn on the LED) and 4 and 5 to LOW (turn off the LEDs connected to 4 and 5)
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
  }
  else { // If the Switch is pressed, the program will ignore the 'if' conditional and enter the 'else'
    digitalWrite(3, LOW);
    digitalWrite(4, LOW); 
    digitalWrite(5, HIGH);
    delay(250); // Delays time for 250ms - a quarter of a second. It freezes the program during this time.
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    delay(250);
  }
}

  • tlc
  • arduino uno
  • arduino_vcp
  • e14presents_makerkaren
  • switches
  • io
  • simplified c
  • arduino ide
  • arduino_projects
  • arduino_tutorials
  • led
  • arduino_uno
  • arduino_classic
  • code
  • spaceship interface
  • arduino starter kit
  • stem projects
  • analog
  • thelearningcircuit
  • Share
  • History
  • More
  • Cancel
Anonymous

Top Comments

  • airbornesurfer
    airbornesurfer over 3 years ago +2

    Aha! Das blinkenlighzen! Great rundown of the basics of Arduino sketching!

  • magiotcz
    magiotcz over 3 years ago +1

    Great  Tomorrow I will build it;)

  • magiotcz
    magiotcz over 3 years ago

    Great Tomorrow I will build it;)

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
  • airbornesurfer
    airbornesurfer over 3 years ago

    Aha! Das blinkenlighzen! Great rundown of the basics of Arduino sketching!

    • Cancel
    • Up +2 Down
    • Reply
    • More
    • Cancel
Element14

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2022 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • Facebook
  • Twitter
  • linkedin
  • YouTube