We Speak PC
  • Home
  • Resources
  • Gallery

  •              Allen@wespeakpc.com
                 Call us: 972-704-5114

Arduino Programming and Electronics

Post Image

Project 5: Physical World Input

Let's expand on our interaction with the arduino. We are going to use a variable resistor (we can change the resistance manually), Have the arduino see the resistance and have it tell us the value of the resistance.

 

MATERIALS NEEDED:

Arduino & cable

Arduino & 10K Ohm Potentiometer (Variable resistor)

POTENTIOMETER

 

 

How to wire it up:

POT

THE PROJECT: (Reading and telling value)

Plug in your arduino and let's start.

1. Double-click the Arduino icon on your desktop.

2. Click on file, Save as , then give it the name SendMSG

3. Copy the following that is in red only. (Remember to be exact. Even the smallest mistake might make your program not work).  We will break it down as you write this program in normal ink since you should be familiar with most.

/*
My Project Name:  Potentiometer Value
What my project does:Checks the resistance value and tells us
*/

int R_Value = 0; //Anytime we have a variable, we want it to start somewhere so we pick a value of 0. we will change this value as you turn your Potentiometer.

void setup ( ) { //set up the Arduino to tell us the value of the resistor

Serial.begin(9600); //This sets up the Arduino to communicate with us. the 9600 is the speed at which it will talk to us, it is a standard # so don't change this value

} /* END SETUP */


void loop (){

R_Value = analogRead(A0); // Reads the current value of the resistor and saves it as the R_Value

Serial.println(R_Value); //this tells Arduino to print the value for us to see it

Delay(150); //We want to give it some time to think to make sure it is reading something stable the next time


} /* END LOOP FUNCTION */

***********************


Now it is time to see if it works.  Click in the check mark on the top left. If there are any errors it will start pointing them out to you.  if you just can’t figure it out please let me know and I will help you out.  once it says it is done, then click on the right arrow button next to it to copy your program from your computer to the Arduino board.

 

************VERY IMPORTANT************

Once the program is uploaded, you need to run the serial monitor in order to see the values change, to do this click on Tools from the menu then select Serial Monitor

Serial Monitor

You should see a window like the following

SerialMonitor

 

 

Activitie(s):

  1. Given the following example, can you make your LEDs blink based on the value of the resistor?

    if (R_Value >= 300) // Which means if the value of the resistor is greater than or equal to 300
    {
    DO SOMETHING
    }