Date 10/19

  • Topic: Digital Fabrication 3 ( Arduino Advanced)

Contents

Pre-class

  • Learning sensor – Photoresistor

    1. Build a physical circuit below
    2. Components
      1. 220 Ohms – for LED
      2. 5k1 Ohms for Photoresistor
    3. Write the codes on Arduino
    4. Upload and test it
    5. Keep this circuit and source codes. We will use them in the class.

In-class

  • Learning sensor – Photoresistor

    1. Using the Arduino photoresistor built in the pre-class, change the amount of light goes to Photoresistor and see what happens.
    2. Open Serial Monitor on Arduino [Tools] – [Serial Monitor]
    3. Your reflections
      1. In Arduino programming, how can you trace data flow while running it?
      2. How did this example get input signal? Analog? Why?

  • An application of Photoresistor, Light Detector

    1. Project Goal: Make a light detector that turns on LED in the dark and turn off when itΒ  is bright.
    2. Use the same circuit from the previous Photoresistor example.
    3. Change the previous codes to achieve the project goal. You can follow following steps to make your codes.
      1. Read the sensor value. => sensorValue = analogRead(A0);
      2. Compare if the sensorValue is greater 200. => if (sensorValue > 200)
      3. If yes, it means it is bright. Then turn off the LED => digitalWrite (13, LOW);
      4. if no, it means it is dark. Then, turn on the LED => digitalWrite (13, HIGH);
      5. wait 0.1 seconds => delay(100);
    4. Sample codes
      1. int sensorValue = 0;void setup()
        {
        pinMode(A0, INPUT);
        Serial.begin(9600);pinMode(13, OUTPUT);
        }void loop()
        {
        // read the value from the sensor
        sensorValue = analogRead(A0);
        // print the sensor reading so you know its range
        Serial.println(sensorValue);
        // map the sensor reading to a range for the LED
        //analogWrite(9, map(sensorValue, 0, 1023, 0, 255));
        if (sensorValue > 200)
        digitalWrite(13, LOW);
        else
        digitalWrite(13, HIGH);
        delay(100); // Wait for 100 millisecond(s)
        }
    5. Run your Arduino and see what happens
    6. Your reflections
      1. Explain the codes you used.
      2. If you want to change the sensitivity of the photo sensor, what parts of the codes do you need to change?
      3. How can you apply this technique into real-world problem-solving?

  • Ultraviolet Sensor and Servo Motor

    • Goal: Build a device that moves a motor 180 degrees when it detects motions.
    • Required Components
      • Ultrasonic sensor
      • Servo motor, MicroServo 9G
    • Download the source codes and run.
      • #include<Servo.h>
        int trig=8;
        int echo=9;
        int dt=10;
        Servo servo;//int distance,duration;
        void setup() {
        // put your setup code here, to run once:
        pinMode(trig,OUTPUT);
        pinMode(echo,INPUT);
        Serial.begin(9600);
        servo.attach(3);
        }void loop() {
        // put your main code here, to run repeatedly:if (calc_dis()<10)
        {
        for (int i=0;i<=180;i++)
        {
        servo.write(i);
        delay(1);
        }
        delay(100);
        for (int i=180;i>=0;i–)
        {
        servo.write(i);
        delay(1);
        }
        delay(100);
        }
        }//This code is written to calculate the DISTANCE using ULTRASONIC SENSORint calc_dis()
        {
        int duration,distance;
        digitalWrite(trig,HIGH);
        delay(dt);
        digitalWrite(trig,LOW);
        duration=pulseIn(echo,HIGH);
        distance = (duration/2) / 29.1;
        Serial.println((String) “Duration: ” + duration + ” Distance: ” + distance);
        return distance;
        }
    • Upload the codes and run your Arduino. Explain how and why your Arduino works

  • Project Project 3: Design an Automatic Hand-Sanitizer Dispenser.

    • Using above the Ultrasonic sensor and a servo Motor, design a hand-sanitizer dispenser
    • Project details
      • Team project. Groups of four.
      • Find a Hand-Sanitizer product from the Internet.
      • Design a physical mechanism that automatically operates the dispenser by the Ultrasonic sensor.
    • Lab report should include
      • a sketch for physical settings. Recommend to use TinkerCAD.
      • a circuit diagram with Arduino, source codes.
      • Anticipated outcomes
    • Post the report to your Open Portfolio.
    • Due Oct 23rd (Friday) 5pm.
  • Reflections
      • What did you learn?
      • How can you apply this example into real-world applications?

Post-class

    • Assignment: [Lab report Automatic Hand-Sanitizer], Due Oct 23rd.
    • Next week
      • Will start the capstone design project.
      • Grouping
        • Basic – Randomizing
        • How? Special Request?
      • Explore Arduino Project. [see next week’s Pre-Class]