Self-driving Toycar: Difference between revisions
No edit summary |
|||
(24 intermediate revisions by 3 users not shown) | |||
Line 34: | Line 34: | ||
Select the serial device of the board from the Tools | Serial Port menu | Select the serial device of the board from the Tools | Serial Port menu. To find outwhich port to use, you can disconnect your board and re-open the menu; the entry that disappears should be the Arduino or Genuino board. Reconnect the board and select that serial port. | ||
[[File: | [[File:Serial-port.png|500px|Select COM port]] | ||
Line 52: | Line 52: | ||
=== Connect the Motor Driver === | === Connect the Motor Driver === | ||
The Motor Driver or Arduino Motor Shield allows you to easily control motor direction and speed using an Arduino. | The Motor Driver or Arduino Motor Shield allows you to easily control motor direction and speed using an Arduino. | ||
[[File:UNADJUSTEDNONRAW_thumb_15da.jpg|500px|Motor shield]] | [[File:UNADJUSTEDNONRAW_thumb_15da.jpg|500px|Motor shield]] | ||
Line 58: | Line 59: | ||
* Connect motor shield and Arduino to the car: Make sure motor, steering and battery cables are connected to the right outputs of the shield | * Connect motor shield and Arduino to the car: Make sure motor, steering and battery cables are connected to the right outputs of the shield | ||
[[File: | [[File:Shield connections.JPG|500px|Connect the motors]] | ||
<pre> | |||
Steering motor -> Shield M1 | |||
Driving motor -> Shield M4 | |||
Car battery wires -> Shield EXT_PWR | |||
</pre> | |||
* Cover the bottom of the Arduino with a piece of tape to prevent a connection of arduino with the battery (short circuit) | * Cover the bottom of the Arduino with a piece of tape to prevent a connection of arduino with the battery (short circuit) | ||
* Put the AA batteries in the car | * Put the AA batteries in the car | ||
* Connect 9 v battery to arduino, then connect the battery to the motor shield | * Connect 9 v battery to arduino, then connect the battery to the motor shield | ||
[[File:UNADJUSTEDNONRAW_thumb_15d4.jpg|500px|battery]] | [[File:UNADJUSTEDNONRAW_thumb_15d4.jpg|500px|battery]] | ||
Line 70: | Line 77: | ||
=== Motors test over serial connection === | === Motors test over serial connection === | ||
* Connect Arduino to your computer | * Connect Arduino to your computer | ||
[[File:UNADJUSTEDNONRAW_thumb_15d6.jpg|500px|connect]] | [[File:UNADJUSTEDNONRAW_thumb_15d6.jpg|500px|connect]] | ||
* | |||
* We've prepared the example code for this workshop that you can download from GitHub: [https://github.com/swummoq/H-D-Self-Driving-Toycar sample code] | |||
* After downloading the zip file from Github open SDC_1_motor_test.ino | * After downloading the zip file from Github open SDC_1_motor_test.ino | ||
* In Arduino go to "Menu" > "Sketch" > "Include library" > "Manage libraries" > search for "Adafruit Motor shield V1 firmware" and add | * In Arduino go to "Menu" > "Sketch" > "Include library" > "Manage libraries" > search for "Adafruit Motor shield V1 firmware" and add | ||
* Test | * Test if the Motor Shield works correctly by opening the Serial Monitor (magnifying glass, right hand corner) | ||
* Test if direction and steering works as expected | |||
* Change the cables on the Motor Shield if necessary | |||
---- | ---- | ||
=== Connect the line sensor === | === Connect the line sensor === | ||
The line detection sensor module sends out short pulses of (invisible) infrared light and measures how much of that light comes back. | |||
It output the brightness/darkness as an analog voltage that the Arduino can use to steer the car. | |||
[[File:UNADJUSTEDNONRAW_thumb_15d9.jpg|500px|line sensor]] | [[File:UNADJUSTEDNONRAW_thumb_15d9.jpg|500px|line sensor]] | ||
* Take 3 cables, put it on the sensor, look carefully at the colours and connections (A0, GND, VCC) | |||
* Take 3 cables, put it on the sensor, look carefully at the colours and connections (A0, GND, VCC). The motor shield has connections for the analog pins on the Arduino conveniently grouped with GND and 5V pins. We use these to connect our sensor to. A0 is the pin right next to the pin marked 9V. | |||
* Connect to the Arduino/Motorshield to the sensor | * Connect to the Arduino/Motorshield to the sensor | ||
Line 88: | Line 104: | ||
VCC -> 5V | VCC -> 5V | ||
GND -> GND | GND -> GND | ||
A0 -> A0</pre> | A0 -> A0 | ||
</pre> | |||
* Connect the line sensor analogue output to A0. | * Connect the line sensor analogue output to A0. | ||
<pre> | |||
Module -> Arduino | |||
- - - - - - - - - - - | |||
GND -> GND | GND -> GND | ||
VCC -> 5V | VCC -> 5V | ||
</pre> | |||
[[File:UNADJUSTEDNONRAW_thumb_15dd.jpg|500px|sensor]] | [[File:UNADJUSTEDNONRAW_thumb_15dd.jpg|500px|sensor]] | ||
[[File: | [[File:Line_sensor.JPG|500px|Connected line sensor]] | ||
=== Sensor testing === | === Sensor testing === | ||
* Test line sensor with: SDC_2_line_sensor_test.ino | * Test line sensor with: SDC_2_line_sensor_test.ino | ||
* Follow instructions in the file to find out the lowest and the highest values to distinct the line from the floor. | * Follow instructions in the file to find out the lowest and the highest values to distinct the line from the floor. | ||
[[File:UNADJUSTEDNONRAW_thumb_15e2.jpg|500px|sensor testing]] | [[File:UNADJUSTEDNONRAW_thumb_15e2.jpg|500px|sensor testing]] | ||
[[File:UNADJUSTEDNONRAW_thumb_15e3.jpg|500px|sensor testing]] | [[File:UNADJUSTEDNONRAW_thumb_15e3.jpg|500px|sensor testing]] | ||
Line 109: | Line 129: | ||
=== Upload the car software === | === Upload the car software === | ||
* Open and upload SDC_3_car_test.ino | * Open and upload SDC_3_car_test.ino | ||
* Adjust the values | * Adjust the values | ||
Line 114: | Line 135: | ||
=== Enhance the software === | === Enhance the software === | ||
* Test on the line and adjust values of speed or sensor if nessessary | * Test on the line and adjust values of speed or sensor if nessessary | ||
=== Tips === | === Tips === | ||
* It can help to remove the V9 battery when you upload the program to the arduino | * It can help to remove the V9 battery when you upload the program to the arduino | ||
* Make sure your sensor is close to the ground | * Make sure your sensor is close to the ground | ||
=== Ideas: === | === Ideas: === | ||
* Add ultrasonic sensor to avoid collisions | * Add ultrasonic sensor to avoid collisions | ||
* Add sound | |||
* The car now always steers either left or right. Can we add straight ahead? | * The car now always steers either left or right. Can we add straight ahead? | ||
* Try to make the steering proportional to the error in the line sensor | * Try to make the steering proportional to the error in the line sensor | ||
* Make the light sensor trainable. (Maybe add a button to switch between training / driving mode?) | * Make the light sensor trainable. (Maybe add a button to switch between training / driving mode?) | ||
== | == Workshop == | ||
* Presentation | |||
** Laptop + powersupply | |||
** Presentation slides | |||
* Electronics | |||
** Arduinos + usb cables | |||
** Motorshields (with pinheaders presoldered on the servo pins) | |||
** 9V battery clips | |||
** tcrt5000 module | |||
** Ultrasonic sensors | |||
** Protoyping cables | |||
** Dupont cables F-F | |||
* Consumables | |||
** Toycars | |||
** AA batteries | |||
** 9V batteries | |||
* Tools | |||
** Soldering irons | |||
** Tin | |||
** Screwdrivers | |||
** Wireclippers | |||
* Other | |||
** Rubber bands | |||
** Colored tape | |||
== External links == | |||
* HC-SR04 ultrasonic sensor library. https://bitbucket.org/teckel12/arduino-new-ping/downloads | * HC-SR04 ultrasonic sensor library. https://bitbucket.org/teckel12/arduino-new-ping/downloads | ||
* L293D https://github.com/sudar/DCMotorBot | * L293D https://github.com/sudar/DCMotorBot | ||
Line 139: | Line 183: | ||
Used modules: | Used modules: | ||
* https://www.hobbyelectronica.nl/product/l293d-motor-shield/ | * https://www.hobbyelectronica.nl/product/l293d-motor-shield/ | ||
* https://opencircuit.nl/Product/10540/TCRT5000-Infrarood-lijn-detectie-module-met-instelbare-gevoeligheid | * https://opencircuit.nl/Product/10540/TCRT5000-Infrarood-lijn-detectie-module-met-instelbare-gevoeligheid | ||
Line 144: | Line 189: | ||
== Stuff that might need explaining? == | == Stuff that might need explaining? == | ||
* Digital and analog / Inputs and outputs | * Digital and analog / Inputs and outputs | ||
* What is an h-bridge? | * What is an h-bridge? | ||
[[Category:Tools]] |
Latest revision as of 19:49, 5 January 2020
Workshop manual
Team up!
- Form teams of 3-4 people
- Give your team a name!
Deconstuct the car
- Remove the screws to remove the top.
- Cut of all the wires going to the PCB, as close as possible to the PCB. (make sure the power switch keeps working and that it is off)
Test the Arduino and the Arduino software
Install Arduino Software
Open your first sketch
Open the LED blink example sketch: File > Examples >01.Basics > Blink.
Select your board type and port
You'll need to select the entry in the Tools > Board menu that corresponds to your Arduino or Genuino board.
Select the serial device of the board from the Tools | Serial Port menu. To find outwhich port to use, you can disconnect your board and re-open the menu; the entry that disappears should be the Arduino or Genuino board. Reconnect the board and select that serial port.
Upload the program
Now, simply click the "Upload" button in the environment. Wait a few seconds - you should see the RX and TX leds on the board flashing. If the upload is successful, the message "Done uploading." will appear in the status bar.
A few seconds after the upload finishes, you should see the pin 13 (L) LED on the board start to blink (in orange). If it does, congratulations! You've gotten Arduino or Genuino up-and-running.
Connect the Motor Driver
The Motor Driver or Arduino Motor Shield allows you to easily control motor direction and speed using an Arduino.
- IMPORTANT! disconnect the (green) jumper marked PWR right next to the screw terminal marked EXT_PWR
- Connect the shield to the Arduino
- Connect motor shield and Arduino to the car: Make sure motor, steering and battery cables are connected to the right outputs of the shield
Steering motor -> Shield M1 Driving motor -> Shield M4 Car battery wires -> Shield EXT_PWR
- Cover the bottom of the Arduino with a piece of tape to prevent a connection of arduino with the battery (short circuit)
- Put the AA batteries in the car
- Connect 9 v battery to arduino, then connect the battery to the motor shield
Motors test over serial connection
- Connect Arduino to your computer
- We've prepared the example code for this workshop that you can download from GitHub: sample code
- After downloading the zip file from Github open SDC_1_motor_test.ino
- In Arduino go to "Menu" > "Sketch" > "Include library" > "Manage libraries" > search for "Adafruit Motor shield V1 firmware" and add
- Test if the Motor Shield works correctly by opening the Serial Monitor (magnifying glass, right hand corner)
- Test if direction and steering works as expected
- Change the cables on the Motor Shield if necessary
Connect the line sensor
The line detection sensor module sends out short pulses of (invisible) infrared light and measures how much of that light comes back. It output the brightness/darkness as an analog voltage that the Arduino can use to steer the car.
- Take 3 cables, put it on the sensor, look carefully at the colours and connections (A0, GND, VCC). The motor shield has connections for the analog pins on the Arduino conveniently grouped with GND and 5V pins. We use these to connect our sensor to. A0 is the pin right next to the pin marked 9V.
- Connect to the Arduino/Motorshield to the sensor
Module -> Arduino - - - - - - - - - - - VCC -> 5V GND -> GND A0 -> A0
- Connect the line sensor analogue output to A0.
Module -> Arduino - - - - - - - - - - - GND -> GND VCC -> 5V
Sensor testing
- Test line sensor with: SDC_2_line_sensor_test.ino
- Follow instructions in the file to find out the lowest and the highest values to distinct the line from the floor.
Upload the car software
- Open and upload SDC_3_car_test.ino
- Adjust the values
- Upload the sofware to the Arduino
Enhance the software
- Test on the line and adjust values of speed or sensor if nessessary
Tips
- It can help to remove the V9 battery when you upload the program to the arduino
- Make sure your sensor is close to the ground
Ideas:
- Add ultrasonic sensor to avoid collisions
- Add sound
- The car now always steers either left or right. Can we add straight ahead?
- Try to make the steering proportional to the error in the line sensor
- Make the light sensor trainable. (Maybe add a button to switch between training / driving mode?)
Workshop
- Presentation
- Laptop + powersupply
- Presentation slides
- Electronics
- Arduinos + usb cables
- Motorshields (with pinheaders presoldered on the servo pins)
- 9V battery clips
- tcrt5000 module
- Ultrasonic sensors
- Protoyping cables
- Dupont cables F-F
- Consumables
- Toycars
- AA batteries
- 9V batteries
- Tools
- Soldering irons
- Tin
- Screwdrivers
- Wireclippers
- Other
- Rubber bands
- Colored tape
External links
- HC-SR04 ultrasonic sensor library. https://bitbucket.org/teckel12/arduino-new-ping/downloads
- L293D https://github.com/sudar/DCMotorBot
Used modules:
- https://www.hobbyelectronica.nl/product/l293d-motor-shield/
- https://opencircuit.nl/Product/10540/TCRT5000-Infrarood-lijn-detectie-module-met-instelbare-gevoeligheid
- https://opencircuit.nl/Product/10037/Ultrasonische-afstands-detectie-module
Stuff that might need explaining?
- Digital and analog / Inputs and outputs
- What is an h-bridge?