Thimble Learning Platform
Back to full view

Creator Set

Introduction

The Creator Set offers reusable modules each with their own unique function. There are 12 included projects but we here at Thimble know that there are much more to be made.

Objectives

  • Learn the Grove/Module Ecosystem
  • Explore the difference between Sensors, Indicators, and Actuators
  • Learn our platform to start inventing your own projects
  • Learn the basics of Arduino
  • Learn the basics of coding for hardware
  • Have fun!
  • I've Never Used an Arduino

    Then this is a great place to start! If you're already familiar with setting up the Arduino and the IDE, you can skip to the next section.

    Terms 

    When we talk about Arduino, the Arduino IDE, and coding, there are a lot of words being thrown around. This section will clear all of those up and get you ready to start building!

    Arduino 

    The Arduino is a electronics prototyping platform. That means it's a flexible platform for building, testing, and, of course, prototyping electronics. That could be simple LEDs that light up at night, or advanced robots. When we talk about the Arduino we are talking about the physical board itself. The one that comes in this kit is red, but they come in many different shapes and colors. The Arduino brand and original board were created by arduino.cc and you can read more about the details of its history here.

    Arduino IDE 

    The Arduino IDE, or Integrated Development Environment, is not hardware, but a piece of software. If you wanted to write an essay, you might use Microsoft Word or Google Docs. If you wanted to edit pictures, you'd probably use Photoshop or Paint.net. If you want to program code for the Arduino, you'd use the Arduino IDE. Its a computer program (tool) that let's you develop and test out code. Once written, the code can be upload to the physical Arduino where it will stay until you upload new code.

    Download

    Since it is a program, you'll need to install it.

    For Windows computers use this link Windows Installer

    Windows 7 users will have an additional step at the bottom of this sections.

    For Mac computers use this link Mac Installer

    After following each link, press the Just Download button to begin downloading the Arduino IDE. The Mac version has a few more steps and we have a video just for that.

    Mac Installation
    For Mac users

    Installation

    Open the executeable file you downloaded. You'll see a screen asking you to agree to their license. You can press I Agree.

    LicenseLicense

    Next up are the installation options. The Install USB Drivers lets the Arduino board communicate with the IDE. We definitely want this. The Associate .ino files makes any Arduino file on your computer open up to the Arduino IDE. Very helpful, so we'll keep that too. Press Next >.

    OptionsOptions

    Now you are being asked where you'd like the Arduino IDE program installed. I don't mind it in the standard Program Files so I just press Install. You can change where it will be installed, just remember what you chose. I recommend not changing it.

    FolderFolder

    Now the IDE is installing.

    InstallingInstalling

    Once completed proceed to the next section.

    CompletedCompleted

    Arduino IDE 101 

    Open up the Arduino IDE for the first time. So, let's figure out what's what.

    Arduino IDEArduino IDE

    There is a mostly empty space in the middle that has this text:

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    }
    

    This is a simple Arduino Sketch. A Sketch is code you write that will later be uploaded to the Arduino board.

    There are few steps to go from code written in a sketch to code that runs on the Arduino board. Those are Verify > Compile > Upload.

    All of these you can get to by going under Sketch on the top bar of the program. Or using the Checkmark and Arrow icons right below that. The Checkmark verifies your code will compile, and the arrow button uploads the code to the Arduino.

    Sketch
    Icons

    Verify - looks at your code and makes sure it can actually run. It checks that there are no errors or things out of place. If your code will work, it goes to the Compile stage.

    Compile - The code you've written is great for human. It is readable and hopefully understandable. But this isn't great for a machine ie the Arduino. The Compile stage takes your written code and translates into something that the Arduino can understand and run, called machine code. It saves that compiled file and tried to Upload it to the board.

    Upload - This takes the compiled files and tries to send it to a plugged in Arduino. The IDE doesn't know where you've plugged in your Arduino or what kind it is. You have to tell it. I'll show you how to set that up in the next section.

    Arduino Board Setup

    For this section, make sure your Arduino Board that came with your kit is plugged in. Use the included micro USB cable to plug your Arduino into any free USB port on you computer.

    Navigate to the Tools section at the top of the Arduino IDE.

    You'll be greeted with a scary drop down. To setup your Arduino to accept uploads, do the following: Go to Board: and make sure Arduino/Genuino Uno is selected.

    BoardBoard

    Next is the Port. For Mac users refer to the video for these instructions. With your Arduino plugged in, you'll see some options. Mine says COM 15. This is the channel that the IDE will use to communicate with your Arduino. If you have a lot of COM # devices and don't know which is your Arduino, unplug your Arduino and take note of that numbers are there. Then plug it back in. Whichever is the new one in the list is your Arduino. Select that port.

    PortPort

    With the board and port selected and ready to go, let's upload our first sketch.

    Sketches

    We are going to upload a simple sketch to make an LED on the board blink. Head to File > Examples > Basics > Blink . You should see this sketch.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    /*
      Blink
    
      Turns an LED on for one second, then off for one second, repeatedly.
    
      Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO
      it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to
      the correct LED pin independent of which board is used.
      If you want to know what pin the on-board LED is connected to on your Arduino
      model, check the Technical Specs of your board at:
      https://www.arduino.cc/en/Main/Products
    
      modified 8 May 2014
      by Scott Fitzgerald
      modified 2 Sep 2016
      by Arturo Guadalupi
      modified 8 Sep 2016
      by Colby Newman
    
      This example code is in the public domain.
    
      http://www.arduino.cc/en/Tutorial/Blink
    */
    
    // the setup function runs once when you press reset or power the board
    void setup() {
      // initialize digital pin LED_BUILTIN as an output.
      pinMode(LED_BUILTIN, OUTPUT);
    }
    
    // the loop function runs over and over again forever
    void loop() {
      digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
      delay(1000);                       // wait for a second
      digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
      delay(1000);                       // wait for a second
    }
    

    Don't worry about the coding for now. Let's upload this sketch. You can press the Arrow icon, go to Sketch then Upload, or you can use the shortcut Ctrl+U in order to upload the code. Your sketch will auto-verify, compile, then upload to your Arduino board.

    Upload the SketchUpload the Sketch

    You will see the message Done uploading and your board should now have a blinking light.

    Uploading Sketches and Code From Thimble 

    We provide example code for all our projects. To use those you'll need to copy them from our website. Then, go into the Arduino IDE, File > New. It's best to then delete all the code already there in the sketch before you paste our code in, as that will avoid any errors from copying over the old code.

    Serial Plotter

    You'll be asked to use the Serial Plotter on some projects. This reads any information coming from the Arduino and displays it on a graph. It can only be accessed after you've uploaded your code. It is in the Tools menu. Once opened, make sure the Baud rate is set to 9600.

    Where to find the Serial Plotter
    Baud rate

    Troubleshooting 

    The most common issues are solved by double checking your Board and Port settings.

    Attention Windows 7 Users 

    Windows 7 needs to have the Arduino drivers installed manually. Follow the instructions at the link below.

    Arduino Drivers

    Libraries

    What are Libraries? 

    Libraries are a reusable collection of code that has already been written. We use them when we want to add functionality without have to write everything from scratch. The advantage of using a library is code re-use.

    Some of the projects in this set need libraries so this section will show you how to install those.

    Libraries to be downloaded 

    Our libraries come in the form of zip files that need to be downloaded, but NOT unzipped.

    LCD Display Library - This is for the LCD Display and all its colors

    OneButton - This is to add some functionality to the buttons found in the set

    Adding Them to the Arduino IDE 

    Open up the Arduino IDE and go to Sketch > Include Library > Add .ZIP Library.... After that navigate to the zip files you downloaded and add them one by one. And that's it!

    Add a LibraryAdd a Library

    Creator Set - Grove

    What are These Things in My Set? 

    When you open up the Creator Set, you'll see a bunch of modules. Each has a certain function. Some are Sensors that measure the environment. That could be the amount of light or sound, for example. Some are Indicators, which show a state or information. These could be an LED or a display. The last kind are Actuators, that interact with the environment. Actuators are things like motors that move or spin.

    Why Use These? 

    These modules are reusable. You can use them in one project and then reuse them in another one. They are much harder to break then the average electrical component. They share a connector that is universal so a cable for one module works for all the rest.

    We want future projects to be more hackable and tinker friendly and using these modules is the answer.

    What Modules Do I Get? 

    I'm glad you asked!

    A Button
    A Piezo Buzzer
    An LED Driver
    With 3 LED colors
    A Light Sensor
    A Rotary Potentiometer
    A Servo
    A Capacitive Touch Sensor
    A Temperature Sensor
    A Sound Sensor
    A WiFi Module. Looks may vary but on the back it will say WiFi no matter the model.
    An LCD Display

    How Do I Use These? 

    There is one step you have to do before getting started with the 12 projects. Open up your kit. Remove the LCD Display at the top and you'll find a board protected by pink foam. This board is called the base shield. Remove the base shield from the foam and put it on top of your Arduino. There are pins on the shield that will match up and slide into the Arduino. This lets us use all the cool features of the modules with a normal Arduino. Now you're ready to get started.

    The Creator Set
    Opened
    Take the LCD and foamed board
    Base Shield and Arduino
    Base shield installed on top of the Arduino

    So What Are These Modules Again? 

    Hey You 

    We want your feedback. It helps us know what's working and what's not. Everyone here at Thimble wants to teach Electronics and Programming the best that we can and your feedback helps us do that. While you build these projects take some notes about what was cool and what could use some work. Post on the forums with your experiences and hacks.

    Happy Hacking!

    Robot Friend

    Start 

    Let's build the first project in your 12-in-1 project kit. A Robot friend that reacts to your environment. He'll end up looking something like this.

    Robot Friend BlueprintRobot Friend Blueprint

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    Servo x 1
    Light x 1
    Cable x 1

    Servo 

    The servo comes in a bag that also has a smaller bag of components in it. You'll need both for this project. Take the servo out as well as the small servo arm and a screw for it. One of the longer screws is better. Take the servo arm and servo and connect them. The arm should be pointing up with none of it hanging off the servo body. After unwrapping the servo cable, plug it into Digital socket D6.

    All the parts you'll need
    Open the plastic bag
    Take out the bag of parts inside...
    ... and the servo
    Open the smaller bag...
    Be careful! There are many little parts
    Take out the small 'Servo Arm'...
    ... and ...
    ... one longer screw
    Now we can get started
    Take the servo...
    ... and the 'Servo Arm'
    Line up the circles
    Place them together with the 'Servo Arm' pointing up on the servo body
    The 'Servo Arm' shouldn't be hanging off the servo body
    Take the wire around the servo...
    ... and unwrap it
    Take the cable ...
    ... plug into Digital socket D6

    How To Upload These Examples

    This is the procedure for each Upload section within each tutorial. First, open a new Arduino sketch in the Arduino IDE. Next, select all of the text and delete it so the sketch is now completely blank. Switch back over to this Learning Module and press Copy to Clipboard. Go back to the Arduino IDE and paste the code you just copied into the sketch. Before uploading, check in the Tools menu on top that 1) Board is selected as Arduino/Genuino UNO and 2) your port is correct for your computer, then press upload. A popup will ask you to save. Change the name to whatever project you're working on and press save. The code will now upload to your Arduino Board.

    Open a new sketch
    Highlight all code and delete it
    A blank sketch
    Copy code from our website
    Paste that into the blank sketch
    Double check
    Press Upload
    Save your sketch

    Upload

    Upload the code shown below. This tutorial uses Digital socket 6. If you are using a different socket, update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    #include <Servo.h>
    
    //Change here if you're using a different socket
    #define servoSocket 6 //<- digital socket number
    
    Servo robotServo;
    
    int pos = 0;
    int servoSpeed = 15;
    
    void setup() {
      robotServo.attach(servoSocket);
    }
    
    void loop() {
      for (pos = 0; pos <= 180; pos += 1) {
        // in steps of 1 degree
        robotServo.write(pos);
        delay(servoSpeed);
      }
      for (pos = 180; pos >= 0; pos -= 1) {
        robotServo.write(pos);
        delay(servoSpeed);
      }
    }
    

    Observe

    Watch the servo move back and forth

    Look at how the servo swings back and forth. There are two loops in the code. One for swinging clockwise and the other for counter-clockwise.

    Modify

    Increase or decrease the servoSpeed variable and watch what changes. It might not do what you'd think.

    How to Modify Code

    All code modifications will be done via variables that are at the top of the sketch. In the copied over Arduino sketch you can change the value of variables, upload the code, and observe what effect your change had.

    The prewritten sketch
    Variable to change
    Changes variable
    Upload and observe

    Experiment

    Play with that variable to make the servo go faster or slower.

    Light Sensor 

    Take a cable and attach one end to the light sensor and the other to an Analog socket, A0.

    All the parts for the next step
    Take a cable
    Unwrap it
    Connect one side to the sensor socket
    The other to Analog socket A0
    Ready to upload code

    Upload

    Upload the code below. This tutorial uses Analog socket A0. If you are using a different socket, update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    //Change here if you're using a different socket
    #define sensorSocket A0//<- analog socket number
    
    int val;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      val = analogRead(sensorSocket);
      Serial.println(val);
    }
    

    Observe

    You'll be asked to use the Serial Plotter on some projects. This reads any information coming from the Arduino and displays it on a graph. It can only be accessed after you've uploaded your code. It is in the Tools menu. Once opened, make sure the Baud rate is set to 9600.

    Where to find the Serial Plotter
    Baud rate

    Open up the Serial Plotter and move your hand over the light sensor. Check out what values you can get. Look at the light value you get when the sensor is uncovered and covered. Remember those because we'll need them for your Robot Friend.

    Record uncovered light value
    And covered value

    Robot Buddy 

    Let's finish up the code for the first project blueprint.

    Upload

    Upload the code shown below. The variable trigger value should be a number close to the covered sensor light value. You'll want it a bit (ie: 10-30) higher than what you measured. For example, if you measured 80, 100 would be a good value to use.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    #include <Servo.h>
    
    #define servoSocket 6
    #define lightSensorSocket A0
    
    Servo robotArm;
    
    int pos;
    int val;
    int trigger = 100; //<- Change to YOUR measured value
    int waveSpeed = 5;
    
    int leftWave = 90;
    int rightWave = 0;
    
    void setup() {
      robotArm.attach(servoSocket);
    }
    
    void loop() {
      val = analogRead(lightSensorSocket);
      if (val < trigger) {
        for (pos = rightWave; pos <= leftWave; pos += 1) {
          robotArm.write(pos);
          delay(waveSpeed);
        }
        for (pos = leftWave; pos >= rightWave; pos -= 1) {
          robotArm.write(pos);
          delay(waveSpeed);
        }
        for (pos = rightWave; pos <= leftWave; pos += 1) {
          robotArm.write(pos);
          delay(waveSpeed);
        }
      }
    }
    

    Observe

    Put your hand over the light sensor and watch the servo move. The change in light triggers the servo to move back and forth, or wave to you.

    The arm moves when covered
    And not when exposed to light

    Modify

    Increasing the trigger will make it more sensitive to the change in light.

    Experiment

    Changing the leftWave and rightWave variables will change how far the Robot waves. waveSpeed changes how fast the Robot waves.

    Robot Template 

    Recommended - PDF Template

    SVG Template

    AI Template

    Print out the template and assemble your new buddy! Find some cardboard and cut out the template. Disconnect the servo from it's socket. Place it through the rectangle hole in the Robot's missing arm. Seat the servo and use some tape to keep it in place. Place another piece of tape behind the servo arm then attach the Robot's arm. Use the screw from the beginning and screw it into the hole in the arm and into the servo. With the construction complete, plug the servo back into the same socket. Wave at your Robot and watch it wave back!

    Some cardboard and the printed template
    Line up your materials
    Cut the solid lines
    All cut out
    Take the servo
    Disconnect it from the socket
    Grabbing the socket end...
    ... stick it through the Robot's missing arm
    All the way through so the servo is snug in the rectangle hole
    You can add some tape to keep it in place
    Now we'll attach the arm
    Get a piece of tape
    Attach it behind the 'Servo Arm'
    Get the Robot's arm...
    ... place it on top of the 'Servo Arm'
    Find that screw from earlier
    It will go through the Robot's arm and into the servo
    Be careful! It's small and pointy
    Through the mounting hole and into the servo
    You're all done with the construction
    High five!
    Take the servo cable...
    ... place back into the same socket
    Test out his waving feature!
    Moving the sensor might make the waving more natural
    You're first blueprint is finished!

    Taking it further 

    Feel free to use this code to explore what else you can do with the servo. Maybe your robot is afraid of light and covers his eyes, rather than waves? Maybe you want your robot to wave at you when triggered by sound? Maybe you want to completely change the look of your robot and not use our template? Maybe you don't want it to be a robot at all?

    As you progress through the project blueprints, revisit this project. Try connecting different sensors as you learn how to use them in the other projects. Don't be afraid to experiment and share any cool modifications with the community. We love seeing and sharing what you make!

    Coding Basics 101

    Start 

    This section will go over the basics of computer programming.

    Variables 

    In math, we use variables to solve equations. For example, when we say x = 2, we know that x is a variable and it equals the value ‘2’. Since we know that x = 2, we can say that x + x = 4. Variables are useful because they give insight to a problem. For example, let’s say I want to calculate the volume of a sphere. We can do the following calculation:

    43.1415333=113.1\frac{4 * 3.1415 * 3^3}{3} = 113.1

    If we showed just this equation to someone else, and asked them what this equation is for without any context, they might be confused. Let’s replace the numbers with a more meaningful equation:

    4πr33=volume of the sphere\frac{4 \pi r^3}{3} = \text{volume of the sphere} Where π=3.1415\pi = 3.1415

    Now we know that if we take two constant numbers 4/3 and pi, and multiply it by a radius, we can get the volume of a sphere. Naming a variable can help a person understand what the problem is doing. Furthermore, since you know that the equation calls for a radius, you can calculate several volumes of different spheres if given different radii.

    This is just one example of a variable in a real life application. Another example is a bank account - consider a single bank account number. This particular bank account stores money and can vary its monetary value by withdrawing or depositing into the account.

    Types 

    There are also variables in code. We can make different types of variables; we will focus on the most basic ones:

    int , any integer, such as 1, -5, or 391

    char , any character, such as a, f, k

    string , any group of character, such as hello, thisIsAlsoAString

    When you want to declare a variable, simply state its type and the variable name:

    type nameOfVariable;

    Notice how the name of the variable does not include any spaces, and has a semicolon at the end. These are simple “grammar” rules in coding that we must follow so that the computer can understand what we want it to do. If we want to assign a value to that variable, simply write the following:

    type nameOfVariable = value;

    Here are some more examples of how a variable is used:

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    int x = 5;
    
    char theLetterC = 'c';
    
    String hello = "Hello World";
    

    Notice how char’s value has ' ' while string’s value has " ". Again, this is just syntax that the code follows.

    Conditionals 

    Conditionals are extremely useful in order to structure your code better. Below are some of the most basic conditionals found in almost all programming languages.

    If / Else

    Whether it’s deciding whether to wear a sweater vs a raincoat or deciding to spend the weekend at the house or with friends, if-else conditions are relevant in every decision you make. Depending on the type of program you make, you can use if-else conditions to make your code run only if it hits a certain condition. Generally, if-else conditions are written as follows:

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    if (statement) {
      // Code goes here
    } else {
      // Code goes here
    }
    

    Let’s take a look at an example. Let’s say we want to make a slot machine game. A player pulls the handle and receives a three digit number. If the three digits are the same, then the player will see the message, “You won!”. If the player receives three digits that are different, then the player will see the message, “Sorry, try again!”

    To code this, we have to recognize that if the player gets three of the same number, then all those variables will have the same value. For example, let’s say the player has three variables, x, y, and z. If the player has x = 5, and the player wins, variables y and z must be assumed to be the same value of x such that x = y = z = 5. If the player has lost, then y and z can be any other number in such a way that x ≠ y ≠ z. Let’s put this thought into code!

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    if (numberOne == numberTwo && numberTwo == numberThree) {
      Serial.print("You win!");
    } else {
      Serial.print("Sorry, try again!");
    }
    

    The && sign means “and”. So, if x == y and y == z, then all three values are the same. If the condition is not fulfilled, then the statement will print “Sorry, try again!”. A programmer can put multiple if statements if desired. To do that you'd use a structure like this.

    Say we wanted to make the slot machine game reward the play if they receive two out of three same numbers. We'd use an "or" which looks like this || . Check this out.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    if (numberOne == numberTwo && numberTwo == numberThree) {
      Serial.print("You win!");
    } else if (numberOne == numberTwo || numberTwo == numberThree || numberOne == numberThree) {
      Serial.print("You half-win!");
    } else {
      Serial.print("Sorry, try again!");
    }
    

    Now if two but not three numbers are the same they player wins something. Now we have three separate conditionals at work. We used an else if statement to add that third condition. You can use else if statements to make as many additional conditionals as you need. The code below uses 4.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    if (condition) {
      // Code goes here
    } else if (condition) {
      // Code goes here
    } else if (condition) {
      // Code goes here
    } else {
      // Code goes here
    }
    
    Nightlight

    Start 

    This project uses the light sensor to create a nightlight that only turns on when it's dark.

    Modules 

    Gather the following parts to complete this project. If your LED module doesn't have an LED on it, then one must be inserted. The Creator Set comes with 3 Light Emitting Diodes, or LEDs. Each LED has a positive side and a negative side. The positive side must be put in the positive hole in the LED Module. The positive LED "leg" is the longer one. The positive hole on the LED Module has a small ‘+’ next to it. Putting the LED in backwards won’t permanently damage it, but it won’t work until correctly inserted.

    LED ModuleLED Module

    Parts

    All Parts x Qty
    LED x 1
    Light x 1
    Button x 1
    Cable x 3

    Starting With the Light Part of Nightlight 

    Take a cable and unwrap it. Plug one side into the light sensor and the other into any Analog socket.

    All the parts needed for this project
    Take a cable...
    ... and unwrap it
    Plug one side into the light sensor...
    ... and the other into Analog socket A0

    Upload

    Upload the code below. This tutorial uses Analog socket A0. If you are using a different socket, update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    //Change here if you're using a different socket
    #define sensorSocket A0
    
    int val;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      val = analogRead(sensorSocket);
      Serial.println(val);
    }
    

    Observe

    Open up the Serial Plotter and move your hand over the light sensor. Check out what values you can get. Look at the light value you get when the sensor is uncovered and covered. We'll need those two later.

    LED Modules 

    Take a cable and unwrap it. Plug one side into the led socket and the other into D6.

    Take a cable...
    ... and unwrap it
    Plug one side into the LED socket
    The other into Digital socket D6

    Upload

    Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket, update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    #define ledSocket 6
    
    int i;
    int fadeTime = 50;
    
    void setup()
    {
    
    }
    
    void loop()
    {
      for (i = 0; i <= 255; i++) {
        analogWrite(ledSocket, i);
        delay(fadeTime);
      }
      for (i = 255; i >= 0; i--) {
        analogWrite(ledSocket, i);
        delay(fadeTime);
      }
    }
    

    Observe

    The LED should be fading in and out.

    Modify

    Change the fadeTime delay value to change the speed of the fading.

    Button 

    Take a cable and unwrap it. Plug one side into the button socket and the other to Digital socket D5.

    Take a cable...
    ... and unwrap it
    Plug one side into the button socket
    The other into Digital socket D5

    Upload

    Upload the code shown below. This tutorial uses Digital socket 5. If you are using a different socket, update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    //If you use different socket numbers update them below
    #define buttonSocket 5
    #define ledSocket 6
    
    void setup()
    {
      pinMode(buttonSocket, INPUT);
      pinMode(ledSocket, OUTPUT);
    }
    
    void loop()
    {
      if (digitalRead(buttonSocket)) {
        digitalWrite(ledSocket,HIGH);
      } else {
        digitalWrite(ledSocket,LOW);
      }
    }
    

    Observe

    Pressing the button makes the LED turn on. This uses two states. An On state and an Off state. The button switches between those two. Now we'll take those two states and make the light sensor switch between them.

    Nightlight 

    At this point, the button can be removed.

    Remove the buttonRemove the button

    Upload

    Upload the code shown below. Add in the covered light value from earlier in the lowTrigger variable. Add in the uncovered light value from earlier in the highTrigger variable.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    //If you use different socket numbers update them below
    #define ledSocket 6
    #define lightSensorSocket A0
    
    int lowTrigger = 250;  //<- Change to YOUR measured value
    int highTrigger = 300; //<- Change to YOUR measured value
    int lightAmount;
    int state;
    
    void setup()
    {
      pinMode(ledSocket, OUTPUT);
    }
    
    void loop()
    {
      lightAmount = analogRead(lightSensorSocket);
      if (lightAmount < lowTrigger) {
        state = 1;
      } if (lightAmount > highTrigger) {
        state = 0;
      }
    
      if (state) {
        digitalWrite(ledSocket, HIGH);
      } else {
        digitalWrite(ledSocket, LOW);
      }
    }
    

    Observe

    The led should now be light sensitive. When exposed to high levels of light it will turn off. Once it gets dark, it will turn on.

    The finished nightlight project
    Uncovered and Off
    Covered to simulate the light level in the dark

    Modify

    Change the trigger number to more accurately have the nightlight turn on at the right darkness.

    Coding Basics 201

    Start 

    This section will go over some additional computer programming topics.

    Loops 

    Loops are used when you want to do the same instruction or a set of instructions multiple times. There are two main types of loops a for loop and a while loop.

    For

    A for loop repeats for a set number of times. Its basic design looks like this.

    Download file Copy to clipboard
    1
    2
    3
    for (initial condition; stopping condition; incrementing value) {
      // Code goes here
    }
    

    Let's say I have 10 leds that I want to turn on. They are pins 1 to 10. I could write this piece of code.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    digitalWrite(1, HIGH);
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
    digitalWrite(9, HIGH);
    digitalWrite(10, HIGH);
    

    Or I could use a for loop.

    Download file Copy to clipboard
    1
    2
    3
    for(int i = 1; i <= 10; i++) {
      digitalWrite(i, HIGH);
    }
    

    Lets go over this code line by line:

    int i = 1

    We need a counting variable to keep track of where we are in our loop. That's what the integer i is doing.

    i <= 10

    We only want the loop to run if i is less than or equal to 10. We don't want to try and turn an led on pin 11 on.

    i++

    i starts at 1 and at the end of each loop i++ runs and add one to i.

    digitalWrite(i, HIGH);

    There is no led pin i. The variable i changes it's value with each run of the loop. Starting at 1 then 2 and all the way to 10.

    While

    A while loop runs while some condition is true. You use it when you're not sure how many loops you'll need. The basic design looks like this.

    Download file Copy to clipboard
    1
    2
    3
    while (condition) {
      // Code goes here
    }
    

    Let's say you want to take a reading with a sensor. You send it a signal to take a reading and must wait for its answer but the time you have to wait is different with each measurement. You'd want to use a while loop.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    digitalWrite(sensorSignal, HIGH);
    
    while (analogRead(sensorReading) == 0) {
      // Do nothing
    }
    
    reading = analogRead(sensorReading);
    

    Our mystery sensor reports back 0 when it's taking a reading. The code above keeps running that empty while loop while the sensor is doing it's job. Once it is finished it reports back a non-zero number. That makes the condition of analogRead(sensorReading) == 0 false, and the loop is over.

    Arduino void loop()

    In every Arduino sketch there is something called the void loop() . So is it a while loop or for loop? It's a different kind of loop. It will repeat as long as the Arduino is powered on, it never stops.

    Clapper

    Start 

    The clapper will turn an LED on and off using a clap or loud noise. This project uses the analog sound sensor as a digital sensor. Analog sensors are used when the output values can have a wide range. For the clapper, we only care about large changes in the sound level and not the sound level itself.

    Modules 

    Gather the following parts to complete this project. If your LED module doesn't have an LED on it, then one must be inserted. The Creator Set comes with 3 light emitting diodes, or LEDs. Each LED has a positive side and a negative side. The positive side must be put in the position hole in the LED Modules. The positive LED side (leg) is the longer one. The positive hole on the LED Module has a small ‘+’ next to it. Putting the LED in backwards won’t permanently damage it, but it won’t work until correctly inserted.

    LED ModuleLED Module

    Parts

    All Parts x Qty
    Sound x 1
    LED x 1
    Cable x 2

    Sound Sensor 

    Take a cable and unwrap it. Plug one side into the sound sensor socket and the other into Analog socket A0.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the sound sensor socket
    ... and the other into any Analog socket

    Upload

    Upload the following code. The example below uses the A0 analog pin. You can use any of them just remember to update the sketch.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    //If you aren't using A0 as your socket change it below
    #define sensorSocket A0
    
    int val;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      val = analogRead(sensorSocket);
      Serial.println(val);
    }
    

    Observe

    Open up the Serial Plotter and check out the what a normal sound level is. Try clapping or talking and watch the sound sensor react. You'll see a big jump in the level of sound. Find a value that the jump goes through but is far away from the ambient sound level.

    A clap
    A clap
    A snap
    A snap

    Clapper 

    Take a cable and unwrap it. Plug one side into the led socket and the other into any Digital socket.

    Take a cable...
    ... and unwrap it
    Plug one side into the led socket
    ... and the other into any Digital socket

    Upload

    Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it. Set the trigger variable as that value you found from above.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    //If you aren't using A0 as your sound sensor socket change it below
    #define soundSensorSocket A0
    
    //If you aren't using pin 6 for your led socket change it below
    #define ledSocket 6
    
    int soundState;
    int ledState;
    int trigger = 600;
    
    void setup()
    {
      pinMode(ledSocket, INPUT);
      pinMode(ledSocket, OUTPUT);
    }
    
    void loop()
    {
      if (analogRead(soundSensorSocket) > trigger) {
        soundState = 1;
      } else {
        soundState = 0;
      }
    
      ledState = digitalRead(ledSocket);
      if (ledState == 1 && soundState == 1) {
        delay(400);
        digitalWrite(ledSocket, LOW);
      }
      if (ledState == 0 && soundState == 1) {
        delay(400);
        digitalWrite(ledSocket, HIGH);
      }
    }
    

    Observe

    Try clapping or making a loud noise. The LED will switch its states.

    A clap
    A clap
    A snap
    A snap
    A finished project
    8 Bit Music Conductor

    Start 

    This project only uses a Piezo Buzzer to create a musical master piece.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    Piezo Buzzer x 1
    Cable x 1

    Basic Music Player 

    Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D6 to start making music.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the buzzer socket
    ... and the other into Digital socket D6
    All finished

    Upload

    Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    //Change here if you're using a different socket
    #define buzzerSocket 6
    
    int length = 15; // the number of notes
    char notes[] = "ccggaagffeeddc "; // a space represents a rest
    int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
    int tempo = 300;
    
    void setup() {
      pinMode(buzzerSocket, OUTPUT);
    
      for (int i = 0; i < length; i++) {
        if (notes[i] == ' ') {
          delay(beats[i] * tempo); // rest
        } else {
          playNote(notes[i], beats[i] * tempo);
        }
    
        // pause between notes
        delay(tempo / 2);
      }
    }
    
    void loop() {
    
    }
    
    void playTone(int tone, int duration) {
      for (long i = 0; i < duration * 1000L; i += tone * 2) {
        digitalWrite(buzzerSocket, HIGH);
        delayMicroseconds(tone);
        digitalWrite(buzzerSocket, LOW);
        delayMicroseconds(tone);
      }
    }
    
    void playNote(char note, int duration) {
      char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };
      int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };
    
      // play the tone corresponding to the note name
      for (int i = 0; i < 8; i++) {
        if (names[i] == note) {
          playTone(tones[i], duration);
        }
      }
    }
    

    Observe

    It plays a simple melody on start up.

    Modify

    You can change the notes and duration to make your own songs.

    Experiment

    Checkout the code below for some examples of how to put together a melody.

    Some NOTEable tunes 

    Below are some pretty well known melodies to get you started. Replace the block of code that contains these variables in the example above.

    Ode to Joy

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    //All the code to make a song is in this block
    int length = 15; // the number of notes
    char notes[] = "eefggfedccdeedd"; // a space represents a rest
    int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1 };
    int tempo = 300;
    

    Super Mario Brothers

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    //All the code to make a song is in this block
    int length = 8; // the number of notes
    char notes[] = "eeecegc"; // a space represents a rest
    int beats[] = { 1, 1, 2, 1, 1, 4, 1};
    int tempo = 120;
    
    Doorbell

    Start 

    This project will use the piezo buzzer and a button to create a doorbell

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    Piezo Buzzer x 1
    Button x 1
    Cable x 2

    Doorbell 

    Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D6. Take another cable and unwrap it. Plug one side into the button socket and the other into Digital socket D5.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the buzzer socket
    ... and the other into Digital socket D5
    Take a cable...
    ... and unwrap it
    Plug one side into the button socket
    ... and the other into Digital socket D6

    Upload

    Upload the code below. The example below uses the 5 and 6 digital pins. You can use any digital pin just remember to update the sketch.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    //If you use any different socket change them below
    #define buttonSocket 5 // <- Socket for button
    #define buzzerSocket 6// <- Socket for piezo buzzer
    
    void setup()
    {
      pinMode(buttonSocket, INPUT);
      pinMode(buzzerSocket, OUTPUT);
    }
    
    void loop()
    {
      digitalWrite(buzzerSocket, digitalRead(buttonSocket));
    }
    

    Observe

    Press the button and listen to the annoying buzzer go.

    The finished doorbell
    Not pressing the button and no sound
    The buzzer plays once pressed
    I would race to door if I kept hearing this thing

    Modify

    Use some tape to mount the button outside a door and the rest of the components inside.

    Doorbell++ 

    Some doorbells play a melody when rung. Buy changing just the code we can do that too.

    Upload

    Upload the code below. The example below uses the 5 and 6 digital pins. You can use any digital pin just remember to update the sketch.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    //If you use any different sockets change them below
    #define buttonSocket 5 // <- Socket for button
    #define buzzerSocket 6// <- Socket for piezo buzzer
    
    void setup()
    {
      pinMode(buttonSocket, INPUT);
      pinMode(buzzerSocket, OUTPUT);
    }
    
    void loop()
    {
      if (digitalRead(buttonSocket)) {
        tone(buzzerSocket, 196);
        delay(600);
        tone(buzzerSocket, 329);
        delay(600);
        tone(buzzerSocket, 261);
        delay(600);
      } else {
        noTone(buzzerSocket);
      }
    }
    

    Observe

    Now press the button. You'll hear a 3 note chime.

    Modify

    By changing the notes and their duration you can put together your own doorbell melodies and chimes.

    Intruder Alarm

    Start 

    This project uses the light sensor as a different kind of trigger than the Robot Buddy. Here we will use some household materials to create a door activated alarm.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    Light x 1
    Piezo Buzzer x 1
    Cable x 2

    Light Sensor 

    Take a cable and attach one end to the light sensor and the other to Analog socket A0.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the light sensor socket
    ... and the other into Analog socket A0

    Upload

    Upload the code below. This tutorial uses Analog socket A0. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    //Change here if you're using a different socket
    #define sensorSocket A0
    
    int val;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      val = analogRead(sensorSocket);
      Serial.println(val);
    }
    

    Observe

    Open up the Serial Plotter and move your hand or cardboard over the light sensor. Check out what values you can get. Look at the light value you get when the sensor is uncovered and covered. Remember those because we'll need them for the intruder alarm to work correctly.

    Uncovered
    Covered

    Buzzer 

    Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D6.

    Parts
    Take a cable...
    ... and unwrap it
    Plug one side into the buzzer socket
    ... and the other into Digital socket D6

    Upload

    Upload this code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    //Change here if you're using a different socket
    #define buzzerSocket 6
    
    void setup()
    {
      pinMode(buzzerSocket, OUTPUT);
    }
    
    void loop()
    {
      delay(2000);
      digitalWrite(buzzerSocket,HIGH);
      delay(100);
      digitalWrite(buzzerSocket,LOW);
    }
    

    Observe

    The buzzer will wait for a second before playing a quick chirp.

    Take a listen. It would be hard not toTake a listen. It would be hard not to

    Modify

    Change up the delays for a quicker or longer chirp sound.

    Intruder Alarm 

    Cover the light sensor before continuing.

    Upload

    Upload this code below. Add in your ambient or uncovered light value for the trigger.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    //If you use different sockets change them below
    #define buzzerSocket 6
    #define lightSensorSocket A0
    
    int lightValue;
    int trigger = 250;
    int alarms = 3;
    int alarmCount = 0;
    
    void setup()
    {
      pinMode(buzzerSocket, OUTPUT);
      Serial.begin(9600);
    }
    
    void loop()
    {
      lightValue = analogRead(lightSensorSocket);
      //Serial.println(lightValue);
      if (lightValue > trigger) {
        while (alarms > alarmCount) {
          Serial.println(alarms);
          digitalWrite(buzzerSocket, HIGH);
          delay(200);
          digitalWrite(buzzerSocket, LOW);
          delay(500);
          alarmCount++;
        }
        alarmCount = 0;
        delay(3000);
      }
    }
    

    Observe

    Uncover your light sensor and listen to that beautiful music? Let's transfer over to battery power with a 9 volt battery and install it.

    Covered alarm
    Let's check it
    Yeah it works
    Grab the USB cable
    Unplug the USB cable
    A battery with the included cable
    Let's go install

    Construction

    Use a piece of cardboard taped to a door frame to cover the sensor. Attach the electronics to the wall. When the door is opened the sensor will move and no longer be covered. This triggers the alarm.

    I've found a door
    Cardboard? Check
    Line it up with the bottom of the door
    Take a piece of tape
    Attach it to the cardboard
    Tape it to the door
    You might need more than one piece of tape
    Make sure the door closes
    The light sensor...
    ... should face the cardboard here
    Just like this
    Light sensor is right up against the cardboard trigger
    Take the battery...
    ... and plug it in
    Green led means the power is on
    Open the door and you should hear the chirps
    Closing the door resets the alarm
    Thermometer

    Start 

    Let's put together a thermometer to sense the temperature and hook that up to a display.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    Temperature x 1
    Button x 1
    LCD Display x 1
    Cable x 3

    Temperature 

    Take a cable and unwrap it. Plug one side into the temperature sensor socket and the other into Analog socket A0.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the temperature sensor socket
    ... and the other into Analog socket A0

    Upload

    Upload the code below. This tutorial uses Analog socket A0. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    #include <math.h>
    
    //Change here if you're using a different socket
    #define tempSensorSocket A0
    
    int temp;
    
    const int B = 4275; // B value of the thermistor;
    const int R0 = 100000; // R0 = 100k;
    
    void setup()
    {
      Serial.begin(9600);
    }
    
    void loop()
    {
      temp = 1.0/(log(1023.0/analogRead(tempSensorSocket)-1.0)/B+1/298.15)-273.15;
      Serial.println(temp);
    }
    

    Observe

    Open up the Serial Monitor and check out the current temperature in Celsius.

    Modify

    Move the temperature sensor around and check out the different temperatures. Try putting it in a hot place and a cold place.

    Body temperature will bring it upBody temperature will bring it up

    Experiment

    See if you can detect the small changes in temperature within a room. The higher you place the sensor in the room, usually the higher the temperature because heat rises.

    Button 

    Take a cable and unwrap it. Plug one side into the button and the other into Digital socket D4.

    Take a cable...
    ... and unwrap it
    Plug one side into the button socket
    ... and the other into Digital socket D4

    Upload

    Upload the code shown below. This tutorial uses Digital socket 4. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    #include <math.h>
    
    //If you use different sockets change them below
    #define buttonSocket 4
    #define tempSensorSocket A0
    int temp;
    int tempC;
    
    const int B = 4275; // B value of the thermistor;
    const int R0 = 100000; // R0 = 100k;
    
    void setup()
    {
      pinMode(buttonSocket, INPUT);
      Serial.begin(9600);
    }
    
    void loop()
    {
      tempC = 1.0/(log(1023.0/analogRead(tempSensorSocket)-1.0)/B+1/298.15)-273.15;
      if (digitalRead(buttonSocket)) {
        Serial.println((far(tempC)));
      } else {
        Serial.println(tempC);
      }
    }
    
    int far(int temp) {
      return temp * 1.8 + 32;
    }
    

    Observe

    Open up the Serial Monitor and press the button. Watch the temperature reading change from Celsius to Fahrenheit. With higher temperatures the difference between the two units is larger.

    LCD Display 

    Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket.

    Take a cable...
    ... and unwrap it
    Plug one side into the LCD socket
    ... and the other into any I2C socket

    Upload

    Upload the code shown below.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    void setup()
    {
    lcd.begin(16, 2);
    lcd.setRGB(colorR, colorG, colorB);
    }
    
    void loop()
    {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0,0);
      lcd.print("This is a");
      lcd.setCursor(0,1);
      lcd.print("message");
      delay(1000);
      clearScreen();
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0,0);
      lcd.print("So is this");
      lcd.setCursor(0,1);
      lcd.print("");
      delay(1000);
      clearScreen();
    }
    
    void clearScreen(){
      lcd.setCursor(0,0);
      lcd.print("                ");
      lcd.setCursor(0,1);
      lcd.print("                ");
    }
    

    Observe

    Take a look at the two messages.

    One of the messagesOne of the messages

    Is The Screen Not Working?

    Double check that the switches found on the Seeeduino and base shield are set to 5V and not 3V3.

    Switch on the Seeeduino
    Switch on the Expansion Board

    Modify

    Change the messages and the delays associated with them.

    All together 

    By combining all these modules we can achieve our goal of a digital display thermometer.

    Upload

    Upload the code shown below.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    #include <math.h>
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    //If you use different sockets change them below
    #define buttonSocket 4
    #define tempSensorSocket A0
    
    int temp;
    
    int tempC;
    
    int far(int temp) {
      return temp * 1.8 + 32;
    }
    
    const int B = 4275; // B value of the thermistor;
    const int R0 = 100000; // R0 = 100k;
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    void setup()
    {
      pinMode(buttonSocket, INPUT);
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
    }
    
    void loop()
    {
      tempC = 1.0 / (log(1023.0 / analogRead(tempSensorSocket) - 1.0) / B + 1 / 298.15) - 273.15;
      if (digitalRead(buttonSocket)) {
        lcd.setRGB(colorR, colorG, colorB);
        lcd.setCursor(0, 0);
        lcd.print("Temp in C");
        lcd.setCursor(0, 1);
        lcd.print(tempC);
        delay(100);
      } else {
        lcd.setRGB(colorR, colorG, colorB);
        lcd.setCursor(0, 0);
        lcd.print("Temp in F");
        lcd.setCursor(0, 1);
        lcd.print((far(tempC)));
        delay(100);
      }
    }
    

    Observe

    With the display working you can unplug your thermometer from your computer and bring it anywhere on battery power. Pressing the button still switches the units.

    Ambient Temperature in Fahrenheit
    Ambient Temperature in Celsius
    Is it getting hot in here?
    Timer

    Start 

    This project yields a programmable timer.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    LCD Display x 1
    Button x 1
    Rotary potentiometer x 1
    Piezo Buzzer x 1
    Cable x 4

    A Countdown 

    Let's start with the most simple timer. Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket. Take another cable and unwrap it. Plug one side into the button socket and the other into Digital socket D6.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the LCD Display socket
    ... and the other into any I2C socket
    Take a cable...
    ... and unwrap it
    Plug one side into the button socket
    ... and the other into Digital socket D6

    Upload

    Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    //Change here if you're using a different socket
    #define buttonSocket 6
    
    int milliseconds;
    int Time;
    int seconds;
    
    int Seconds(int milliseconds) {
      seconds = milliseconds / 1000;
      return seconds;
    }
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    void setup()
    {
      pinMode(buttonSocket, INPUT);
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
      Serial.begin(9600);
    
    }
    
    void loop()
    {
      Serial.println(Time);
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Press to start:");
      lcd.setCursor(0, 1);
      lcd.print(" ");
      Time = 10;
      if (digitalRead(buttonSocket)) {
        while (Time > 0) {
          lcd.setRGB(colorR, colorG, colorB);
          lcd.setCursor(0, 0);
          lcd.print("Time remaining:");
          lcd.setCursor(0, 1);
          lcd.print("       ");
          lcd.setCursor(0, 1);
          lcd.print(Time);
          delay(1000);
          Time = Time - 1;
          Serial.println(Time);
        }
        while (!digitalRead(buttonSocket)) {
          lcd.setRGB(colorR, colorG, colorB);
          lcd.setCursor(0, 0);
          lcd.print("Time is up!     ");
          lcd.setCursor(0, 1);
          lcd.print("       ");
        }
        delay(100);
      }
    }
    
    

    Observe

    After pressing the button, the countdown will begin. The clock ticks down in seconds.

    The screen shows the starting text
    And with a press of the button...
    ... the countdown starts
    A message when the time is up

    Modify

    Changing the time value in the code will change the countdown.

    Adding Some Sound 

    Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D8.

    Take a cable...
    ... and unwrap it
    Plug one side into the buzzer socket
    ... and the other into Digital socket D8

    Upload

    Upload the code shown below. This tutorial uses Digital socket 8. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    //If you use different sockets change them below
    #define buttonSocket 6
    #define buzzerSocket 8
    
    int Time;
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    void setup()
    {
      pinMode(buttonSocket, INPUT);
      pinMode(buzzerSocket, OUTPUT);
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
    
    }
    
    void loop()
    {
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Press to start:");
      lcd.setCursor(0, 1);
      lcd.print(" ");
      Time = 10;
      digitalWrite(buzzerSocket, LOW);
      if (digitalRead(buttonSocket)) {
        while (Time > 0) {
          lcd.setRGB(colorR, colorG, colorB);
          lcd.setCursor(0, 0);
          lcd.print("Time remaining:");
          lcd.setCursor(0, 1);
          lcd.print("       ");
          lcd.setCursor(0, 1);
          lcd.print(Time);
          delay(1000);
          Time = Time - 1;
        }
        while (!digitalRead(buttonSocket)) {
          lcd.setRGB(colorR, colorG, colorB);
          lcd.setCursor(0, 0);
          lcd.print("Time is up!     ");
          lcd.setCursor(0, 1);
          lcd.print("       ");
          digitalWrite(buzzerSocket, HIGH);
        }
        delay(100);
      }
    }
    

    Observe

    When the timer has reached the end of its countdown, the buzzer turns on. A button press will reset it.

    Alarming!Alarming!

    Adding some control 

    Now we'll add a rotary potentiometer so we can set the timer amount without needing a computer. Take a cable and unwrap it. Plug one side into the rotary potentiometer and the other into Analog socket A3.

    Take a cable...
    ... and unwrap it
    Plug one side into the rotary potentiometer socket
    ... and the other into Analog socket A3

    Upload

    Upload the code below. This tutorial uses Analog socket A3. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    //Change here if you're using a different socket
    #define buttonSocket 6
    #define buzzerSocket 8
    #define dialSocket A3
    
    int Time;
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    void setup()
    {
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
    
      pinMode(buttonSocket, INPUT);
      pinMode(buzzerSocket, OUTPUT);
    }
    
    void loop()
    {
      digitalWrite(buzzerSocket, LOW);
      lcd.setRGB(colorR, colorG, colorB);
      lcd.setCursor(0, 0);
      lcd.print("Timer Amount:   ");
      lcd.setCursor(0, 1);
      lcd.print("       ");
      lcd.setCursor(0, 1);
      lcd.print((map(analogRead(dialSocket), 0, 1024, 0, 3600)));
      delay(100);
      if (digitalRead(buttonSocket)) {
        Time = (map(analogRead(dialSocket), 0, 1024, 0, 3600));
        while (Time > 0) {
          lcd.setRGB(colorR, colorG, colorB);
          lcd.setCursor(0, 0);
          lcd.print("Time remaining:");
          lcd.setCursor(0, 1);
          lcd.print("       ");
          lcd.setCursor(0, 1);
          lcd.print(Time);
          delay(1000);
          Time = Time - 1;
        }
        while (!digitalRead(buttonSocket)) {
          lcd.setRGB(colorR, colorG, colorB);
          lcd.setCursor(0, 0);
          lcd.print("Time is up!");
          lcd.setCursor(0, 1);
          lcd.print("       ");
          digitalWrite(buzzerSocket, HIGH);
        }
      }
    }
    
    

    Observe

    Now the timer amount can be set to any amount between 0 and 3600 seconds (one hour).

    Changeable!Changeable!

    Modify

    Changing the maxTime variable will change what time range can be chosen.

    LCD Backlight Disco

    Start 

    This project only uses the backlight from the LCD Display to create a disco party.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    LCD Display x 1
    Piezo Buzzer x 1
    Cable x 2

    Disco isn 

    Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the LCD Display socket
    ... and the other into any I2C socket

    Upload

    Upload the following code and let's start grooving.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    int delayTime = 100;
    
    void setup() {
      // put your setup code here, to run once:
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
      clearScreen();
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      lcd.setRGB(255 , 0, 0);
      delay(delayTime);
      lcd.setRGB(0 , 255, 0);
      delay(delayTime);
      lcd.setRGB(0 , 0, 255);
      delay(delayTime);
    }
    
    void clearScreen() {
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("                ");
    }
    

    Observe

    There isn't text being displayed on the display. This is normal for this code. You can see we aren't writing anything to it. Instead, we are just are just setting the backlight of the LCD Display.

    Red
    Green
    Blue

    Modify

    The backlight is following a pattern. With some different code we can make the pattern more random.

    Upload the code below to give that a try!

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    int delayTime = 100;
    
    void setup() {
      // put your setup code here, to run once:
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
      clearScreen();
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
      delay(delayTime);
      lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
      delay(delayTime);
      lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
      delay(delayTime);
    }
    
    void clearScreen() {
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("                ");
    }
    

    Experiment

    Change around some of the random set variables to see what kind of patterns you can make.

    Adding Some Sound 

    Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D6.

    Take a cable...
    ... and unwrap it
    Plug one side into the buzzer socket
    The other into Digital socket D6

    Upload

    Upload the following code. The example below uses the 6 digital socket. You can use any of them just remember to update the sketch.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    #include <Wire.h>
    #include "rgb_lcd.h"
    
    #define NOTE_C3  131
    #define NOTE_CS3 139
    #define NOTE_D3  147
    #define NOTE_DS3 156
    #define NOTE_E3  165
    #define NOTE_F3  175
    #define NOTE_FS3 185
    #define NOTE_G3  196
    #define NOTE_GS3 208
    #define NOTE_A3  220
    #define NOTE_AS3 233
    #define NOTE_B3  247
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    int delayTime = 100;
    
    //If you use a different socket for the buzzer update the number below
    #define buzzerSocket 6
    
    int notes[] = {NOTE_C3, NOTE_CS3, NOTE_D3, NOTE_DS3,
                   NOTE_E3, NOTE_F3, NOTE_FS3, NOTE_G3,
                   NOTE_GS3, NOTE_A3, NOTE_AS3, NOTE_B3
                  };
    
    void setup() {
      // put your setup code here, to run once:
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
      clearScreen();
    }
    
    //tone() = tone(pin number, note or frequency, duration of note/frequency);
    
    void loop() {
      // put your main code here, to run repeatedly:
      lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
      tone(buzzerSocket, notes[random(0, 12)], delayTime / 2);
      delay(delayTime);
      lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
      tone(buzzerSocket, notes[random(6, 12)], delayTime / 2);
      delay(delayTime);
      lcd.setRGB(random(0, 255) , random(0, 255), random(0, 255));
      tone(buzzerSocket, notes[random(0, 6)], delayTime / 2);
      delay(delayTime);
    }
    
    void clearScreen() {
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("                ");
    }
    

    Observe

    Now sounds play when the color switches.

    Analog Indicator

    Start 

    This project is a dial indicator. It takes a signal coming from a sensor and displays using the servo. It's an example of how a device that is normally an Actuator can be used as an Indicator.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    Servo x 1
    Light x 1
    Temperature x 1
    Sound x 1
    Cable x 3

    Trigger Values 

    The servo comes in a bag that also has a smaller bag of components in it. You'll need both for this project. Take the servo out as well as the small servo arm and a screw for it. One of the longer screws is better. Take the servo arm and servo and connect them. The arm should be pointing up with none of it hanging off the servo body. After unwrapping the servo cable, plug it in to Digital socket D6. For this example we'll be using the light sensor. Take a cable and attach one end to the light sensor and the other to Analog socket A0.

    All the part you'll need
    Open the plastic bag
    Take out the bag of parts inside...
    ... and the servo
    Open the smaller bag...
    Be careful! There are many little parts
    Take out the small 'Servo Arm'...
    ... and ...
    ... one longer screw
    Now we can get started
    Take the servo...
    ... and the 'Servo Arm'
    Line up the circles
    Place them together with the 'Servo Arm' pointing up on the servo body
    The 'Servo Arm' shouldn't be hanging off the servo body
    Take the wire around the servo...
    ... and unwrap it
    Take the cable ...
    ... plug into Digital socket D6
    Plug in the light sensor to Analog socket A0

    Upload

    Upload the code shown below. This tutorial uses Analog socket A0. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    //Change here if you're using a different socket
    #define sensorSocket A0
    
    int val;
    
    void setup() {
      Serial.begin(9600);
    }
    
    void loop() {
      val = analogRead(sensorSocket);
      Serial.println(val);
    }
    

    Observe

    Open the Serial Plotter and take note of what is the highest and lowest values. One will be when light is hitting it and the other is when the sensor is covered.

    Minimum
    Middle
    Maximum

    Modify

    Upload the code below. Change the trigger variables in lowTrigger and highTrigger . for the values you recorded.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    #include <Servo.h>
    
    //Change here if you're using a different socket
    #define sensorSocket A0
    #define servoSocket 6
    
    Servo indicatorServo;
    
    int val;
    int lowTrigger = 16;   //<- Change to YOUR measured value
    int highTrigger = 560; //<- Change to YOUR measured value
    
    void setup() {
      indicatorServo.attach(servoSocket);
    }
    
    void loop() {
      val = analogRead(sensorSocket);
      val = map(val,lowTrigger,highTrigger,179,1);
      indicatorServo.write(val);
      delay(1000);
    }
    

    Construction

    Recommended - PDF Template

    SVG Template

    AI Template

    Print out the template and assemble your old fashioned indicator. Find some cardboard and cut out the template. Disconnect the servo from its socket. Place it through the rectangle hole in the middle. Seat the servo and use some tape to keep it in place. Place another piece of tape behind the servo arm then attach the pointer. Use the screw from the beginning and screw it into the hole in the pointer and into the servo. With the construction complete, plug the servo back into the same socket. Check out your data streamed in real time.

    Printed out template and some spare cardboard
    Line it up
    Cut it out
    All cut out
    Disconnect the servo from its socket
    Place it through the rectangle hole in the middle
    Seat the servo
    Place a piece of tape...
    ... behind the servo arm
    Take the pointer
    Place it on top of the servo arm
    Tape it down
    Use the screw from the beginning
    Screw it into the hole in the pointer
    Into the servo
    Hand tighten is fine. A screwdriver is easier
    Almost done
    Take the servo cable
    Plug the servo back into the same socket
    A lot of light
    A little light
    Finished
    Music Machine

    Start 

    Using a couple of sensors, this project with change the pitch of a piezo buzzer to create a simple musical instrument.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    Piezo Buzzer x 1
    Rotary Potentiometer x 1
    Light x 1
    Button x 1
    Cable x 4

    Light based Theremin 

    A theremin is an electronic musical instrument that is controlled by moving your hands near the machine without actually touching it. Here we'll make something like that with a light sensor.

    Take a cable and unwrap it. Plug one side into the buzzer socket and the other into Digital socket D6 to start making music. Take another cable and attach one end to the light sensor and the other to Analog socket A0.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the buzzer socket
    The other into any Digital socket
    Take a cable...
    ... and unwrap it
    Plug one side into the light sensor socket
    The other into any Analog socket

    Upload

    Upload the code the below. This tutorial uses Analog socket A0 and Digital socket 6. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    #define NOTE_C3  131
    #define NOTE_CS3 139
    #define NOTE_D3  147
    #define NOTE_DS3 156
    #define NOTE_E3  165
    #define NOTE_F3  175
    #define NOTE_FS3 185
    #define NOTE_G3  196
    #define NOTE_GS3 208
    #define NOTE_A3  220
    #define NOTE_AS3 233
    #define NOTE_B3  247
    
    int notes[7] = {NOTE_C3, NOTE_D3, NOTE_E3,
                    NOTE_F3, NOTE_G3, NOTE_A3,
                    NOTE_B3
                   };
    
    #define buzzerSocket 6
    #define lightSensorSocket A0
    
    int lightMin = 350;  // <-- This should be the lowest value that you get from your light sensor.
    int lightMax = 750;  // <-- This should be the highest value that you get from your light sensor.
    int freq = 0;
    
    void setup() {
    
    }
    
    void loop() {
      freq = map(freq, lightMin, lightMax, 0, 6);  // Convert reading to note number between 0 and 6
      freq = constrain(freq, 0, 6);  // Make sure that the value stays between 0 and 6
    
      tone(buzzerSocket, notes[freq]);
    }
    

    Observe

    There isn't a lot of control here. It plays notes all the time. So let's add some.

    A Better Theremin 

    Take a cable and unwrap it. Plug one side into the rotary potentiometer and the other into Analog socket A1. Take another cable and attach one end to a button and the other to Digital socket D4.

    Take a cable...
    ... and unwrap it
    Plug one side into the rotary potentiometer socket
    The other into Analog socket A1
    Take a cable...
    ... and unwrap it
    Plug one side into the button socket
    The other into any Digital socket D4

    Upload

    Upload the code below. This tutorial uses Analog socket A1 and Digital socket 4. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    #define NOTE_B0  31
    #define NOTE_C1  33
    #define NOTE_CS1 35
    #define NOTE_D1  37
    #define NOTE_DS1 39
    #define NOTE_E1  41
    #define NOTE_F1  44
    #define NOTE_FS1 46
    #define NOTE_G1  49
    #define NOTE_GS1 52
    #define NOTE_A1  55
    #define NOTE_AS1 58
    #define NOTE_B1  62
    #define NOTE_C2  65
    #define NOTE_CS2 69
    #define NOTE_D2  73
    #define NOTE_DS2 78
    #define NOTE_E2  82
    #define NOTE_F2  87
    #define NOTE_FS2 93
    #define NOTE_G2  98
    #define NOTE_GS2 104
    #define NOTE_A2  110
    #define NOTE_AS2 117
    #define NOTE_B2  123
    #define NOTE_C3  131
    #define NOTE_CS3 139
    #define NOTE_D3  147
    #define NOTE_DS3 156
    #define NOTE_E3  165
    #define NOTE_F3  175
    #define NOTE_FS3 185
    #define NOTE_G3  196
    #define NOTE_GS3 208
    #define NOTE_A3  220
    #define NOTE_AS3 233
    #define NOTE_B3  247
    #define NOTE_C4  262
    #define NOTE_CS4 277
    #define NOTE_D4  294
    #define NOTE_DS4 311
    #define NOTE_E4  330
    #define NOTE_F4  349
    #define NOTE_FS4 370
    #define NOTE_G4  392
    #define NOTE_GS4 415
    #define NOTE_A4  440
    #define NOTE_AS4 466
    #define NOTE_B4  494
    #define NOTE_C5  523
    #define NOTE_CS5 554
    #define NOTE_D5  587
    #define NOTE_DS5 622
    #define NOTE_E5  659
    #define NOTE_F5  698
    #define NOTE_FS5 740
    #define NOTE_G5  784
    #define NOTE_GS5 831
    #define NOTE_A5  880
    #define NOTE_AS5 932
    #define NOTE_B5  988
    #define NOTE_C6  1047
    #define NOTE_CS6 1109
    #define NOTE_D6  1175
    #define NOTE_DS6 1245
    #define NOTE_E6  1319
    #define NOTE_F6  1397
    #define NOTE_FS6 1480
    #define NOTE_G6  1568
    #define NOTE_GS6 1661
    #define NOTE_A6  1760
    #define NOTE_AS6 1865
    #define NOTE_B6  1976
    #define NOTE_C7  2093
    #define NOTE_CS7 2217
    #define NOTE_D7  2349
    #define NOTE_DS7 2489
    #define NOTE_E7  2637
    #define NOTE_F7  2794
    #define NOTE_FS7 2960
    #define NOTE_G7  3136
    #define NOTE_GS7 3322
    #define NOTE_A7  3520
    #define NOTE_AS7 3729
    #define NOTE_B7  3951
    #define NOTE_C8  4186
    #define NOTE_CS8 4435
    #define NOTE_D8  4699
    #define NOTE_DS8 4978
    
    #define buttonSocket 4
    #define buzzerSocket 6
    #define lightSensorSocket A0
    #define dialSocket A1
    
    int noteMatrix[5][7] = {
      {NOTE_C2, NOTE_D2, NOTE_E2, NOTE_F2, NOTE_G2, NOTE_A2, NOTE_B2},
      {NOTE_C3, NOTE_D3, NOTE_E3, NOTE_F3, NOTE_G3, NOTE_A3, NOTE_B3},
      {NOTE_C4, NOTE_D4, NOTE_E4, NOTE_F4, NOTE_G4, NOTE_A4, NOTE_B4},
      {NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5},
      {NOTE_C6, NOTE_D6, NOTE_E6, NOTE_F6, NOTE_G6, NOTE_A6, NOTE_B6}
    };
    
    int freq = 0;
    int scale = 0;
    int lightMin = 350;
    int lightMax = 750;
    
    void setup() {
      // put your setup code here, to run once:
      pinMode(buttonSocket, INPUT);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      freq = analogRead(lightSensorSocket);
      freq = map(freq, lightMin, lightMax, 0, 6);
      freq = constrain(freq, 0, 6);
      scale = analogRead(dialSocket);
      scale = map(scale, 0, 1024, 0, 4);
    
      if (digitalRead(buttonSocket)) {
        tone(buzzerSocket, noteMatrix[freq][scale]);
      } else {
        noTone(buzzerSocket);
      }
    }
    

    Observe

    Now by using the one hand over the light sensor and another on the potentiometer and button we have access to more notes. The button plays the note. The potentiometer changes the octave. The light sensor changes the note and you control the music!

    FinishedFinished

    Simon Says

    Start 

    Using many inputs and some random instructions, this project recreates the feel of the classic Simon Says game.

    Modules 

    Gather the following parts to complete this project.

    Parts

    All Parts x Qty
    LCD Display x 1
    Button x 1
    Touch x 1
    Cable x 4

    OneButton 

    Take a cable and unwrap it. Plug one side into the LCD Display and the other into any I2C socket. Take another cable and attach one end to a button and the other to Digital socket D6.

    All the parts you'll need
    Take a cable...
    ... and unwrap it
    Plug one side into the LCD Display socket
    The other into any I2C socket
    Take a cable...
    ... and unwrap it
    Plug one side into the button socket
    The other into any Digital socket

    Upload

    Upload the code below. This tutorial uses Digital socket 6. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    #include <rgb_lcd.h>
    #include <OneButton.h>
    
    #define buttonSocket 6
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    OneButton button1(buttonSocket, false);
    
    void setup() {
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
    
      button1.attachClick(click1);
      button1.attachDoubleClick(doubleclick1);
      button1.attachLongPressStart(longPressStart1);
      button1.attachLongPressStop(longPressStop1);
      button1.attachDuringLongPress(longPress1);
    }
    
    void loop() {
      button1.tick();
      lcd.setCursor(0, 0);
      lcd.print("Press the Button");
    }
    
    
    void click1() {
      lcd.setCursor(0, 0);
      lcd.print("Button click    ");
      delay(1000);
    }
    
    
    void doubleclick1() {
      lcd.setCursor(0, 0);
      lcd.print("Button Doubleclk");
      delay(1000);
    }
    
    
    void longPressStart1() {
      lcd.setCursor(0, 0);
      lcd.print("Longpress Start ");
      delay(1000);
    }
    
    
    void longPress1() {
      lcd.setCursor(0, 0);
      lcd.print("Longpress Press ");
      delay(1000);
    }
    
    
    void longPressStop1() {
      lcd.setCursor(0, 0);
      lcd.print("Longpress Stop  ");
      delay(1000);
    }
    

    Observe

    Press the button once. Press the button twice. Hold it down. Check out all the features of the OneButton library. What was once a simple button now has many uses.

    Press the button
    Let's do it
    Holding the button down

    Simple Simon 

    Take a cable and attach one end to a touch sensor and the other to Digital socket D7.

    Take a cable...
    ... and unwrap it
    Plug one side into the touch socket
    The other into Digital socket D7

    Upload

    Upload the code below. This tutorial uses Digital socket 7. If you are using a different socket update the code after copying it.

    Download file Copy to clipboard
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    #include <rgb_lcd.h>
    #include <OneButton.h>
    
    #define buttonSocket 6
    #define touchSocket 7
    
    rgb_lcd lcd;
    const int colorR = 0;
    const int colorG = 0;
    const int colorB = 0;
    
    OneButton button(buttonSocket, false);
    OneButton touch(touchSocket, false);
    
    String actions[] = {"buttonSingle", "buttonDouble", "touchSingle", "touchDouble"};
    String currentAction = "";
    String actionTaken = "";
    
    
    void setup() {
      lcd.begin(16, 2);
      lcd.setRGB(colorR, colorG, colorB);
    
      button.attachClick(buttonSingle);
      button.attachDoubleClick(buttonDouble);
      touch.attachClick(touchSingle);
      touch.attachDoubleClick(touchDouble);
    
      currentAction = actions[random(0, 4)];
    
      lcd.setCursor(0, 0);
      lcd.print("Action To Do:");
      lcd.setCursor(0, 1);
      lcd.print(currentAction);
    }
    
    void loop() {
      button.tick();
      touch.tick();
    }
    
    
    void buttonSingle() {
      actionTaken = "buttonSingle";
      correctCheck();
    }
    
    void buttonDouble() {
      actionTaken = "buttonDouble";
      correctCheck();
    }
    
    void touchSingle() {
      actionTaken = "touchSingle";
      correctCheck();
    }
    
    void touchDouble() {
      actionTaken = "touchDouble";
      correctCheck();
    }
    
    void correctCheck() {
      if (currentAction == actionTaken) {
        clearScreen();
        lcd.setRGB(0, 255, 0);
        lcd.setCursor(0, 0);
        lcd.print("Correct!");
        lcd.setCursor(0, 1);
        lcd.print("Picking Action");
        delay(2000);
        lcd.setRGB(colorR, colorG, colorB);
        currentAction = actions[random(0, 4)];
        clearScreen();
        lcd.setCursor(0, 0);
        lcd.print("Action To Do:");
        lcd.setCursor(0, 1);
        lcd.print(currentAction);
      } else {
        lcd.setRGB(255, 0, 0);
        delay(500);
        lcd.setRGB(colorR, colorG, colorB);
      }
    }
    
    void clearScreen() {
      lcd.setCursor(0, 0);
      lcd.print("                ");
      lcd.setCursor(0, 1);
      lcd.print("                ");
    }
    

    Observe

    Follow the actions on screen. Green for correct and red for try again.

    An action is displayed
    Let's do it
    Correct!
    Wrong!

    Modify

    You can change the colors that the LCD Display uses.