element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
  • Settings
The Learning Circuit
  • Challenges & Projects
  • element14 presents
  • The Learning Circuit
  • More
  • Cancel
The Learning Circuit
Documents Arduino Starter Kit: Spaceship Interference -- The Learning Circuit 12
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join The Learning Circuit to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: tariq.ahmad
  • Date Created: 22 May 2018 8:15 PM Date Created
  • Last Updated Last Updated: 23 May 2018 7:24 AM
  • Views 2456 views
  • Likes 10 likes
  • Comments 2 comments
Related
Recommended

Arduino Starter Kit: Spaceship Interference -- The Learning Circuit 12

image

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 image

The Learning Circuit
Featured Bonus Content
See All Episodes

 

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

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
  • Sign in to reply

Top Comments

  • airbornesurfer
    airbornesurfer over 7 years ago +2
    Aha! Das blinkenlighzen! Great rundown of the basics of Arduino sketching!
  • magiotcz
    magiotcz over 6 years ago +1
    Great Tomorrow I will build it;)
Parents
  • magiotcz
    magiotcz over 6 years ago

    Great image Tomorrow I will build it;)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • magiotcz
    magiotcz over 6 years ago

    Great image Tomorrow I will build it;)

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
element14 Community

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 © 2025 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

  • X
  • Facebook
  • linkedin
  • YouTube