项目作者: lastralab

项目描述 :
MIPT Arduino Devices and Ideas
高级语言: C++
项目地址: git://github.com/lastralab/Building-Arduino-Robots-and-Devices.git


Traffic Light

(Week 1):

Wiring:

screenshot 2017-02-13 09 12 14

Schematics:

screenshot 2017-02-13 10 34 45

Code:

  1. // Author: Niam Moltta
  2. // the setup routine runs once when you press reset:
  3. void setup() {
  4. // initialize the digital pin as an output.
  5. pinMode(8, OUTPUT);
  6. pinMode(10, OUTPUT);
  7. pinMode(12, OUTPUT);
  8. }
  9. void loop() {
  10. digitalWrite(8, HIGH); //red on
  11. delay(5000); //eight seconds
  12. digitalWrite(8, LOW); //red off
  13. digitalWrite(12, HIGH); //green on
  14. delay(5000); //three seconds
  15. digitalWrite(12, LOW); //green off
  16. delay(500);
  17. digitalWrite(12, HIGH); //green on
  18. delay(500); //one second
  19. digitalWrite(12, LOW); //green off
  20. delay(500);
  21. digitalWrite(12, HIGH); //green on
  22. delay(500); //one second
  23. digitalWrite(12, LOW); //green off
  24. delay(500);
  25. digitalWrite(12, HIGH); //green on
  26. delay(500); // one sec
  27. digitalWrite(12, LOW); //green off
  28. digitalWrite(10, HIGH); //yellow on
  29. delay(3000); //three sec
  30. digitalWrite(10, LOW); //yellow off
  31. //repeat from the beginning
  32. }

Demo:

Radar

(Week 3)

Build a sonar using arduino, a servo, and a ping and visualize it as a radar with Processing.

it deserved its own repository:
https://github.com/TaniaMol/ArduinoRadar

Ava’s Traffic Intersection

(Week 4):

screenshot 2017-02-10 10 54 37

Instructions:

Vehicle circulation can be blocked by the barrier if the train appears or the pedestrian presses the button for the green light.

The green light button is activated if there is no train approaching, and enough time (9 sec) has passed since the button was last activated.

The green light is activated for 5 seconds, which is followed by an intermittent beep. Then, the green light blinks for 3 seconds and the intermittent beep becomes more frequent. After that, the red light is activated again, and the timer counts the time from 0 to 9 seconds.

If the train appears when the green light is on for pedestrians, the red signal is activated urgently and a continuous beep of a different height can be heard.

You can imagine the intersection happening like this:

screenshot 2017-02-10 13 37 41

Black path is for cars, white & gray path is for the train and brown path is for people to cross.

While the train is passing, the switch cannot request a green light.

When the train comes again, the green light turns off and the red light turns on.

When the photoresistor is bright, that means the train is not passing but when you turn it dark, it means the train is passing.

Wiring:

screenshot 2017-02-12 22 09 27

Schematics:

screenshot 2017-02-13 09 48 36

