Friday, May 5, 2017

Automatically reading data with Adafruit INA219 Current Sensor Breakout

 


The Adafruit INA219 Current Sensor Breakout connects to the Arduino and the circuit you want to measure. This allows one to automatically take data rather than using two multimeters.

The following link gives the assembly process, the wiring diagrams, and the programming needed to use the board: https://learn.adafruit.com/adafruit-ina219-current-sensor-breakout/assembly


After soldering the six-pin header and the 2 pin screw terminal to the board, I was able to make the proper connections from the board to the Arduino shown in Figure 1 below.


adafruit_products_Current_Measurement_Signals_bb-1024.jpg
Figure 1


Then I connected a battery and a resistor (as the load) to the current sensor breakout board. Figure 2 below shows all the proper connections.


Figure 2 

After making these proper connections, I downloaded the zip file with the library needed for the Arduino. Again, all the needed information is located in the link https://learn.adafruit.com/adafruit-ina219-current-sensor-breakout/programming.

NOTE: The link above does not include the correct way to add a library. The following link will help with this (See Importing a .zip Library section): https://www.arduino.cc/en/guide/libraries

The code will then upload to the Arduino and print the output shown in Figure 3.

Figure 3
 
The next step would be to use the PV cell rather than using the battery. Then it would be a good ida to save the data to a file.

 

Monday, March 13, 2017

Video!

Here is a short video of the solar tracker finding the sun!

 

Sunday, March 12, 2017

Troubleshooting the motor

For the last two weeks, the motor hasn't been doing exactly what it should be doing. The black wheel would turn for a couple degrees but then it seemed to get stuck and just bounce back a forth. We first went through the code printing the position of the motor and everything seemed to be working correctly on the serial monitor. When it would get stuck, it seemed like it usually happened at 180 degrees which is the maximum value the motor can reach.

After looking at the code, we decided to look at the motor itself. When the wheel began to wobble, applying the slightest pressure to the bottom of the outside of the wheel seemed to stop the wobbling and allowed the wheel to turn in either direction. After troubleshooting, it was discovered that the wheel was slightly off balance and when it turned just right, it began to wobble back and forth. (RESONANCE!)

To further test this issue, we put a pipe cleaner that was spiraled enough to sit on the wood and to reach the wheel so that it could apply slight pressure as the wheel turned. This seemed to work and proved that the wheel is slightly off-balance and may need supports to work properly.

Solar Tracker Apparatus

 
The apparatus, shown in the picture below, automatically rotates the photovoltaic cell (PV) to track the sun.
 
 
 The PV cell is placed on this padding in the picture below, which is a close-up of the upper right corner in the photo above. This is also where the photo-resistor sensors are located. At the bottom of this platform, there are two photoresistors that look like two small circles separated by a wooden wall. The purpose of this wall is to ensure that the PV cell is facing directly at the sun. If it is not, then it casts a shadow on one of the sensors. As I explained in a previous blog post, the sensors have different resistance values depending on how much light they are exposed to. This idea is the basis for the C++ code. If one resistor value is smaller than the other, than the Arduino outputs to the motor to turn one direction. If the other resistor value is smaller, than the Arduino outputs to the motor to turn in the opposite direction. This process will continue to take place until both sensors are receiving the same amount of light and no shadows are cast on them.
 
The last main piece to the apparatus is the servo motor. The motor is connected to the bottom of the black wheel shown below. On either side of the wheel is a track that allows the wheel to move left and right. This allows the wheel to be pushed up against the lazy susan (which is barely shown on the right hand side of the picture). As the motor turns, the black wheel turns and when it is pushed up against the lazy susan, that turns as well. This is what rotates the PV cell in the phi direction.
 

Wednesday, March 1, 2017

How to calculate the values of the sensors


As I mentioned in a previous post, this is the output that is printing on the serial monitor of the Arduino IDE when I have four photoresistors set up in a voltage divider with four 10k ohm resistors. (The schematic diagram and an image of the actual circuit can be found on 2/7/17.)

The values that are printing for each of the four sensors are actually the voltages outputted from the voltage divider as a 10 bit number.
 
