Using A Smartphone's 3.5mm Audio Jack For Data Exchange
Using A Smartphone's 3.5mm Audio Jack For Data Exchange
Using A Smartphone's 3.5mm Audio Jack For Data Exchange
smartphone’s
3.5mm audio
jack for data
exchange
Android Ground
Analog IN
Arduino Pro Mini
USB
UNO
No USB
Two Version: 3.3V and 8 MHz or 5V and 16 MHz.
USB
MEGA
uUSB ADK
Arduino on the Web
http://arduino.cc
Getting Started with Arduino
(Make: Projects)
by Massimo Banzi,
Co-founder of the Arduino Project
Programming Arduino
Getting Started with Sketches
by Simon Monk
Copyright © 2012 Wolf Paulus
Setup Initialization const int ledPin = 13;
const int outPin = 11;
const int freq = 2000;
const int duration = 1000;
const int pause = 500;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(outPin, OUTPUT);
}
void loop() {
Main Loop
digitalWrite(ledPin, HIGH);
tone(outPin, freq);
delay(duration);
noTone(outPin);
digitalWrite(ledPin, LOW);
delay(pause);
}
10K
1uF
Gnd
2K 2K
H e l l o W
o r l d !
0x48 0x65 0x6C 0x6C 0x6F 0x20 0x57
0x6F 0x72 0x6C 0x64 0x21
Mapping Sensor Reading
to Frequency
ASCII: 45 .. 64
Frequency: 5,000 to 14,000
430.65 * C - 14211.45 Hz
4.
ACSII(‘?’) = 63 ➜ 12,919 Hz
ASCII(‘1’) = 49 ➜ 6,890 Hz
ASCII(‘5’) = 53 ➜ 8,613 Hz
ASCII(‘9’) = 57 ➜ 10,335 Hz
ASCII(’@’) = 64 ➜ 13,350 Hz
Copyright © 2012 Wolf Paulus http://wolfpaulus.com
Usable Frequency Range depends on the Hardware
Initialization
const int ledPin = 13; // built-in LED
const int outPin = 11; // PWM Port out
const int inPin = 0; // Light Sensor
const double FREQ_RES = (double) SAMPLE_RATE / SAMPLES; // 86.13 frq per bin
const int DURATION = (int) REPEAT * (1000 / FREQ_RES); // about 35ms
const int ENC_ETX = encodeAscii(ETX); // pre-calc for later use in loop
/**
* Encode the message into an frequency array
* Wrap the message into Start and End tags
*/
void encodeInt(int m) {
char message[5];
itoa( m,message,10 );
}
}
2 of 3
Encoding a single char and main loop
unsigned int encodeAscii(char c) {
return (unsigned int) ((5 * (c-45) + OFFSET) * FREQ_RES);
}
void loop() {
const int brightness = analogRead(inPin); // reads value 0-1023
encodeInt(brightness); // into global frq[]
digitalWrite(ledPin, HIGH);
int i=0;
do {
tone(outPin, frq[i]);
delay(DURATION);
noTone(outPin);
}
while (frq[i++] != ENC_ETX);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(brightness);
} 3 of 3
Copyright © 2012 Wolf Paulus http://wolfpaulus.com
Demo 2
• 512 Samples