by Hsiao-Ho Hsu

This PicBasic Pro sample reads a Merlin Systems Stretch Sensor in a .Wheatstone Bridge circuit. See also the Op Amp Bridge code sample.

Back to Stretch Sensor report.

DEFINE  ADC_BITS        10             ' Set number of bits in result
DEFINE  ADC_CLOCK       3          ' Set clock source (3=rc)
DEFINE  ADC_SAMPLEUS    20          ' Set sampling time in uS

SensorValue var word

'tx var portc.6
'rx var portc.7
n9600 con 16468

output portb.7
output portb.3

'for keyboard

' Set PORTA to all input
TRISA = %11111111
' Set up ADCON1
ADCON1 = %10000010


HIGH portb.3
'adding pull-down resistors tightens the range.
ADCin 0, sensorValue

if SensorValue < 500 then ' 500 is when you strecth a bit but not much.....
                          ' since our user may just be able to move a bit
high portb.7


low portb.7


'serout2 tx, n9600, [Dec sensorValue, 13,10 ]  'the only diff btwn this and
pause 50                                      'the other code is DEC(ascii cmnd)

Goto main

arduino code (modified from the Physical Computing Analog Lab)

const int ledPin = 9;       // pin that the LED is attached to

const int ledPin2 = 10;       // pin that the 2nd LED is attached to

int analogValue = 0;        // value read from the pot

int brightness = 0;         // PWM pin that the LED is on.

void setup() {

    // initialize serial communications at 9600 bps:


    // declare the led pin as an output:

    pinMode(ledPin, OUTPUT);

    pinMode(ledPin2, OUTPUT);


void loop() {

    analogValue = analogRead(A0);      // read the pot value

    brightness = analogValue /4;       //divide by 4 to fit in a byte

    analogWrite(ledPin, brightness);   // PWM the LED with the brightness value

    Serial.println(brightness);        // print the brightness value back to the serial monitor

if (analogValue < 500)

digitalWrite (ledPin2, HIGH);

} else {

digitalWrite (ledPin2, LOW);