2021W1 – Lab 1: Sensation

WEEK OF SEPT 13

Learning Goals

This lab will introduce you to the basics of robot sensation. As a result, you’ll become familiar with general safety guidelines for the COGS lab and basic circuitry. Start by programming and completing the circuit the LED blink activity, the “Hello World!” equivalent for Arduino, then move on to sensing.

This is also the first time you will be working with your team. You may find that you have to divide the work up to be able to complete the whole lab in time. Before starting, have a brief discussion about what everyone feels comfortable doing and what everyone would like to have practice with. Delegate tasks by balancing each person’s strengths with each person’s weaknesses. You may want to delegate roles such as note-taker, coder, circuit-builder, coordinator, and/or explainer.

Challenges are offered to guide your creative expression and are not necessary to complete. We’re happy with you coming up with your own challenges!

Pre-Lab

  1. Review the Arduino Uno schematic in the appendix and circuitry basics,
  2. Run through this Arduino Set Up Tutorial
  3. Skim over the COGS 300 Lab Manual
  4. Draft a circuit that connects Arduino Pin 13 to a resistor then to an LED then to ground.
  5. Download the Arduino IDE

Lab

Part 1: Safety Overview

In the COGS 300 Lab, you will be handling live current. You can cause damage to yourself, others and your equipment unless you are being careful.

With that in mind, please adhere to the following guidelines:

  1. Don’t touch leads together (power to ground with no resistance)
  2. Always set up your circuit “from the ground up” – set up your ground first, and plug in your power source last.
  3. If you break a component or need something extra, talk to your TA.
  4. Always charge your batteries when you are finished.
  5. Refrain from using batteries before a lab you are not in – this will make it more difficult for other groups to perform their lab tasks as they will be working with drained batteries. Instead, recharge them.
  6. Clean up your workstation completely after you are done. This means putting away Lego into the right bins, putting all your components back into your bin, and throwing away any garbage.
  7. Always use electrical tape to cover bare wire.

Part 2: Blink Program

Materials: 1x Arduino, 1x Resistor (resistance between 230 ~ 5k Omhs is okay), 1x LED

  1. Follow the Arduino Blink tutorial to build your circuit. Remember, you can damage your board if things are not plugged in correctly, so show your TA if you are unsure.

The code is pretty self explanatory, but notice the general structure of the code. It starts with a setup function, where relevant variables are declared, while the actual functionality of your Arduino is dictated by the contents of the loop function. 

Part 3: Potentiometers

Everyone should complete this portion on their own board.

  1. Build a circuit the circuit shown in this instructable.
  2. Make sure you read the output in the Serial Monitor. You can find the Serial Monitor under “Tools” for Windows. Does it make sense?
  3. Make two circuits!
    1. Take the unused analog output and attach an LED. Use the Blink circuit as a guide, but attach the LED to pin 09. Remember that the LONG end of the LED is for the “power” and the SHORT end is for the “ground.”
    2. Make the LED change brightness depending on the potentiometer output.
  4. If you’d like, show your TA that it works.

Part 4: Photoresistors

Depending on the size of your group, you may find it useful to use some people’s breadboards to work ahead or test other circuit configurations. Keep this portion on at least one person’s breadboard to show the TA at the end.

  1. Build a circuit the circuit shown in this instructable
  2. You can run the program from the instructable as is, but it might be helpful to add Serial.begin(9600); to the setup function of the program. Then add Serial.println(value); to the loop function of the program. Then go to the Serial Monitor to see the output values.
  3. If you’re not getting good responsiveness, try varying the brightness threshold (at 25 in the above instructable).
  4. Modify the program and circuit to vary LED brightness with photoresistor readings.
  5. Show your TA before moving onto the challenge component.

Optional Challenge: Ultrasonic sensor

Challenge components are offered to help deepen your understanding of the material and provide insight into future labs. Labs are designed so that you should be able to get to the challenge component with enough time, especially if you are dividing the work. However, it is important information for us if you cannot complete the lab in time, so tell your TA if you’re stuck!

  1. Build a circuit for the Ultrasonic sensor show in this resource.
    • Scroll down and use the Source code with New Ping.
    • Download and use the New Ping Library by going to Tools > Manage Libraries… and then searching for “New Ping” in the top search bar.
  2. Program the Arduino to output distance in inches and centimetres.
  3. Play with all of the components you learned about today. What can you make them to together?
  4. Show the TA and post to Discord.

Post-lab

Go to the Discord server and post a hello message. Include a picture of any of your circuits!

 

Feel free to review other Arduino resources for sensors/other attachments relevant for the COGS Lab this term:

Troubleshooting

  • Make sure you’ve chosen the correct port and console
  • longer stick on the LED is the positive side
  • always use a resistor!
  • Copying and pasting code doesn’t always work, you may need to type it out!
  • When printing out things in the console, make sure you have Serial.beging(9600); in your setup
  • If blink doesn’t work, change your arduino

Appendix

(Click the photo below for larger image!)