Wednesday, 26 June 2013

About PWM in Arduino board

PWM is Pulse Width Modulation, it is a technique which will represents  analog values with using digital means. If you want to get different results, you can change the pulse width. Therefore, we can output results with using function analogWrite().

Syntax:
analogWrite(pin, value); 
where "pin" is the pin number will be written to, and "value" is the duty cycle which is between 0(off) and 255(on). Furthermore, duty cycle is shown in Figure 1:

                                  Figure 1: Duty cycle of PWM, taken from Arduino

If you want to adjust the speed of motor, you can only change the value in function analogWrite(). We use Lego motor to test this function, so we need to connect the white wire to pin 3 and black wire to pin GND. Therefore, pin=3. For example, analogWrite(3, 0) means the Motor cannot rotate, analogWrite(3, 255) represents the motor will rotate at full speed, thus, analogWrite(3, 127) means that motor will rotate at half speed. 

Note: Not all pins in Arduino can be used to output PWM, the pins which is labeled "~" means that it can be used for outputting PWM as shown in Figure2.

                                       Figure 2: Arduino board, taken from Arduino

In above picture, pin 3, 5, 6, 9, 10, 11 can be used for PWM, thus, the function analogWrite() is only effective for this pins. If this function is used for other pins, it works abnormally. So there are 6 pins used for PWM output. 


Reference: 

1. Arduino, http://arduino.cc/en/


Tuesday, 25 June 2013

Test Lego Motor with application on iPad

This experiment is divided into two parts: one is control and another is feedback control, thus, testing Lego Motor with application on iPad is extremely important for control part. This is the basic of this experiment.

We refer the article "iOS Sensor Apps with Arduino" to develop the Apple software to control the Lego motor. The interface of software is shown in Figure 1:

                                             Figure 1: Software Interface on iPad

Each switch is off initially, and when we press it, and then it will be opened. When it opened, the corresponding signal will be transferred from iPad to Arduino board via Redpark Serial Cable as shown in Figure 2. The transferred information is shown in following Figure 3:


                                               Figure 2: Redpark Serial Cable



                                Figure 3: Transmitted information via Redpark Serial Cable

When we switch the button, two-byte message will be transmitted from iPad to Arduino board. The first byte will indicate the pin number and the second pin will be 0 or 1 which is the state of the switch (on/off). If the switch is on, the corresponding pin is HIGH, otherwise, the pin is LOW.

After that, connect iPad to Arduino board, and then upload the corresponding the program to Arduino board.
Note: The receive (RX) pin (pin0) in Arduino is connected to the transmission (TX) pin in the adopter. The transmission (TX) pin (pin1) in Arduino is connected to the receive (RX) line in the adopter. The ground (GND) pin is connected with each other. 




  • Testing

Finally, we will test Lego Motor with iOS application. Before that, we need to connect the power supply board to Lego Motor and Arduino board. When we turn on the corresponding switches, the motor will rotate forward or backward. In this test, we only test the above motor. Pin 9 and Pin 11 will control this motor as shown in Figure 4 and 5.



Figure 4: Pin 9 is on, Pin 11 is off, rotate forward


Figure 5: Pin 9 is off, Pin 11 is on, rotate backward


Monday, 24 June 2013

Test Lego Motor

For this experiment, we also need to know how to use the Lego Motor. First of all, we need to define forward rotation of Lego Motor as shown in Figure 1:


           Figure 1: Definition of forward rotation, taken from Reference 1

We need to understand the input wire for controlling Lego Motor, so the details are in the follows (Reference 1):

Cable Color                                  Functions
White                                     Motor Power Supply (Use)
Black                                     Motor Power Supply (Use)
Red                                        Rotation detector supply
Green                                     Rotation detector supply
Yellow                                   Rotation detector output 1
Blue                                       Rotation detector output 2

From above information, we know that the white and black wire determines the direction of rotation. Therefore, we only use these two wires in this experiment. The test results are as shown in follows:

Input Signal (White, Black)                        Rotation
10                                                            Forward
01                                                            Backward
00/11                                                       Stop

We use 10, 01 for rotation and 00 for stop in this experiment.





Reference:
  1. Input and Output of Lego NXT Servo Motor, http://trivox.tripod.com/lego-nxt-motor-input-output.html



Friday, 21 June 2013

Test analog data reading for Arduino UNO

We need to test how to read analog data from actual circuits before completing the solar tracker experiment. In Arduino board, we use analogRead() function to read the analog data. Let's look at the usage of this function first.

Syntax:
analogRead(Pin);
where "Pin" represents the pin number of the input pin which read from. Furthermore, the return value is integers from 0 to 1023 and the analog value can be read from 0 to 5V. Therefore, the resolution of measurement is approximately 4.88mV.

In the test, we design the circuit that voltage of photo-resistor can be read via Arduino UNO. Therefore, the power supply (+5V) is connected to the resistor, one terminal of photo-resistor is connected to ground and another terminal is connected to the Arduino (e.g. A0) as shown in following Figure 1.

         
                                               Figure 1: Circuit for testing data reading
 
After that, upload the program from computer to Arduino board and then open the Serial Monitor. Observe the voltage of photo-resistor as shown in following Figure 2:


                                               Figure 2: Voltage of photo-resistor

When the strength of light increase, the voltage of photo-resistor becomes smaller as shown in following Figure 3:


                             Figure 3: Voltage of photo-resistor with increasing strength of light

When the strength of light decrease, the voltage of photo-resistor becomes larger as shown in following Figure 4:


                             Figure 4: Voltage of photo-resistor with decreasing strength of light



Thursday, 13 June 2013

Try to use Arduino board - Blink

We are trying to use Arduino board to test a basic and sample program today.  For blinking the LED light, the algorithm are as shown in following:

1. Set the pin 13 as the output
2. Set the voltage of pin 13 to be high at the beginning.
3. After 1 second, set the voltage of pin 13 to be low.
4. Repeat the second and third step.

The basic step is shown as following:
1. Click "Verify" to compile the program.
2. Connect the Arduino board to the PC.
3. Click "upload" to transfer the compiled code to Arduino board.
4. Observe the experimental result as shown in following Figure.


                                                                          Figure 1: LED is lighted



                                                             Figure 2: LED is extinct after one second