Lucas's Engineering 2 Notebook

From CHS Sigma
Jump to: navigation, search

Lmiller87 (talk)

lmiller87@charlottesvilleschools.org
Giphy2.gif

lucashagstrommiller@icloud.com

LED Fade with Serial

My first Engineering 2 Project

Abstract

Basically a code made to make an LED fade in and out and to have the Serial Monitor print dashes.

Code

Code for LED Fade and Serial Monitor

//Lucas Miller
//This code is used to make an LED fade and to have the serial monitor print a certain (thing) into it.
int led = 9; //Tells the board that the LED is wired to that set pin.
int brightness = 0; // the default brightness
int fadeAmount =5;
int dash = "-"; // the set fade amount
void setup()
{
	Serial.begin(9600);	
	pinMode(led, OUTPUT);//it tekks a specified pin the be either an imput or output in this case output
 
} 
void loop(){
 
	brightness = brightness + fadeAmount; //0,5,10,15 etc. it gets brighter with this set of code.
	if (brightness <= 0 || brightness >= 255) {  //this if statemnt basically makes the led fade, 
	fadeAmount = -fadeAmount //it means if bightness is less than or equal to 0 
											   //and the brightness needs to be greater than or equal to 255
	 										  //the last statement means fadeamound equals negative fadeamount
 
	}
	Serial.println();
	analogWrite(led, brightness);
	for(int dash=0; dash < brightness/10; dash++){
 
	Serial.print("-");
	}
 
 
	delay(30); // how fast the LED will blink
}
 
 
 
//digitlWrite is specified to one pin while analog can vary
//I used it to set the led and brightness.
//The for statement is used to repeat a block of statements enclosed in curly braces. An increment counter is usually used to increment and terminate the loop. The for statement is useful for any repetitive operation,
// and is often used in combination with arrays to operate on collections of data/pins.
//By arduino
//Inspired by Tom Igoe

Wiring & Pictures

Learn arduino fritzing pin 13.jpg 450px-Arduino 3615-1-.JPG

Reflections & Solutions

This was a very easy project to work on we got to copy all the code off other websites as long as we sited where they where from and who made them. As easy as it sounds it was actually quite annoying at some points, for instance throughout this project, I kept getting "Error with exit code" at the bottom of my sublime. This was very annoying because it was hard to tell what was wrong with the code, (you copied it off the internet, you expect it to work the first time) It was especially annoying to find out I wasted 10 minutes of my time because the board was connected to the wrong port. These problems effected me more as I got into the Serial Monitor part of the project because I had to open a whole new part of sublime so I got a little confused sometimes. Other than that the project was a walk in the park. I used a site to find the code for my project.

https://www.arduino.cc/en/tutorial/fade

I used the white board for the Serial Monitor part because I had to use a for loop code which I had never even heard of so I looked it up.

https://www.arduino.cc/reference/en/language/structure/control-structure/for/

Lastly I got help from Mr. Helmstetter and that assistant for my wiring.

Links

Ultrasonic Servo

Abstract

Basically we are wiring an ultrasonic monitor and servo up to an arduino in order to make it spin the opposite direction every time you put your hand in front of it. Also we had to use a new type of serial monitor code in order to print out distances. (The ultrasonic monitor can recognize distance and obstacle is away from it and show it so we made a code to show how far away that obstacle is so every time you put your hand in front of it, it switches the servo direction and prints a certain distance in centimeters in the serial monitor.

Code

This is the code for Ultrasonic Servo

#include <Servo.h>
int trigPin = 11;    //Trig - green Jumper
int echoPin = 12;    //Echo - yellow Jumper
long duration, cm, inches;
Servo servo;
void setup() {
  //Serial Port begin
  Serial.begin (9600);
  //Define inputs and outputs
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servo.attach(10);
}
 
void loop()
{
 
  getDistance();
  Serial.print(inches);    // all of this is telling the serial moniter to print distnaces.
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  servo.write(cm+60);
  delay(250);
}
 
void getDistance() {
	// The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
 
  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);
  // convert the time into a distance
  cm = (duration/2) / 29.1;
  inches = (duration/2) / 74; 
}
 
