BEETS Camp 2014
With Dominic Canare, John Harrison, and Tom McGuire
Rube Goldberg created his fame by making cartoons of overly complicated devices designed to perform simple tasks in not-so simple ways.
Project Synopsis
Students will be provided with a kit, including DC motors, an Arduino, photocells, rods, tubing, wire, foam, plexiglass, glue, rubber bands, screws, etc. Students will also be provided with instruction to design pieces and parts on the foam-cutting machine.
On the final day, students will evaluate other group projects based on the the complexity/difficulty of the course they have designed for their vehicle, and the ability of their vehicle to negotiate their course. The highest scoring team will be awarded a prize!
Schedule
Day 1 |
|
---|---|
Day 2 |
|
Day 3 |
|
Day 4 |
|
Requirements
- Your module must tell a story
- Your module must have a visual aspect (we should SEE stuff happening!)
- Must include (at least) one found item
-
Input and outputs:
- Output: each module must drop a golf into a cup at the end of their series of events
- Input: each module must react to a ball dropping into a cup. The cup must be easily movable to accommodate the output from the previous module.
- No water
- No fire
Judging
You will be judged! No, seriously though, we're going to bring in some guest judges to check out your stuff. We may even have a glorious prize for the highest rated modules!
Inspiration
Building blocks and samples from Tom, Dom, and John
Tom's Demos
http://tinyurl.com/beetscode
Sensing bumps with "whiskers"
This is a very simple sensor. Whiskers can be made out of simple metal wire, which can be connected to the Arduino. When a whisker touches an object, the object pushes the whisker to another metal contact which is also connected to the Arduino. This closes a circuit, just like a switch.
In this example, the Arduino will enable LEDs corresponding to the whiskers when they are activated.
// "Whisker" / Bump Sensing Example // Refer to LED pins using a name instead of a number int LED_R = 11; // Red LED is on pin 11 int LED_G = 12; // Green LED is on 12 // Refer to whisker pins using a name instead of a number int WHISKER_L = A4; // Left whisker is on analog 4 int WHISKER_R = A5; // Right whisker is on analog 5 void setup() { // setup() - called once at the beginning pinMode(LED_RED, OUTPUT); // We are outputting data to the LEDs pinMode(LED_GREEN, OUTPUT); pinMode(WHISKER_L INPUT); // And receiving data from the whiskers pinMode(WHISKER_R, INPUT); digitalWrite(WHISKER_L, HIGH); // Set a default value for the whiskers digitalWrite(WHISKER_R, HIGH); // This prevents environment noise } void loop() { // loop() - called repeatedly if(digitalRead(WHISKER_L)==LOW){ // If the left whisker is bumped digitalWrite(LED_R, HIGH); // Turn ON the red LED }else{ // If it's not bumped digitalWrite(LED_R, LOW); // Turn OFF the red LED } if (digitalRead(WHISKER_R)==LOW){ // If the right whisker is bumped digitalWrite(LED_G, HIGH); // Turn ON the green LED }else{ // If it's not bumped digitalWrite(LED_G, LOW); // Turn OFF the green LED } }
Sensing light with a photocell
The photocell is a semiconductor whose electrical resistance is dependent on the amount of light shining into it.
In this example, the photocell is connect to an analog pin, so that its value can be read. With that information, the Arduino adjusts the brightness of the LED.
// Photocell Example void setup(){ // setup() - called once at the beginning pinMode(A0, INPUT); // We'll read the photocell on Analog pin 0 digitalWrite(A0, HIGH); // Set a default value pinMode(3, OUTPUT); // We will control the LED on pin 3 digitalWrite(3, 0); // Turn the LED off } void loop(){ // loop() - called repeatedly int value = analogRead(A0); // Read the photocell's value float percent = (float)value/340; // By experimenting, we found that 340 is // about the highest possible value // So we'll calculate a number as a // percentage of 340 int output = 255 * percent; // The highest value we can send to the // LED is 255, so find the % of that if(output > 255){ // If, somehow, we've calculated a higher output = 255; // number than 255, cap it. } analogWrite(3, output); // Turn the LED on and off really fast // So fast, the LED seems dimmer/brighter // Higher values = LED on longer // 0 = off, 128 = 50%, 255 = 100% }
Sensing proximity with an IR emitter/receiver
Infrared light is invisible to the human eye, but not to this sensor. By shining IR light and detecting its reflection, the sensor can determine how close or far an object is.
In this example, the distance is measured first and a far object activates the green LED. A somewhat close object activates the yellow LED, and a very close object activates the red LED.
The servo sweeps the sensor back and forth, giving it a great field of view. This is optional.
// IR Proximity Sensing Example #include <Servo.h> // Load a library which makes it really easy to Servo myServo; // control a servo. void setup(){ // setup() - called once at the beginning pinMode(A0, INPUT); // Read the distance sensor on Analog pin 0 pinMode(2, OUTPUT); // Pin 2 controls the green LED pinMode(3, OUTPUT); // Pin 3 controls the yellow LED pinMode(4, OUTPUT); // Pin 3 controls the red LED myServo.attach(9); // Pin 9 controls the servo myServo.write(0); // Set the servo to 0 degrees } int dir = 1; // Keep track of which direction we're turning int pos = 0; // Keep track of current servo position void loop(){ // loop() - called repeatedly int led_r = 0; // Only one LED will be enabled. Assume all int led_y = 0; // will be turned off until we know which one int led_g = 0; // will be turned on int value = analogRead(A0); // Read the current distance if(value < 100){ // If the distance is small led_r = 1; // we should enable the red LED }else if(value < 500){ // If the distance is moderate led_y = 1; // we should enable the yellow LED }else{ // If the distance is large led_g = 1; // we should enable the green LED } digitalWrite(2, led_r); // Update the LED's digitalWrite(3, led_y); digitalWrite(4, led_g); if(pos > 179){ // If the servo is far right then dir = -1; // we should start moving left }else if(pos < 1){ // If the servo is far left then dir = 1; // we should start moving right } pos += dir; // Increase the position in the correct direction myServo.write(pos); // Tell the servo where it should be delay(20); // Do nothing for 20ms (gives time to move) }
Controlling a DC motor with a transistor
A transistor can function like a switch which we can be controlled electronically.
In this example, the Arduino controls the speed of a motor by rapidly flipping the "switch" off and on using Pulse Width Modulation.
// DC Motor Control Example void setup() { // setup() - called once at the very beginning pinMode(A2, INPUT); // Potentiometer's value is read on Analog pin 2 pinMode(3, OUTPUT); // Motor speed is controlled using Digital pin 3 digitalWrite(3, 0); // Turn the motor off initially } void loop() { // loop() - called repeatedly int value = analogRead(A2); // Read the current value (10 bits) // NOTE: We can only send 8 bits of data to the // analogWrite function below. So we must the 2 // least significant digits from the value we // read in. value = value << 2; // Drop the 2 least significant digits analogWrite(3, value); // Flip the transistor on and off really fast // Higher values = transistor on longer // 0 = off, 128 = 50%, 255 = 100% }
Controlling a servo
In this example, a potentiometer acts as an analog input, and the servo acts as an output.
A potentiometer is a resistor whose value can be altered by turning a knob.
The Arduino will sense the position of the potentiometer and rotate the servo to match.
// Example #includeServo myServo; void setup() { // setup() - called once at the very beginning pinMode(A0, INPUT); // Potentiometer's value is read on Analog pin 0 myServo.attach(9); // The servo's control signal is sent on digital pin 9 } void loop() { // loop() - called repeatedly int value = analogRead(A0); // Read the current value (10 bits (0-1023)) // NOTE: We can only send 8 bits (0-255) of data to // the analogWrite function below. So we will map // one range onto the other value = map(value, 0, 1023, 0, 255); myServo.write(value); // Move the servo! // Higher values = larger angle // 0 = 0 degrees, 128 = 90 degrees, 255 = 180 degrees }
Other resources
Most of the tools we're using for this course are 100% Open Source and FREE!
- Code from Tom's demos
- Arduino IDE - for programming the Arduino
- Inkscape - for drawing vector graphics we can cut out of foam
- Arduino Tutorials
- Fritzing - the program used to make the pretty diagrams