Logo
  • Home
  • Equipment
  • Tutorials
  • Calendar
  • TPZ Staff Page
  • (Beta) Tech Ai Support
The Possible Zone
Fab Lab Website
Fab Lab Website
/
Tutorials
/
Main Tutorials Database
/Intro to Arduino
Intro to Arduino
Intro to Arduino
Intro to Arduino

Intro to Arduino

Project

Arduino electronics examples

Date Created
February 14, 2026
Author
U
Untitled
Tools & Skills
arduinoroboticscoding
[CoF] Careers of the Future
Technology
Launch Lab Connection
Competency
Problem SolvingSTEAM Agency
Status
Complete
  • Material List
  • Safety First
  • Circuit Safety
  • ✅ What to do
  • 🚫 What not to do
  • Introduction to the Arduino and Components
  • Getting to know Arduino
  • Make a basic LED circuit
  • Use a breadboard to connect your components
  • Getting started with Arduino
  • Getting Started with Arduino IDE
  • Connect LED to Arduino
  • Adding two LEDs
  • Adding & Reading Sensors
  • Working with Sensors
  • Using the Serial Monitor
  • Optional: Additional Sensors
  • NeoPixels (color LEDs)
  • DC motors & Fans
  • Servo Motor
  • Pressure Sensor (FSR)
  • Distance Sensor
  • Potentiometer (knob)
  • Flex Sensor
image

In this workshop, you’ll build simple circuits and write a little code to make lights and sensors do fun things. You’ll start with one blinking LED, then try a sensor that “notices” light. By the end, you’ll know how to:

  • Plug parts into a breadboard
  • Connect to the Arduino the right way
  • Upload code and see your project come to life
💡

You don’t need experience. We’ll go step by step.

Quick safety rules:

  • Unplug the USB cable before moving wires.
  • If something gets hot or smells weird, unplug right away and ask for help.
  • Do not connect an LED straight from 5V to GND without a resistor.
‣

Material List

Supplies
Quantity
URL
Arduino Uno (or compatible) + USB cable
1
Arduino boards
Laptop/desktop with Arduino IDE installed
1
Arduino IDE download
Breadboard
1
Jumper wires (assorted, M/M)
10+
LEDs (5mm or similar)
2+
220Ω resistor (for the 2nd LED example)
1
Photoresistor / photocell (LDR)
1
10kΩ resistor (pulldown for photoresistor)
2
Optional: NeoPixel strip (WS2812/NeoPixel)
1
Adafruit NeoPixel Library
Optional: Small DC motor or fan (3–6V)
1
Optional: Micro servo (e.g., SG90)
1
Optional: Pressure sensor (FSR)
1
Optional: Ultrasonic distance sensor (HC-SR04 or similar)
1
Optional: Jumper wires (F/F) for distance sensor
4
Optional: Potentiometer ("pot")
1
Adafruit Arduino Lesson 8: Analog Inputs
Optional: Flex sensor
1
Optional: Resistor for flex sensor circuit (22kΩ)
1

Safety First

Electronics are safe when you go slow and double-check your wires. If you are not sure, ask a staff member before plugging in.

Circuit Safety

✅ What to do

  • Unplug the USB cable before you move any wires.
  • Keep water and snacks away from the table.
  • If you are stuck, ask for help. Troubleshooting is part of making.

🚫 What not to do

  • Do not force parts into the board. If it does not fit, check the holes.
  • Do not put random wires into 5V and GND “to see what happens.”
  • Do not leave your project plugged in when you walk away.

Introduction to the Arduino and Components

In this step, you’ll get to know the Arduino and the parts you’ll use today. We’ll build circuits with LEDs and a breadboard.

‣

Getting to know Arduino

Arduino is a small computer that can control real-world stuff like lights, buzzers, and motors.

  • An input is something the Arduino reads (like a button or light sensor).
  • An output is something the Arduino controls (like an LED).

You tell the Arduino what to do by uploading code (your instructions) to the board.

Image shows picture of the database of Equipment in a grid view. The grid shows the image and name of the equipment.
Figure 1: Arduino Board
💡
Figure 2: Parts of Arduino
Figure 2: Parts of Arduino

