Difference between revisions of "270j Final Project"

From CSclasswiki
Jump to: navigation, search
(External References)
(External References)
Line 13: Line 13:
 
* [http://www.science.smith.edu/dftwiki/images/2/2e/ELEGOOMega2560Lessons.pdf ELEGOO kit documentation]
 
* [http://www.science.smith.edu/dftwiki/images/2/2e/ELEGOOMega2560Lessons.pdf ELEGOO kit documentation]
 
* [https://create.arduino.cc/projecthub/SAnwandter1/programming-4-digit-7-segment-led-display-2d33f8 4-digit-7-segment display tutorial]
 
* [https://create.arduino.cc/projecthub/SAnwandter1/programming-4-digit-7-segment-led-display-2d33f8 4-digit-7-segment display tutorial]
* [https://www.tutorialspoint.com/arduino/arduino_ultrasonic_sensor.htm Ultrasonic sensor tutorial]
+
* [https://create.arduino.cc/projecthub/Isaac100/getting-started-with-the-hc-sr04-ultrasonic-sensor-036380 Ultrasonic sensor tutorial]
  
 
==Part 1==
 
==Part 1==

Revision as of 18:52, 6 May 2020

Project Proposal

This is an Arduino-Only project.

Goal

The goal of this project is to implement a safety fan blade whose rotational speed is dependent on the distance between an ultrasonic sensor and an object in front of it. The distance is read from the ultrasonic sensor. The smaller the distance, the slower the fan will operate; and when the distance is smaller than 5cm, the fan will stop operating.

External References

Part 1

Connect a 64-LED matrix display to my Arduino and program it to display my name "NOX".

Schematic

Wiring of a 8x8 LED matrix to Arduino Mega2650

Source Code

The following program displays the letters 'N', 'O', 'X' one at a time repeatedly.

/*  
 *  led64
 *  Nox Yu 
 *  part 1 of the final project for csc270
 *  this program makes the 8x8 LED matrix displays N, O, X, one at a time repeatedly
 */
#include <LedControl.h>

int DIN = 12;
int CS = 11;
int CLK = 10;
byte n[8] = {0xE3, 0xF3, 0xFB, 0xDD, 0xDD, 0xCF, 0xCF, 0xC7};
byte o[8] = {0x3C, 0x7E, 0xE7, 0xC3, 0xC3, 0xE7, 0x7E, 0x3C};
byte x[8] = {0x81, 0xC3, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0xC3};
LedControl lc = LedControl(DIN, CLK, CS, 0);

// display each row on the matrix according to the bytes array input
void printByte(byte bytes[]){
  int i=0;
  for (i=0; i<8; i++ ){
    lc.setRow(0, i, bytes[i]); 
  }
}

void setup() {
  // put your setup code here, to run once:
  lc.shutdown(0, false); // shutdown the power saving mode
  lc.setIntensity(0, 15); // set brightness to max
  lc.clearDisplay(0);
}

void loop() {
  // put your main code here, to run repeatedly:
  printByte(n);
  delay(1000);
  printByte(o);
  delay(1000);
  printByte(x);
  delay(1000); 
}

Part 2

Connect an ultrasonic sensor to my Arduino. To verify that it works correctly, the 4-digit-7-segment display will show the distance between the sensor and an object in front of it in cm.

Part 3

Connect the fan and its motor to my Arduino. To verify that it works correctly, a push button is implemented. By default (when the program was initiated), the fan is not operating. It will only start to operate after the button is pressed. It will stop operating if the button is pressed again.

Part 4

The fan is controlled by a push button. By default (upon initiation of the program), the fan does not operate. It starts operating after the button has been pressed. If the button is pressed again, the fan will stop operating.

The fan blade's rotational speed should be proportional to the distance read from the ultrasonic sensor. It should have four levels:

  • if the nearest object is within 5cm: fan does not operate
  • if the nearest object is 5cm ~ 10cm away: fan operates at 1/3 of its maximum rotation speed
  • if the nearest object is 10cm ~ 20cm away: fan operates at 2/3 of its maximum rotation speed
  • if the nearest object is > 20cm away: fan operates at its maximum rotation speed