Allie's Final Project

From CSclasswiki
Jump to: navigation, search

Proposal

Overview

I plan to create an Arduino-only project that will include the 64-LED matrix, the temperature and humidity sensor, and the DC motor. I will write all programs in C using the Arduino IDE.

Depending on the temperature and humidity reading from the sensor, the DC motor will turn on or off, powering a fan. The 64-LED matrix will display the temperature and humidity, and indicate when the fan is switched on or off.

Before taking the steps I outline in the next section, I will explore each of the modules I plan to use to make sure I understand how it works, and how to properly integrate it in my project.

Steps

Here are the steps I will take to build the project (these correspond to the 4 parts of the project):

  1. I will connect the 64-LED matrix to the Arduino, and write a sketch that makes it display my name.
  2. I will connect the temperature and humidity sensor to the Arduino, with the 64-LED matrix still connected. The temperature and humidity values detected by the sensor will be displayed by the 64-LED matrix.
  3. I will connect the DC motor to the Arduino, with the 64-LED matrix still connected. I will wire a circuit with a button, so that when the button is pressed, the DC motor turns on and rotates a fan. The 64-LED matrix will indicate whether the fan is on or off.
  4. I will connect all three modules to the Arduino. The temperature and humidity reading from the sensor will control whether the DC motor with the fan is turned on or off (higher temperature or humidity will turn on the fan). The 64-LED matrix will continuously display the temperature and humidity reading from the sensor, and if the fan is turned on or off it will display a message indicating this.

Project

Part 1

Materials

  • Arduino Mega2560
  • MAX7219 LED Dot Matrix Module
  • breadboard
  • wires

Schematic

Part1 bb.png

Code

/*
 * part1.ino 
 * Allie Klump
 * 
 * Writes my name on the LED matrix
 */

#include <LedControl.h>                       // include library to work with LED matrix

int DIN = 12;                                 // define pins
int CS = 11;
int CLK = 10;

LedControl matrix = LedControl(DIN,CLK,CS,1); // initialize matrix

int delayTime = 750;                          // set standard delay time

void setup() {
  matrix.shutdown(0,false);                   // wakeup call for LED matrix
  matrix.setIntensity(0,8);                   // set brighness to medium values
  matrix.clearDisplay(0);                     // clear the display
}

void writeA() {                               // write the capital letter A
  byte A[5] = {B00111111,                     // array of bytes to write A
               B01000100,
               B01000100,
               B01000100,
               B00111111};
  matrix.clearDisplay(0);                     // clear display
  matrix.setRow(0,2,A[0]);                    // write letter A using array
  matrix.setRow(0,3,A[1]);
  matrix.setRow(0,4,A[2]);
  matrix.setRow(0,5,A[3]);
  matrix.setRow(0,6,A[4]);
  delay(delayTime);                           // delay to show letter
}

void writel() {                               // write the lower case letter L
  byte l[3] = {B00000001,                     // array of bytes to write l
               B01111111,
               B01000001};        
  matrix.clearDisplay(0);                     // clear display
  matrix.setRow(0,4,l[0]);                    // write letter l using array
  matrix.setRow(0,5,l[1]);
  matrix.setRow(0,6,l[2]);
  delay(delayTime);                           // delay to show letter
}

void writei() {                               // write the lower case letter I
  byte i[3] = {B00000001,                     // array of bytes to write i
               B01011111,
               B00010001};
  matrix.clearDisplay(0);                     // clear display
  matrix.setRow(0,4,i[0]);                    // write letter i using array
  matrix.setRow(0,5,i[1]);
  matrix.setRow(0,6,i[2]);
  delay(delayTime);                           // delay to show letter
}

void writee() {                               // write the lower case letter E
  byte e[5] = {B00001100,                     // array of bytes to write e
               B00010101,
               B00010101,
               B00010101,
               B00001110};
  matrix.clearDisplay(0);                     // clear display
  matrix.setRow(0,2,e[0]);                    // write letter e using array
  matrix.setRow(0,3,e[1]);
  matrix.setRow(0,4,e[2]);
  matrix.setRow(0,5,e[3]);
  matrix.setRow(0,6,e[4]);
  delay(delayTime);                           // delay to show letter
}

void writeSpace() {                           // write a space
  matrix.clearDisplay(0);                     // clear display
  delay(delayTime);                           // delay to show space
}

void loop() {
  writeA();                                   // write letters A-l-l-i-e...
  writel();                   
  writel();
  writei();
  writee();
  writeSpace();                               //...followed by a space
}

Video

Part1.gif

Part 2

Materials

  • Arduino Mega2560
  • MAX7219 LED Dot Matrix Module
  • DHT11 Temperature and Humidity Sensor
  • breadboard
  • wires

Schematic

Part2 bb.png

Code

/*
 * part2.ino 
 * Allie Klump
 * 
 * Measure the temperature and humidity and
 * display the values on the LED matrix
 */