//Thank you Seanan Shanks

Wiring & Pictures

Ripvine.JPG

Sebastians Engineering Notebook

Reflections & Solutions

In this project we used an ultrasonic monitor in order to switch the direction and speed of a servo at a certain distance. It was a very easy project because we got a code from Seanan and where able to wire wiring to it and explain it. Seanan's Engineering Notebook

NewPing

Abstract

This aloud us to read different distacnes with an ultrasonic monitor, this helped us create our ultrasonic robot project.

Code

//Makes a light turn on when it register something in front of it
#include <NewPing.h>
 
#define TRIGGER_PIN  11 //This is using NewPing
#define ECHO_PIN     12 //triggerpin and echo pin help the HC-SR04 register tge distance using sonar
#define MAX_DISTANCE 200
 
int led = 7;
long duration, cm, inches;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
 
void setup() {
 
  Serial.begin(9600); //starts the serial monitor
  pinMode(led, OUTPUT); //define the input
 
}
 
void loop() {
 
  delay(200);
 cm = sonar.ping_cm();
  Serial.print(cm); //this area registers the centimeters distance
  Serial.println(" cm");
 
  if (cm <=15){ //this is saying if it registers less than 15 then the light will turn on.
    digitalWrite(led,HIGH);
 
  }
  else digitalWrite(led,LOW); // this is saying if it doesn't register less than 15 it won't turn on.
 
}
//Thanks Jude

Wiring & Pictures

Lmaoxd.JPG

Reflections & Solutions

Talk about what you learned. Discuss your obstacles and how you got around them. Include links to any websites you used to complete your project.

This should be the longest section in the assignment.

Hello LCD

Abstract

The main goal of this activity was to use a code that printed "Hello World" , and a clock counting in seconds, on a monitor.

Code

//Lucas Miller
//Hello LCD.ino
//prints hello world and the amount of seconds ince the program started to an lcd.
#include <LiquidCrystal.h>
//initilizes lcd
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
 
void setup() {
  // put your setup code here, to run once:
  lcd.begin(16,2);
  //Prints Hello World to the LCD
  lcd.print("Hello world");
}
 
void loop() {
  // put your main code here, to run repeatedly:
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}
 
//Seanan shanks's code.

Wiring & Pictures

Lcd bb.png

Reflections & Solutions

Talk about what you learned. Discuss your obstacles and how you got around them. Include links to any websites you used to complete your project.

This should be the longest section in the assignment.

LCD/Backpack

Abstract

In this project we learned how to wire and code an LCD backpack and an LCD Screen to each other and allow them to display a button click counter in both negative and positive values, it also required a switch flip system that allows it to switch the way its counting.

Code

#include <LiquidCrystal.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7);
// sometimes 0x27 works when 0x3F doesn't
// that's the I2C address of the backpack 
 
 
 
 
int buttonPin = 9; 
int a = 0;
int buttonState = 0;
int oldButtonState = 0;
int switchPin = 13;
int switchState = 0;
 
void setup() {
  lcd.begin (16,2);
  lcd.setBacklightPin(3,POSITIVE); 
  lcd.setBacklight(HIGH); 
  lcd.print("Button presses:");
  pinMode(buttonPin, INPUT); 
  pinMode(switchPin, INPUT);
}
 
void loop() {
  switchState = digitalRead(switchPin); 
  buttonState = digitalRead(buttonPin);
  lcd.setCursor(0,1); 
  if (buttonState == HIGH && oldButtonState == LOW && switchState == 0){
    lcd.setCursor(0,1);
    lcd.print(a++);
    lcd.print(" ");
    delay (200);
  }
   if (buttonState == HIGH && oldButtonState == LOW && switchState == 1){ 
    lcd.setCursor(0,1);
    lcd.print(a--); 
    lcd.print(" "); 
    delay (200);
  }
  oldButtonState = buttonState;
 
}

Wiring Pictures

"coming soon"

Reflections/Solutions

