├── .gitignore ├── README.md ├── melody_example ├── melody_example.ino └── pitches.h ├── motor_L293D └── motor_L293D.ino ├── obstacle_detection_robot ├── Obstacle Avoiding Bot Stage 1.fzz ├── README.md └── obstacle_detection_robot.ino ├── push_button_led └── push_button_led.ino ├── ultrasonic_buzzer └── ultrasonic_buzzer.ino └── ultrasonic_sensor_HC_SR04 └── ultrasonic_sensor_HC_SR04.ino /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | libraries 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Play ground for arduino projects. Read README.md of sub folders for more details on project -------------------------------------------------------------------------------- /melody_example/melody_example.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Melody 3 | 4 | Plays a melody 5 | 6 | circuit: 7 | * 8-ohm speaker on digital pin 8 8 | 9 | created 21 Jan 2010 10 | modified 30 Aug 2011 11 | by Tom Igoe 12 | 13 | This example code is in the public domain. 14 | 15 | http://www.arduino.cc/en/Tutorial/Tone 16 | 17 | */ 18 | #include "pitches.h" 19 | 20 | int buzzerPin = 8; 21 | 22 | // notes in the melody: 23 | int melody[] = { 24 | NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4 25 | }; 26 | 27 | // note durations: 4 = quarter note, 8 = eighth note, etc.: 28 | int noteDurations[] = { 29 | 4, 8, 8, 4, 4, 4, 4, 4 30 | }; 31 | 32 | void setup() { 33 | // iterate over the notes of the melody: 34 | for (int thisNote = 0; thisNote < 8; thisNote++) { 35 | 36 | // to calculate the note duration, take one second 37 | // divided by the note type. 38 | //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. 39 | int noteDuration = 1000 / noteDurations[thisNote]; 40 | tone(buzzerPin, melody[thisNote], noteDuration); 41 | 42 | // to distinguish the notes, set a minimum time between them. 43 | // the note's duration + 30% seems to work well: 44 | int pauseBetweenNotes = noteDuration * 1.30; 45 | delay(pauseBetweenNotes); 46 | // stop the tone playing: 47 | noTone(buzzerPin); 48 | } 49 | } 50 | 51 | void loop() { 52 | 53 | } 54 | -------------------------------------------------------------------------------- /melody_example/pitches.h: -------------------------------------------------------------------------------- 1 | /************************************************* 2 | * Public Constants 3 | *************************************************/ 4 | 5 | #define NOTE_B0 31 6 | #define NOTE_C1 33 7 | #define NOTE_CS1 35 8 | #define NOTE_D1 37 9 | #define NOTE_DS1 39 10 | #define NOTE_E1 41 11 | #define NOTE_F1 44 12 | #define NOTE_FS1 46 13 | #define NOTE_G1 49 14 | #define NOTE_GS1 52 15 | #define NOTE_A1 55 16 | #define NOTE_AS1 58 17 | #define NOTE_B1 62 18 | #define NOTE_C2 65 19 | #define NOTE_CS2 69 20 | #define NOTE_D2 73 21 | #define NOTE_DS2 78 22 | #define NOTE_E2 82 23 | #define NOTE_F2 87 24 | #define NOTE_FS2 93 25 | #define NOTE_G2 98 26 | #define NOTE_GS2 104 27 | #define NOTE_A2 110 28 | #define NOTE_AS2 117 29 | #define NOTE_B2 123 30 | #define NOTE_C3 131 31 | #define NOTE_CS3 139 32 | #define NOTE_D3 147 33 | #define NOTE_DS3 156 34 | #define NOTE_E3 165 35 | #define NOTE_F3 175 36 | #define NOTE_FS3 185 37 | #define NOTE_G3 196 38 | #define NOTE_GS3 208 39 | #define NOTE_A3 220 40 | #define NOTE_AS3 233 41 | #define NOTE_B3 247 42 | #define NOTE_C4 262 43 | #define NOTE_CS4 277 44 | #define NOTE_D4 294 45 | #define NOTE_DS4 311 46 | #define NOTE_E4 330 47 | #define NOTE_F4 349 48 | #define NOTE_FS4 370 49 | #define NOTE_G4 392 50 | #define NOTE_GS4 415 51 | #define NOTE_A4 440 52 | #define NOTE_AS4 466 53 | #define NOTE_B4 494 54 | #define NOTE_C5 523 55 | #define NOTE_CS5 554 56 | #define NOTE_D5 587 57 | #define NOTE_DS5 622 58 | #define NOTE_E5 659 59 | #define NOTE_F5 698 60 | #define NOTE_FS5 740 61 | #define NOTE_G5 784 62 | #define NOTE_GS5 831 63 | #define NOTE_A5 880 64 | #define NOTE_AS5 932 65 | #define NOTE_B5 988 66 | #define NOTE_C6 1047 67 | #define NOTE_CS6 1109 68 | #define NOTE_D6 1175 69 | #define NOTE_DS6 1245 70 | #define NOTE_E6 1319 71 | #define NOTE_F6 1397 72 | #define NOTE_FS6 1480 73 | #define NOTE_G6 1568 74 | #define NOTE_GS6 1661 75 | #define NOTE_A6 1760 76 | #define NOTE_AS6 1865 77 | #define NOTE_B6 1976 78 | #define NOTE_C7 2093 79 | #define NOTE_CS7 2217 80 | #define NOTE_D7 2349 81 | #define NOTE_DS7 2489 82 | #define NOTE_E7 2637 83 | #define NOTE_F7 2794 84 | #define NOTE_FS7 2960 85 | #define NOTE_G7 3136 86 | #define NOTE_GS7 3322 87 | #define NOTE_A7 3520 88 | #define NOTE_AS7 3729 89 | #define NOTE_B7 3951 90 | #define NOTE_C8 4186 91 | #define NOTE_CS8 4435 92 | #define NOTE_D8 4699 93 | #define NOTE_DS8 4978 94 | -------------------------------------------------------------------------------- /motor_L293D/motor_L293D.ino: -------------------------------------------------------------------------------- 1 | // Motor Code Adopted From: http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/?ALLSTEPS 2 | int motor_left[] = {2, 3}; 3 | int motor_right[] = {7, 8}; 4 | 5 | void setup() { 6 | for(int i = 0; i < 2; i++){ 7 | pinMode(motor_left[i], OUTPUT); 8 | pinMode(motor_right[i], OUTPUT); 9 | } 10 | } 11 | 12 | void loop() { 13 | delay(50); 14 | drive_forward(); // Change this line to other methods like drive_backward, turn_left, turn_right to test the rotation of wheels 15 | } 16 | 17 | void drive_forward() { 18 | digitalWrite(motor_left[0], HIGH); 19 | digitalWrite(motor_left[1], LOW); 20 | 21 | digitalWrite(motor_right[0], HIGH); 22 | digitalWrite(motor_right[1], LOW); 23 | } 24 | 25 | void drive_backward() { 26 | digitalWrite(motor_left[0], LOW); 27 | digitalWrite(motor_left[1], HIGH); 28 | 29 | digitalWrite(motor_right[0], LOW); 30 | digitalWrite(motor_right[1], HIGH); 31 | } 32 | 33 | void turn_left() { 34 | digitalWrite(motor_left[0], LOW); 35 | digitalWrite(motor_left[1], HIGH); 36 | 37 | digitalWrite(motor_right[0], HIGH); 38 | digitalWrite(motor_right[1], LOW); 39 | } 40 | 41 | void turn_right() { 42 | digitalWrite(motor_left[0], HIGH); 43 | digitalWrite(motor_left[1], LOW); 44 | 45 | digitalWrite(motor_right[0], LOW); 46 | digitalWrite(motor_right[1], HIGH); 47 | } 48 | 49 | void motor_stop(){ 50 | digitalWrite(motor_left[0], LOW); 51 | digitalWrite(motor_left[1], LOW); 52 | 53 | digitalWrite(motor_right[0], LOW); 54 | digitalWrite(motor_right[1], LOW); 55 | } 56 | -------------------------------------------------------------------------------- /obstacle_detection_robot/Obstacle Avoiding Bot Stage 1.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DroneBotWorkshop/arduino-projects/bb41902bce38573f2b0e44e67ad23625e0f9a9e7/obstacle_detection_robot/Obstacle Avoiding Bot Stage 1.fzz -------------------------------------------------------------------------------- /obstacle_detection_robot/README.md: -------------------------------------------------------------------------------- 1 | Simple obstacle avoiding robot using arduino 2 | 3 | [![Video](http://img.youtube.com/vi/zFlNvsFM9kY/0.jpg)](https://www.youtube.com/watch?v=zFlNvsFM9kY "Video") 4 | 5 | 7 | 8 | Instructions : http://tech.endeepak.com/blog/2016/01/02/simple-obstacle-avoiding-robot-using-arduino 9 | -------------------------------------------------------------------------------- /obstacle_detection_robot/obstacle_detection_robot.ino: -------------------------------------------------------------------------------- 1 | // Motor Code Adopted From: http://www.instructables.com/id/Control-your-motors-with-L293D-and-Arduino/?ALLSTEPS 2 | // Ping Code Adopted From: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home#!single-pin-sketch 3 | 4 | #include 5 | 6 | #define PING_PIN 12 // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor. 7 | #define PING_MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. 8 | 9 | NewPing sonar(PING_PIN, PING_PIN, PING_MAX_DISTANCE); // NewPing setup of pin and maximum distance. 10 | 11 | #define MAX_DISTANCE_FROM_OBSTACLE_IN_CMS 20 // Change this if needed, depending on position of the ultrasonic sensor in the robot chasis 12 | 13 | int motor_left[] = {2, 3}; 14 | int motor_right[] = {7, 8}; 15 | 16 | void setup() { 17 | Serial.begin(9600); 18 | for(int i = 0; i < 2; i++){ 19 | pinMode(motor_left[i], OUTPUT); 20 | pinMode(motor_right[i], OUTPUT); 21 | } 22 | } 23 | 24 | void loop() { 25 | delay(50); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings. 26 | unsigned int distanceInCms = sonar.ping() / US_ROUNDTRIP_CM; // Send ping, get ping time in microseconds (uS) and convert it to centimeters (cm) 27 | Serial.println("Distance: " + String(distanceInCms) + "cm"); 28 | 29 | if(distanceInCms != NO_ECHO && distanceInCms < MAX_DISTANCE_FROM_OBSTACLE_IN_CMS) { 30 | rotate_right(90); 31 | } else { 32 | drive_forward(); 33 | } 34 | } 35 | 36 | void rotate_right(int angleInDegrees) { 37 | for(int i=0; i< angleInDegrees; i++) { 38 | turn_right(); 39 | delay(25); // Test this out and change it approriately based on your motor speed 40 | } 41 | } 42 | 43 | void drive_forward() { 44 | digitalWrite(motor_left[0], HIGH); 45 | digitalWrite(motor_left[1], LOW); 46 | 47 | digitalWrite(motor_right[0], HIGH); 48 | digitalWrite(motor_right[1], LOW); 49 | } 50 | 51 | void drive_backward() { 52 | digitalWrite(motor_left[0], LOW); 53 | digitalWrite(motor_left[1], HIGH); 54 | 55 | digitalWrite(motor_right[0], LOW); 56 | digitalWrite(motor_right[1], HIGH); 57 | } 58 | 59 | void turn_left() { 60 | digitalWrite(motor_left[0], LOW); 61 | digitalWrite(motor_left[1], HIGH); 62 | 63 | digitalWrite(motor_right[0], HIGH); 64 | digitalWrite(motor_right[1], LOW); 65 | } 66 | 67 | void turn_right() { 68 | digitalWrite(motor_left[0], HIGH); 69 | digitalWrite(motor_left[1], LOW); 70 | 71 | digitalWrite(motor_right[0], LOW); 72 | digitalWrite(motor_right[1], HIGH); 73 | } 74 | 75 | void motor_stop(){ 76 | digitalWrite(motor_left[0], LOW); 77 | digitalWrite(motor_left[1], LOW); 78 | 79 | digitalWrite(motor_right[0], LOW); 80 | digitalWrite(motor_right[1], LOW); 81 | } 82 | -------------------------------------------------------------------------------- /push_button_led/push_button_led.ino: -------------------------------------------------------------------------------- 1 | 2 | int led = 3; 3 | int button = 2; 4 | 5 | void setup() { 6 | pinMode(button, INPUT_PULLUP); 7 | pinMode(led, OUTPUT); 8 | } 9 | 10 | void loop() { 11 | int isButtonPressed = digitalRead(button) == LOW; 12 | int desiredLedState = isButtonPressed ? HIGH : LOW; 13 | digitalWrite(led, desiredLedState); 14 | } 15 | -------------------------------------------------------------------------------- /ultrasonic_buzzer/ultrasonic_buzzer.ino: -------------------------------------------------------------------------------- 1 | // From http://www.instructables.com/id/Hack-an-HC-SR04-to-a-3-pin-sensor/?ALLSTEPS 2 | // From https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home#!download-install 3 | // --------------------------------------------------------------------------- 4 | // NewPing library sketch that interfaces with all but the SRF06 sensor using 5 | // only one Arduino pin. You can also interface with the SRF06 using one pin 6 | // if you install a 0.1uf capacitor on the trigger and echo pins of the sensor 7 | // then tie the trigger pin to the Arduino pin (doesn't work with Teensy). 8 | // --------------------------------------------------------------------------- 9 | 10 | #include 11 | 12 | #define PING_PIN 12 // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor. 13 | #define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. 14 | #define BUZZER_PIN 8 15 | #define LED_PIN 13 16 | #define NOTE_A6 1760 17 | 18 | NewPing sonar(PING_PIN, PING_PIN, MAX_DISTANCE); // NewPing setup of pin and maximum distance. 19 | 20 | void setup() { 21 | pinMode(LED_PIN, OUTPUT); 22 | Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results. 23 | } 24 | 25 | void loop() { 26 | delay(300); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings. 27 | unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS). 28 | int distanceInCms = uS / US_ROUNDTRIP_CM; 29 | Serial.print("Ping: "); 30 | Serial.print(distanceInCms); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo) 31 | Serial.println("cm"); 32 | 33 | if(distanceInCms != NO_ECHO && distanceInCms < 20) { 34 | digitalWrite(BUZZER_PIN, HIGH); 35 | digitalWrite(LED_PIN, HIGH); 36 | } else { 37 | digitalWrite(BUZZER_PIN, LOW); 38 | digitalWrite(LED_PIN, LOW); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ultrasonic_sensor_HC_SR04/ultrasonic_sensor_HC_SR04.ino: -------------------------------------------------------------------------------- 1 | // Ping Code Adopted From: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home#!single-pin-sketch 2 | #include 3 | 4 | #define PING_PIN 12 // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor. 5 | #define PING_MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm. 6 | 7 | NewPing sonar(PING_PIN, PING_PIN, PING_MAX_DISTANCE); // NewPing setup of pin and maximum distance. 8 | 9 | void setup() { 10 | Serial.begin(9600); 11 | } 12 | 13 | void loop() { 14 | delay(500); // Wait 500ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings. 15 | unsigned int distanceInCms = sonar.ping() / US_ROUNDTRIP_CM; // Send ping, get ping time in microseconds (uS) and convert it to centimeters (cm) 16 | Serial.println("Distance: " + String(distanceInCms) + "cm"); 17 | } 18 | --------------------------------------------------------------------------------