#include <LedControl.h>                       // include library to work with LED matrix
#include <SimpleDHT.h>                        // include library to work with temp and humidity sensor

int DIN = 12;                                 // define pins
int CS = 11;
int CLK = 10;
int sensorPin = 2;

LedControl matrix = LedControl(DIN,CLK,CS,1); // initialize matrix
SimpleDHT11 sensor;                           // initialize temp and humidity sensor

int delayTime = 500;                          // set standard delay time

void setup() {
  matrix.shutdown(0,false);                   // wakeup call for LED matrix
  matrix.setIntensity(0,8);                   // set brighness to medium values
  matrix.clearDisplay(0);                     // clear the display
}

void writeDegC() {                            // write deg C
  byte degC[8] = {B00010010,
                  B00100001,
                  B00100001,
                  B00011110,
                  B01100000,
                  B10010000,
                  B10010000,
                  B01100000};
  matrix.clearDisplay(0);
  matrix.setRow(0,0,degC[0]);
  matrix.setRow(0,1,degC[1]);
  matrix.setRow(0,2,degC[2]);
  matrix.setRow(0,3,degC[3]);
  matrix.setRow(0,4,degC[4]);
  matrix.setRow(0,5,degC[5]);
  matrix.setRow(0,6,degC[6]);
  matrix.setRow(0,7,degC[7]);
  delay(delayTime);
}

void writePercent() {                         // write %
  byte percent[5] = {B00100011,
                     B00010011,
                     B00001000,
                     B01100100,
                     B01100010};
  matrix.clearDisplay(0);
  matrix.setRow(0,1,percent[0]);
  matrix.setRow(0,2,percent[1]);
  matrix.setRow(0,3,percent[2]);
  matrix.setRow(0,4,percent[3]);
  matrix.setRow(0,5,percent[4]);
  delay(delayTime);
}

void writeData(int data) {                    // write integer data
  byte nums[10][5] = {{B00111110, B01010001, B01001001, B01000101, B00111110}, 
                      {B0, B0, B00000001, B01111111, B00100001},  
                      {B00110001, B01001001, B01000101, B01000011, B00100001},  
                      {B01000110, B01101001, B01010001, B01000001, B01000010},  
                      {B00000100, B01111111, B00100100, B00010100, B00001100},  
                      {B01001110, B01010001, B01010001, B01010001, B01110010},  
                      {B00000110, B01001001, B01001001, B00101001, B00011110},  
                      {B01110000, B01001000, B01000111, B01000000, B01100000},  
                      {B00110110, B01001001, B01001001, B01001001, B00110110}, 
                      {B00111100, B01001010, B01001001, B01001001, B00110000}};
  int tens = data / 10;                       // get tens digit
  int ones = data % 10;                       // get ones digit
  matrix.clearDisplay(0);
  matrix.setRow(0,1,nums[tens][0]);           // write tens digit
  matrix.setRow(0,2,nums[tens][1]);
  matrix.setRow(0,3,nums[tens][2]);
  matrix.setRow(0,4,nums[tens][3]);
  matrix.setRow(0,5,nums[tens][4]);
  delay(delayTime);
  matrix.clearDisplay(0);
  matrix.setRow(0,1,nums[ones][0]);           // write ones digit
  matrix.setRow(0,2,nums[ones][1]);
  matrix.setRow(0,3,nums[ones][2]);
  matrix.setRow(0,4,nums[ones][3]);
  matrix.setRow(0,5,nums[ones][4]);
  delay(delayTime);
}

void writeSpace() {                           // write a space
  matrix.clearDisplay(0);
  delay(delayTime);
}

void loop() {
  byte temperature = 0;                       // initialize temperature...
  byte humidity = 0;                          // ...humidity...
  byte data[40] = {0};                        // ...and data
  sensor.read(sensorPin,                      // read data from the sensor
              &temperature, 
              &humidity, 
              data);
  writeData((int) temperature);               // write the temp to the LED matrix
  writeDegC();
  writeSpace();
  writeData((int) humidity);                  // write humidity to the LED matrix
  writePercent();
  writeSpace();
}

Video

Part2.gif

Part 3

Materials

  • Arduino Mega2560
  • MAX7219 LED Dot Matrix Module
  • DC motor and fan blade
  • breadboard
  • wires

Schematic

Code

Video

Part 4

Materials

  • Arduino Mega2560
  • MAX7219 LED Dot Matrix Module
  • DHT11 Temperature and Humidity Sensor
  • DC motor and fan blade
  • breadboard
  • wires

Schematic

Code

Video

References

  • I used the pdf guide that came with the Elegoo most complete starter kit to understand how to use the modules
  • I used the code for the different Elegoo lessons as a starting point for my code
  • I used Fritzing to generate the schematics
  • I used https://ezgif.com/ to generate the gifs