Skip to content

12. Output devices

Group Assignment

In this part we measured the power consumption of a servo motor using a servo motor output board. Power (in Watt) is calculated by P = V x I, where V is the voltage across the load and I is the current passing through the load. To measure voltage, the digital multimeter (DMM) is connected in parallel with the load, and to measure the current passing through, the DMM is connected in series with the load. Remember to move DMM positive test lead to current measuring position before connecting in series with the load.

P = 4.88 x 0.00268 P = 0.0130784 Watt P = 13.0784 mWatt

via GIPHY

via GIPHY

This assignment is to add an output device to a circuit board that has been designed and program it to do something. To this task choose to work with two output devices: Servo Motor.

this was part of my final project

The work was divided into three stages:

eagle files

PCB design and production

a) Milling board. We worked with the milling parameters from previous assignments. The files for the layout of the board were obtained from the website of the academy.

Servomotor (According the trace can connect six servos)

I used eagle again schematic first

and added pins to fit the motors the light and the electric Vcc and ground input.

milling the boreD WAS COOL

and added pins to fit the motors the light and the electric Vcc and ground input.

b) Installation of electronic components to the board. To weld the components was based on the distribution found in the page of the academy.

CONTTECTING TO SERVO

via GIPHY

TESTED WITH A LIGH FIRST

i CONNECTED THE sERVOS TO THE BREAD AND CONTROL IT WITH hc-05 MODULE\

via GIPHY

Led Light

I USED THE FAST LED LIBRARY

  • Getting started We start with the absolute basics here and cover the following:

What is FastLED? Hardware and power delivery Setting up to code Writing your first pattern YouTube video

Episode 1 - Getting started We start with the absolute basics here and cover the following:

What is FastLED? Hardware and power delivery Setting up to code Writing your first pattern YouTube video

via GIPHY

via GIPHY

Results

