鍩轰簬鍠墖姗焥tm32鐨勫湴闇囨帰娓櫒绯荤当 - 鐗╄伅缍� 宓屽叆寮忥紙鍚唬纰硷級

** 鍩轰簬鍠墖姗熺殑鍦伴渿鎺㈡脯鍣ㄧ郴绲� **

  • 闆e害绯绘暩锛�4鍒�
  • 宸ヤ綔閲忥細4鍒�
  • 鍓垫柊榛烇細3鍒�

1 绨′粙

鍩轰簬Arduino鍠墖姗熺殑鍔犻€熷害鍌虫劅鍦伴渿鎺㈡脯鍣紝浣跨敤3杌稿姞閫熷害瑷圓DXL335浣滅偤鍌虫劅鍣ㄤ締妾㈡脯鍦伴渿鐨勫偩鏂溿€侀~鍕曟垨浠讳綍闇囧嫊銆侫DXL335鍔犻€熷害瑷堣垏Arduino鍜孡CD椤ず灞忛€f帴妲嬫垚銆�

2 涓昏鍣ㄤ欢

  • Arduino Uno闁嬬櫦鏉�
  • ADXL335鍔犻€熷害瑷堟ā濉�
  • 1602娑叉櫠椤ず灞�
  • 铚傞炒鍣�
  • LED鎸囩ず鐕�

3 瀵︾従鏁堟灉

榛炴搳閬嬭锛屽湒褰㈠氨鏈冮枊濮嬮亱琛屻€傛悥鍕曞姞閫熷害瑷堝苟瑙€瀵熷湒琛ㄣ€�

4 纭欢瑷▓

3杌稿姞閫熷害瑷圓DXL335


瑭插姞閫熷害瑷堟ā濉婂熀浜庢祦琛岀殑ADXL335涓夎桓妯℃摤鍔犻€熷害瑷圛C锛岃┎IC璁€鍙朮銆乊鍜孼鍔犻€熷害浣滅偤妯℃摤闆诲銆傞€氶亷娓噺鐢变簬閲嶅姏寮曡捣鐨勫姞閫熷害锛屽姞閫熷害瑷堝彲浠ユ壘鍑虹浉灏嶄簬鍦扮悆鍌炬枩鐨勮搴︺€傞€氶亷妾㈡脯鍕曟厠鍔犻€熷害锛屽姞閫熷害瑷堝彲浠ユ壘鍑鸿ō鍌欑Щ鍕曠殑閫熷害鍜屾柟鍚戙€傚埄鐢ㄩ€欏叐鍊嬪爆鎬э紝鎮ㄥ彲浠ュ埗浣滃悇绋緢閰风殑闋呯洰锛屽緸妯傚櫒鍒版苯杌婏紙鎴栧厭绔ユ苯杌婏級涓婄殑閫熷害鐩h鍣ㄣ€傚姞閫熷害瑷堥潪甯稿鏄撲娇鐢�3鍊嬫ā鎿几鍏ュ紩鑵抽€f帴鍒癆rduino寰帶鍒跺櫒锛屽苟涓斿彲浠ヨ垏鍏朵粬澶у鏁稿井鎺у埗鍣紙渚嬪PIC鎴朅VR锛変竴璧蜂娇鐢ㄣ€�

鐗瑰緛锛�

  • 3V-6V DC闆绘簮闆诲
  • 鏉胯級LDO绌╁鍣�
  • 鍙互鑸�3V3鎴�5V鍠墖姗熼€f帴銆�
  • 瓒呬綆鍔熻€楋細娓噺妯″紡涓嬬偤40uA锛屽緟姗熸檪鐐�0.1uA
  • 鑷敱钀介珨妾㈡脯
  • 妯℃摤杓稿嚭

ADXL335鍔犻€熷害瑷堢殑宸ヤ綔鍘熺悊

鏈€甯哥敤鐨勮ō鍌欐槸澹撻浕鍔犻€熷害瑷堛€傞¨鍚嶆€濈京锛屽畠閲囩敤浜嗗闆绘晥鎳夊師鐞嗐€傝┎鍣ㄤ欢鐢卞闆荤煶鑻辨櫠楂旂祫鎴愶紝鍦ㄥ叾涓婃柦鍔犱簡瑕佹脯閲忓叾鍊肩殑鍔犻€熷姏銆�

鐢变簬鐗规畩鐨勮嚜鐢熺壒鎬э紝鏅堕珨鐢㈢敓鐨勯浕澹撹垏鍔犻€熷姏鎴愭姣斻€�


闆昏矾鍦栧拰閫f帴


5 閮ㄥ垎鏍稿績浠g⒓