Original Image from Elegoo

1.2 First Look Arduino.pdf3.3 MiB
‣

Make a basic LED circuit

A light-emitting diode or

LED

lights up when electricity passes through it. Because diodes only conduct electricity in one direction, it matters which lead of the LED is connected to the positive or negative poles of a battery.

To tell which lead of the LED is positive or negative, look at the length of each lead.

  • The positive lead is longer
  • The negative lead is shorter
  1. Place the battery between the LED legs.
  2. Touch the long leg (positive) to the battery side marked with a +.
  3. Touch the short leg (negative) to the other side of the battery.
Image shows picture of the database of Equipment in a grid view. The grid shows the image and name of the equipment.
Figure
image
⚠️

If the LED doesn't light up, make sure you didn't connect it backwards!

You have just created a circuit. A circuit is a loop that electricity can travel through.

  • Power is where electricity starts.
  • Ground (GND) is where it goes back.

If your circuit is not a full loop, nothing will turn on.

‣

Use a breadboard to connect your components

image

A breadboard is a plastic block with an array of small square holes. You can gently push the wire leads of LEDs or other components into the holes to make strong but temporary electrical connections. Use jumper wires to connect components on the breadboard to Arduino pins or to one another. Each numbered row of pins is connected by a metal strip inside the breadboard, so that electricity can flow between any wires you plug into any given row.

  • For example, in row 1, holes A through E are all interconnected. So are F through J. But note that the A-E group is not connected to F-J. The photo above shows why: the dark areas are metal which conducts electricity, and the white is plastic insulation.
  • ⚡

    Also note the long columns at either edge of the breadboard marked with red and blue lines. Each of these columns (sometimes called a bus) is one continuous connection. The buses are a handy place to connect the positive and negative sides of your power supply, since just about anything you put in the rows will need to be connected to power and ground.

    Conventionally, red indicates positive and blue or black indicates negative.

  1. Put your LED into the breadboard so the two legs are in different rows.
  2. Double-check that the LED legs are not in the same row.
  3. Remember which leg is positive (long) and which is negative (short).

Getting started with Arduino

In this step, you’ll open the Arduino app, plug in your board, and upload your first program to make an LED blink.

‣

Getting Started with Arduino IDE

  1. Open the Arduino IDE coding environment (If you need to install it, download it from the Arduino site.)
  2. image
  3. Connect the Arduino board to your laptop using a USB cable.
  4. Go to the Tools Menu, Click on Select Board and verify that "Arduino Uno" is selected.
  5. image
  6. Copy and paste the following code into your sketch:

This is the same code as in File → Examples → Basics → Blink, but with extra comments to help you understand it.

  1. Click Upload (the arrow button) to send the code to your Arduino.
  2. image
‣

Connect LED to Arduino

  1. Use jumper wires to connect the positive side (long leg) of your LED to pin 13 on the Arduino.
    • The jumper wires are all functionally the same, regardless of color …
    • … but conventionally, we use red for positive and black for ground. It's more standard, and it makes your circuit easy to "read"
  2. Connect the negative side of the LED to any GND (ground) pin on the Arduino.
Image shows picture of the database of Equipment in a grid view. The grid shows the image and name of the equipment.
Figure
❓

Read the code and see if you can tell what it's doing. How would you modify the code so that the LED blinks faster?

‣

Adding two LEDs

image
  1. Refer to the image above to connect a second LED.
    • Notice the 220 ohm resistor between the LED and Arduino pin 8.
    • As its name implies, the resistor is there to add resistance to the circuit. Without it, too much current would run out of the board and through the LED, and the Arduino will shut down.
    • We didn't need a resistor for the first LED because pin 13 already has a resistor built in.
    • Unlike LEDs, resistors have no polarity. You don't have to think about which leg is which.
    • In this diagram, both LEDs have their negative leads connected to the ground bus. Because the ground wires are all going to the same place, using the bus row minimizes the number of wires running between the breadboard and the Arduino. Your breadboard doesn't have to replicate the diagram exactly. What matters is the electrical path.

  2. Replace the entire contents of your sketch with the following code:
  • Note that we have created a new variable named led2 and set its value to 8.
  • This corresponds to Arduino pin 8, which you wired to the second LED.
  • Why store the pin number in a variable? Because it makes your code easier to edit later. If you want to use a different pin, you'll only have to change the one line where the value of led2 is set. Without the variable, you'd have to manually change every line that addresses the LED, and you might miss one!
