Difference between revisions of "Bear's Engineering II Notebook"

From CHS Sigma
Jump to: navigation, search
(Abstract)
(Code)
 
(9 intermediate revisions by one user not shown)
Line 5: Line 5:
 
=== Abstract ===
 
=== Abstract ===
  
''In this assignment I made an LED fade between bright and dim. And the serial monitor should print dashes corresponding to the brightness. ''
+
''In this assignment I made an LED fade between bright and dim. And the serial monitor should print dashes corresponding to the brightness. We had to learn about FOR loops which told it to fade in right after it faded out and the other way around.  ''
  
 
=== Code ===
 
=== Code ===
Line 48: Line 48:
 
=== Reflections & Solutions ===
 
=== Reflections & Solutions ===
  
''I learned more about wiring and coding. I do not remember the obstacles and how I got around them.''
+
'' In this assignment I learned more about wiring and coding and how to use FOR loops and analog write.''
 
+
''This should be the longest section in the assignment.''
+
 
+
 
+
  
 
== hello serial  monitor ==
 
== hello serial  monitor ==
Line 63: Line 59:
 
=== Code ===
 
=== Code ===
  
<div style="height:15em; overflow:auto; border: 1px solid #008">
+
<div style="height:30em; overflow:auto; border: 1px solid #008">
 
<syntaxhighlight lang="c">
 
<syntaxhighlight lang="c">
  
Line 221: Line 217:
  
 
'' What I've learned is how functions work and how to switch between them. I like that functions save space in your code by compacting multiple actions. By just putting all the regular code down and then calling it a function makes it a Function. Also I learned more about ultrasonic sensors and how to wire them with a servo. I learned that one side of the ultrasonic sensor is a speaker and the others side is a receiver.  ''
 
'' What I've learned is how functions work and how to switch between them. I like that functions save space in your code by compacting multiple actions. By just putting all the regular code down and then calling it a function makes it a Function. Also I learned more about ultrasonic sensors and how to wire them with a servo. I learned that one side of the ultrasonic sensor is a speaker and the others side is a receiver.  ''
 
''This should be the longest section in the assignment.''
 
  
 
== New Ping ==
 
== New Ping ==
Line 294: Line 288:
 
=== Abstract (or Description, your choice) ===
 
=== Abstract (or Description, your choice) ===
  
