Login Shopping cart Checkout Distributors Tutorials Gallery  


Search



Join our mail list

Email:

 Subscribe
 Unsubscribe

This tutorial explains how to connect analog sensors to an Arduino.  Analog means that the sensor gives a signal proportional to pressure or stretch. These types of sensors are resistive, so they change their resistance when the external action occours.

The analog signal will be converted in levels by the Arduino.  The Arduino works with 1024 levels, where level 0 is 0V, level 1023 is 5V.  This means that each level is fixed in 4.8 mV (milliVolt). That is the value of the maximum accuracy you will obtain from your system. For each increase (or decrease) in the input voltage of 4.8 mV the Arduino will add (or deduct) one level and it will store the total number of levels in a variable that has been defined by the user. 


What you need is:

- one Lilypad
- one FTDI board
- one USB A to mini B cable
- one analog textile press button or a stretch sensor
- 4 crocodile cables
- a 10 kOhm resistor
- a 1 kOhm resistor


This is the schematic to connect your analog sensor to the Lilypad: it uses one resistor, and a variable resistor, which is the sensor itself.

pulldown analog


Start by connecting the +5V pad of your Lilypad to your sensor. Sensors are not polarized, so it does not matter how you connect it.  This procedure is shown for an analog textile press button, but the same one could be applied for a stretch sensor.


Connect Lilypad to sensor

Then connect the output of the sensor to the analog input a0 of the Lilypad. You can choose which is the input you want to read in the program.
Connect sensor output to Lilypad


Then connect the output of the sensor to the 1 kOhm resistor.

connect sensor output to resistor



And the other terminal of the resistor to "-" pad on the Lilypad (black cable).

connect resitor to 0V


Plug the USB cable in your USB port of your laptop, and in the USB port of the FTDI board and copy, paste and upload the following program to the Lilypad:

int softPot = 0;    // this line selects the input pin a0 for the sensor
int ledPin = 13;      // this line selects the pin 13 for the LED output
int tempPot = 0;  // variable to store the value coming from the sensor

void setup() {
  // this line declares the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the value from the soft potentiometer
  tempPot = analogRead(softPot);  
  // it turns the LED on
  digitalWrite(ledPin, HIGH);
  // stop the program for <tempPot> milliseconds:
  delay(tempPot);        
  // turn the LED off:      
  digitalWrite(ledPin, LOW); 
  // stop the program for for <tempPot> milliseconds:
  delay(tempPot);                
}


Once completed you should see the LED on the Lilypad blinking. By pressing the button the LED should blink at a slower frequency.


blinking LED

 
Exercises:

1. Switch off and replace the 1 kOhm resistor with the 10 kOhm resistor and see the difference.
2. Switch off and swap the positions of the resistor and of the sensor in the schematic. See what has changed.



 

Currency

 


Shopping cart

There are no products in your shopping cart.

New products