#include<LiquidCrystal.h> // lcd Header LiquidCrystal lcd(7,6,5,4,3,2); // pins for LCD Connection #define buzzer 12 // buzzer pin #define led 13 //led pin #define x A0 // x_out pin of Accelerometer #define y A1 // y_out pin of Accelerometer #define z A2 // z_out pin of Accelerometer /*variables*/ int xsample=0; int ysample=0; int zsample=0; long start; int buz=0; /*Macros*/ #define samples 50 #define maxVal 20 // max change limit #define minVal -20 // min change limit #define buzTime 5000 // buzzer on time void setup() {
lcd.begin(16,2); //initializing lcd Serial.begin(9600); // initializing serial delay(1000);
lcd.print("EarthQuake ");
lcd.setCursor(0,1);
lcd.print("Detector ");
delay(2000);
lcd.clear();
lcd.print("Calibrating.....");
lcd.setCursor(0,1);
lcd.print("Please wait...");
pinMode(buzzer, OUTPUT);
pinMode(led, OUTPUT);
buz=0;
digitalWrite(buzzer, buz);
digitalWrite(led, buz); for(int i=0;i<samples;i++) // taking samples for calibration {
xsample+=analogRead(x);
ysample+=analogRead(y);
zsample+=analogRead(z);
}