''Our project was a self driving car using ultra sonic censors and used 2 servos and a caster. Our goal was to have the car drive well and not break down, My partner made the code and we both di the solid works part of it and we are almost finished .''
+
''Our project was a self driving car using ultra sonic censors and used 2 servos and a caster. Our goal was to have the car drive well and not break down, My partner made the code and we both did the solid works part of it and we are almost finished .''
  
 
[http://wiki.chssigma.com/index.php?title=Reece%27s_Engineering_Notebook#Potentiometer | Here's a great example]
 
[http://wiki.chssigma.com/index.php?title=Reece%27s_Engineering_Notebook#Potentiometer | Here's a great example]
Line 308: Line 302:
  
 
This is an empty text box, put your COMMENTED code inside, by hitting {edit}
 
This is an empty text box, put your COMMENTED code inside, by hitting {edit}
<div style="height:20em; overflow:auto; border: 1px solid #008">
+
<div style="height:30em; overflow:auto; border: 1px solid #008">
 
   <syntaxhighlight lang="c">
 
   <syntaxhighlight lang="c">
  
 
#include <Servo.h>
 
#include <Servo.h>
 
const int trigPin = 9;
 
const int trigPin = 9;
const int echoPin = 10;
+
const int echoPin = 10; // this is the set up of our code
 
long duration;
 
long duration;
 
int distance;
 
int distance;
Line 328: Line 322:
 
void loop() {
 
void loop() {
 
   distance = sensor();
 
   distance = sensor();
   if (distance > 10) {
+
   if (distance > 10) {   // telling it when to sensor things and when to drive and turn
 
     moveservoLeft();
 
     moveservoLeft();
 
   }
 
   }
Line 341: Line 335:
 
   digitalWrite(trigPin, LOW);
 
   digitalWrite(trigPin, LOW);
 
   delay(2);
 
   delay(2);
   digitalWrite(trigPin, HIGH);
+
   digitalWrite(trigPin, HIGH); // switch it on and off again top reset it
 
   delayMicroseconds(10);
 
   delayMicroseconds(10);
 
   digitalWrite(trigPin, LOW);
 
   digitalWrite(trigPin, LOW);
Line 363: Line 357:
  
 
void stopservoLeft() {
 
void stopservoLeft() {
   servoLeft.write(180);
+
   servoLeft.write(180); // this is the code that tells the wheels to turn
 
}
 
}
  
Line 374: Line 368:
  
 
Take a second to look at the text box.  Is it too short?  Change the height.  Too tall , empty space at the bottom?  Make it shorter.  etc, etc.  Play with the variables!
 
Take a second to look at the text box.  Is it too short?  Change the height.  Too tall , empty space at the bottom?  Make it shorter.  etc, etc.  Play with the variables!
 
=== Wiring & Pictures ===
 
[[Wiki Formatting]]
 
  
 
=== Reflections & Solutions ===
 
=== Reflections & Solutions ===
  
 
'' I learned how to use solid works more efficiently and and how to work through obstacles. some obstacles were that our whole car got deleted from our computers so we made a new one and we had to make multiple versions of the same car because there would be one or two holes that didn't line up.''
 
'' I learned how to use solid works more efficiently and and how to work through obstacles. some obstacles were that our whole car got deleted from our computers so we made a new one and we had to make multiple versions of the same car because there would be one or two holes that didn't line up.''
 
''This should be the longest section in the assignment.''
 

Latest revision as of 14:36, 9 July 2019

This Engineering Note book belongs to Bear

LED FADE

Abstract

In this assignment I made an LED fade between bright and dim. And the serial monitor should print dashes corresponding to the brightness. We had to learn about FOR loops which told it to fade in right after it faded out and the other way around.

Code

//Bear Webster 
//LED fade 
//It makes a light fade in and out
int ledPin = 9;    // LED connected to digital pin 9
 
void setup() {
  Serial.begin(9600);
  while(!Serial);
  Serial.print("Serial is on");// nothing happens in setup
}
 
void loop() {
  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
    Serial.print()
  }
 
  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
}

Wiring & Pictures

Fade bear.jpg

Reflections & Solutions

In this assignment I learned more about wiring and coding and how to use FOR loops and analog write.

hello serial monitor

Abstract

In this assignment you make a LED fade in and out with AnalogWrite. The second part is to see on the serial monitor the pattern of dots and waves.

Code

//Bear webster
// this is making a light fade and not blink
#include "Arduino.h"
int WLED = 9;
//WLED is my variable for the LED
 
void setup()
{
     pinMode (13, HIGH);
     Serial.begin(9600); // make sure there is no problems
     while (!Serial);
     Serial.print("cha ching");
} 
 
void loop() {
     for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 10) {
// I made the LED fade in from 255 to 0 in increments of 1...
     analogWrite(WLED, fadeValue); //AnalogWrite
//AnalogWrite makes a variable pulse of electricity 
          delay(30);     // 30 milliseconds 
 
          for (int dash =0; dash < fadeValue /25 ; dash++)
          {
               Serial.print("-");
          }
          Serial.println(fadeValue);
//This for loop makes the dash on the serial monitor increase of 1
 
     }
 
 
 
     for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 10) {
          // back to 0 again of 1
     analogWrite(WLED, fadeValue);
//Serial.println("-----------------");
     for (int dash =0; dash < fadeValue /25 ; dash++)
     {
     Serial.print("-");
 
     }
     Serial.println(fadeValue);
          delay(30);   // 30 milliseconds again
     } 
}

Wiring & Pictures

Dot Wave Snip.PNG


Credit goes to Abby P. for the image!

Reflections & Solutions

This assignment makes an LED fade in and out using analogWrite and it was hard coding and it required you to learn more arduino commands. The first thing you have to do is learn how to use AnalogWrite and using it in multiple loops.

Hello Functions

Description

this moves a servo depending on what the ultrasonic sensor detects. this is done with a hzsr04 giving us distances and we used an if statement and decided which function to use based on the distance .

Code

//Bear Webster
//Hello Functions
// getting a servo to do different things based on the reading from the ultrasonic sensor 
#include <Servo.h> 
const int trigPin = 11; // this and echo pin are the pins to the ultrasonic sensor
const int echoPin = 12;
long duration; //how long it takes to bounce back in microseconds
int cm;
Servo myServo;
int servoPin = 10;
 
 
 
void setup() {
pinMode(trigPin, OUTPUT); 
pinMode(echoPin, INPUT); 
Serial.begin(9600);
myServo.attach(servoPin);
}
 
 
 
void loop() {
cm = sensor();  //we call sensor() here to get us a distance from the ultrasonic sensor.
 
if(cm < 30){
     moveServo();
}
 
else{
     stopServo();
     }
 
}
 
 
 
 
int sensor(){
     int distance = 0;
 
          digitalWrite(trigPin, LOW);
          delay(3);
          digitalWrite(trigPin, HIGH); // this function makes a sound wave
          delayMicroseconds(20);
          digitalWrite(trigPin, LOW);
          duration = pulseIn(echoPin, HIGH); //records the time it takes for the echo to come back
 
if (duration == 0) {  // If it gets zeros this is what tries to fix it
     digitalWrite(echoPin, LOW); 
     delay(3);
     pinMode(echoPin, INPUT);
}
 
     distance = (duration/2) *0.034/2; // converts time and distance into a speed of sound
     Serial.print(cm);
     Serial.println("cm");
     delay(40); 
}
 
 
 
 
void moveServo(){  //this function is self explanatory, and the VOID just means it does stuff, but doesn't return any values
                   // back to the main code.
     myServo.write(180);
}
 
 
void stopServo(){
     myServo.write(90);
}

Wiring & Pictures

Bearshellofunctions.jpg

Reflections & Solutions

What I've learned is how functions work and how to switch between them. I like that functions save space in your code by compacting multiple actions. By just putting all the regular code down and then calling it a function makes it a Function. Also I learned more about ultrasonic sensors and how to wire them with a servo. I learned that one side of the ultrasonic sensor is a speaker and the others side is a receiver.

New Ping

Description

This code does the same thing as the Hello Functions code except it used the new ping library which makes the codes shorter and more compact. The if statement makes it so it will stop reading above 200.

Code

// Bear webster 
// new ping
#include <NewPing.h>
//New code added
#include <Servo.h>
 
#define TRIGGER_PIN 11
#define ECHO_PIN 12
#define MAX_DISTANCE 200
 //New code that sets up the HC-Sr04
int ledPin = 10;
int cm; 
 
NewPing myHCSR04(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
 
void setup() {
//declares inputs
 Serial.begin(9600);
 pinMode(TRIGGER_PIN, OUTPUT);
 pinMode(ECHO_PIN, INPUT);
 pinMode(ledPin, OUTPUT);
}
 
void loop() {
// LED turn on at a distance of 10 centimeters
     cm = myHCSR04.ping_cm();
 
     if (cm !=0){
          if (cm < 10){
               ledOn();
          }
     else{
          ledOff();
     }
     }
     Serial.println(cm);
     delay(50);
}
 //Functions to make the LED go on and off without having to write digitalWrite 
void ledOn(){
     digitalWrite(ledPin, HIGH);
}
 
void ledOff(){
     digitalWrite(ledPin, LOW);
}

Wiring & Pictures

Bearshellofunctions.jpg

Reflections & Solutions

This assignment was very easy and simple, all you have to do is add the library of functions and then rewrite some of your code form Hello Functions.

Ultrasonic Car

Abstract (or Description, your choice)

Our project was a self driving car using ultra sonic censors and used 2 servos and a caster. Our goal was to have the car drive well and not break down, My partner made the code and we both did the solid works part of it and we are almost finished .

| Here's a great example

Code

More than just a copy paste of your code, ask yourself: "If a stranger read this code, "

  • Would these variable names make sense?
  • Are there comments explaining decisions we made?
  • Are there comments explaining chunks of code / functions / each IF, ELSE, FOR, etc...
  • Did I space this out well, or is this an unreadable wall of text?
  • ARE THE FIRST THREE LINES OF MY CODE // NAME , // TITLE OF ASSIGNMENT , // BRIEF, SINGLE LINE DESCRIPTION OF WHAT THIS CODE DOES?


This is an empty text box, put your COMMENTED code inside, by hitting {edit}

#include <Servo.h>
const int trigPin = 9;
const int echoPin = 10;  // this is the set up of our code
long duration;
int distance;
Servo servoRight;
Servo servoLeft;
int servoPin = 10;
void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servoLeft.attach(7);
  servoRight.attach(13);
}
 
void loop() {
  distance = sensor();
  if (distance > 10) {    // telling it when to sensor things and when to drive and turn
    moveservoLeft();
  }
  else {
    stopservoLeft();
  }
}
 
int sensor() {
  int distance = 0;
 
  digitalWrite(trigPin, LOW);
  delay(2);
  digitalWrite(trigPin, HIGH);  // switch it on and off again top reset it
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
 
  if (duration == 0) {
    digitalWrite(echoPin, LOW);
    delay(1);
    pinMode(echoPin, INPUT);
  }
 
  distance = (duration / 2) * 0.034 / 2;
  delay(50);
  return distance;
 
}
 
void moveservoLeft() {
  servoLeft.write(180);
}
 
void stopservoLeft() {
  servoLeft.write(180);  // this is the code that tells the wheels to turn
}

Take a second to look at the text box. Is it too short? Change the height. Too tall , empty space at the bottom? Make it shorter. etc, etc. Play with the variables!

Reflections & Solutions

I learned how to use solid works more efficiently and and how to work through obstacles. some obstacles were that our whole car got deleted from our computers so we made a new one and we had to make multiple versions of the same car because there would be one or two holes that didn't line up.