User Tools

Site Tools


notes:c4eng:fall2022:projects:fso1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:c4eng:fall2022:projects:fso1 [2022/11/16 21:55] – [CIRCUIT] mward14notes:c4eng:fall2022:projects:fso1 [2022/11/17 14:07] (current) – [DEMONSTRATION] cmille71
Line 13: Line 13:
 ====OVERVIEW==== ====OVERVIEW====
  
 +#include <wiringPi.h>
 +#include <stdio.h>
 +#include <sys/time.h>
 +#include <softTone.h>
 +#include <stdlib.h>
 +#include <math.h>
 +
 +#define rled    28
 +#define yled    27
 +#define buzzer  8
 +#define trigPin 4
 +#define echoPin 5
 +#define MAX_DISTANCE 220        // define the maximum measured distance
 +#define timeOut MAX_DISTANCE*60 // calculate timeout according to the maximum m$
 +#define gled     1
 +//function pulseIn: obtain pulse time of a pin
 +int pulseIn(int pin, int level, int timeout);
 +float getSonar(){   //get the measurement result of ultrasonic module with unit$
 +    long pingTime;
 +    float distance;
 +    digitalWrite(trigPin,HIGH); //send 10us high level to trigPin
 +    delayMicroseconds(10);
 +    digitalWrite(trigPin,LOW);
 +    pingTime = pulseIn(echoPin,HIGH,timeOut);   //read plus time of echoPin
 +    distance = (float)pingTime * 340.0 / 2.0 / 10000.0; //calculate distance wi$
 +    return distance;
 +}
 +
 +int main(){
 +    printf("Program is starting ... \n");
 +
 +    wiringPiSetup();
 +    softToneCreate (buzzer);
 +    float distance = 0;
 +    pinMode(trigPin,OUTPUT);
 +    pinMode(echoPin,INPUT);
 +    pinMode(gled, OUTPUT);
 +//    pinMode(buzzer, OUTPUT);
 +    while(1){
 +        distance = getSonar();
 +        printf("The distance is : %.2f cm\n",distance);
 +        softToneWrite(buzzer, 1000-distance*15);
 +        if (distance>=20)
 +        {
 +                digitalWrite(gled, HIGH);
 +        }
 +        else
 +        {
 +                digitalWrite(gled, LOW);
 +        }
 +        if (distance<20)
 +        {
 +                digitalWrite(yled, HIGH);
 +        }
 +        else
 +        {
 +                digitalWrite(yled, LOW);
 +        }
 +        if (distance<10)
 +        {
 +                digitalWrite(rled, HIGH);
 +                digitalWrite(yled, LOW);
 +        }
 +        else
 +        {
 +                digitalWrite(rled, LOW);
 +        }
 +
 +        delay(10);
 +    }
 +    return 1;
 +}
 +
 +int pulseIn(int pin, int level, int timeout)
 +{
 +   struct timeval tn, t0, t1;
 +   long micros;
 +   gettimeofday(&t0, NULL);
 +   micros = 0;
 +   while (digitalRead(pin) != level)
 +   {
 +      gettimeofday(&tn, NULL);
 +      if (tn.tv_sec > t0.tv_sec) micros = 1000000L; else micros = 0;
 +      micros += (tn.tv_usec - t0.tv_usec);
 +      if (micros > timeout) return 0;
 +   }
 +   gettimeofday(&t1, NULL);
 +   while (digitalRead(pin) == level)
 +   {
 +      gettimeofday(&tn, NULL);
 +      if (tn.tv_sec > t0.tv_sec) micros = 1000000L; else micros = 0;
 +      micros = micros + (tn.tv_usec - t0.tv_usec);
 +      if (micros > timeout) return 0;
 +   }
 +   if (tn.tv_sec > t1.tv_sec) micros = 1000000L; else micros = 0;
 +   micros = micros + (tn.tv_usec - t1.tv_usec);
 +   return micros;
 +}
 ====CIRCUIT==== ====CIRCUIT====
  
Line 188: Line 286:
 I used LEDs to replace the seconds component of the LCD screen and removed the seconds and milliseconds from the display so it only displays hours and minutes. This is made to separate the seconds component from the system time and mathematically derive what LEDs should be lit and which ones should not. I used LEDs to replace the seconds component of the LCD screen and removed the seconds and milliseconds from the display so it only displays hours and minutes. This is made to separate the seconds component from the system time and mathematically derive what LEDs should be lit and which ones should not.
 ====CIRCUIT==== ====CIRCUIT====
 +The LCD screen is wired like before: VCC pin being connected to 5v, GND connected to ground, SDA connected to an SDA Pi pin, and SCL connected to an SCL pin on the Pi.
 +
 +The LEDs are also wired how we have wired them in the past. Each LED is wired to a common ground with the other lead of the LED connected to a different GPIO pin, all with 220Ω resistors.
 +
 {{:notes:c4eng:fall2022:projects:pi.jpeg?400|}} {{:notes:c4eng:fall2022:projects:pi.jpeg?400|}}
-====DEMONSTRATION==== 
  
-=====PROJECT 7=====+====Code==== 
 +This LCD screen utilizes a library written in python so the code for the LEDs are as well. Python is very similar to C with only minor syntax differences for what is used for this project.
  
-====OVERVIEW====+the ''datetime.now()'' function will take the current time to the millisecond and apply it to a choses variable.
  
-====CIRCUIT====+''time datetime.now()'' will set the variable "time" to the current system time from hours through milliseconds.
  
-====DEMONSTRATION====+Seconds can be isolated by simply putting ''.second'' at the end of the variable name. so ''time.second'' will be the isolated second value. 
 +=====Proximity Sensor=====
  
 +====OVERVIEW====
 +Basically my fso1 was a distance sensor with a buzzer and light system. As you get closer the buzzer gets higher pitched If distance>30cm the green light was on and the buzzer was off. If distance<30cm the yellow light turned on and the green light turned off. If distance<10cm the red light turned on and the yellow light turned off.
 +====CIRCUIT====
 +{{:notes:c4eng:fall2022:projects:20221110_105850.jpg?400|}}
 +====DEMONSTRATION====
 +{{ :notes:c4eng:fall2022:projects:20221116_224819_202914968439831.mp4 |}}
 =====PROJECT 8===== =====PROJECT 8=====
  
Line 233: Line 342:
  
  
-=====PROJECT 11=====+==========Model Rocket Thrust Vector Control (TVC)============
  
 ====OVERVIEW==== ====OVERVIEW====
 +In this project, I used the Adafruit Gy-521 and two Servos. These electronics were used for the goal of making sure that a model rocket is properly orientated during its flight and guaranteeing a nominal trajectory for it.
  
-====CIRCUIT====+The GY-521 is an accelerometer/gyroscope that will detect a change in the orientation of the craft as it is flying and will send a signal to the Arduino that the orientation of the craft is off. This will then send a signal to the servos that the orientation is off and needs to be fixed. Determining how much of a correction needs to be made is determined by a Proportional Integral Derivative (PID). A device that will automatically apply an accurate and responsive correction to a control function. This basically determines how fast/ intensely the servo responds to an error in the orientation of the device.
  
-====DEMONSTRATION==== 
  
 =====PROJECT 12===== =====PROJECT 12=====
notes/c4eng/fall2022/projects/fso1.1668635713.txt.gz · Last modified: 2022/11/16 21:55 by mward14