Core Lab Final

Test:

 

Demo:

 

Code:

#include “Wire.h”
#include “I2Cdev.h”
#include “MPU6050.h”

float axx[2] = {0}, ayy[2] = {0}, azz[2] = {0};

float x = 0, y = 0, z = 0;
int reading = 0;
/* MPU6050 */

MPU6050 accelgyro;

unsigned long now, lastTime = 0;
float dt; //time

int16_t ax, ay, az, gx, gy, gz; //the raw data
float aax=0, aay=0,aaz=0, agx=0, agy=0, agz=0; //angle variable
long axo = 0, ayo = 0, azo = 0; //accelerometer offset
long gxo = 0, gyo = 0, gzo = 0; //gyroscopic offset

float pi = 3.1415926;
float AcceRatio = 16384.0; //The ratio of the accelerometer
float GyroRatio = 131.0; //The ratio of gyroscopes

uint8_t n_sample = 8; //The sampling number of the accelerometer filter algorithm
float aaxs[8] = {0}, aays[8] = {0}, aazs[8] = {0}; //x,y
long aax_sum, aay_sum,aaz_sum;

 

/* RGB LED */
int redpin = 9; //select the pin for the red LED
int greenpin =10; // select the pin for the green LED
int bluepin =11; // select the pin for the blue LED
int val;
int r_val;
int g_val;
int b_val;

/* switch */
const int lzPin = 2;
int lzState;
const int ledPin = 13;

unsigned long lastDebounceTime = 0;
unsigned long debounceDelay = 180000;

void setup() {
pinMode(lzPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
pinMode(redpin, OUTPUT);
pinMode(greenpin, OUTPUT);
pinMode(bluepin, OUTPUT);
Wire.begin();
Serial.begin(115200);

accelgyro.initialize(); //initialization

unsigned short times = 200;
for(int i=0;i<times;i++){
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
axo += ax; ayo += ay; azo += az;
gxo += gx; gyo += gy; gzo += gz;

}

axo /= times; ayo /= times; azo /= times; //Calculate the accelerometer deviation
gxo /= times; gyo /= times; gzo /= times; //Calculate the gyro shift
}

void loop() {

reading = digitalRead(lzPin);

if (reading != lzState) {
lastDebounceTime = millis();
}

unsigned long now = millis(); //time(ms)
dt = (now – lastTime) / 1000.0; //(s)
lastTime = now; //last time(ms)

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); //raw data

float accx = ax / AcceRatio; //x acceleration
float accy = ay / AcceRatio; //y acceleration
float accz = az / AcceRatio; //z acceleration

aax = atan(accy / accz) * (-180) / pi; //the angle between the Y-axis and z axis
aay = atan(accx / accz) * 180 / pi; //x,z
aaz = atan(accz / accy) * 180 / pi; //z,y

aax_sum = 0;
aay_sum = 0;
aaz_sum = 0;

for(int i=1;i<n_sample;i++){
aaxs[i-1] = aaxs[i];
aax_sum += aaxs[i] * i;
aays[i-1] = aays[i];
aay_sum += aays[i] * i;
aazs[i-1] = aazs[i];
aaz_sum += aazs[i] * i;
}

aaxs[n_sample-1] = aax;
aax_sum += aax * n_sample;
aax = (aax_sum / (11*n_sample/2.0)) * 9 / 7.0; //chang the angle between 0-90°
aays[n_sample-1] = aay;
aay_sum += aay * n_sample;
aay = (aay_sum / (11*n_sample/2.0)) * 9 / 7.0;
aazs[n_sample-1] = aaz;
aaz_sum += aaz * n_sample;
aaz = (aaz_sum / (11*n_sample/2.0)) * 9 / 7.0;

axx[0] = axx[1];
axx[1] = aax;
ayy[0] = ayy[1];
ayy[1] = aay;
azz[0] = azz[1];
azz[1] = aaz;

x = axx[1] – axx[0];
y = ayy[1] – ayy[0];
z = azz[1] – azz[0];

if ((millis() – lastDebounceTime) < debounceDelay && lastDebounceTime != 0) {
digitalWrite(ledPin, HIGH);

if(x<5 && y<5 && z <5){
reading = digitalRead(lzPin);
if (reading != lzState) {
digitalWrite(ledPin, LOW);

analogWrite(9, 0);
analogWrite(10, 0);
analogWrite(11, 0);
}
}

// red
else if(aaz > -95 && aaz < -85){
r_val = 250;
g_val = 0;
b_val = 0;
analogWrite(9, r_val);
analogWrite(10, g_val);
analogWrite(11, b_val);
}

// green
else if(aaz > 85 && aaz < 95){
r_val = 0;
g_val = 255;
b_val = 0;
analogWrite(9, r_val);
analogWrite(10, g_val);
analogWrite(11, b_val);
}

// blue
else if(aay > -95 && aay < -85){
r_val = 0;
g_val = 0;
b_val = 255;
analogWrite(9, r_val);
analogWrite(10, g_val);
analogWrite(11, b_val);
}

// yellow
else if(aay > 85 && aay < 95){
r_val = 240;
g_val = 205;
b_val = 12;
analogWrite(9, r_val);
analogWrite(10, g_val);
analogWrite(11, b_val);
}

// purple
else if(aax > -95 && aax < -85){
r_val = 237;
g_val = 12;
b_val = 240;
analogWrite(9, r_val);
analogWrite(10, g_val);
analogWrite(11, b_val);
}

// cyan
else if(aax > 85 && aax < 95){
// r_val = 16;
// g_val = 192;
// b_val = 224;
// analogWrite(9, r_val);
// analogWrite(10, g_val);
// analogWrite(11, b_val);
for(val=255; val>0; val–)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
Serial.println(val);
delay(1);
}
for(val=0; val<255; val++)
{
analogWrite(11, val);
analogWrite(10, 255-val);
analogWrite(9, 128-val);
delay(1);
}
}

// black
else{
analogWrite(9, r_val);
analogWrite(10, g_val);
analogWrite(11, b_val);
}
}

