arduino pwm

2
[Arduino] Speed control with DC Motor and Pot Here the scheme: Components: 1 DC Motor 1 Potentiometer 10k 1 TIP120 1 diode (1N4001) 1 10kohm resistor 2 100ohm resistor 1 red led 1 green led arduino wires Here a demo video:

Upload: al-inal

Post on 20-Dec-2015

4 views

Category:

Documents


0 download

DESCRIPTION

pwm arduino

TRANSCRIPT

Page 1: Arduino PWM

[Arduino] Speed control with DC Motor and

Pot

Here the scheme:

Components:

– 1 DC Motor

– 1 Potentiometer 10k

– 1 TIP120

– 1 diode (1N4001)

– 1 10kohm resistor

– 2 100ohm resistor

– 1 red led

– 1 green led

– arduino

– wires

Here a demo video:

Page 2: Arduino PWM

Here the code:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

int analogInPin = A0;

int sensorValue = 0;

int outputValue = 0;

int transistorPin = 3;

void setup() {

Serial.begin(9600);

pinMode(8, OUTPUT);

pinMode(9, OUTPUT);

pinMode(transistorPin, OUTPUT);

}

void loop() {

sensorValue = analogRead(analogInPin)/4;

outputValue = map(sensorValue, 0, 1023, 0, 255);

analogWrite(transistorPin, sensorValue);

if (sensorValue >= 160) { //example

digitalWrite(8, HIGH);

digitalWrite(9, LOW);

} else {

digitalWrite(9, HIGH);

digitalWrite(8, LOW);

}

delay(10);

}