Jamaya's Final Project

From CSclasswiki
Jump to: navigation, search

Proposal

Overview

The goal of this project is to integrate 2-3 sensors from the Elegoo device kit and design functions that allow them to work together. My project will contain three parts as follows:

Part One: I will connect the 64-LED matrix to the Arduino and program it to make it display my name, ' J A M A Y A '.
Part Two: Using the water level detector from the kit, I will also connect this device to the Arduino, then making sure that it works the way it should by carrying out simple experiments.
Part Three: Then using the light sensor from the kit, I will also connect it to the Arduino, making sure that it works.
Part Four: This last part of the project connects the 64-LED matrix, the water sensor, the light sensor, and the Arduino together in such a way that the 64-LED will display a certain message in accordance to the water level of my cat's water bowl (which is what it will be monitoring) along with the current ambient temperature of his bowl area.

My Plan

  1. Gather the necessary materials.
  2. Get familiar with all materials by reviewing online documentation and tutorials.
  3. Connect 64-LED matrix and write a sketch for it to display my name.
  4. Connect additional sensors/devices to Arduino and write sketches to get both of them working independently.
  5. Connect all of the devices together and write a sketch that utilizes all sensors in a way that they are working together.
  6. Document progress by taking photos/videos and updating the wiki page.

The Project

Materials

  • Arduino Mega 2560
  • 64-LED Matrix display
  • Water Level Detection Sensor
  • Light sensor
  • 830 Tie-Points Breadboard
  • Breadboard Jumper Wires
  • Female-to-Male Dupont Wires
  • 220 Ohm Resistors

Part One: 64-LED Matrix

The following image (sourced from Circuit.io) shows the schematics used to connect the LED matrix to the Arduino:

LEDmatrixschematics.png


Using C in Arduino, the following sketch programs the LED matrix display print one letter of my name every second, wrapping back around the beginning when it completes.

/* Jamaya (May) Smith
 * Final Project 
 * This is the sketch for Part 1 of my final project which utilizes a 64-LED matrix
 * to display my name; 'J A M A Y A'
 * 
 * References:
 * LED Control library: http://wayoda.github.io/LedControl/
 * Google Chrome app: LED Byte Generator
 */
 
#include <LedControl.h> 

// initialize pins on matrix
int DIN = 50;
int CLK = 51;
int CS = 53;

// create LED control object
LedControl lc = LedControl( DIN, CLK, CS, 0);

// byte arrays for letters in name
// makes letters readable to LED matrix
byte j[8] = {0x8,0x0,0x8,0x8,0x8,0x8,0x48,0x30};
byte a[8] = {0x0,0x0,0x18,0x24,0x3c,0x24,0x24,0x0};
byte m[8] = {0x0,0x0,0x36,0x49,0x49,0x49,0x41,0x0};
byte y[8] = {0x0,0x24,0x24,0x24,0x1c,0x4,0x24,0x18};

// initial setup of LED matrix display
void setup() {
  lc.shutdown(0,false);       // power-saving mode on startup
  lc.setIntensity(0,5);     
  lc.clearDisplay(0);         // clear last display
}

// prints ' J A M A Y A'
void loop() {
  printByte( j );
  delay( 1000 );

  printByte( a );
  delay( 1000 );

  printByte( m );
  delay( 1000 );

  printByte( a );
  delay( 1000 );

  printByte( y );
  delay( 1000 );

  printByte( a );
  delay( 1000 ); 
}

// function to loop through & print components of byte array to LED matrix
void printByte(byte character[]) {
  int i = 0;
  for( i=0; i<8; i++ ){
    lc.setRow( 0, i, character[i] );
  }
}

To see the LED Matrix in action, refer to my video linked here and shown below:

Part Two: Adding the water level detector

Schematics:

Part2-schematics.jpeg


Code:

/* May Smith
 * Final Project
 * This is the sketch for Part 2 of my final project which activates the water level detection
 * sensor connected to the Arduino. 
 * 
 * References:
 * https://www.instructables.com/id/How-to-use-a-Water-Level-Sensor-Arduino-Tutorial/
 */

int water_lvl = 0;
int water_sensor = A8;

void setup() {
  Serial.begin( 9600 );

}

void loop() {
  int water_lvl = analogRead( water_sensor );

  Serial.print("Water level: ");
  Serial.println( water_lvl );

  delay( 5000 );

}



Images


Part Three: Adding the light sensor

Schematics:

Lightsensor.jpg


Code:

