Tanja ∈ Fab Academy 2018

Week 11: Output Devices

Many thanks to Aleksandra Konopek who gave me an advice to take a look at the page of Funduino and to test the circuits. Thanks to Peter von der Bey for the helpf ull tipps about the wiring and our instructor Tobias Poppe for helping me to solve the problem which occured with the wiring the laboratory power supply with my board.
This week, we should issue a signal and use a self made board for it. I would have liked to build a new board that I could tailor to the task. Unfortunately, the time this week was not enough for milling a new board.

I have decided to test the small blue servo motor SG90 with the plastic case this week. I also wanted to test the RGB LED. The green RGB LED should light up whenn the green segment of the logo turns and so on .
Servo where to purchise .
Servo control using Arduino IDE.

A few excerpts from the data sheet with the basic data of the servo:
The first attempt to operate the servos I had done with Arduino UNO and that had worked.
For the wiring only three cables were needed:
VCC, Red cable (+)
GND, Brown cable (-)
and PWM Signal, Orange cable

Something I did not know as I used the Funduino code example was this: "Servo can rotate approximately 180 degrees (90 in each direction)". In the Funduino code ther are commands to turn up to 180°. This could damage the servo over the long term using.
I found the following script for the servo control at Funduino ( FUnduino.de ) and used it for the control. I just extended it to three servos. At first, I had the servos switched at the same time (with a PIN) and later one by one so I needed three variables .

Three servos I conected as to see on the folowing image, where I used Fritzing.app

Fritzing.app beta version
to visualise the conections.
Folowing image shows the prozes of wiring the Arduino board in Fritzing.app. I decided to use Arduino-Symbolics instead of Atmega328p becauese it was simplier than insluding many headers adittionally to atmega and other components.

Wiring step
In Fritzing.app you cann also switch to the board layout and do all the settings in that layer, as same as using Eagle.

Boardshema not finished as I did not used it.
This is how the wiring of the breadbord looked like for my servo motor connection. The pins on the Arduino board are not the same as the pins I used on Atmega328p.

Wiring three servos

What is PWM? (Source: barrgroup.com)

PWM (Pulse width modulation) is a way of digitally encoding analog signal levels. Through the use of high-resolution counters, the duty cycle of a square wave is modulated to encode a specific analog signal level. The PWM signal is still digital because, at any given instant of time, the full DC supply is either fully on or fully off. The voltage or current source is supplied to the analog load by means of a repeating series of on and off pulses. The on-time is the time during which the DC supply is applied to the load, and the off-time is the period during which that supply is switched off. Given a sufficient bandwidth, any analog value can be encoded with PWM (Pulse width modulation).
In the folowing graphic the red line show the red line shows the switch-on behavior of the current:

PWM Period
Here is the formula for calculation of the Duty Cicle in which is the period and

the value of the voltage over the duty cicle period.
The first part 1a of the folowing figure shows a PWM output at a 10% duty cycle. That is, the signal is on for 10% of the period and off the other 90%. Figures 1b and 1c show PWM outputs at 50% and 90% duty cycles, respectively. These three PWM outputs encode three different analog signal values, at 10%, 50%, and 90% of the full strength. If, for example, the supply is 9V and the duty cycle is 10%, a 0.9V analog signal results.

PWM signals of varying duty cycles
If we made a simple circuit that could be driven using PWM. A 9 V battery powers an incandescent lightbulb. If we closed the switch connecting the battery and lamp for 50 ms, the bulb would receive 9 V during that interval. If we then opened the switch for the next 50 ms, the bulb would receive 0 V. If we repeat this cycle 10 times a second, the bulb will be lit as though it were connected to a 4.5 V battery (50% of 9 V). We say that the duty cycle is 50% and the modulating frequency is 10 Hz.
Folowing image shows the Duty Cycle of Servo Motor SG90 (From Servo Datasheet .)

Duty Cycle (PWM)
Later I noticed that the servos could also be connected to a normal pin, which has no PWM function. I had to connect the servos to the normal pins because the LED needed the PWM pins.

Here is the code used which I changed for the controll of three servos using Funduino code as an example:
        
#include         // Servo Library is called. Will be needed, for the easier control of the servo motor  
 
Servo servoblue;          // For this programm here will be created a servo named „servoblue“
Servo servogreen;
Servo servored;
 
void setup()
{

servoblue.attach(PD5);      // This is the Information that servo connecting
                            //the control wire (blue) is connected with  pin PD5 . You can take 
                            //any other pin for this connection.
servogreen.attach(PD6);
servored.attach(PD5);
}

void loop()

{     //In the „loop“ using the write-command „servoblue.write(Grad)“
      //the servo will be controled. Between the positions (Grad) there 
      //will be a pause, so the servo becommes enough time to reach the desired position.

servored.write(0);      //Activate position 1 on servored with the angle 0 °
delay(3000);            //The program stops for 3 seconds

servogreen.write(0);    //Activate position 1 on servogreen with the angle 0 °
delay(3000);           

servoblue.write(0);     //Activate position 1 on servoblue with the angle 0 °
delay(3000);            

servored.write(30);     //Activate position 2 on servored with the angle 30 °
delay(3000);           

servogreen.write(30);   //Activate position 2 on servogreen with the angle 30 °
delay(3000);           

servoblue.write(30);    //Activate position 2 on servoblue with the angle 30 °
delay(3000);         

servored.write(60);     //Position 3 on servored control with the angle 60 °
delay(3000);            
servogreen.write(60);   //Position 3 on servogreen control with the angle 60 °
delay(3000);            
servoblue.write(60);    //Position 3 on servoblue control with the angle 60 °
delay(3000);           

servored.write(90);     
delay(3000);           
servogreen.write(90);    
delay(3000);
servoblue.write(90); 
delay(3000);

servored.write(60);
delay(3000);
servogreen.write(60); 
delay(3000);
servoblue.write(60); 
delay(3000);

servored.write(30); 
delay(3000); 
servogreen.write(30); 
delay(3000); 
servoblue.write(30); 
delay(3000); 

}  
When I tried to power the servos with my board (Atmega328p_au), it had not worked. One could perceive only a weak impulse as an attempt of the motor axis to move.
At this point I had read the note in our Fab Academy group by Peter von der Bey, in which he recommends us to use external power supply. First I used battery just for the short test. It had worked !!!


I wanted to have the help of the servos, a picture consisting of three parts assemble. The image should be the logo of the Fab Academy. That is why I needed at least three servos.

Wiring vour servos with Atmega328p and battery.

I have cut three segments of the logo in three colors and a white circle with the vinyl cutter and stuck them on a cardboard circle.

Fab Academy imported in Incscape / Fab Academy Logo Laser Cut Parts / Fab Academy heat press
And here is the video with the finished structure of the servos in motion.

Logo Movie
Since I also planned to connect an RGB (Red Green Blue) LED to the servos I searched for existing code at Funduino afterwards.

RGB LED
The RGB LED has one leg that is longer than the other three. This is then either the cathode (+) or the anode (-). Which of the two versions is you can only find out by connecting the LED to the power supply.

RGB LED Shema
and RGB LED Wavelength
Here you will find data sheets of an RGB LED from the supplier RS.
The figure shows the wiring in the Fritzing.app including RGB LED. Each color requires a resistance of 200 ohms.

Fritzing.app Wiring Servos with RGB LED
First I only tested the LED:

and then only servos:

later combined it with the servo motors.
As I was trying to connect the RGB LED to my board, I noticed that some pins did not work. Since I had occupied with the servos allready three pins remained only two left for the use of the LED.
I also had to note that the RGB LED needs PWM pins, i. E. pins designed for pulse width modulation.
I decided in the end for a test run simply disconnect the servo of the green segment and run the program. The result can be seen in the following video:

The following code shows the combination of these two output devices.
        #include         // Servo Library is called. Will be needed, for the easier control of the servo motor  
 
        Servo servoblue;          // For this programm here will be created a servo named „servoblue“
        Servo servogreen;
        Servo servored;

        int LEDred = PD5;       // Colour red will be at pin PB2 (PWM)
        int LEDgreen = PD3;     // Colour blue at PB1 (PWM)
        int LEDblue = PD6;      // Green at Pin PD6 (PWM)
        int p = 3000;           // p is a pause with 1000ms (1 second)
        int brightness1a = 100; //  Value between 0 and 255 - indicates the luminosity of each color
        int brightness1b = 200; 
        int brightness1c = 200; 
        int dark = 0;           // Value 0 means Voltage 0V - so LED off.


        void setup()
        {

        servoblue.attach(PD7);      // This is the Information that servo connecting
                                    //the control wire (blue) is connected with  pin PD5 . You can take 
                                    //any other pin for this connection.
        servogreen.attach(PB4);   
        servored.attach(PD4);

        pinMode(LEDred, OUTPUT);
        pinMode(LEDblue, OUTPUT);
        pinMode(LEDgreen, OUTPUT);
        pinMode(LEDred, OUTPUT);

        }

        void loop()

        {     //In the „loop“ using the write-command „servoblue.write(Grad)“
              //the servo will be controled. Between the positions (Grd) there 
              //will be a pause, so the servo becommes enough time to reach the desired position.

        servored.write(0);                  //Activate position 1 on servored with the angle 0 °
        analogWrite(LEDred, brightness1a);  // red LED on
        delay(p);                           //The program stops for p seconds

        servogreen.write(0);                  //Activate position 1 on servogreen with the angle 0 °
        analogWrite(LEDred, dark);            // red LED off
        analogWrite(LEDgreen, brightness1b); // green LED on         
        delay(p);  

        servoblue.write(0);                   //Activate position 1 on servoblue with the angle 0 °
        analogWrite(LEDgreen, dark);        // green LED off
        analogWrite(LEDblue, brightness1c);   //  blue LED on
        delay(p);            

        servored.write(30);     //Activate position 2 on servored with the angle 30 °
        analogWrite(LEDblue, dark);         // blue LED off
        analogWrite(LEDred, brightness1a); 
        delay(p);           

        servogreen.write(30);   //Activate position 2 on servogreen with the angle 30 °
        analogWrite(LEDred, dark);            // red LED off
        analogWrite(LEDgreen, brightness1b);
        delay(p);           

        servoblue.write(30);    //Activate position 2 on servoblue with the angle 30 °
        analogWrite(LEDgreen, dark);        // green LED off
        analogWrite(LEDblue, brightness1c); 
        delay(p);         

        servored.write(60);     //Position 3 on servored control with the angle 60 °
        analogWrite(LEDblue, dark);         // blue LED off
        analogWrite(LEDred, brightness1a); 
        delay(p);            

        servogreen.write(60);   //Position 3 on servogreen control with the angle 60 °
        analogWrite(LEDred, dark);            // red LED off
        analogWrite(LEDgreen, brightness1b);
        delay(p);            

        servoblue.write(60);    //Position 3 on servoblue control with the angle 60 °
        analogWrite(LEDgreen, dark);        // green LED off
        analogWrite(LEDblue, brightness1c); 
        delay(p);           

        servored.write(30); 
        analogWrite(LEDblue, dark);         // blue LED    
        delay(p);           

        servogreen.write(30);    
        analogWrite(LEDgreen, brightness1b);
        delay(p);

        servoblue.write(30); 
        analogWrite(LEDgreen, dark);        // green LED off
        analogWrite(LEDblue, brightness1c); 
        delay(p);

        servored.write(15);
        analogWrite(LEDblue, dark); 
        delay(p);

        servogreen.write(15); 
        analogWrite(LEDgreen, brightness1b);
        delay(p);

        servoblue.write(15); 
        analogWrite(LEDgreen, dark);        // green LED off
        analogWrite(LEDblue, brightness1c); 
        delay(p);

        servored.write(0); 
        analogWrite(LEDblue, dark); 
        delay(p); 

        servogreen.write(0); 
        analogWrite(LEDgreen, brightness1b);
        delay(p); 

        servoblue.write(0); 
        analogWrite(LEDgreen, dark);        // green LED off
        analogWrite(LEDblue, brightness1c); 
        delay(p); 
        }    

Groupassignement: Power supply and measurement of the power consumption with the laboratory power supply device

Here you can find the datasheet of the DC bench power supply BK Precision model 1550 with 108 watt power supply (1-36 V and 0-3 A) from BK Precision.com which I used for powering my Atmega 328p board.

DC Bench
Here I will insert the Introduction for using it from the User Manual of the BK Precision:
"Using the 1550 switching mode power supply The unit is a Micro-controller based DC power supply with a total supply capability of 108W. By using a digital + / - keypad operation control, you can set the output voltage and current easily. It is a clean supply with quiet operation making it ideal for laboratory, work shop or educational applications where work bench space is limited. The 1550 has a USB charger output, constant current operation, tracking OVP, floating ground design, small footprint, output on/off push button and a small form factor."

"3.1 Ground Connection Depending on the application, the power supply output terminals can be grounded in any one of the following grounding conditions: Negative ground black (-) negative terminal is shorted with green GND terminal. Positive ground red (+) positive terminal is shorted with green GND terminal. Floating ground green terminal is not shorted with any of the output terminals. Remarks: When operating this power supply as a floating ground, high impedance leakage can exist between the power supply circuitry and the chassis ground."

When I connected the board with the three servos to the laboratory power supply, the following reading were to see:


The first image shows the power consumption of the servo start-up phase (the impulse phase is high: 5.1 V and 120 mA). Second image shows the power consumption of the low phase (5.1 V and 10 mA). Here was the servo just turned off (the phase of the pulse was over).

Downloads


Fritzing_Servos.fzz Download wiring shema using Fritzing.app
OnlyServos.ino Download C-Code of Servo Control
Fritzing_ServosAndRGBLED.fzz Download wiring shema using Fritzing.app
ServosPlus_RGBLED.ino Download C-Code of Servos and RGB LED control
in three colors