![](https://i.imgur.com/fb0gV3k.jpg()

via GIPHY

via GIPHY

via GIPHY

Coding

>
*/code by zaid marji

*/

#include <Servo.h>
#include <FastLED.h>
#include <SoftwareSerial.h>
//moto
Servo mot_one;  // create servo object to control a servo
Servo mot_two;
Servo mot_three;
Servo mot_four;
Servo mot_five;
Servo mot_six;
SoftwareSerial MyBlue(7, 8); // RX | TX
// Leds
#define NUM_LEDS  124
#define LED_PIN   13

CRGB leds[NUM_LEDS];

// twelve servo objects can be created on most boards
int pos = 0;    // variable to store the servo position
int cnt1 = 0;
int mot = 0;
char blueData;  
void setup() {
 FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(1000);



  mot_one.attach(3);  // that's motor one
  mot_two.attach(5);
  mot_three.attach(6);
  mot_four.attach(9);
  mot_five.attach(10);
  mot_six.attach(11); //that's motor 6 on port number two
  mot_six.write(0);
  delay(1000);
  Serial.begin(9600);
  MyBlue.begin(9600);
 Serial.println("Ready to connect\nDefualt password is 1234 or 000");
}

void loop() {

 if (MyBlue.available()>0) {
   blueData = MyBlue.read();
  // Serial.println(blueData);
 if (blueData == 'a')
 {
   mot_one.write(0);
   mot_two.write(0);
   mot_three.write(0);
   mot_four.write(30);
   mot_five.write(30);
   mot_six.write(30);

   fill_rainbow(leds, NUM_LEDS, 0, 255 / NUM_LEDS);
  FastLED.show();
  delay(500);

   Serial.println("rose up cherry closed");
 }
 else if (blueData == 'b')
 {
   mot_one.write(30);
   mot_two.write(0);
   mot_three.write(0);
   mot_four.write(30);
   mot_five.write(30);
   mot_six.write(30);

  fill_solid(leds, NUM_LEDS, CRGB::Red);
  FastLED.show();
  delay(500);

   Serial.println("cherry up rose closed");
 }
   else if (blueData == 'c')
 {
  zero();
   mot_one.write(0);
   mot_two.write(30);
   mot_three.write(0);
   mot_four.write(30);
   mot_five.write(30);
   mot_six.write(30);

     fill_solid(leds, NUM_LEDS, CRGB(50,0,200));
  FastLED.show();
  delay(500);

   Serial.println("roseup whiefull closed");
 }

 else if (blueData == 'd')
 {
  zero();
   mot_one.write(0);
   mot_two.write(0);
   mot_three.write(30);
   mot_four.write(30);
   mot_five.write(30);
   mot_six.write(30);

   fill_solid(leds, NUM_LEDS, CRGB(101,0,11));
  FastLED.show();
  delay(500);

   Serial.println("Motors are in Pos 30");
 }
 else if (blueData == 'e')
 {
  zero();
   mot_one.write(0);
   mot_two.write(0);
   mot_three.write(0);
   mot_four.write(0);
   mot_five.write(30);
   mot_six.write(30);
   Serial.println("Motors are in Pos 30");
 }
 else if (blueData == 'f')
 {
  zero();
   mot_one.write(0);
   mot_two.write(0);
   mot_three.write(0);
   mot_four.write(30);
   mot_five.write(0);
   mot_six.write(30);
   Serial.println("Motors are in Pos 30");
 }
 else if (blueData == 'g')
 {
  zero();
   mot_one.write(0);
   mot_two.write(0);
   mot_three.write(0 );
   mot_four.write(30);
   mot_five.write(30);
   mot_six.write(30);
   Serial.println("Motors are in Pos 30");
 }
 }
/*
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    mot_six.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    mot_six.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }  
*/
/*
  int mot = 0 ; // pin7 is motor 1, pin 6 is motor 2, till pin2 is motor 6

  Serial.println("Monitor cleared, loop Func started");
  int pos = 0;
  Serial.println("pos variable currently = ");
  Serial.println(pos);


  Serial.println("Servos will ALL be sent to zero with 0.5 second delays");

  mot_one.write(pos);
  delay(1500);
  mot_two.write(pos);
  delay(1500);
  mot_three.write(pos);
  delay(1500);
  mot_four.write(pos);
  delay(1500);
  mot_five.write(pos);
  delay(1500);
  mot_six.write(pos);

  Serial.println("Now, All should be at angle: ");
  Serial.println(pos);

  for (pos = 0; pos <= 180; pos += 15) { // goes from 0 degrees to 180 degrees

    Serial.println("servos should now go to angle: ");
    Serial.println(pos);
    Serial.println("Motors will rotate each by ++15 Degrees now");

    mot_one.write(pos);
    Serial.println(pos);
    delay(1500);
    mot_two.write(pos);
    Serial.println(pos);
    delay(1500);
    mot_three.write(pos);
    Serial.println(pos);
    delay(1500);
    mot_four.write(pos);
    Serial.println(pos);
    delay(1500);
    mot_five.write(pos);
    Serial.println(pos);
    delay(1500);
    mot_six.write(pos);
    Serial.println(pos);
    delay(1500);

    delay(1500);// waits 15ms for the servo to reach the position
    Serial.println("servos shoul've ALL moved by ++15 degrees now");
  }
*/

}

void zero(){
  mot_one.write(0);
   mot_two.write(0);
   mot_three.write(0);
   mot_four.write(30);
   mot_five.write(30);
   mot_six.write(30);
   Serial.println("Motors are in Pos Zero");
}

via GIPHY

via GIPHY

Code 2

This week I worked SERVO MOTORs it is a part of my final project

I updated the input design to merge between ultra sonic as an input and servomotor as output I tasted using Arduino

``` #include

Servo myservo;

const int trigPin = 11; const int echoPin = 10;

long duration; int distance; int led = 5; int led_feedBack;

int x; int timer; void setup() { pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode( led , OUTPUT ); myservo.attach(6); myservo.write(0); Serial.begin(9600); } void loop() {

ultra();

if( distance < 100 ) { state:
ultra(); timer = 0;

 Serial.println( distance );

 if( distance > 100 )
 {
   if( x == 0 ){ x = 1; }else{ x = 0; }
 }
 else
 {
   goto state;   
 }

} else if( x == 1 ) { timer++; }

if( timer >= 500 ) //time to close { x = 0; timer = 0; Serial.println(“Timer end”); }

if( x == 0 ) { myservo.write(0);

 if( led_feedBack == 1 )
 {
   for( int i = 255; i > 0; i-- )
   {
     analogWrite( led , i );
     delay(5);
   }
   led_feedBack = 0;
 }

}

if( x == 1 ) { myservo.write(180);

     if( led_feedBack == 0 )
 {
   for( int i = 0; i < 255; i++ )
   {
     analogWrite( led , i );
     delay(5);
   }
   led_feedBack = 1;
 }

}

}

void ultra() { digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH ); distance= duration*0.034/2; //Serial.println(distance); } ```

code 3

#include <Servo.h>

Servo myservo;
Servo myservo2;
const int trigPin = 1;
const int echoPin = 0;

long duration;
int distance;
int led = 5;
int led_feedBack;

int x;
int timer;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode( led , OUTPUT );
myservo.attach(3);
 myservo2.attach(2);
 myservo.write(0);
myservo2.write(0);
}
void loop() {

ultra();



 if( distance < 100 )
 {
   state:    
   ultra();
   timer = 0;



   if( distance > 100 )
   {
     if( x == 0 ){ x = 1; }else{ x = 0; }
   }
   else
   {
     goto state;   
   }

 }
 else if( x == 1 )
 {
   timer++;
 }



 if( timer >= 500 ) //time to close
 {
   x = 0;
   timer = 0;

 }





 if( x == 0 )
 {
   myservo.write(0);
    myservo2.write(180);
   if( led_feedBack == 1 )
   {
     for( int i = 255; i > 0; i-- )
     {
       analogWrite( led , i );
       delay(5);
     }
     led_feedBack = 0;
   }
 }

 if( x == 1 )
 {
   myservo.write(180);
   myservo2.write(0);
       if( led_feedBack == 0 )
   {
     for( int i = 0; i < 255; i++ )
     {
       analogWrite( led , i );
       delay(5);
     }
     led_feedBack = 1;
   }

 }


}




void ultra()
{
 digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH );
distance= duration*0.034/2;
//Serial.println(distance);
}


Last update: July 12, 2021