else{
digitalWrite(ledPin, LOW);

analogWrite(9, 0);
analogWrite(10, 0);
analogWrite(11, 0);
}

lzState = LOW;
}

Interactive 3d Print(Core Lab)

Sketch:

3D model:

Background Story:

Kawakappa
Kappa which is also known as water monkey is probably the most well-known Japanese folklore. It looks like Goblin but with the scales of fish and the shell of a turtle. On the head of a Kappa, it has a plate full of water from its original spring. Once the water spilled out, it would lose its superpower. Kappa likes cucumber. Human beings sometimes gave Kappa cucumbers to gain their favors. Another feature of Kappa is that they always keep promises. In Japan, different Kappa has different names. Once a Kappa fails to keep its promise for too many times, its plate would break immediately and degenerate to a lower level Kappa which is called Kawakappa. Kawakappa is normally a bad creature. It’s very small in size (size of a 5-year-old child) but very cunning. It likes to steal the fortune from human beings and likes to play tricks on human beings. Losing its superpower, Kawakappa’s only weapon is its intelligence and ability to lie.
Once there was a small village in Japan that was bothered by Kawakappa. There were too many Kawakappa in this village. They stole things from the villagers and poked fun at them. Although Kawakappa was too weak to hurt any human beings, their actions were so annoying that the villagers had to seek help from outside. As the scum of Kappa community, Kawakappa was also hated by other Kappas. Kappas believed that they have a sense of mission to clear those Kawakappa. Answered to the villagers’ help, some Kappa came and eliminated the Kawakappa that was bothering this village. The villagers prepared hundreds of cucumbers to thank those good Kappa. They even built a status of Kappa in their village and claimed that Kappa is this village’s guardian angel.
However, there were still some good Kawakappa. Losing supernatural was a punishment for their actions of breaking promises. If they kept doing good to human beings, they would have a chance to gain back their power.

The extraterrestrial is my inspiration. I want to create a monster basic on water monkey of Japanese folklore. It looks like Goblin but with the scales of fish and the shell of a turtle. I add two antlers in his head in order to look stranger. I use the Sculpture to make this 3D model. I will try adding some circuit into this monster in order to make a monster lamp.

Midterm for Core Lab

match lamp

I want to make a lamp with high technology, but it looks very ordinary. People should not forget the match that brings light to us.

Research:

The smart home market will take off if IoT device prices come down and the general public comes to understand the benefits of these products. And from smart homes, the next logical step is smart cities, which would take the IoT to the next level.

 

 

Inspiration:

The movement of the user is tracked using the light bulb to create digital art. properties such as speed, vector, rotation are determined for each particle based on the movement of the user. I was considering about some motion tracking with the smart home.

The match was the first tool to bring light to people. I want to make a  normal surface likes like the matchbox with high technology.

Description:

  • Material: Infrared Obstacle Avoidance Sensor
  • Sound Microphone Sensor,RGB LED strip
  • Skill: laser cutting, Arduino
  • Target population: young people who like new things

 

Test vedio:

 

Demo:

1.Functuon:Infrared Obstacle Avoidance Sensor & LED

2.Function:Sound Microphone Sensor & LED

Code:

#include <Adafruit_NeoPixel.h>