/* Jamaya (May) Smith
 * Final Project
 * This is the sketch for Part 3 of my final project which activates the 
 * light sensor connected to the Arduino.
 * 
 * References:
 * https://www.allaboutcircuits.com/projects/an-arduino-controlled-light-sensor/
 */
int lightDetection = 0;
int val = 0;

void setup() {
  Serial.begin( 9600 );
}

void loop() {
  int lightDetection = analogRead( A4 );
  Serial.println( lightDetection );
}

Part Four: Putting it all together

Below is the sketch that incorporates the use of the Arduino, the LED matrix, the light sensor, and the water-level sensor:

/* Jamaya (May) Smith
 * Final Project
 * This is the sketch for Part 4 of my final project which logically connects 
 * all previous sensors/devices to the Arduino in such a way that they can work together.
 * 
 * For this project, the water-level detector will monitor the amount of water in my cat's water bowl. Corresponding to
 * the level of water detected, the LED matrix will either display " =) " " =( " or " ok ". 
 * The light sensor will detect whether it is day or night which will be reflected on the LED matrix by displaying "Zzz's" or a sun symbol. 
 */

#include <LedControl.h> 

/*LED matrix variables*/
int DIN = 50;
int CLK = 51;     //initialize pins on matrix
int CS = 53;

LedControl lc = LedControl( DIN, CLK, CS, 0); // create LED control object

/*byte arrays for symbols to be printed*/
// sun
byte sun[8] = {0x0,0x8,0x2a,0x1c,0x7f,0x1c,0x2a,0x8};

// zzz
byte z1[8] = {0x0,0x0,0xfb,0x10,0x20,0x40,0xfb,0x0};
byte z2[8] = {0x0,0x0,0xef,0x41,0x82,0x4,0xef,0x0};
byte z3[8] {0x0,0x0,0xbe,0x4,0x8,0x10,0xbe,0x0};

// smile
byte smile1[8] = {0x0,0x24,0x24,0x24,0x0,0x81,0x42,0x3c};
byte smile2[8] = {0x0,0x24,0x24,0x24,0x0,0xff,0x42,0x3c};

// ok
byte ok[8] = {0x0,0x0,0x65,0x96,0x96,0x65,0x0,0x0};

// frown
byte frown[8]= {0x24,0x24,0x24,0x0,0x3c,0x42,0x81,0x81};

/*water sensor variables*/
int water_lvl = 0;

int low_threshold = 200; // indicates # for low water level
int high_threshold = 235; // indicates # for high water level

/*light sensor variables*/
int lightDetection = 0;


void setup() {
  Serial.begin( 9600 );

  /* LED control */
  lc.shutdown(0,false);       // power-saving mode on startup -- change to false when testing
  lc.setIntensity(0,5);     
  lc.clearDisplay(0);
}

void loop() {
  /* retrieve data from water sensor */
  int water_lvl = analogRead( A8 );
  /* retrieve data from light sensor*/
  int lightDetection = analogRead( A4 );

  if ( lightDetection > 20 ) {
    printByte( sun );
    delay( 2000 );
    
    waterDetect( water_lvl ); 
  } 
  else {
    // displays zzz in sliding motion
    delay( 100 );
    printByte( z1 );
    delay( 500 );
    printByte( z2 );
    delay( 500 );
    printByte( z3 );
    delay( 500 );
    printByte( z2 );
    delay( 500 );
    printByte( z1 );
    delay( 2000 );
    
    waterDetect( water_lvl );
  }

}

/* Determines which symbol to print based on water level measured with sensor*/
void waterDetect( int water_lvl ){
  if ( water_lvl <= low_threshold ) {
      printByte( frown );
      delay( 5000 );
  } 
  else if ( water_lvl >= high_threshold ) {
    printByte( smile1 );
    delay( 700 );
    printByte( smile2 );
    delay( 5000 );
  } 
  else {
    printByte( ok );
    delay( 5000 );
  }
}

/* Function to print bytes*/
void printByte(byte character[]) {
  int i = 0;
  for(i=0;i<8;i++){
    lc.setRow(0,i,character[i]);
  }
}

Images


Progress Log

  • 27 April: Successfully connected 64-LED Matrix to Arduino and made sure it worked correctly. Wrote sketch that makes it display my name.
  • 30 April: Successfully connected water-level detection sensor to Arduino. Wrote sketch that prints data received by the water sensor.
  • 4 May: Successfully connected light sensor to Arduino. Wrote sketch that prints data received from sensor sent as through analog connection.
  • 5 May: Wrote sketch that utilizes all devices/sensors and programs them to all work together for the final result.

References

LED Control library

Google Chrome app: LED Byte Generator

Water Level Sensor Tutorial

Light sensor tutorial