# Weekly Journal – PWM & Motors (Janosch Spohner)

Feb. 27

We were using Pulse Width Modulation (PWM) to create a flickering candle effect with an RGB LED. PWM is basically a ratio of high voltages to low voltages which are sent from the arduino to control whatever component is in the circuit. In our case if the arduino was sending a large ratio of high voltages to low voltages, the LED would appear brighter because it was flickering on for longer. Below is a good visual describing what is happening.

On the digital pins of the arduino, a few have this symbol next to them (~), this means that those pins can send analog values. This is how you control the ratio of high to low voltages. As above, 255 would be high voltage the whole time while 191 sends high voltage for about 75% of the time. Since we were using an RGB LED, we had to send 3 values of 0-255 for the Red, Green and Blue. We used a Potentiometer to control the brightness of the LED by reading the potValue and dividing it by 1023 to give us a number between 0 and 1. Then we multiplied that by predetermined numbers that gave us the desired colors.

```void loop() {

int pick;
pick = random(1,4);
if (pick == 1) {
analogWrite(blue, 0);
analogWrite(green, (potValue * 75) / 1023);
analogWrite(red, (potValue * 225) / 1023);
} /*code not shown*/
delay(random(75, 100));
}

```

March 1st

In class we worked on Motors and Servos. The difference between the two is that a motor just turns when supplied with the sufficient current while the Servo can actually tell how much it has turned. This lets you be very accurate with how much something should move or turn. Motors can be controlled with a simple analogWrite() function while servos require a library to be imported which will then allow you to use the Servo object which is needed to control them. Another interesting fact is that we were able to power the Servo with the arduino only but needed to supply the motor with voltage from the wall. Below is a video of a Servo moving based on the position of a Potentiometer.