#define PIN 6
int Led = 15;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Led, PIN, NEO_GRB + NEO_KHZ800);
int state =0;
int ledNum;
int val;
int buttonPin0 =2;
int buttonPin1 =3;
boolean buttonState0 = false;
boolean buttonState1 = false;
long st,st0,st1;
int changdiState = 0;
long changdiTime;

void setup() {
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to ‘off’
}

void loop() {
ButtonCK();
if(state==1){
if(millis()-st>100 & ledNum<Led){
st=millis();
ledNum++;
strip.setPixelColor(ledNum, strip.Color(200, 0, 200));
}

}else if(state==2){
ledNum=0;
rainbowCycle(20);
}else if(state==3){
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
}else{
ledNum=0;
for(int i=0; i<Led; i++){
strip.setPixelColor(i, strip.Color(0, 0, 0));
}
}
strip.show();

}

void ButtonCK(){
buttonCheck();
val=analogRead(A0);
if(changdiState==0 & buttonState0 & millis()-changdiTime>500){
changdiState=1;
changdiTime=millis();
}
if(changdiState==1 & buttonState1){
state++;
changdiState=0;
}
if(state>3)state=1;
if(val>800){
state=0;
}
Serial.print(val);
Serial.print(“,”);
Serial.println(state);
}

void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
ButtonCK();
}
ButtonCK();
if(state!=2)break;
strip.show();
delay(wait);
}
}

uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 – WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 – WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 – WheelPos * 3);
}
}

void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
ButtonCK();
if(state!=3)break;
}
}

void buttonCheck(){
if(!buttonState0 & !digitalRead(buttonPin0)){
st0=millis();
buttonState0 = true;
}else if(buttonState0 & digitalRead(buttonPin0)){
buttonState0 = false;
}

if(!buttonState1 & !digitalRead(buttonPin1)){
st1=millis();
buttonState1 = true;
}else if(buttonState1 & digitalRead(buttonPin1)){
buttonState1 = false;
}
}

Interactive Story(Core Lab)

The interactive story project is a big challenge for me because I never did the similar project before. I plan to use the all Arduino hardware that is our learning from the class such as RGB Led, photoresistor, and potentiometer. Then, I want to describe my daily life by the processing part.
In the first page, I am drawing the sunrise at the mountain in the background, and it expresses the morning. The photoresist to control the screen brightness. In the second page, I create a bouton which is the button of the RGB Led with Arduino because my first thing is turning on the light in the morning. The RGB Led is cycled color when the mouse clicked the button in the processing. In the third page, I want to express the rainy day, and I add the buzzer in order to simulate the sound of lightning. In the fourth page, A row rectangle represents the subway, and the background changes color when I rotate the potentiometer. In the fifth page, it is similar to the first page, and I want to express the sunset.

Laser Cutting Lamp (Core Lab)

The circuit below here.

The lamp.

Function: The RGB LED inside and it was cycling through colors.

code:

int redLedPin = 4;
int greenLedPin = 5;
int buleLedPin = 6;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(redLedPin, OUTPUT);
pinMode(greenLedPin, OUTPUT);
pinMode(buleLedPin, OUTPUT);

}

void loop() {

//red
analogWrite(redLedPin, 255);
analogWrite(greenLedPin, 0);
analogWrite(buleLedPin, 0);
delay(500);

//green
analogWrite(redLedPin, 0);
analogWrite(greenLedPin, 255);
analogWrite(buleLedPin, 0);
delay(500);

//bule
analogWrite(redLedPin, 0);
analogWrite(greenLedPin, 0);
analogWrite(buleLedPin, 255);
delay(500) ;
}

 

Core lab week1 assignment

Arduino week1 assignment

 

  1. i) Types of connection to the Arduino

 

  • Uno R3 Controller Board 1PC

The microcontroller on the board is programmed using the Arduino programming language (based on Wiring) and the Arduino development environment (based on Processing).

 

  • LCD 1602 Module (with pin header 1PC)

16×2 Character LCD module based on the HD44780 controller.

White characters on blue background with backlight.

Comes with headers, a diode and a variable resistor for your peace of mind.

 

  • Prototype Expansion Board 1PC

The ProtoShield is prototype expansion board with 2 LEDs and 2 button, which can be used directly and more convenience. All the pins and power have been lead out. It is very suitable for building prototype circuit with Arduino.

 

  • Power Supply Module 1PC

This module has power-down stored function and can store 10 groups preset value.

 

  • ULN2003 Stepper Motor Diver Board 1PC

This is a convenient package of seven Darlington transistors.

 

  • Stepper Motor 1PC

This is a ready-to-go cable and a machined drive shaft (so you can easily attach stuff). We drove it with an Adafruit motor shield for Arduino and it hummed along nicely at 50 RPM.

 

  • Servo Motor (SG90)1PC

core motor

 

  • 5v Relay 1PC

