CxD Archive
Internet of Things Project
Internet of Things Project
  • IoT Project Background
  • IoT Project Challenge
  • IoT Project Outline
    • 1-1 Smartphone Research
    • 1-2 Smart Thermostat Research
    • 1-3 Smart Device Research
    • 1-4 Introduction to Photon Kit
    • 1-5 Build Smart Lightbulb
    • 1-6 Generate Project Ideas
    • 1-7 Build Smart Thermostat
    • 2-1 Evaluate Project Ideas
    • 2-2 Plan User Research
    • 2-3 Compile Research Data
    • 2-4 Construct Personas
    • 2-5 Construct Journey Map
    • 2-6 Define Value Proposition
    • 2-7 Define Design Requirements
    • 3-1 Generate Solution Ideas
    • 3-2 Evaluate and Refine Solution Ideas
    • 3-3 Create System Model of Solution
    • 3-4 Create Wireflow for Web App
    • 3-5 Create Storyboard for Solution
    • 3-6 Evaluate Solution Design
    • 3-7 Present Project Proposal
    • 4-1 Track Progress and Issues
    • 4-2 Build Smart Device
    • 4-3 Create Photon App
    • 4-4 Create Web App
    • 4-5 Conduct Integration Testing
    • 4-6 Create Product Demo Video
    • 4-7 Create Product Marketing Website
    • 5-1 Evaluate Smart Device and Web App
    • 5-2 Evaluate Product Marketing Website
    • 5-3 Improve Solution Based on Evaluations
    • 6-1 Create Project Poster
    • 6-2 Present Project to Public
    • 6-3 Write Personal Reflection
  • References for Wiring & Coding
    • Creating Circuits
    • Wiring Programming Language
    • Particle Cloud
    • Hello World App for Photon
    • LED Light
    • Push Button
    • Micro OLED Display
    • Humidity and Temp Sensor
    • Speaker
    • Servo Motor
    • Motion Sensor
    • Magnetic Switch
    • Potentiometer
    • Photocell
    • Moisture Sensor
    • Accelerometer
    • RFID Reader
    • Fingerprint Scanner
    • GPS Receiver
    • Camera
    • Microphone
    • Force Sensitive Resistor
    • Keypad
    • Continuous Rotation Servo Motor
  • Glossary
  • Updated Project Guidebook
  • Updated Code Guidebok
Powered by GitBook
On this page
  • WHAT TO DO
  • Code for Hello-World
Export as PDF
  1. References for Wiring & Coding

Hello World App for Photon

PreviousParticle CloudNextLED Light

Last updated 6 years ago

When learning a new coding language, many people first create what is called a "Hello World" program. Traditionally, this involves displaying the text "Hello World" on the screen. The purpose is to demonstrate that you can create a simple working program in the new coding language.

Creating a working device with an electronics kit involves both building the physical device and programming it. So if your device doesn't work as expected, the reason could be that some of the parts are connected incorrectly – or the program might have a mistake – or it could be both.

So you will create a different kind of "Hello World" app for your Photon device: an app that doesn't require connecting any additional parts to the Photon, so you can first focus on getting some code to work.

The Photon has a built-in blue LED light that is connected to its D7 pin. This "Hello World" app will turn this blue LED on and off in a repeating pattern. This will be your first app before you start to connect additional parts to program more complex devices.

This app – like all apps that run on Photon devices – is coded in a programming language called Wiring. Here's an overview of the .

WHAT TO DO

  1. Login to your account. If necessary, here's a .

  2. Create a new app titled: hello-world

  3. Delete the placeholder code that Particle Build inserted for your new app (the empty setup() and loop() functions).

  4. Copy and paste the code below into your new app. Save the app in Particle Build, and then load ("flash") the app onto your Photon device. During "flashing", Particle Build transfers the app to your device over Wi-Fi. The RGB light on your Photon blinks magenta as the new app is being flashed, and then the Photon restarts. Be patient – sometimes it takes longer for your first app to flash because Particle may need to also update the firmware (OS) on your Photon device.

  5. After the Photon has reconnected to Wi-Fi, the new app will automatically start running. If everything worked correctly, the blue D7 LED on your Photon device should blink on and off repeatedly. It may not seem like much, but you've just taken your first step in coding with the Wiring language.

  6. Once you get the app working, try modifying the code to change the LED blinking pattern. Flash your modified app to your Photon to see what your changes do. Can you make the LED blink faster? Can you make it blink slower? Can you make it blink in a more complex pattern (maybe similar to Morse code)?

Code for Hello-World

// HELLO WORLD app - introductory program that doesn't require connecting any parts

// GLOBAL VARIABLES - variables that will be used in multiple functions
// declare integer variable called "led" and assign it value of D7 (built-in LED)
int led = D7;

// SETUP function runs one time at start when device is powered on
void setup() {
    // set "led" pin to be an output
    pinMode(led, OUTPUT);
}

// LOOP function runs in repeating loop (after setup finishes)
void loop() {
    // turn on "led" pin (built-in blue LED light)
    digitalWrite(led, HIGH);

    // wait 1 second (1000 milliseconds)
    delay(1000);

    // turn off "led" pin
    digitalWrite(led, LOW);

    // wait 1 second
    delay(1000);

    // loop repeats itself again
}

A couple of things to note about the code:

  • The lines that begin with two forward slashes are comments. Comments are just notes for people reading the code. The comments are ignored by the device when the app runs. Comments are optional, but it can be helpful to include comments to explain certain parts of the app.

  • Integers are supposed to be whole numbers, but the Wiring language treats input and output pin names (D7, etc.) as "integer" variables.

Wiring programming language
Particle Build
brief overview of navigating and using Particle Build
Hello World in BASIC