11. Output devices¶
Assignment
group assignment : measure the power consumption of an output device
individual assignment : add an output device to a microcontroller board you’ve designed, and program it to do something
Board design ¶
About MOSFET ¶
MOSFET means Metal Oxide Semiconductor Field Effect Transistor. There is two types of MOSFET : N or P-channel. There both have three pins : Drain, Gate, Source.
N-Channel MOSFET | P-Channel MOSFET |
---|---|
Warning
Small arrow indicate direction of electron flow
Specifications :
Vgs : voltage between Gate and Source. Vgsth is Vgs min to unlock MOSFET (it’s a range) and Vgs should not exceed Vgsmax given by the datasheet.
if Vgs < Vgsthmin : MOSFET is blocked.
if Vgsmax > Vgs > Vgsth(max) : MOSFET is passing.
Id : drain current. Depend on temperature. Id should be lower than Idmax given by the datasheet.
Rdson : electrical resistance between Drain and Source when MOSFET is passing.
Vds = Rdson x Id : voltage between Drain and Source
To use MOSFET as a switch we should have the smallest Vds and that for, the smallest Id and the biggest Vgs.
Here I use first MOSFET IRF740 and find some informations in the datasheet here.
Channel type | Vgsthmin | Vgsthmax | Vgsmaw | Id | Rdqon |
---|---|---|---|---|---|
N | 2V | 4V | +-20V | 10A at 25°C |
So with this MOSFET I use 0 volt to block MOSFET and 5V to unblock it.
You can find more about MOSFET here.
TinkerCad simulation ¶
You can find the TinkerCad file here.
// C++ code
//
int counter;
void setup()
{
pinMode(2, OUTPUT);
}
void loop()
{
for (counter = 0; counter < 10; ++counter) {
digitalWrite(2, HIGH);
delay(4000); // Wait for 4000 millisecond(s)
digitalWrite(2, LOW);
delay(6000); // Wait for 6000 millisecond(s)
}
}
Test with Arduino UNO ¶
Here motor is replaced by an air pump. |
Diode added as described on schema before. Used to avoid disturbance using air pump. |
Board design ¶
Board production ¶
Output devices ¶
Air pump ¶
I use a AIRPO D2028B pump described here.
Speaker ¶
I use a PWM output to modulate output signal which can’t be analogic with our micro. PWM means : Pulse Width Modulation.
So I use a digital output which has only two values (HIGH 5V and LOW 0V).
With PWM output you can have modulation by changing HIGH and LOW values very quickly : you can have 256 different values generated by average from HIGH and LOW periods (from 0 to 255).
PWM = 0 > 0V | PWM = 25 > 0.5V | PWM = 75 > 1.5V | PWM = 255 > 5V |
To calculate Voltage you make a cross product.
For example PWM = 75
75 / 255 x 100 = 30%
30 / 100 x 5V = 1.5V
PWM | % | V |
---|---|---|
PWM = 0 | 0% | 0 V |
PWM = 25 | 10% | 0.5 V |
PWM = 75 | 30% | 1.5 V |
PWM = 100 | 40% | 2 V |
PWM = 255 | 100% | 5 V |
More informations about PWM here.
How to program PWM output :
int broche_PWM = 3;
int Valeur_PWM = 0;
void setup()
{
pinMode(broche_PWM, OUTPUT); // Pin 3 (named broche_PWM) as PWM output
}
void loop()
{
analogWrite(broche_PWM, 0); // 0% sent on broche_PWM > 0V
delay(4000); // Wait for 4000 millisecond(s)
analogWrite(broche_PWM, 25); // 25% sent on broche_PWM > 0.5V
delay(4000);
analogWrite(broche_PWM, 50);
delay(4000);
analogWrite(broche_PWM, 75);
delay(4000);
analogWrite(broche_PWM, 100);
delay(4000);
analogWrite(broche_PWM, 125);
delay(4000);
analogWrite(broche_PWM, 150);
delay(4000);
analogWrite(broche_PWM, 175);
delay(4000);
analogWrite(broche_PWM, 200);
delay(4000);
analogWrite(broche_PWM, 225);
delay(4000);
analogWrite(broche_PWM, 255); // 100% sent on broche_PWM > 5V
delay(4000);
}
I test an other function to generate modulate output :
tone(pin, frequency, duration).
I use frequencies of a pentatonic scale :
note | frequency |
---|---|
ré# | 311 Hz |
fa | 349 Hz |
sol | 392 Hz |
la | 440 Hz |
si | 494 Hz |
void setup()
// ajouter l'initialisation
void loop()
{
tone(3, 311, 500);
tone(3, 349, 500);
tone(3, 392, 500);
tone(3, 440, 500); // La 440
tone(3, 494, 500);
}
DC Motor ¶
I change speaker by DC motorand use PWM program seen before.
int broche_PWM = 3;
int Valeur_PWM = 0;
void setup()
{
pinMode(broche_PWM, OUTPUT);
}
void loop()
{
analogWrite(broche_PWM, 0);
delay(4000); // Wait for 4000 millisecond(s)
analogWrite(broche_PWM, 25);
delay(4000);
analogWrite(broche_PWM, 50);
delay(4000);
analogWrite(broche_PWM, 75);
delay(4000);
analogWrite(broche_PWM, 100);
delay(4000);
analogWrite(broche_PWM, 125);
delay(4000);
analogWrite(broche_PWM, 150);
delay(4000);
analogWrite(broche_PWM, 175);
delay(4000);
analogWrite(broche_PWM, 200);
delay(4000);
analogWrite(broche_PWM, 225);
delay(4000);
analogWrite(broche_PWM, 250);
delay(4000);
analogWrite(broche_PWM, 500);
delay(4000);
}