Code that didn’t work and you are welcome to suggest any improvements:

  1. //Ava's TRAFFIC INTERSECTION
  2. //Author: Niam Moltta
  3. #include <Servo.h>
  4. #define SENSOR A0
  5. #define BUZZER 10
  6. #define BUTTON 9
  7. #define BARRIER 11
  8. #define GREEN 13
  9. #define RED 12
  10. int a = 2;
  11. int b = 3;
  12. int c = 4;
  13. int d = 5;
  14. int e = 6;
  15. int f = 7;
  16. int g = 8;
  17. int count;
  18. Servo myservo;
  19. void setup() {
  20. pinMode(SENSOR, INPUT); //photoresistor
  21. pinMode(BUZZER, OUTPUT);
  22. pinMode(BUTTON, INPUT);
  23. pinMode(BARRIER, OUTPUT); //servo
  24. pinMode(GREEN, OUTPUT);
  25. pinMode(RED, OUTPUT);
  26. pinMode(a, OUTPUT); //DISPLAY FROM 2 TO 9
  27. pinMode(b, OUTPUT);
  28. pinMode(c, OUTPUT);
  29. pinMode(d, OUTPUT);
  30. pinMode(e, OUTPUT);
  31. pinMode(f, OUTPUT);
  32. pinMode(g, OUTPUT);
  33. digitalWrite(BUTTON, HIGH);
  34. myservo.attach(BARRIER);
  35. Serial.begin(9600);
  36. }
  37. void loop() {
  38. int Train = analogRead(A0); // Value of photoresistor.
  39. int Button = digitalRead(BUTTON); // Request for crossing
  40. Serial.println(Train);
  41. delay(5); //print value to serial
  42. switch (count) {
  43. case 0:
  44. digitalWrite(a, LOW);
  45. digitalWrite(b, LOW);
  46. digitalWrite(c, LOW);
  47. digitalWrite(d, LOW);
  48. digitalWrite(e, LOW);
  49. digitalWrite(f, LOW);
  50. digitalWrite(g, HIGH);
  51. delay(1000);
  52. break;
  53. case 1:
  54. digitalWrite(a, HIGH);
  55. digitalWrite(b, LOW);
  56. digitalWrite(c, LOW);
  57. digitalWrite(d, HIGH);
  58. digitalWrite(e, HIGH);
  59. digitalWrite(f, HIGH);
  60. digitalWrite(g, HIGH);
  61. delay(1000);
  62. break;
  63. case 2:
  64. digitalWrite(a, LOW);
  65. digitalWrite(b, LOW);
  66. digitalWrite(c, HIGH);
  67. digitalWrite(d, LOW);
  68. digitalWrite(e, LOW);
  69. digitalWrite(f, HIGH);
  70. digitalWrite(g, LOW);
  71. delay(1000);
  72. break;
  73. case 3:
  74. digitalWrite(a, LOW);
  75. digitalWrite(b, LOW);
  76. digitalWrite(c, LOW);
  77. digitalWrite(d, LOW);
  78. digitalWrite(e, HIGH);
  79. digitalWrite(f, HIGH);
  80. digitalWrite(g, LOW);
  81. delay(1000);
  82. break;
  83. case 4:
  84. digitalWrite(a, HIGH);
  85. digitalWrite(b, LOW);
  86. digitalWrite(c, LOW);
  87. digitalWrite(d, HIGH);
  88. digitalWrite(e, HIGH);
  89. digitalWrite(f, LOW);
  90. digitalWrite(g, LOW);
  91. delay(1000);
  92. break;
  93. case 5:
  94. digitalWrite(a, LOW);
  95. digitalWrite(b, HIGH);
  96. digitalWrite(c, LOW);
  97. digitalWrite(d, LOW);
  98. digitalWrite(e, HIGH);
  99. digitalWrite(f, LOW);
  100. digitalWrite(g, LOW);
  101. delay(1000);
  102. break;
  103. case 6:
  104. digitalWrite(a, LOW);
  105. digitalWrite(b, HIGH);
  106. digitalWrite(c, LOW);
  107. digitalWrite(d, LOW);
  108. digitalWrite(e, LOW);
  109. digitalWrite(f, LOW);
  110. digitalWrite(g, LOW);
  111. delay(1000);
  112. break;
  113. case 7:
  114. digitalWrite(a, LOW);
  115. digitalWrite(b, LOW);
  116. digitalWrite(c, LOW);
  117. digitalWrite(d, HIGH);
  118. digitalWrite(e, HIGH);
  119. digitalWrite(f, LOW);
  120. digitalWrite(g, HIGH);
  121. delay(1000);
  122. break;
  123. case 8:
  124. digitalWrite(a, LOW);
  125. digitalWrite(b, LOW);
  126. digitalWrite(c, LOW);
  127. digitalWrite(d, LOW);
  128. digitalWrite(e, LOW);
  129. digitalWrite(f, LOW);
  130. digitalWrite(g, LOW);
  131. delay(1000);
  132. break;
  133. case 9:
  134. digitalWrite(a, LOW);
  135. digitalWrite(b, LOW);
  136. digitalWrite(c, LOW);
  137. digitalWrite(d, LOW);
  138. digitalWrite(e, HIGH);
  139. digitalWrite(f, LOW);
  140. digitalWrite(g, LOW);
  141. delay(1000);
  142. break;
  143. break;
  144. }
  145. if (Train > 628) { //Train passing by.
  146. digitalWrite(GREEN, LOW);
  147. digitalWrite(RED, HIGH);
  148. tone(BUZZER, 1000, 500);
  149. myservo.write(0); //barrier down
  150. }
  151. else {
  152. digitalWrite(GREEN, LOW);
  153. digitalWrite(RED, HIGH);
  154. myservo.write(90); //barrier up
  155. }
  156. if (Train < 628 && Button == LOW) { //Button pressed.
  157. Walker();
  158. }
  159. }
  160. int Walker() {
  161. myservo.write(0); //barrier down
  162. delay(1000);
  163. digitalWrite(RED, LOW);
  164. delay(50);
  165. digitalWrite(GREEN, HIGH);
  166. count = 1;
  167. delay(5000);
  168. tone(BUZZER, 380, 500); //starts blinking and beeping
  169. digitalWrite(GREEN, LOW);
  170. delay(500);
  171. digitalWrite(GREEN, HIGH);
  172. delay(500);
  173. tone(BUZZER, 380, 500);
  174. digitalWrite(GREEN, LOW);
  175. delay(500);
  176. digitalWrite(GREEN, HIGH);
  177. delay(500);
  178. tone(BUZZER, 380, 500);
  179. digitalWrite(GREEN, LOW);
  180. delay(500);
  181. digitalWrite(GREEN, HIGH);
  182. delay(500);
  183. tone(BUZZER, 380, 500);
  184. digitalWrite(GREEN, LOW); //blinking becomes more frequent
  185. delay(150);
  186. digitalWrite(GREEN, HIGH);
  187. delay(150);
  188. tone(BUZZER, 580, 150); //tone goes higher
  189. digitalWrite(GREEN, LOW);
  190. delay(150);
  191. digitalWrite(GREEN, HIGH);
  192. delay(150);
  193. tone(BUZZER, 580, 150);
  194. digitalWrite(GREEN, LOW);
  195. delay(150);
  196. digitalWrite(GREEN, HIGH);
  197. delay(150);
  198. tone(BUZZER, 580, 150);
  199. digitalWrite(GREEN, LOW);
  200. delay(50);
  201. digitalWrite(GREEN, HIGH);
  202. delay(50);
  203. count = 9;
  204. tone(BUZZER, 580, 50);
  205. digitalWrite(GREEN, LOW);
  206. digitalWrite(RED, HIGH);
  207. myservo.write(90); //barrier up
  208. }