xsample/=samples; // taking avg for x ysample/=samples; // taking avg for y zsample/=samples; // taking avg for z delay(3000);
lcd.clear();
lcd.print("Calibrated");
delay(1000);
lcd.clear();
lcd.print("Device Ready");
delay(1000);
lcd.clear();
lcd.print(" X Y Z ");
} void loop() { int value1=analogRead(x); // reading x out int value2=analogRead(y); //reading y out int value3=analogRead(z); //reading z out int xValue=xsample-value1; // finding change in x int yValue=ysample-value2; // finding change in y int zValue=zsample-value3; // finding change in z /*displying change in x,y and z axis values over lcd*/ lcd.setCursor(0,1);
lcd.print(xValue);
lcd.setCursor(6,1);
lcd.print(yValue);
lcd.setCursor(12,1);
lcd.print(zValue);
delay(100); /* comparing change with predefined limits*/ if(xValue < minVal || xValue > maxVal || yValue < minVal || yValue > maxVal || zValue < minVal || zValue > maxVal)
{ if(buz == 0)
start=millis(); // timer start buz=1; // buzzer / led flag activated } else if(buz == 1) // buzzer flag activated then alerting earthquake {
lcd.setCursor(0,0);
lcd.print("Earthquake Alert "); if(millis()>= start+buzTime)
buz=0;
} else {
lcd.clear();
lcd.print(" X Y Z ");
}

digitalWrite(buzzer, buz); // buzzer on and off command digitalWrite(led, buz); // led on and off command /*sending values to processing for plot over the graph*/ Serial.print("x=");
Serial.println(xValue);
Serial.print("y=");
Serial.println(yValue);
Serial.print("z=");
Serial.println(zValue);
Serial.println(" $");
} 
import processing.serial.*;
PFont f6,f8,f12,f10;
PFont f24;
Serial myPort; // The serial port int xPos = 0; // horizontal position of the graph float y1=0; float y2=0; float y3=0; void setup () { // set the window size: and Font size f6 = createFont("Arial",6,true);
f8 = createFont("Arial",8,true);
f10 = createFont("Arial",10,true);
f12 = createFont("Arial",12,true);
f24 = createFont("Arial",24,true);
size(1200, 700); // List all the available serial ports println(Serial.list());
myPort = new Serial(this, "COM10", 9600);
println(myPort);
myPort.bufferUntil('\n');
background(80);
} void draw () {
serial ();
} void serial() {
String inString = myPort.readStringUntil('$'); // reading incomming date from serial if (inString != null)
{ // extracting all required values of all three axis: int l1=inString.indexOf("x=")+2;
String temp1=inString.substring(l1,l1+3);
l1=inString.indexOf("y=")+2;
String temp2=inString.substring(l1,l1+3);
l1=inString.indexOf("z=")+2;
String temp3=inString.substring(l1,l1+3); //mapping x, y and z value with graph dimensions float inByte1 = float(temp1+(char)9);
inByte1 = map(inByte1, -80,80, 0, height-80); float inByte2 = float(temp2+(char)9);
inByte2 = map(inByte2,-80,80, 0, height-80); float inByte3 = float(temp3+(char)9);
inByte3 = map(inByte3,-80,80, 0, height-80); float x=map(xPos,0,1120,40,width-40); //ploting graph window, unit strokeWeight(2);
stroke(175);
Line(0,0,0,100);
textFont(f24);
fill(0,00,255);
textAlign(RIGHT);
xmargin("EarthQuake Graph (SESMIOGRAPH)",200,100);

fill(100);
strokeWeight(100);
line(1050,80,1200,80);

strokeWeight(1);
textAlign(RIGHT);
fill(0,0,255);
String temp="X:"+temp1;
Text(temp,100,95);

fill(0,255,0);
temp="Y:"+temp2;
Text(temp,100,92);

fill(255,0,0);;
temp="Z:"+temp3;
Text(temp,100,89); //ploting x y and z values over graph strokeWeight(2); int shift=40;

stroke(0,0,255); if(y1 == 0)
y1=height-inByte1-shift;
line(x, y1, x+2, height-inByte1-shift) ;
y1=height-inByte1-shift;

stroke(0,255,0); if(y2 == 0)
y2=height-inByte2-shift;
line(x, y2, x+2, height-inByte2-shift) ;
y2=height-inByte2-shift;

stroke(255,0,0); if(y2 == 0)
y3=height-inByte3-shift;
line(x, y3, x+2, height-inByte3-shift) ;
y3=height-inByte3-shift;

xPos+=1; if (x >= width-30) // go back to begining {
xPos = 0;
background(80);
}
}
} void Line(int x1, int y1, int x2, int y2) { float xx1=map(x1,0,100,40,width-40); float xx2=map(x2,0,100,40,width-40); float yy1=map(y1,0,100,height-40,40); float yy2=map(y2,0,100,height-40,40);

line(xx1,yy1,xx2,yy2);
xx2=map(100,0,100,40,width-40);
yy2=map(0,0,100,height-40,40);
line(xx1,yy1,xx2,yy2);

strokeWeight(1); for(int i=1;i<21;i++)
{
yy2=map(i*10,0,200,height-40,40);
yy1=yy2;
line(xx1,yy1,xx2,yy2);
}
yy2=map(100,0,100,height-40,40);
yy1=map(0,0,100,height-40,40); for(int i=1;i<41;i++)
{
xx1=map(i*5,0,200,40,width-40);
xx2=map(i*5,0,200,40,width-40);
line(xx1,yy1,xx2,yy2);
}

textAlign(RIGHT); // 100 degree // result+=yy1; fill(255);
strokeWeight(1);
textFont(f12); for(int i=-10;i<11;i++)
{
String result="";
result+=5*i;
ymargin(result, x1,y1);
y1+=5;
}

x1=0;
y1=0;
strokeWeight(1);
textFont(f10); for(int i=0;i<41;i++)
{
String result="";
result+=28*3*i;
xmargin(result, x1,y1);
x1+=5;
}

textAlign(RIGHT);

textAlign(RIGHT);
} void ymargin(String value, int x1, int y1) { float xx1=map(x1,0,100,40,width-40); float yy1=map(y1,0,100,height-40,40);
text(value,xx1-5,yy1+5);
} void xmargin(String value, int x1, int y1) { float xx1=map(x1,0,200,40,width-40); float yy1=map(y1,0,100,height-25,25);
text(value,xx1+7,yy1);
} void Text(String value, int x1, int y1) { float xx1=map(x1,0,100,40,width-40); float yy1=map(y1,0,100,height-25,25);
text(value,xx1,yy1);
} 

瀹屾暣浠g⒓鍙€茬兢鍏嶈不闋樺彇銆�

宓屽叆寮忕墿鑱恫鐨勫缈掍箣璺潪甯告极闀凤紝涓嶅皯浜哄洜鐐哄缈掕矾绶氫笉灏嶆垨鑰呭缈掑収瀹逛笉澶犲皥妤€岄尟澶遍珮钖猳ffer銆備笉閬庡垾鎿斿績锛屾垜鐐哄ぇ瀹舵暣鐞嗕簡涓€浠�150澶欸鐨勫缈掕硣婧愶紝鍩烘湰涓婃兜钃嬩簡宓屽叆寮忕墿鑱恫瀛哥繏鐨勬墍鏈夊収瀹广€傞粸鎿婁笅鏂归張鎺ワ紝0鍏冮牁鍙栧缈掕硣婧愶紝璁撲綘鐨勫缈掍箣璺洿鍔犻爢鏆紒瑷樺緱榛炶磰銆侀棞娉ㄣ€佹敹钘忋€佽綁鐧煎摝锛�

榛炴搳閫欓噷鎵惧皬鍔╃悊0鍏冮牁鍙栵細鎺冪⒓閫茬兢闋樿硣鏂�

the end

瑭曡珫锛�0锛