5V Relay Module 4-Channel.This is a 5V 4-Channel Relay interface board. Be able to control various appliances, and other equipment with large current. Indication LED’s for Relay output status.

 

  • IR Receiver Module 1PC

Arduino Mini infrared wireless remote control kit consists of 38KHz infrared remote control and infrared receiver modules, Mini IR can transmit distances of up to 8 m

 

  • Joystick Module 1PC

The kind of program that we need to monitor the joystick has to make a polling to two of the analog pins.

 

  • DHT 11 Temperature and Humidity Module 1PC

The DHT11 is a basic, ultra low-cost digital temperature and humidity sensor. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air, and spits out a digital signal on the data pin (no analog input pins needed).

 

  • Ultrasonic Sensor 1PC

The HRLV-MaxSonar-EZ sensor line is the fastest way to get precision range-finding into your computer.

 

  • 3-6v Motor 1PC

electric scooter motor.

 

  • Active Buzzer 1PC

An active buzzer will generate a tone using an internal oscillator, so all that is needed is a DC voltage

 

  • Tilt Switch 1PC

Tilt sensors are switches that can detect basic motion/orientation.

 

  • 74HC5951PC

These chips are DIP package so you can easily plug them into any breadboard or perfboard with 0.1″ spacing. The digital outputs are good for about 20mA, which makes them ideal for LEDs or driving power transistors.

 

  • Button(Small)5PCS

 

  • Potentiometer 1PC

Manufactured by Spectra Symbol, these are nice little ribbon controllers (also known as ‘soft potentiometers’) with an adhesive backing.

 

  • 1 Digit 7-Segment Display 1PC

this a single LED.

 

  • 4 Digit 7-segment Display 1PC

this a single LED.

 

  • Passive Buzzer 1PC

An active buzzer will generate a tone using an internal oscillator, so all that is needed is a DC voltage

 

  • Remote 1PC

Remote controller.

 

  • Breadboard 1PC

These nice switches are perfect for use with breadboard and perfboard projects. They have 0.1″ spacing and snap in nicely into a solderless breadboard.

 

  • USB Cable 1PC

This here is your standard A to micro-B USB cable, for USB 1.1 or 2.0. Perfect for connecting a PC to your NETduino.

 

  • Female-to-male Dupont wire 10 PCS

Having different colors they greatly facilitate their recognition within a prototype (often a tangle of wires) so that they can be classified by function: red 5V, black GROUND, yellow PWM signal and so on.

 

  • 65 Jumper Wire 1PC

For bread-boarding with unusual non-header-friendly surfaces, these cables will be your best friends! No longer will you have long strands of alligator clips that are grabbing little wires.

 

  • Battery with DC 1PC

battery wire

 

  • 9v Battery 1PC

Battery

 

  • Resistor 120PCS

handy resistor packs

 

  • LED 25PCS

LED light ball

 

  • RGB 1PC

Color LED light ball

 

  • Thermistor 1PC

This epoxy-coated precision 1% 10K thermistor is an inexpensive way to measure temperature in weather or liquids. T

 

  • Diode Rectifier 1N4007 2PCS

put it between your DC power jack and circuitry to avoid a negative-voltage that would zap your delicate electronics

 

  • Photoresistor (Photocell)2PCS

CdS cells are little light sensors. As the squiggly face is exposed to more light, the resistance goes down. When its light, the resistance is about 5-10KΩ, when dark it goes up to 200KΩ.

 

  • NPN Transistor PN22222PCS

NPN transistors whenever we need to control medium-power electronics such as small motors, solenoids, or IR LEDs.

 

ii)A sample Fritzing schematic

iii)function or library is needed to make it work

 

Blink

 

Turns an LED on for one second, then off for one second, repeatedly.

 

Most Arduinos have an on-board LED you can control. On the UNO, MEGA and ZERO

it is attached to digital pin 13, on MKR1000 on pin 6. LED_BUILTIN is set to

the correct LED pin independent of which board is used.

If you want to know what pin the on-board LED is connected to on your Arduino

model, check the Technical Specs of your board at:

https://www.arduino.cc/en/Main/Products

 

modified 8 May 2014

by Scott Fitzgerald

modified 2 Sep 2016

by Arturo Guadalupi

modified 8 Sep 2016

by Colby Newman

 

This example code is in the public domain.

 

http://www.arduino.cc/en/Tutorial/Blink

*/

 

// the setup function runs once when you press reset or power the board

void setup() {

// initialize digital pin LED_BUILTIN as an output.

pinMode(LED_BUILTIN, OUTPUT);

}

 

// the loop function runs over and over again forever

void loop() {

digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

delay(1000);                       // wait for a second

digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

delay(1000);                       // wait for a second

}