‣

Optional: Resistors and Ohm's Law

This part is for curious minds. You do not need to memorize this to build projects today.

Big idea: A resistor is like a “speed bump” for electricity, so LEDs do not get too much current.

image

https://www.electronics-lab.com/article/light-emitting-diode/

The chart above gives you information about the different color LEDs.  They’re made out of different materials (first column) and the material determines the wavelength, or color, of the light that is emitted.  Within visible light, red is the longest and lowest energy wavelength, around 640 nanometers (0.000000640 meters), and blue is highest, around 480nm.  The voltage drop across the diode is given in the second column, it’s labelled “Vf at 20mA”. That’s giving the voltage across the diode (Vf stands for “V forward” meaning that current is flowing) when 20mA of current (0.020 Amps) is running through the LED.  So a red LED will light up when there is 20mA of current running through it and around 1.8V across it.  A blue one will have 3.6V across it when 20mA is running through it.  Why does this matter?

We know our circuit is a loop with current flowing out of a battery (or Arduino, or any power source), through a resistor, through the LED, and back into the battery.  With this Arduino, we know we supply 5V to the circuit.  A red LED wants 1.8V and 20mA of current.  That leaves

5V - 1.8V = 3.2V.  (If we try to give the whole 5V to the LED, too much current will flow, everything will heat up, and the Arduino will protect itself by shutting down.)

So our job in selecting a resistor is to pick a value of resistance that will have 3.2V drop across it when around 20mA runs through it.  We can use Ohm’s Law:

V = IR

Voltage = Current x Resistance.

Our voltage is 3.2 Volts, the current is 0.02 Amps.  What resistance do we need?

Resistance = 3.2 Volts/0.02 Amps = 160 Ohms

In reality, there’s a good bit of flexibility in the exact value.  We can have more or less than the 20mA of current, which will make the LED brighter or dimmer.  The resistor “resists” the current, so if you want the LED dimmer, increase the resistance.  If you want it brighter, then decrease the resistance.

There’s a lot more to learn to set up circuits and pick values, but this gives you a starting point.

Adding & Reading Sensors

A sensor helps your Arduino notice the world (like light or touch). In this section, you’ll use a sensor and make your Arduino react.

‣

Working with Sensors

A sensor is a part that measures something.

A photoresistor (also called a photocell) is a sensor that changes when it gets brighter or darker.

Now you will rewire your circuit to add the photoresistor.

image
image
  1. Add the photocell to the breadboard with one leg connected to the Arduino 5V pin (5 volts), and the other to Arduino analog input pin A0 as sketched below.
    • It does not matter which way you put the photoresistor in.
  2. Connect the red bus row to 5V.
  3. Add the 10kΩ resistor between A0 and GND.
    • This helps the Arduino get a steady reading.
  4. Copy and paste the following code into your sketch:
❓

What happens when you upload the new code? Put your finger on the photocell to block the light. What changes?

If nothing happened, don't worry. Let's use the serial monitor to view the light values the photoresistor is picking up.

‣

Using the Serial Monitor

The Serial Monitor is like a little window that lets the Arduino “talk” to you by printing numbers and messages. It helps you troubleshoot when things do not work yet.

  1. Click on the Serial Monitor icon in the upper right corner of the Arduino IDE window.
  2. image
  3. Watch the numbers in the serial monitor area.
    • On every iteration of the loop, the photocell's output is stored in a variable called lightValue. The Serial Monitor displays this number in real time.
    • The line of code that makes this happen is Serial.println( lightValue ).
    • When you place your finger over your photocell, you should see the numbers change.
    • If the number you see does not drop below 100, update your code to reflect this by changing the condition if ( lightValue < 100 ).
❓

How would you change the code so that the LED turns off when light hits the photocell?

Optional: Additional Sensors

