Friday, December 9, 2011

Circuit 14 - Soft Potentiometer

Purpose: To control the colour of an RGB led by using the touch sensor of a soft Potentiometer.

Equipment:

  • Arduino x 1
  • Breadboard x 1
  • Arduino Holder x 1
  • CIRC - 14 Breadboard Sheet
  • RGB LED x 1
  • Soft Potentiometer x 1
  • 330 Ohm Resistor x 3
  • Wire x 9

References:
In this circuit, a soft potentiometer is introduced. It is similar to the potentiometer in the past except this potentiometer senses touch and not torque. The soft potentiometer senses resistance between 100 to 10k ohms depending on where pressure is applied. In this circuit it will be used to change the colour of an RGB LED. 

The programming sector is quite easy as well. No new concepts are introduced so all this is previous knowledge. First all pins and set and declared. Then the value of the soft pot is read and used to calculate the values of each the red, green and blue pigments. The red, green and blue pigments are then constrained, meaning that any value above or below the range would be viewed as maximums of the range, no higher or lower. The green is constrained so that it is always between red and blue. After the constraining, the program writes (to the RGB LED) to display its colour using the calculated amounts of colour. 

Time to Complete: 10 mins to assemble
                                10 mins to code

Results: The first time I ran this program, only the red led could be seen and the colour of the RGB LED would only become dim red to bright red as pressure was applied to the potentiometer, barely any blue or green could be seen. Then analogWrite(RED_LED_PIN, redValue); was deleted from the program and the circuit was re-tested. This time the colours changed from blue - green as pressure was applied so the purpose of this exercise was complete. There was no need to put the red back in as it overpowered the other two led's. 

Photo:

Video: 


Tips:
  • Place RGB leads correctly, the correct side can be adjusted by looking at the flat side
  • Make sure to connect the lead from the potentiometer to ANALOG PIN 0 and not DIGITAL PIN 0.
  • Remove or Reduce the output light of the red LED as it may overpower the others. 

Further Work: I will try and use HSB colour codes rather than RGB colour codes in order to have a cleaner fade from red to violet when using the soft potentiometer. 

Program Modifications: 
This program is almost the same as the one in the link below:


Program:
// declares the pin each lead is connected to
const int RED_LED_PIN = 9;        
const int GREEN_LED_PIN = 10; 
const int BLUE_LED_PIN = 11;   

void setup() // no setup needed
{
}

void loop()
{

  int sensorValue = analogRead(0);   //reads the value of the soft potentiometer
  
  //calculates the red value using the sensor value (255-0 over the range 0-512)
  int redValue = constrain(map(sensorValue, 0, 512, 255, 0),0,255); 
  
  //calculates the green value (0-255 over 0-512 & 255-0 over 512-1023)
  int greenValue = constrain(map(sensorValue, 0, 512, 0, 255),0,255)-constrain(map(sensorValue, 512, 1023, 0, 255),0,255);  
  
  //calculates the blue value 0-255 over 512-1023
  int blueValue = constrain(map(sensorValue, 512, 1023, 0, 255),0,255); 

  //uses the calculated values to display a colour using the RGB
  analogWrite(RED_LED_PIN, redValue);
  analogWrite(GREEN_LED_PIN, greenValue);
  analogWrite(BLUE_LED_PIN, blueValue);

No comments:

Post a Comment