├── .DS_Store ├── .gitignore ├── ArduAutoCar └── ArduAutoCar.ino ├── ArduAutoController └── ArduAutoController.ino ├── ArduinoNunchukDemo └── ArduinoNunchukDemo.ino ├── LICENSE ├── README.md ├── RF24_demo ├── .DS_Store ├── receiver │ └── receiver.ino └── transmitter │ └── transmitter.ino ├── bare_receiver └── bare_receiver.ino ├── bare_transmitter └── bare_transmitter.ino ├── distance_sensor └── distance_sensor.ino └── motor_demo └── motor_demo.ino /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futureshocked/arduauto/b8c48cb439e1e7246e2f12fbb4c9509350bb13ac/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /ArduAutoCar/ArduAutoCar.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "nRF24L01.h" 3 | #include "RF24.h" 4 | 5 | const int E1 = 5; 6 | const int M1 = 4; 7 | const int E2 = 6; 8 | const int M2 = 7; 9 | 10 | #define trigPin 2 11 | #define echoPin 3 12 | 13 | const int obstacle_pin = 8; // Use this pin to connect an LED. If an obstacle is detected, the LED will turn on. 14 | // Beware that I have not shown this connection in the schematic, it is simply here for 15 | // debugging. 16 | 17 | RF24 radio(9, 10); 18 | 19 | // Radio pipe addresses for the 2 nodes to communicate. 20 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 21 | 22 | void setup() 23 | { 24 | Serial.begin(9600); 25 | Serial.println("Starting car."); 26 | pinMode(obstacle_pin, OUTPUT); 27 | pinMode(trigPin, OUTPUT); 28 | pinMode(echoPin, INPUT); 29 | radio.begin(); 30 | radio.openWritingPipe(pipes[1]); 31 | radio.openReadingPipe(1,pipes[0]); 32 | radio.startListening(); 33 | } 34 | 35 | void loop() 36 | { 37 | // if there is data ready 38 | if ( radio.available() ) 39 | { 40 | byte transmission[7]; 41 | 42 | // Fetch the payload 43 | while (radio.available()) { 44 | radio.read( &transmission, sizeof(transmission)); 45 | } 46 | 47 | // Spew it 48 | Serial.print(transmission[0]); 49 | Serial.print(" "); 50 | Serial.print(transmission[1]); 51 | Serial.print(" "); 52 | Serial.print(transmission[2]); 53 | Serial.print(" "); 54 | Serial.print(transmission[3]); 55 | Serial.print(" "); 56 | Serial.print(transmission[4]); 57 | Serial.print(" "); 58 | Serial.print(transmission[5]); 59 | Serial.print(" "); 60 | Serial.print(transmission[6]); 61 | Serial.print(" "); 62 | 63 | byte speedValue = transmission[1]; 64 | byte turnValue = transmission[0]; 65 | 66 | if (obstacle()) 67 | { 68 | // speed(128); //This will stop the motor from spinning 69 | speed(speedValue, true); 70 | } 71 | else 72 | { 73 | speed(speedValue, false); 74 | } 75 | 76 | turn(turnValue); 77 | 78 | // Delay just a little bit to let the other unit 79 | // make the transition to receiver 80 | delay(10); 81 | 82 | 83 | // First, stop listening so we can talk 84 | radio.stopListening(); 85 | 86 | // Send the final one back. 87 | byte response = B0; 88 | radio.write( &response, sizeof(response) ); 89 | 90 | // Now, resume listening so we catch the next packets. 91 | radio.startListening(); 92 | } else 93 | { 94 | //speed(128, false); //If there is no contact with the controller, stop the car 95 | } 96 | } 97 | 98 | void speed(byte speedValue, bool obstacle) 99 | { 100 | if (speedValue < 127) 101 | { 102 | int mappedVal = map(speedValue,0,126,0,255); 103 | //Going reverse 104 | Serial.print(mappedVal); 105 | Serial.print(" - "); 106 | Serial.println(255-mappedVal); 107 | digitalWrite(M1,LOW); 108 | analogWrite(E1, 255-mappedVal); //PWM Speed Control 109 | delay(10); 110 | } else if (speedValue > 129 && !obstacle ) 111 | { 112 | //Going forward 113 | // int mappedVal = map(speedValue-128,0,255,0,255); 114 | int mappedVal = map(speedValue,130,255,0,255); 115 | Serial.print(mappedVal); 116 | Serial.print(" - "); 117 | Serial.println(255-mappedVal); 118 | digitalWrite(M1,HIGH); 119 | analogWrite(E1, 255-mappedVal); //PWM Speed Control 120 | delay(10); 121 | } else 122 | { 123 | Serial.println("Obstacle - stopping"); 124 | digitalWrite(M1,LOW); 125 | analogWrite(E1, 0); 126 | } 127 | } 128 | 129 | void turn(byte turnValue) 130 | { 131 | if (turnValue < 125) 132 | { 133 | int mappedVal = map(turnValue,0,255,0,255); 134 | //Turn righ 135 | digitalWrite(M2,LOW); 136 | // analogWrite(E2, mappedVal); //PWM Speed Control 137 | analogWrite(E2, 255); 138 | delay(10); 139 | } else if (turnValue > 130) 140 | { 141 | //Turn left 142 | int mappedVal = map(turnValue-128,0,255,0,255); 143 | digitalWrite(M2,HIGH); 144 | // analogWrite(E2, mappedVal); //PWM Speed Control 145 | analogWrite(E2, 0); 146 | delay(10); 147 | } else 148 | { 149 | digitalWrite(M2,LOW); 150 | analogWrite(E2, 0); //Set turning wheels to straight. 151 | } 152 | } 153 | 154 | boolean obstacle() 155 | { 156 | long duration, distance; 157 | digitalWrite(trigPin, LOW); // Added this line 158 | delayMicroseconds(2); // Added this line 159 | digitalWrite(trigPin, HIGH); 160 | delayMicroseconds(10); // Added this line 161 | digitalWrite(trigPin, LOW); 162 | duration = pulseIn(echoPin, HIGH); 163 | distance = (duration/2) / 29.1; 164 | 165 | if (distance >= 30 || distance <= 0){ 166 | Serial.println("No obstacle"); 167 | digitalWrite(obstacle_pin,LOW); 168 | return false; 169 | } 170 | else { 171 | // Serial.print("DANGER! "); 172 | Serial.print(distance); 173 | Serial.println(" cm"); 174 | digitalWrite(obstacle_pin,HIGH); 175 | return true; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /ArduAutoController/ArduAutoController.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "nRF24L01.h" 5 | #include "RF24.h" 6 | 7 | #define BAUDRATE 57600 8 | 9 | const int led_pin = 13; 10 | 11 | ArduinoNunchuk nunchuk = ArduinoNunchuk(); 12 | 13 | RF24 radio(9, 10); 14 | 15 | // Radio pipe addresses for the 2 nodes to communicate. 16 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 17 | 18 | void setup() 19 | { 20 | Serial.begin(BAUDRATE); 21 | pinMode(led_pin, OUTPUT); 22 | nunchuk.init(); 23 | radio.begin(); 24 | radio.openWritingPipe(pipes[0]); 25 | radio.openReadingPipe(1,pipes[1]); 26 | 27 | } 28 | 29 | void loop() 30 | { 31 | nunchuk.update(); 32 | 33 | byte analogX = nunchuk.analogX; 34 | byte analogY = nunchuk.analogY; 35 | byte accelX = nunchuk.accelX; 36 | byte accelY = nunchuk.accelY; 37 | byte accelZ = nunchuk.accelZ; 38 | byte zButton = nunchuk.zButton; 39 | byte cButton = nunchuk.cButton; 40 | byte car_data[7]; 41 | car_data[0] = analogX; 42 | car_data[1] = analogY; 43 | car_data[2] = accelX; 44 | car_data[3] = accelY; 45 | car_data[4] = accelZ; 46 | car_data[5] = zButton; 47 | car_data[6] = cButton; 48 | 49 | Serial.print(car_data[0], DEC); 50 | Serial.print(' '); 51 | Serial.print(car_data[1], DEC); 52 | Serial.print(' '); 53 | Serial.print(car_data[2], DEC); 54 | Serial.print(' '); 55 | Serial.print(car_data[3], DEC); 56 | Serial.print(' '); 57 | Serial.print(car_data[4], DEC); 58 | Serial.print(' '); 59 | Serial.print(car_data[5], DEC); 60 | Serial.print(' '); 61 | Serial.println(car_data[6], DEC); 62 | 63 | radio.stopListening(); 64 | radio.write( &car_data, 7 ); 65 | // Now, continue listening 66 | radio.startListening(); 67 | 68 | // Wait here until we get a response, or timeout (250ms) 69 | unsigned long started_waiting_at = millis(); 70 | bool timeout = false; 71 | while ( ! radio.available() && ! timeout ) 72 | if (millis() - started_waiting_at > 200 ) 73 | timeout = true; 74 | 75 | // Describe the results 76 | if ( timeout ) 77 | { 78 | Serial.println("Failed, response timed out."); 79 | } 80 | else 81 | { 82 | // Grab the response, compare, and send to debugging spew 83 | byte response; 84 | radio.read( &response, sizeof(response) ); 85 | Serial.println(response,BIN); 86 | 87 | if (response == B0) 88 | { 89 | digitalWrite(led_pin,HIGH); 90 | Serial.println("Ok"); 91 | } 92 | else 93 | { 94 | digitalWrite(led_pin,LOW); 95 | Serial.println("No connection"); 96 | } 97 | } 98 | // Try again later 99 | delay(150); 100 | } 101 | -------------------------------------------------------------------------------- /ArduinoNunchukDemo/ArduinoNunchukDemo.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * ArduinoNunchukDemo.ino 3 | * 4 | * Copyright 2011-2013 Gabriel Bianconi, http://www.gabrielbianconi.com/ 5 | * 6 | * Project URL: http://www.gabrielbianconi.com/projects/arduinonunchuk/ 7 | * 8 | */ 9 | 10 | #include 11 | #include 12 | 13 | #define BAUDRATE 19200 14 | 15 | ArduinoNunchuk nunchuk = ArduinoNunchuk(); 16 | 17 | void setup() 18 | { 19 | Serial.begin(BAUDRATE); 20 | nunchuk.init(); 21 | } 22 | 23 | void loop() 24 | { 25 | nunchuk.update(); 26 | 27 | Serial.print(nunchuk.analogX, DEC); 28 | Serial.print(' '); 29 | Serial.print(nunchuk.analogY, DEC); 30 | Serial.print(' '); 31 | Serial.print(nunchuk.accelX, DEC); 32 | Serial.print(' '); 33 | Serial.print(nunchuk.accelY, DEC); 34 | Serial.print(' '); 35 | Serial.print(nunchuk.accelZ, DEC); 36 | Serial.print(' '); 37 | Serial.print(nunchuk.zButton, DEC); 38 | Serial.print(' '); 39 | Serial.println(nunchuk.cButton, DEC); 40 | } 41 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Peter Dalmaris 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | arduauto 2 | ======== 3 | 4 | Code repository for the Arduauto Course: An Arduino remote controlled car 5 | -------------------------------------------------------------------------------- /RF24_demo/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/futureshocked/arduauto/b8c48cb439e1e7246e2f12fbb4c9509350bb13ac/RF24_demo/.DS_Store -------------------------------------------------------------------------------- /RF24_demo/receiver/receiver.ino: -------------------------------------------------------------------------------- 1 | //Receiver 2 | 3 | #include 4 | #include "nRF24L01.h" 5 | #include "RF24.h" 6 | 7 | RF24 radio(9, 10); 8 | 9 | // Radio pipe addresses for the 2 nodes to communicate. 10 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 11 | 12 | void setup() 13 | { 14 | Serial.begin(9600); 15 | 16 | radio.begin(); 17 | radio.openWritingPipe(pipes[1]); 18 | radio.openReadingPipe(1, pipes[0]); 19 | radio.startListening(); 20 | Serial.println("Listening"); 21 | } 22 | 23 | void loop() 24 | { 25 | // if there is data ready 26 | if ( radio.available() ) 27 | { 28 | Serial.print("Receiver."); 29 | char transmission; 30 | bool done = false; 31 | 32 | while (radio.available()) { 33 | radio.read( &transmission, 1 ); 34 | } 35 | 36 | // Spew it 37 | Serial.print("Received from transmitter:"); 38 | Serial.println(transmission); 39 | 40 | // Delay just a little bit to let the other unit 41 | // make the transition to receiver 42 | delay(20); 43 | 44 | // First, stop listening so we can talk 45 | radio.stopListening(); 46 | 47 | // Send the final one back. 48 | byte response = B0; 49 | radio.write( &response, sizeof(response) ); 50 | Serial.println("Sent response.\n\r"); 51 | 52 | // Now, resume listening so we catch the next packets. 53 | radio.startListening(); 54 | 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /RF24_demo/transmitter/transmitter.ino: -------------------------------------------------------------------------------- 1 | //Transmitter 2 | 3 | #include 4 | #include "nRF24L01.h" 5 | #include "RF24.h" 6 | 7 | const int led_pin = 8; 8 | char message = 'A'; 9 | 10 | RF24 radio(9,10); 11 | 12 | // Radio pipe addresses for the 2 nodes to communicate. 13 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 14 | 15 | void setup() 16 | { 17 | Serial.begin(9600); 18 | Serial.println("Starting radio..."); 19 | 20 | radio.begin(); 21 | radio.openWritingPipe(pipes[0]); 22 | radio.openReadingPipe(1,pipes[1]); 23 | Serial.println("Radio started..."); 24 | 25 | } 26 | 27 | void loop() 28 | { 29 | radio.stopListening(); 30 | Serial.print("Sending:"); 31 | Serial.print(message); 32 | Serial.print(" "); 33 | radio.write( &message, 1 ); 34 | 35 | // Now, continue listening 36 | radio.startListening(); 37 | 38 | // Wait here until we get a response, or timeout (250ms) 39 | unsigned long started_waiting_at = millis(); 40 | bool timeout = false; 41 | while ( ! radio.available() && ! timeout ) 42 | if (millis() - started_waiting_at > 200 ) 43 | timeout = true; 44 | 45 | // Describe the results 46 | if ( timeout ) 47 | { 48 | Serial.println("Failed, response timed out."); 49 | 50 | } 51 | else 52 | { 53 | // Grab the response, compare, and send to debugging spew 54 | byte response; 55 | radio.read( &response, sizeof(response) ); 56 | Serial.print("Transmitter. Received response from receiver:"); 57 | Serial.println(response,BIN); 58 | 59 | if (response == B0) 60 | { 61 | digitalWrite(led_pin,HIGH); 62 | Serial.println("Ok"); 63 | } 64 | else 65 | { 66 | digitalWrite(led_pin,LOW); 67 | Serial.println("No connection"); 68 | } 69 | } 70 | 71 | // Try again later 72 | delay(150); 73 | 74 | } 75 | -------------------------------------------------------------------------------- /bare_receiver/bare_receiver.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "nRF24L01.h" 3 | #include "RF24.h" 4 | 5 | RF24 radio(9, 10); 6 | 7 | // Radio pipe addresses for the 2 nodes to communicate. 8 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 9 | 10 | void setup() 11 | { 12 | Serial.begin(57600); 13 | 14 | radio.begin(); 15 | 16 | radio.openWritingPipe(pipes[1]); 17 | radio.openReadingPipe(1, pipes[0]); 18 | 19 | radio.startListening(); 20 | Serial.println("Listening..."); 21 | } 22 | 23 | void loop() 24 | { 25 | // if there is data ready 26 | if ( radio.available() ) 27 | { 28 | byte transmission[7]; 29 | 30 | while (radio.available()) { 31 | radio.read( &transmission, sizeof(transmission)); 32 | } 33 | 34 | // Spew it 35 | Serial.print(transmission[0]); 36 | Serial.print(" "); 37 | Serial.print(transmission[1]); 38 | Serial.print(" "); 39 | Serial.print(transmission[2]); 40 | Serial.print(" "); 41 | Serial.print(transmission[3]); 42 | Serial.print(" "); 43 | Serial.print(transmission[4]); 44 | Serial.print(" "); 45 | Serial.print(transmission[5]); 46 | Serial.print(" "); 47 | Serial.print(transmission[6]); 48 | Serial.print(" "); 49 | 50 | // Delay just a little bit to let the other unit 51 | // make the transition to receiver 52 | delay(20); 53 | 54 | // First, stop listening so we can talk 55 | radio.stopListening(); 56 | 57 | // Send the final one back. 58 | byte response = B0; 59 | radio.write( &response, sizeof(response) ); 60 | Serial.println("Sent response.\n\r"); 61 | 62 | // Now, resume listening so we catch the next packets. 63 | radio.startListening(); 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /bare_transmitter/bare_transmitter.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "nRF24L01.h" 5 | #include "RF24.h" 6 | 7 | #define BAUDRATE 57600 8 | 9 | const int led_pin = 8; 10 | 11 | ArduinoNunchuk nunchuk = ArduinoNunchuk(); 12 | 13 | 14 | RF24 radio(9, 10); 15 | 16 | // Radio pipe addresses for the 2 nodes to communicate. 17 | const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; 18 | 19 | void setup() 20 | { 21 | Serial.begin(BAUDRATE); 22 | randomSeed(analogRead(0)); 23 | 24 | pinMode(led_pin, OUTPUT); 25 | nunchuk.init(); 26 | radio.begin(); 27 | 28 | radio.openWritingPipe(pipes[0]); 29 | radio.openReadingPipe(1, pipes[1]); 30 | 31 | 32 | } 33 | 34 | void loop() 35 | { 36 | nunchuk.update(); 37 | 38 | byte analogX = nunchuk.analogX; 39 | byte analogY = nunchuk.analogY; 40 | byte accelX = nunchuk.accelX; 41 | byte accelY = nunchuk.accelY; 42 | byte accelZ = nunchuk.accelZ; 43 | byte zButton = nunchuk.zButton; 44 | byte cButton = nunchuk.cButton; 45 | byte car_data[7]; 46 | 47 | car_data[0] = analogX; 48 | car_data[1] = analogY; 49 | car_data[2] = accelX; 50 | car_data[3] = accelY; 51 | car_data[4] = accelZ; 52 | car_data[5] = zButton; 53 | car_data[6] = cButton; 54 | 55 | Serial.print(car_data[0], DEC); 56 | Serial.print(' '); 57 | Serial.print(car_data[1], DEC); 58 | Serial.print(' '); 59 | Serial.print(car_data[2], DEC); 60 | Serial.print(' '); 61 | Serial.print(car_data[3], DEC); 62 | Serial.print(' '); 63 | Serial.print(car_data[4], DEC); 64 | Serial.print(' '); 65 | Serial.print(car_data[5], DEC); 66 | Serial.print(' '); 67 | Serial.println(car_data[6], DEC); 68 | 69 | 70 | radio.stopListening(); 71 | radio.write( &car_data, 7 ); 72 | // Now, continue listening 73 | radio.startListening(); 74 | 75 | // Wait here until we get a response, or timeout (250ms) 76 | unsigned long started_waiting_at = millis(); 77 | bool timeout = false; 78 | while ( ! radio.available() && ! timeout ) 79 | if (millis() - started_waiting_at > 200 ) 80 | timeout = true; 81 | 82 | // Describe the results 83 | if ( timeout ) 84 | { 85 | Serial.println("Failed, response timed out."); 86 | 87 | } 88 | else 89 | { 90 | // Grab the response, compare, and send to debugging spew 91 | byte response; 92 | radio.read( &response, sizeof(response) ); 93 | Serial.println(response, BIN); 94 | 95 | if (response == B0) 96 | { 97 | digitalWrite(led_pin, HIGH); 98 | Serial.println("Ok"); 99 | } 100 | else 101 | { 102 | digitalWrite(led_pin, LOW); 103 | Serial.println("No connection"); 104 | } 105 | } 106 | 107 | // Try again later 108 | delay(150); 109 | 110 | } 111 | -------------------------------------------------------------------------------- /distance_sensor/distance_sensor.ino: -------------------------------------------------------------------------------- 1 | #define trigPin 13 2 | #define echoPin 12 3 | 4 | void setup() 5 | { 6 | Serial.begin(9600); 7 | pinMode(trigPin, OUTPUT); 8 | pinMode(echoPin, INPUT); 9 | } 10 | 11 | void loop() 12 | { 13 | long duration, distance; 14 | digitalWrite(trigPin, LOW); 15 | delayMicroseconds(2); 16 | digitalWrite(trigPin, HIGH); 17 | delayMicroseconds(10); 18 | digitalWrite(trigPin, LOW); 19 | duration = pulseIn(echoPin, HIGH); 20 | distance = (duration/2) / 29.1; 21 | if (distance >= 200 || distance <= 0) 22 | { 23 | Serial.println("Out of range"); 24 | } 25 | else 26 | { 27 | Serial.print(distance); 28 | Serial.println(" cm"); 29 | } 30 | delay(500); 31 | } 32 | -------------------------------------------------------------------------------- /motor_demo/motor_demo.ino: -------------------------------------------------------------------------------- 1 | //Arduino PWM Speed Control: 2 | //int E1 = 5; 3 | //int M1 = 4; 4 | 5 | int M1=7; 6 | int E1=6; 7 | 8 | void setup() 9 | { 10 | pinMode(M1, OUTPUT); 11 | pinMode(E1, OUTPUT); 12 | } 13 | 14 | void loop() 15 | { 16 | int value; 17 | for(value = 0 ; value <= 255; value+=1) 18 | { 19 | digitalWrite(M1,HIGH); 20 | analogWrite(E1, value); //PWM Speed Control 21 | delay(30); 22 | } 23 | 24 | for(value = 0 ; value <= 255; value+=1) 25 | { 26 | digitalWrite(M1,LOW); 27 | analogWrite(E1, value); //PWM Speed Control 28 | delay(30); 29 | } 30 | } 31 | --------------------------------------------------------------------------------