// Copyright Luc Volders

// A small program that sends distance data over bluetooth
// Full working version for Arduino Nano
#include <SoftwareSerial.h>
/* Allows Pin Change Interrupt Vector Sharing */
#define TxD 0 //pin 5 from Attiny85 to pin RXD of the bluetooth module
#define RxD 1 //pin 6 from Attiny85 to pin TXD of the bluetooth module
SoftwareSerial blueToothSerial(RxD,TxD);
int trigPin = 2;
int echoPin = 3;
void setup()
{
pinMode(RxD, INPUT);
pinMode(TxD, OUTPUT);
blueToothSerial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
blueToothSerial.print("Distance is ");
blueToothSerial.println(distance);
delay(1000);
}

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.