M'S

  • Home
  • About
  • Assignments
    • Student Agreement
    • 1. Principles and Practices, Project Management.
    • 2. Computer-Aided Design.
    • 3. Computer-Controlled Cutting.
    • 4. Embedded Programming.
    • 5. 3D Scanning and Printing.
    • 6. Electronics Design.
    • 7. Computer-Controlled Machining.
    • 8. Electronics Production.
    • 9. Output Devices.
    • 10. Mechanical Design, Machine Design.
    • 11. Input Devices.
    • 12. Molding and Casting.
    • 13. Embedded Networking and Communications.
    • 14. Interface and Application Programming.
    • 15. Wildcard Week.
    • 16. Applications and Implications.
    • 17. Invention, Intellectual Property and Business Models.
    • 18. Project Development.
    • 19. Final Project
  • Final Project


Output Devices




Group assignment

  • Measure the power consumption of an output device.
  • Document your work on the group work page and reflect on your individual page what you learned.

In this assignment we were planning to measure the power consumption for the following components:

Image

We connected each component with an external power supply, with the rated voltage for each one, and we set a 2A as an upper limit for the current.

For the first 3 components, the result was as shown below:

Image

The second test was for the 2 motors below:

Image

The rest of components are shown below:

Image

We conclude that every components takes different amount of current, based on the load of the component, higher load means higher current means more power consumption.



Individual assignment

Since this week is to deal with an output devices and I have already designed a board to control a DC motor since it represents an output device in Week08, I will use the same board but this time to control a servo motor.

The board with the previous connection:

Image

I will use a SG90 servo motor, and since it is the first time I deal with a servo motor, I went through the datasheet of motor and I found that is has 3 lines, 2 lines for powering and the third one is for data to control the position of rotation(PWM).

Image

The pulse width modulation(pwm) is a technique used to control the amount of the power delivered to a certain device, by varying the width of a series of pulses of a fixed frequency the more pulses the more power delivered. In another way the pwm simulate an analog voltage using a digital signal, by rapidly turning a digital signal on and off, here is a helpful video explains what happens.

Servo motors in general are rotates from 0 degree up to 180 degree, However, if we need to rotate a standard servo motor beyond its normal 180 degree range, we can modify the servo by removing the mechanical stop that limits its rotation. This is known as "modifying the servo for continuous rotation", but I should note that it may not provide accurate positioning control and could potentially damage the servo.

To start dealing with the servo on IDE, first I had to install the servo library, the library will let me to interface with the built-in hardware PWM signals on the ESP32 without having to worry about the details of generating the PWM signal.

I installed the library from this Website:

Image

After downloading the library, I unzipped the file and renamed the file to ESP32_Arduino_Servo_Library, then I moved the file to the Arduino IDE installation libraries folder(usually in Documents) then I reopened the IDE.

I have connected the servo to a GND pin, and supplied it with 3.3V and the pwm pin was pin number 25.

Image

I wrote the following code, I included the servo library using this command #include , the Servo myservo is to control a specific servo motor connected to one of the Esp32's digital pins. Then the myservo.attach(25); tells the Servo library that I want to control the servo motor connected to pin 25.

In void loop the digitalRead() function returns LOW if the push button is pressed and HIGH if it's not, if the push button is pressed (pb_status is LOW), The first for loop, for (pos = 0; pos <= 180; pos += 1), gradually increases the pos variable from 0 to 180 in steps of 1 degree,and myservo.write(pos); sets the servo motor's position to the current value of pos. In addition a small delay of 15 milliseconds (delay(15);) is added to allow the servo to reach the desired position smoothly. Finally After reaching 180 degrees, another for loop is used to sweep the servo from 180 to 0 degrees in steps of 1 degree.


                  
                    #include 

                      int pb=5; // to define the pushbutton
                      int pb_status=0; // variable to store the pb state
                      int pos = 0;    // variable to store the servo position
                      
                      Servo myservo;  // create servo object to control a servo
                      // twelve servo objects can be created on most boards
                      
                      void setup() {
                      
                        pinMode(pb, INPUT_PULLUP); // set the pb pin as an input pin
                        Serial.begin(115200);
                        myservo.attach(25);  // attaches the servo on pin 25 to the servo object
                      }
                      
                      void loop() {
                      
                      pb_status= digitalRead(pb);
                      if (pb_status == LOW) 
                      { 
                        for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
                          // in steps of 1 degree
                          myservo.write(pos); 
                          Serial.println(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
                          myservo.write(pos); 
                          Serial.println(pos);               // tell servo to go to position in variable 'pos'
                          delay(15);                       // waits 15ms for the servo to reach the position
                        }
                      }
                      }
                      
                   
                


The result is shown below:

Your browser does not support the video tag.




Direct Files links
  • Eagle File

  • Useful links
  • Esp32.
  • ESP32 with Servo.
  • Servo Motors with Arduino Complete Guide
  • © Copyright Mohammad Shuqwara. All Rights Reserved
    Template by BootstrapMade