The hardest part of this project was just making sure the wires where in properly, otherwise it wouldn't work, other than that all I had to do was find someones work and credit it.

Photo Interupter

Abstract

The point of this assignment was to designs code and wiring system that turned an LED on with a interrupter, basically what it does is when you put something in between the two legs of the PI, and it turns the LED on.

Code

const byte ledPin = 7;
const byte interruptPin = 2;
volatile byte state = LOW;
int counter = 0;
 
 
void setup() {
  pinMode(ledPin, OUTPUT);
  attachInterrupt(0, blink, RISING);
  attachInterrupt(1, off, FALLING);
  Serial.begin(9600);
}
 
 
 
void loop() {
 
  Serial.println(counter);
}
 
void blink() {
 digitalWrite(ledPin, HIGH); 
 counter++;
}
 
void off() {
 digitalWrite(ledPin, LOW); 
 }
 
//Thanks Sam

Wiring/Pictures

PhotoI2912.JPG

Reflections/Solutions

The only hard part about this project was figuring out if the wiring was working with the code because you had very few ways of knowing if it was all connected, other than that it was quite easy to figure out.

Potentiometer

Abstract

To use a potentiaometer and turn up something on the LCD screen

Code

 #include <LiquidCrystal.h> //LCD library
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
int ledPin = 9;
int brightness = 0;
 
void setup() {
	lcd.begin(16,2); //Set up for the size of the screen
	lcd.setBacklightPin(3,POSITIVE); //Backlight setup for the LCD
	lcd.setBacklight(HIGH); //Backlight setup cont.
	lcd.print("BRIGHTNESS:"); //What will show up on the LCD screen
	pinMode(ledPin, OUTPUT); //Establishing that the LED pin is an output
	Serial.begin(9600); //Starting the serial monitor
}
 
void loop() {
	brightness = map(analogRead(0),0,1023,255,0); //The brightness equals what the potentiometer is at
	analogWrite(ledPin, brightness); //Setting the LED brightness according to the potentiometer
	Serial.println(brightness); //Printing the brightness of the LED to the serial monitor
	lcd.setCursor(0,1); //Where to print the message
	lcd.print(map(brightness,0,255,0,10)); //Having the brightness be on a scale of 0-10 instead of 0-255
	lcd.print("   "); //Clearing the screen
	delay(100); //A delay
}
//thanks sebastian/sam

Wiring/Pictures

Potentiometerpicture20199.jpg

Reflections/Solutions

This was the easiest project that I have done I had no problems with it.

Motor Control

Abstract

Code

#include <LiquidCrystal.h> 
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
int ledPin = 9;
int brightness = 0;
 
void setup() {
	lcd.begin(16,2); //Sets up the screen
	lcd.setBacklightPin(3,POSITIVE); //
	lcd.setBacklight(HIGH); //
	lcd.print("BRIGHTNESS:"); //prints "brightness" to the screen
	pinMode(ledPin, OUTPUT); 
	Serial.begin(9600); 
}
 
void loop() {
	brightness = map(analogRead(0),0,1023,255,0); //Brightness equals what the potentiometer is at
	analogWrite(ledPin, brightness); //Sets the LED brightness according to the potentiometer
	Serial.println(brightness); //Printing the brightness of the LED to the serial monitor
	lcd.setCursor(0,1); 
	lcd.print(map(brightness,0,255,0,10)); //Makes brightness on a scale of 1-10
	lcd.print("   "); 
	delay(100);
//Thank you Nico for the code and picture

Wiring/Pictures

MotorFritzing.png

"Thank you for the picture Nico"

Reflections/Solutions

The biggest issue I had with this project was that I didn't know that i needed a diod and it wasn't working.

CAD

Abstract

All i had to do was make 4 parts and turn them into a mate that could move, it was very simple and easy but i had a few problems

Pictures

AMM.sam-b.PNG "I couldn't upload pictures so i got someone from someone else." "Thank you Sam"

Reflections/Solutions

The only difficult part for me was finding out how to fillet the corners and do the mechanical mate.