These are extra challenges if you finish early. Pick one with a staff member.

‣

NeoPixels (color LEDs)

NeoPixels are LEDs that can light up in lots of colors.

‣
Step 1: Install the NeoPixel library
  1. Download the Adafruit_NeoPixel folder.
  2. Put it into your Arduino libraries folder.
  3. Close and reopen the Arduino app.
  4. Check: File → Examples should now include Adafruit NeoPixel.
  5. image
‣
Step 2: Wire the strip
  1. Connect GND to GND.
  2. Connect 5V to 5V.
  3. Connect DI to pin 6.
  4. image
‣
Step 3: Run code
  1. Open a NeoPixel example and upload it.
  2. Find a line like pixels.Color(0,150,0).
  3. Those numbers mean red, green, blue (0 to 255).
  4. Try changing the numbers to make new colors.
‣

DC motors & Fans

image
image

A fan is just a motor.

Wire it up

  1. Fan + (positive) → a PWM pin (try pin 9).
  2. Fan - (negative) → GND.

Run code

Open the Fade example: File → Examples → Basic → Fade

  • This makes the motor change speed slowly.
  • If your motor does not spin, ask a staff member.

This code will make the fan speed up and slow down continuously by varying the PWM signal sent to pin 9. You can adjust the fadeAmount and delay() values to change how quickly the fan speeds up or slows down.

‣

Explore more

❓

You will notice that you can also get the motor to run at its fullest when plugged directly into 5V.

Why is this?

The speed of the fan is determined by the current through the fan. The 5V pin can source a higher current than the digital pins. But the digital pins give us control to turn the fan on and off. So what can we do to turn on and off the fan with higher current?

We can use a component called a transistor. A transistor acts like an electronic switch. It has three connections. One goes to the digital pin, controlling the switch. The other two are basically the path for current through the fan. One goes to 5V (from the arduino or another power source if you need even more current). The other completes the pathway for current, for example connecting to the fan and then ground. The exact setup depends on the transistor.

Challenge: Hook up a potentiometer and use it to control the speed of the fan.

https://circuitdigest.com/microcontroller-projects/dc-motor-speed-control-using-arduino-and-potentiometer

‣

Servo Motor

image

A servo is a motor that can point to different angles.

‣
Wire it up (check your servo colors first)
  • Red → 5V
  • Brown/Black → GND
  • Yellow/White → pin ~9
image

Arduino Sketch:

‣

Pressure Sensor (FSR)

This sensor changes when you press it.

We will use a PWM pin so the LED can get brighter and dimmer.

Wiring Your Pressure Sensor

  1. Connect one end of the FSR (Force Sensitive Resistor) to 5V
  2. Connect the other end to Analog pin 0
  3. Connect one end of a 10K resistor from Analog 0 to ground
  4. Connect an LED from pin 11 (a PWM pin) through a resistor to ground
  5. image

Running the Code

Press the sensor and watch the LED.

Press harder and the LED should get brighter.

Open the Serial Monitor to see the numbers change too!

‣

Distance Sensor

image

Wiring Your Distance Sensor

  1. Place the Distance sensor on the breadboard so that its pins span 4 rows
  2. Place one F/F wire in each of the four rows
  3. Connect the wire placed in the same row as the VCC pin of the distance sensor to the 5V pin
  4. Similarly connect GND to GND next to the 5V pin, Trig to pin 2, and Echo to pin ~3
  5. image

Arduino Sketch:

  1. Upload the code.
  2. Hold your hand in front of the sensor.
  3. Watch the numbers in the Serial Monitor.
    • Those numbers are the distance (in centimeters).
‣

Potentiometer (knob)

A potentiometer is a knob you can turn.

When you turn it, the Arduino reads a number that changes.

Demo from Adafruit

Wiring Your Potentiometer

  1. Connect one outer pin of the potentiometer to 5V
  2. Connect the other outer pin to GND
  3. Connect the middle pin (slider) to Analog pin A0
  4. image

Running the Code

  1. Load the following sketch onto your Arduino:
/*
Adafruit Arduino - Lesson 8. Analog Inputs
*/