analogRead() returns a value, in bits, and automatically defaults to 10 bits (returns values between 0-1023) (https://www.arduino.cc/en/Reference/AnalogReadResolution). I am using 5v as power. This is the maximum voltage which maps over to the maximum value in bits, 1023. 

The values printed as the sensor values can be calculated using a proportion. The equation will be the output voltage from the voltage divider over the maximum voltage (5v) which is equal to the value printed on the serial monitor over the maximum voltage in bits (1023).

For example, if the photoresistor, at a particular moment, had a value that was equal to the other resistor in the voltage divider, which in this case is 10,000 ohms, then the voltage divider will output exactly half of the initial power, which is 5v. This means that the output will be 2.5v so the value that will print on the serial monitor will be that number in bits which is calculated below:

2.5v  =    x   
 5v        1023

So the value of x is about 512.

Tuesday, February 14, 2017

Rotating the motor when one sensor value is greater than the other

The following code should be added to the code from the previous post in order to first read the output values from each of the four photoresistors and then, depending on which photoresistor has the greatest output, rotate the motor. This code rotates the motor in one direction if sensor 3 or 4 is greater and then rotates the motor in the opposite direction if 1 or 2 is greater.

-------------------------------------------------------------------------------------------------------------------------------------
//If photoresistor 1 or 2 is greater, spin motor one way and if 3 or 4 is greater, spin motor opposite way
  if (greatestValue==3 || greatestValue==4){   
    if(pos<180){ 
      pos = ++pos;
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      //delay(15); // waits 15ms for the servo to reach the position
     Serial.print("\t");
     //Serial.print(pos);
    }
    else{
      pos = 180;
      Serial.print("\t");
      //Serial.print(pos);
   }}

 
  if (greatestValue==1 || greatestValue==2){  
     if(pos>0){
      pos = --pos;
      myservo.write(pos);              // tell servo to go to position in variable 'pos'
      //delay(15);                       // waits 15ms for the servo to reach the position
      Serial.print("\t");
      //Serial.print(pos);
     }
     else{
      pos=0;
      Serial.print("\t");
      //Serial.print(pos);
   }}
 
  delay(200);        // delay in between reads for stability

--------------------------------------------------------------------------------------------------------------------------


I have also come up with a design that allows me to use the servo motor that only turns 180 degrees. I will build a cardboard disk the same size as the lazy susan with rubber around the circumference, and mount it on top of the motor. This will then be pressed up against the lazy susan so as the motor/cardboard disk rotates, the lazy susan will rotate.

This coming week, I plan to start building the final design. I will also modify the code so that the motor doesn't respond for such small changes in the sensor output values. I plan on changing the code so that the motor only rotates when the difference between the sensors is greater than 75. This means that the motor will not rotate all the time but rather when there is a clear difference in lighting

Tuesday, February 7, 2017

Voltage Divider with Four Photoresistors and Servo Motor Connections


This past week I worked on writing code that would read in values from four different photoresistors and print them on the serial monitor of the Arduino. To do this, I made the circuit shown in figures 1 and 2. This circuit includes four photoresistors set up in a voltage divider and the output of each voltage divider is connected to Analog pins 0-3 on the Arduino.


Figure 1: Schematic of voltage divider circuit with four photoresistors and four 10K ohm resistors.
 
Figure 2: Voltage divider circuit with four photoresistors and four 10K ohm resistors.


The C code that reads the output values from each of the four photoresistors and prints the one that is exposed to the most light (Greatest output value) is included below:

 ___________________________________________________________________________________
 
void setup() {
  Serial.begin(9600);  //Begin serial communication
}

void loop() {

// reads the input on analog pins 0-3
  int sensorValue0 = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  int sensorValue3 = analogRead(A3);

// prints the headings of the columns
  Serial.println();
  Serial.print("Sensor 1");
  Serial.print("\t");   
  Serial.print("Sensor 2");
  Serial.print("\t");
  Serial.print("Sensor 3");
  Serial.print("\t");
  Serial.print("Sensor 4");
  Serial.print("\t");
  Serial.println("The Sensor with most light");

//prints the values from each of the four voltage dividers     
  Serial.print(sensorValue0);
  Serial.print("\t");
  Serial.print("\t"); 
  Serial.print(sensorValue1);
  Serial.print("\t");
  Serial.print("\t"); 
  Serial.print(sensorValue2);
  Serial.print("\t");
  Serial.print("\t"); 
  Serial.print(sensorValue3);
  Serial.print("\t");
  Serial.print("\t");

 
/*Finds the photoresistor that is exposed to the most amount
  of light which is the highest output value and prints the
  the number of the photoresistor
*/
  int greatestValue;
  if (sensorValue0 > sensorValue1)
    if (sensorValue0 > sensorValue2)
      if (sensorValue0 > sensorValue3)
        //Serial.print("Sensor 1");
        greatestValue = 1;
  if (sensorValue1 > sensorValue0)
    if (sensorValue1 > sensorValue2)
      if (sensorValue1 > sensorValue3)
        //Serial.print("Sensor 2");
        greatestValue = 2;  
  if (sensorValue2 > sensorValue0)
    if (sensorValue2 > sensorValue1)
      if (sensorValue2 > sensorValue3)
        //Serial.print("Sensor 3");
        greatestValue = 3; 
  if (sensorValue3 > sensorValue0)
    if (sensorValue3 > sensorValue1)
      if (sensorValue3 > sensorValue2)
        //Serial.print("Sensor 4");
        greatestValue = 4;
  Serial.print(greatestValue);  
  delay(1000);       
}

___________________________________________________________________________________

 
Example of the output on the Serial Monitor is shown in the Figure below.

 
Figure 3: Data that is displayed on the serial monitor of the Arduino IDE.
I am in the process of figuring out exactly what these numbers mean. The relationship between these output values and the amount of light is that the more the sensor is exposed to light, the greater the output value. This is opposite from the resistance because the more the sensor is exposed to light, the lower the resistance.


The servo motor came in this week and I started to play with the motor to see how it works. The following link was very helpful with understanding how to connect the servo motor to the Arduino and the figures below show the proper connections(Figures 4 and 5): https://www.arduino.cc/en/Tutorial/Sweep

The link includes example code that is also found in the Arduino Examples that rotates the motor 180 degrees in one direction and then 180 degrees in the other direction.


Figure 4 shows the proper connections between the Arduino and the servo motor.

Figure5 shows the schematic of the proper connections between the Arduino and the servo motor
 

When running this example code, I discovered that the servo motor only turns 180 degrees (90 degrees in each direction). This is a problem because if the tiny servo motor turns 180 degrees, this would only turn the Lazy Susan a few degrees. I will have to come up with a design that works like a gear system so that I am able to turn the Lazy Susan 180 degrees.

This coming week, I will figure out a design to turn the Lazy Susan more than just a few degrees. I will also modify the code so that when photoresistor 1 or 2 is receiving the most light, then the motor turns one direction and when photoresistor 3 or 4 is receiving the most light, the motor turns in the opposite direction.