Add Ultrasonic (HC-SR04) code
This commit is contained in:
parent
ab7d406f0a
commit
2c748ea18a
Binary file not shown.
|
@ -0,0 +1,187 @@
|
||||||
|
:100000000C9462000C948A000C948A000C948A0070
|
||||||
|
:100010000C948A000C948A000C948A000C948A0038
|
||||||
|
:100020000C948A000C948A000C948A000C948A0028
|
||||||
|
:100030000C948A000C948A000C948A000C948A0018
|
||||||
|
:100040000C94DE020C948A000C94AC020C94860290
|
||||||
|
:100050000C948A000C948A000C948A000C948A00F8
|
||||||
|
:100060000C948A000C948A000000000024002700F1
|
||||||
|
:100070002A0000000000250028002B0000000008D6
|
||||||
|
:10008000000201000003040700000000000000005F
|
||||||
|
:1000900000000000230026002900040404040404D6
|
||||||
|
:1000A0000404020202020202030303030303010227
|
||||||
|
:1000B00004081020408001020408102001020408F6
|
||||||
|
:1000C00010206D0311241FBECFEFD8E0DEBFCDBFDF
|
||||||
|
:1000D00011E0A0E0B1E0E0E7FBE002C005900D9286
|
||||||
|
:1000E000A432B107D9F721E0A4E2B1E001C01D922A
|
||||||
|
:1000F000AF3DB207E1F710E0C2E6D0E004C02197BF
|
||||||
|
:10010000FE010E94A105C136D107C9F70E94B903BB
|
||||||
|
:100110000C94B6050C940000AF92BF92CF92DF9280
|
||||||
|
:10012000EF92FF920F931F93CF93DF936C017B01AC
|
||||||
|
:100130008B01040F151FEB015E01AE18BF08C0173D
|
||||||
|
:10014000D10759F06991D601ED91FC910190F081B0
|
||||||
|
:10015000E02DC6010995892B79F7C501DF91CF9173
|
||||||
|
:100160001F910F91FF90EF90DF90CF90BF90AF90D5
|
||||||
|
:100170000895FC01538D448D252F30E0842F90E0AD
|
||||||
|
:10018000821B930B541710F0CF9608950197089592
|
||||||
|
:10019000FC01918D828D981761F0A28DAE0FBF2F5B
|
||||||
|
:1001A000B11D5D968C91928D9F5F9F73928F90E0B1
|
||||||
|
:1001B00008958FEF9FEF0895FC01918D828D981720
|
||||||
|
:1001C00031F0828DE80FF11D858D90E008958FEF5D
|
||||||
|
:1001D0009FEF0895FC01918D228D892F90E0805C26
|
||||||
|
:1001E0009F4F821B91098F739927089581E391E0B6
|
||||||
|
:1001F0000E94EA0021E0892B09F420E0822F089573
|
||||||
|
:1002000080E090E0892B29F00E94F60081110C9487
|
||||||
|
:1002100000000895FC01A48DA80FB92FB11DA35AA9
|
||||||
|
:10022000BF4F2C91848D90E001968F739927848F16
|
||||||
|
:10023000A689B7892C93A089B1898C918370806439
|
||||||
|
:100240008C93938D848D981306C00288F389E02DDA
|
||||||
|
:1002500080818F7D80830895EF92FF920F931F938B
|
||||||
|
:10026000CF93DF93EC0181E0888F9B8D8C8D981369
|
||||||
|
:100270001AC0E889F989808185FF15C09FB7F89475
|
||||||
|
:10028000EE89FF896083E889F989808183708064C1
|
||||||
|
:1002900080839FBF81E090E0DF91CF911F910F910C
|
||||||
|
:1002A000FF90EF900895F62E0B8D10E00F5F1F4F1B
|
||||||
|
:1002B0000F731127E02E8C8D8E110CC00FB607FC2A
|
||||||
|
:1002C000FACFE889F989808185FFF5CFCE010E94B8
|
||||||
|
:1002D0000A01F1CFEB8DEC0FFD2FF11DE35AFF4F1B
|
||||||
|
:1002E000F0829FB7F8940B8FEA89FB898081806246
|
||||||
|
:1002F000CFCFCF93DF93EC01888D8823B9F0AA8903
|
||||||
|
:10030000BB89E889F9898C9185FD03C0808186FDD0
|
||||||
|
:100310000DC00FB607FCF7CF8C9185FFF2CF80811F
|
||||||
|
:1003200085FFEDCFCE010E940A01E9CFDF91CF9189
|
||||||
|
:10033000089590E0FC01E458FF4F2491FC01E25540
|
||||||
|
:10034000FF4F3491FC01E656FF4FE491EE23C9F0D4
|
||||||
|
:10035000222339F0233001F1A8F4213019F12230A1
|
||||||
|
:1003600029F1F0E0EE0FFF1FEE58FF4FA591B49179
|
||||||
|
:100370008FB7F894EC91611126C030953E233C93E1
|
||||||
|
:100380008FBF08952730A9F02830C9F0243049F7ED
|
||||||
|
:10039000809180008F7D03C0809180008F77809353
|
||||||
|
:1003A0008000DFCF84B58F7784BDDBCF84B58F7DB0
|
||||||
|
:1003B000FBCF8091B0008F778093B000D2CF809137
|
||||||
|
:1003C000B0008F7DF9CF3E2BDACFCF93DF9390E053
|
||||||
|
:1003D000FC01E255FF4F249186569F4FFC0184910A
|
||||||
|
:1003E0008823D1F090E0880F991FFC01E859FF4F56
|
||||||
|
:1003F000A591B491FC01EE58FF4FC591D4916111C4
|
||||||
|
:100400000EC09FB7F8948C91E22FE0958E238C93C9
|
||||||
|
:100410002881E223E8839FBFDF91CF9108958FB7B2
|
||||||
|
:10042000F894EC91E22BEC938FBFF6CF3FB7F894A2
|
||||||
|
:100430008091290190912A01A0912B01B0912C016A
|
||||||
|
:1004400026B5A89B05C02F3F19F00196A11DB11D2F
|
||||||
|
:100450003FBFBA2FA92F982F8827BC01CD01620F6B
|
||||||
|
:10046000711D811D911D42E0660F771F881F991F26
|
||||||
|
:100470004A95D1F708958F929F92AF92BF92CF92F3
|
||||||
|
:10048000DF92EF92FF924B015C010E9416026B011A
|
||||||
|
:100490007C010E9416026C197D098E099F09683E35
|
||||||
|
:1004A000734081059105A8F321E0821A9108A10803
|
||||||
|
:1004B000B10888EEC80E83E0D81EE11CF11C81143F
|
||||||
|
:1004C0009104A104B10429F7FF90EF90DF90CF9041
|
||||||
|
:1004D000BF90AF909F908F90089560E083E00E945E
|
||||||
|
:1004E000990160E084E00E94990160E085E00C944D
|
||||||
|
:1004F0009901FC0101900020E9F73197AF01481BF9
|
||||||
|
:10050000590BBC0181E391E00C948C001F920F9277
|
||||||
|
:100510000FB60F9211242F933F934F935F936F93D6
|
||||||
|
:100520007F938F939F93AF93BF93EF93FF9381E359
|
||||||
|
:1005300091E00E940A01FF91EF91BF91AF919F91CD
|
||||||
|
:100540008F917F916F915F914F913F912F910F907C
|
||||||
|
:100550000FBE0F901F9018951F920F920FB60F921B
|
||||||
|
:1005600011242F938F939F93EF93FF93E091410179
|
||||||
|
:10057000F09142018081E0914701F091480182FDB4
|
||||||
|
:100580001BC0908180914A018F5F8F7320914B0136
|
||||||
|
:10059000821741F0E0914A01F0E0EF5CFE4F958F49
|
||||||
|
:1005A00080934A01FF91EF919F918F912F910F902E
|
||||||
|
:1005B0000FBE0F901F9018958081F4CF1F920F925D
|
||||||
|
:1005C0000FB60F9211242F933F938F939F93AF9366
|
||||||
|
:1005D000BF938091250190912601A0912701B091B0
|
||||||
|
:1005E00028013091240123E0230F2D3758F501967F
|
||||||
|
:1005F000A11DB11D20932401809325019093260114
|
||||||
|
:10060000A0932701B09328018091290190912A019C
|
||||||
|
:10061000A0912B01B0912C010196A11DB11D8093D9
|
||||||
|
:10062000290190932A01A0932B01B0932C01BF9133
|
||||||
|
:10063000AF919F918F913F912F910F900FBE0F908F
|
||||||
|
:100640001F90189526E8230F0296A11DB11DD2CF49
|
||||||
|
:10065000CF92DF92EF92FF920F931F93E82FF92F23
|
||||||
|
:1006600005C0015011092109310961F190819623DA
|
||||||
|
:100670009417B9F305C0015011092109310911F18D
|
||||||
|
:10068000908196239413F7CFC12CD12CE12CF12C1F
|
||||||
|
:100690000AC08FEFC81AD80AE80AF80A0C151D0517
|
||||||
|
:1006A0002E053F0579F080818623841791F36C2D08
|
||||||
|
:1006B0007D2D8E2D9F2D1F910F91FF90EF90DF903C
|
||||||
|
:1006C000CF90089560E070E080E090E01F910F917E
|
||||||
|
:1006D000FF90EF90DF90CF900895CF93DF93E1E309
|
||||||
|
:1006E000F1E01382128288EE93E0A0E0B0E0848310
|
||||||
|
:1006F0009583A683B78384E091E09183808385EC22
|
||||||
|
:1007000090E09587848784EC90E09787868780ECDB
|
||||||
|
:1007100090E0918B808B81EC90E0938B828B82ECCC
|
||||||
|
:1007200090E0958B848B86EC90E0978B868B118E76
|
||||||
|
:10073000128E138E148ECEECD1E089E090E09D8372
|
||||||
|
:100740008C8388E090E09F838E8360E089E00E9444
|
||||||
|
:10075000E50161E08E810E94E501188A87EE93E051
|
||||||
|
:10076000A0E0B0E08C879D87AE87BF87DF91CF91F7
|
||||||
|
:100770000895CF93DF93CDB7DEB7A1970FB6F89466
|
||||||
|
:10078000DEBF0FBECDBF789484B5826084BD84B5D2
|
||||||
|
:10079000816084BD85B5826085BD85B5816085BD7C
|
||||||
|
:1007A00080916E00816080936E0010928100809134
|
||||||
|
:1007B00081008260809381008091810081608093BC
|
||||||
|
:1007C0008100809180008160809380008091B100E1
|
||||||
|
:1007D00084608093B1008091B00081608093B0000C
|
||||||
|
:1007E00080917A00846080937A0080917A008260A0
|
||||||
|
:1007F00080937A0080917A00816080937A00809162
|
||||||
|
:100800007A00806880937A001092C100E0914101E3
|
||||||
|
:10081000F091420182E08083E0913D01F0913E0140
|
||||||
|
:100820001082E0913F01F09140018FEC80831092A3
|
||||||
|
:100830004901E0914501F091460186E08083E09115
|
||||||
|
:100840004301F0914401808180618083E091430104
|
||||||
|
:10085000F0914401808188608083E0914301F091B0
|
||||||
|
:100860004401808180688083E0914301F0914401DC
|
||||||
|
:1008700080818F7D808361E083E00E94E50161E0FB
|
||||||
|
:1008800084E00E94E50161E085E00E94E50160E00E
|
||||||
|
:1008900089E00E94E50161E088E00E94E50193E0C3
|
||||||
|
:1008A000A92EB12C23E2222E312C3AE0432E512CDA
|
||||||
|
:1008B000612C712C40E0842E40E0942E1092D601E1
|
||||||
|
:1008C0001092D7011092D8011092D90160E0809166
|
||||||
|
:1008D000D4010E949901C5010197F1F761E080916F
|
||||||
|
:1008E000D4010E949901C1010197F1F760E0809164
|
||||||
|
:1008F000D4010E949901C5010197F1F78091D201BD
|
||||||
|
:100900009091D3019927FC01E255FF4F6491FC01BE
|
||||||
|
:10091000E656FF4FE491F0E0EE0FFF1FE057FF4F68
|
||||||
|
:100920008591949100EF19E422E030E0462F0E9477
|
||||||
|
:1009300028036B017C01C114D104E104F10439F0F6
|
||||||
|
:100940008FEFC81AD80AE80AF80A9FE0F922C09285
|
||||||
|
:10095000D601D092D701E092D801F092D90169E195
|
||||||
|
:1009600070E080E090E00E943B02A4E6B0E0A701C6
|
||||||
|
:1009700096010E9496052AEF36E140E050E00E9481
|
||||||
|
:10098000770520932D0130932E0140932F01509332
|
||||||
|
:10099000300182E191E00E9479028EE191E00E94B3
|
||||||
|
:1009A0007902C0902D01D0902E01E0902F01F0909F
|
||||||
|
:1009B0003001F7FE56C06DE281E391E00E942C0108
|
||||||
|
:1009C00022273327A9012C193D094E095F0919A2D5
|
||||||
|
:1009D000FE01B1967F01CA01B901A30192010E94F3
|
||||||
|
:1009E0005505605DF70162937F01211531054105D1
|
||||||
|
:1009F000510589F7E114F10419F0C7010E94790249
|
||||||
|
:100A00008EE191E00E94790281E291E00E947902F8
|
||||||
|
:100A10008EE191E00E94790280912D0190912E014A
|
||||||
|
:100A2000A0912F01B091300188309105A105B10549
|
||||||
|
:100A300074F50E946D0260E083E00E94990164E613
|
||||||
|
:100A400070E080E090E00E943B028114910409F480
|
||||||
|
:100A500035CF0E94F600882309F430CF0E940000B1
|
||||||
|
:100A60002DCFA701960119A2CE0181967C01CA0162
|
||||||
|
:100A7000B901A30192010E945505605DF7016293DF
|
||||||
|
:100A80007F01211531054105510589F7B3CF0F9736
|
||||||
|
:100A9000A105B1052CF40E946D0260E084E0CDCF89
|
||||||
|
:100AA0000E946D0260E085E0C8CFA1E21A2EAA1B69
|
||||||
|
:100AB000BB1BFD010DC0AA1FBB1FEE1FFF1FA2170E
|
||||||
|
:100AC000B307E407F50720F0A21BB30BE40BF50B0B
|
||||||
|
:100AD000661F771F881F991F1A9469F76095709594
|
||||||
|
:100AE000809590959B01AC01BD01CF010895052E25
|
||||||
|
:100AF00097FB1EF400940E948E0557FD07D00E94BC
|
||||||
|
:100B0000550507FC03D04EF40C948E055095409586
|
||||||
|
:100B1000309521953F4F4F4F5F4F089590958095A9
|
||||||
|
:100B2000709561957F4F8F4F9F4F08950E94A70545
|
||||||
|
:100B3000A59F900DB49F900DA49F800D911D112431
|
||||||
|
:100B40000895EE0FFF1F0590F491E02D0994A29FE8
|
||||||
|
:100B5000B001B39FC001A39F700D811D1124911D91
|
||||||
|
:100B6000B29F700D811D1124911D0895F894FFCF3F
|
||||||
|
:100B7000000000002C018C00B9007901EA00C800D7
|
||||||
|
:100B8000DC0044697374616E6369613A20000D0A88
|
||||||
|
:040B900000636D0091
|
||||||
|
:00000001FF
|
|
@ -0,0 +1,47 @@
|
||||||
|
// Ultrasonic sensor
|
||||||
|
#include <SR04.h>
|
||||||
|
|
||||||
|
#define red 3
|
||||||
|
#define yellow 4
|
||||||
|
#define green 5
|
||||||
|
#define echo 9
|
||||||
|
#define trig 8
|
||||||
|
SR04 sr04 = SR04(echo, trig);
|
||||||
|
long length;
|
||||||
|
|
||||||
|
void turnOff() {
|
||||||
|
digitalWrite(red, LOW);
|
||||||
|
digitalWrite(yellow, LOW);
|
||||||
|
digitalWrite(green, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void turnOn(int LED) {
|
||||||
|
turnOff();
|
||||||
|
digitalWrite(LED, LOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
Serial.begin(9600);
|
||||||
|
pinMode(red, OUTPUT);
|
||||||
|
pinMode(yellow, OUTPUT);
|
||||||
|
pinMode(green, OUTPUT);
|
||||||
|
pinMode(echo, INPUT);
|
||||||
|
pinMode(trig, OUTPUT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
length = sr04.Distance();
|
||||||
|
Serial.println("Distancia: ");
|
||||||
|
Serial.println(length);
|
||||||
|
Serial.println("cm");
|
||||||
|
|
||||||
|
if(length < 8){
|
||||||
|
turnOn(red);
|
||||||
|
} else if (length < 15){
|
||||||
|
turnOn(yellow);
|
||||||
|
} else {
|
||||||
|
turnOn(green);
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(100);
|
||||||
|
}
|
Loading…
Reference in New Issue