int potPin = A0;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int reading = analogRead(potPin);
  Serial.println(reading);
  delay(500);
}
  1. Open the Serial Monitor.
  2. Turn the knob and watch the numbers change between 0 and 1023.
    • The Serial Monitor is showing the analog reading from A0.
    • The voltage at A0 is being turned into a number between 0 and 1023.
    • image

Source: Adafruit Arduino Lesson 8. Analog Inputs

‣

Flex Sensor

A flex sensor changes when it bends.

‣
Wire it up
  1. Put the flex sensor legs into the breadboard (so each leg is in a different row).
  2. One leg → 5V.
  3. The other leg → A0.
  4. Add a 22kΩ resistor from A0 to GND.
image
image

Arduino Sketch: Upload this code and look at the readings you get from bending the sensor.

Bend the sensor and watch the numbers.

Write down:

  • The number when it is straight
  • The number when it is bent a lot

You will use those numbers to “calibrate” your project. The following code is where we will modify this.

int flex0to100 = map(flexSensorReading, 154, 479, 0, 100);
  1. Change this line so it uses your straight and bent numbers:
int flex0to100 = map(flexSensorReading, value when not bent, value when most bent, 0, 100);
  1. After you have a good 0–100 scale, try using flex0to100 to control something else (like an LED brightness or a vibrating motor).
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
// Lines that begin with 2 slashes like this one are COMMENTS. 
// The computer ignores the comment lines. Use them to make notes 
// for your future self about what the code is doing.
/*
You can also "comment out" multiple lines by enclosing them between the slash-asterisk and asterisk-slash, as shown here
*/
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;
// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}
// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}
/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led1 = 13;
int led2 = 8;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led1, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(led2, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                // wait for a second

  digitalWrite(led1, LOW);    // turn the LED off by making the voltage LOW
  digitalWrite(led2, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                // wait for a second
}
int lightPin = A0;  //define a pin for Photoresistor (input)
int ledPin = 13; // the pin for the led (output)


void setup()
{
    Serial.begin(9600);  //Begin serial communication
    pinMode( lightPin, INPUT );
    pinMode( ledPin, OUTPUT );
}
void loop()
{
    int lightValue = analogRead( lightPin );
    Serial.println( lightValue ); //Write the value of the photoresistor to the serial monitor.
    // if there is not enough light
    if ( lightValue < 100 ){
       // turn on the LED
       digitalWrite( ledPin, HIGH );
     }
    else{
       // otherwise, turn it off
       digitalWrite( ledPin, LOW );
      }
    delay(10); //short delay for faster response to light
}
/*
  Fade
  This example shows how to fade an LED on pin 9 using the analogWrite()
  function.
  The analogWrite() function uses PWM, so if you want to change the pin you're
  using, be sure to use another PWM capable pin. On most Arduino, the PWM pins
  are identified with a "~" sign, like ~3, ~5, ~6, ~9, ~10 and ~11.
  This example code is in the public domain.
  http://www.arduino.cc/en/Tutorial/Fade
*/
int led = 9;           // the PWM pin the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by
// the setup routine runs once when you press reset:
void setup() {
  // declare pin 9 to be an output:
  pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);
  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;
  // reverse the direction of the fading at the ends of the fade:
  if (brightness &lt;= 0 || brightness &gt;= 255) {
    fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(200);
}
int pwmPin = 12; // assigns pin 12 to variable pwm
int pot = A0; // assigns analog input A0 to variable pot
int c1 = 0;   // declares variable c1
int c2 = 0;   // declares variable c2
void setup() {
  pinMode(pwmPin, OUTPUT); 
  pinMode(pot, INPUT);  
}
void loop() {
  c2= analogRead(pot); 
  c1= 1024-c2;         // subtracts c2 from 1000 ans saves the result in c1
  digitalWrite(pwmPin, HIGH); 
  delayMicroseconds(c1);   
  digitalWrite(pwmPin, LOW);  
  delayMicroseconds(c2);  
}
/*
Into Robotics
*/
 
#include <Servo.h>
 
int servoPin = 9;
 
Servo servo;  
 
int servoAngle = 0;   // servo position in degrees
 
void setup()
{
  Serial.begin(9600);  
  servo.attach(servoPin);
}


void loop()
{
//control the servo's direction and the position of the motor
   servo.write(0);      // Turn SG90 servo Left to 45 degrees
   delay(1000);          // Wait 1 second
   servo.write(90);      // Turn SG90 servo back to 90 degrees (center position)
   delay(1000);          // Wait 1 second
   servo.write(180);     // Turn SG90 servo Right to 135 degrees
   delay(1000);          // Wait 1 second
   servo.write(90);      // Turn SG90 servo back to 90 degrees (center position)
   delay(1000);
//end control the servo's direction and the position of the motor
//control the servo's speed  
//if you change the delay value (from example change 50 to 10), the speed of the servo changes
//  for(servoAngle = 0; servoAngle < 180; servoAngle++)  //move the micro servo from 0 degrees to 180 degrees
//  {                                  
//    servo.write(servoAngle);              
//    delay(50);                  
//  }
//
//  for(servoAngle = 180; servoAngle > 0; servoAngle--)  //now move back the micro servo from 0 degrees to 180 degrees
//  {                                
//    servo.write(servoAngle);          
//    delay(10);      
//  }
  //end control the servo's speed  
}
/* FSR testing sketch. 
 
Connect one end of FSR to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground 
 
For more information see www.ladyada.net/learn/sensors/fsr.html */
 
int fsrAnalogPin = 0; // FSR is connected to analog 0
int LEDpin = 11;      // connect Red LED to pin 11 (PWM pin)
int fsrReading;      // the analog reading from the FSR resistor divider
int LEDbrightness;
 
void setup(void) {
  Serial.begin(9600); // We'll send debugging information via the Serial monitor
  pinMode(LEDpin, OUTPUT);
}
void loop(void) {
  fsrReading = analogRead(fsrAnalogPin);
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
 
  // we'll need to change the range from the analog reading (0-1023) down to the range
  // used by analogWrite (0-255) with map!
  LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
  // LED gets brighter the harder you press
  analogWrite(LEDpin, LEDbrightness);
 
  delay(100);
}
// set up the range finder, HC-SR04
int rangeTriggerPin = 2;
int rangeEchoPin = 3;
long currentDistance; // (cm) 
/** 
 * initialization code, happens once
 **/
void setup() 
{
  // for printing
  Serial.begin( 9600 );
 
  // set up the range finder
  pinMode(rangeTriggerPin, OUTPUT);
  pinMode(rangeEchoPin, INPUT);
}
/**
 * loops after setup
 **/
void loop() 
{ 
  // get current distance
  currentDistance = senseCurrentDistance();
  
  // print it out
  Serial.println( currentDistance );
  
  // wait a little before next iteration
  delay( 500 );
}
/**
 * Use the range finder to determine distance to the 
 * closest object. 
 **/
long senseCurrentDistance() 
{
  // The PING is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  digitalWrite(rangeTriggerPin, LOW);
  delayMicroseconds(2);
  digitalWrite(rangeTriggerPin, HIGH);
  delayMicroseconds(5);
  digitalWrite(rangeTriggerPin, LOW);
  // A different pin is used to read the signal from the PING: a HIGH
// pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  long duration = pulseIn(rangeEchoPin, HIGH);
  
  return microsecondsToCentimeters( duration );
}
/** 
 * Determine the distance based on how long it took to echo back.
 **/
long microsecondsToCentimeters(long microseconds)
{
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;
}
int flexSensorPin = A0; //analog pin 0
void setup(){
  Serial.begin(9600);
}
void loop(){
  int flexSensorReading = analogRead(flexSensorPin); 
  //Serial.println(flexSensorReading);
  //In my tests I was getting a reading on the arduino between 154, and 479. 
  //Using map(), you can convert that to a larger range like 0-100. 
  //To find your range uncomment the top serial print
  //comment out the one below and then bend your sensor in every direction
  // and see what minimum and maximum values you get and then use them below
  
  int flex0to100 = map(flexSensorReading, 154, 479, 0, 100);
  Serial.println(flex0to100);
  delay(250); //just here to slow down the output for easier reading
}