Demo:

Coward Robot example

(Week 5)

A robot who runs from the enemy as soon as he finds it in front of him.

Wiring:

screenshot 2017-02-13 15 42 31

Schematics:

screenshot 2017-02-13 21 23 30

Code:

  1. //Coward Robot
  2. //Author: Niam Moltta
  3. //this coward Starts reversing when it founds something close.
  4. #define E1 10 // Enable Pin for motor 1
  5. #define I2 8 // Control pin 1 for motor 1
  6. #define I1 9 // Control pin 2 for motor 1
  7. const int Ping = A0; //Ultrasonic sensor
  8. void setup() {
  9. Serial.begin(9600);
  10. pinMode(E1, OUTPUT);
  11. pinMode(I1, OUTPUT);
  12. pinMode(I2, OUTPUT);
  13. }
  14. void loop() {
  15. //analogWrite(E1, 255); // Run in half speed
  16. long duration, inches, cm;
  17. pinMode(Ping, OUTPUT);
  18. digitalWrite(Ping, LOW);
  19. delayMicroseconds(2);
  20. digitalWrite(Ping, HIGH);
  21. delayMicroseconds(5);
  22. digitalWrite(Ping, LOW);
  23. pinMode(Ping, INPUT);
  24. duration = pulseIn(Ping, HIGH);
  25. inches = microsecondsToInches(duration);
  26. cm = microsecondsToCentimeters(duration);
  27. // Serial monitor
  28. Serial.print(inches);
  29. Serial.print("in, ");
  30. Serial.print(cm);
  31. Serial.print("cm");
  32. Serial.println();
  33. delay(15);
  34. if (cm <= 30) {
  35. delay(1000);
  36. digitalWrite(E1, HIGH);
  37. digitalWrite(I1, LOW); //ccw
  38. digitalWrite(I2, HIGH);
  39. }
  40. else {
  41. digitalWrite(E1, HIGH); //cw
  42. digitalWrite(I1, HIGH);
  43. digitalWrite(I2, LOW);
  44. }
  45. }
  46. long microsecondsToInches(long microseconds) {
  47. return microseconds / 74 / 2;
  48. }
  49. long microsecondsToCentimeters(long microseconds) {
  50. return microseconds / 29 / 2;
  51. }

Demo: