Skip to content

10. Output devices

Group assignment page:

If you want to check out our group assignment page, check this link

Power consumtion of an output device:

To calculate power consumption of any appliance, you have to multiply it’s wattage by the number of hours it is being used (operational hours).

For example, a 1000 watt electric iron running for one hour will consume (1000 watt X 1 hour) 1000 watt hour or 1 kilowatt hour (kWh) of electricity. Similarly to calculate the monthly power consumption multiply the daily power consumption by 30 days and for annual power consumption multiply the daily power consumption by 365 days.

(SOURCE: LETSAVELECTRICITY])

I still needed some concepts to be clear for me, that’s why I made more research:

What is the difference between Volts, Amps, and Watts

What is the Difference Between a Kilowatt and a Kilowatt-hour (kW vs. kWh)?

Well, according to SolarSolutionLLC kW stands for kilowatt. A kilowatt is simply 1,000 watts, which is a measure of power. So a 1,000 watt drill needs 1,000 watts (1 kW) of power to make it work, and uses 1 kWh of energy in an hour. That’s why, if you leave a TV or computer on standby, it is still using power and creating a kWh cost on your energy bill.


(Source: SolarSolutionLLC)

Measure the power consumption of an output device

For measuring the power consumption, we used an GW-INSTEK GPD-3303D Programmable Linear D.C. Power Supply

(Source il.farnell)

In this case, I worked with two different output devices:

The first one was a stepper mottor:

As you can see, we put the 12V (standard volts for a motor) and the amps as the video shows, it has 0.06A
Doing the calculation of P = I * V we have:
P = 0.06A * 12V
P = 0.72W

The power consumption of the stepper mottor is 0.72 Watt

The second one was my final PCB “mate”.

We used 5V and as you can see in the video, it has an amp that goes from 0.01A to 0.05A, so let’s take the average of 0.03A.
Doing the calculation of P = I * V we have:
P = 0.03A * 5V
P = 0.15W

The power consumption of my PCB is 0.15 Watt

Interfacing output device to microcontroller:

First we need to know what “Interfacing” means.
According to Macmillan Dictionary, is the equipment or software that allows two computers or programs to interface.

With this, we can have an idea of what about “Interfacing” does.
In this course I learnt about Interfacing: ADC and DCA
From the website Components101, for example, it explains about “What is an ADC (Analog to Digital Converter)?”:
An analog to digital converter is a circuit that converts a continuous voltage value (analog) to a binary value (digital) that can be understood by a digital device which could then be used for digital computation. These ADC circuits can be found as an individual ADC ICs by themselves or embedded into a microcontroller. They’re called ADCs for short.

A good video that talks about it is the following:

Basically, interfacing output device is the “result” of a miriad of stimulus that an input device is receiving. In my case, the piezzo, is “talking” due to the signals that are being received from an input device.

Research

I decided to work with a DC motor, using my PCB that I designed.

So first, what I did was to look more information about DC motors.

This video answers to the question “Why the motor starts to work when you just turn it on?”.
It covers the basic of electricity and magnets, and then put it all together to understand how the motor works.

As Wikipedia says:
DC motor is any of a class of rotatory electrical motors that converts direct current (DC) electrical energy into mechanical energy.

https://www.electronicwings.com/sensors-modules/dc-motor
https://www.electronicwings.com/sensors-modules/dc-motor

One good question that presented to me was Can we connect DC motor to microcontroller?.

According to Electronicshub

The power requirements of most of DC motors is out of reach of the microcontroller and even the back emf (electro motive force) which is produced by the motor may damage the microcontroller. Hence, it is not good to interface DC motor directly to the controller. So, we use motor driver circuit in between a DC motor and the microcontroller.

For this reason I will need to work with a motor driver.

Luckily, my instructor gave me the advice to work with the a4953. Which datasheet is found in one of the archives of Fab Academy by the brand Allegro

Here you can find a lot of information, even the Pin-out Diagram

Important Note

By the end of the day, I decided to change the output device to a Piezzo, because that is what I’m going to use as a device for my final project. I changed the name of the project and I started a new KiCAD file.
Even though, this research allowed me to learn more about output devices, speciffically about DC motors.

Creation of the PCB:

After weeks of training and development in my skills of making schematics, I finally could advance in a next level of designing in KiCAD.
You can clearly see my progress in this comparisson, I’m very proud about it:

The details of my PCB are here:

Milling process:

For milling, I just used Fabmods.
If you want to know how I used it, or you want to learn how to use it, just follow the following link. It will direct you to the *Electronic design week, where you can find a very good tutorial of mine.


Programming:

For programming I used the OS Linux, where is a very solid OS for programming.
I tried to program on my laptop that has Windows, but was impossible for me.

I also used my old trustfull Programmer that I made on the Electronic design week for programming it.
Here you can see the piezzo (output-device) with the distance sensor (input-device)

Getting different Frequencies:

So for this part, I used a beautiful chord path:

I took this frequencies from the following website

(Source: mtdu.edu)

Once that I had the frequencies that I wanted I installed an app for android called Music Note Identifier

And I started to look for the appropiate frequency:

This is the following code:

Code:

Important Note

The code that appears here is the same code for the “Input week” because both weeks are inside of my final project.

Note about the code

Inside of the code you will find the double-bars “//” that will explain the code

//
//
// Theremin
//
// simple software to measure distance and make sound delays
//
// (c) Babken Chugaszyan, Ruslan Gindullin, Ashod Bzdigian 2022
// This work may be reproduced, modified, distributed,
// performed, and displayed for any purpose. Copyright is
// retained and must be preserved. The work is provided
// as is; no warranty is provided, and users accept all
// liability.
//

#include <avr/io.h>
#include <util/delay.h>

#define output(directions,pin) (directions |= pin) // set port direction for output
#define input(directions,pin) (directions &= (~pin)) // set port direction for input
#define set(port,pin) (port |= pin) // set port pin
#define clear(port,pin) (port &= (~pin)) // clear port pin
#define pin_test(pins,pin) (pins & pin) // test for port pin
#define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set
#define Short_delay() _delay_ms(1) // Short delay (CHANGE DELAY VALUE IN MILISECONDS)
#define Long_delay() _delay_ms(1) // Long delay (CHANGE DELAY VALUE IN MILISECONDS)

#define led_port PORTB
#define led_direction DDRB
#define buz (1 << PB3)

short int re;//reading variable

void initADC()
{
  ADMUX =
            (0 << ADLAR) |     // left shift result
            (0 << REFS1) |     // Sets ref. voltage to VCC, bit 1
            (0 << REFS0) |     // Sets ref. voltage to VCC, bit 0
            (0 << MUX3)  |     // use ADC2 for input (PB4), MUX bit 3
            (0 << MUX2)  |    
            (1 << MUX1)  |    
            (0 << MUX0);      

  ADCSRA =
            (1 << ADEN)  |     // Enable ADC
            (1 << ADPS2) |     // set prescaler to 64, bit 2
            (1 << ADPS1) |     // set prescaler to 64, bit 1
            (0 << ADPS0);      // set prescaler to 64, bit 0  
}

void delay2micros(short int i){   // Delay microseconds
      while (i != 0) {
      _delay_us(2);
      --i;
      }
}
int valuecleaner(){  // Averaging input to eliminate analog noise
short int i = 0;
int val = 0;
for(i = 0; i < 10; ++i){    // reading 10 times
  initADC();
      ADCSRA |= (1 << ADSC);         // start ADC measurement
      while (ADCSRA & (1 << ADSC) ); // wait till conversion complete
    val += ADCW;
    }
    val /=10;  // dividing by 10
    return val;
    }

int main(void) {

   //
   // main
   //

   //
   // set clock divider to /1
   //
   CLKPR = (1 << CLKPCE);
   CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);
   //
   // initialize LED pins
   //
   clear(led_port, buz);
   output(led_direction, buz);
   //
   // main loop
   //
   while (1) {

    if(valuecleaner() < 65) re = 0;  // Capping low values to eliminate noise
    else re = valuecleaner();


      set(led_port,buz);
      delay2micros(5000/re);     // Dividing a constant by variable to linearize the scale and delaying for the result amount of microseconds

      clear(led_port,buz);
      delay2micros(5000/re);  // Dividing a constant by variable to linearize the scale

   }
}

Note about the Frequency

If you want to change the frequency you need to change the values of this part of the code:

set(led_port,buz);  
delay2micros(5000/re);     // Dividing a constant by variable to linearize the scale and delaying for the result amount of microseconds

clear(led_port,buz);  
delay2micros(5000/re);  // Dividing a constant by variable to linearize the scale

Note about the instrument

The process of changing the tone (frequency) is still rusty and maybe a bit tedious to do. Because first you need to change the value, and then look into the app for the correct pitch.
I’m planning to find a better way in the future.

Some problems

My first PCB model was good, but it has a “tiny” problem:

I had a “stupid mistake”. I forgot to put the pad for FTDI cable:

So I had to design my schematics again, with another wires and PADS.
And yes, it took longer than expected.

Testing Output:

As the distance sensor is going to be my input device, and the output will be a piezzo. There is no need to check if my output works with a program, due to the piezzo will be the main tester.

For checking my Input week, click here.

Files:

Schematics
KiCAD
SCH
PCB

Code
For the code, just go to the section “Code” in the content bar, and copy it. There is a button on the top right corner for easy copy.


Last update: July 4, 2022