Project#3: Coding Matrix and Pressure Sensor

Final version of the project

This week I completed my project using what I learn from the previous 2 weeks. I used the script from the first week to manage the matrix of led that I built in the last week. I also change a little the final idea of the project because I had available only a pressure sensor.

What i used

  • Forse sensitive resistor (pressure sensor)
  • 4x4 LEDs Matrix
  • Arduino

My Project

A led of matrix can blink because  takes as input energy from the line of the cathodes and the line of the anodes, for instance if i give energy in the cathodes 4 and the anodes 4 the last led in the matrix in the line 4 and column four will be switch on, if the energy goes in the 4 c(cathode) 3c and 4a(anodes) 3a all the 4,4 3,4 3,3 4,3 LEDs will schich on, and so on.

FIG9

I linked the cathodes wires in the 9,10,11,12 pin of arduino and in the 5,6,7,8 other pins i linked the anodes. Using the script that I made I can manage easily the LEDs matrix.

IMG_20160127_153637

Here a snippet of my code:

// anodes
int row[] = {5,6,7,8};
// cathodes
int col[] = {9,10,11,12};
// bit patterns for each row
byte data[] = {
 0,0,0,0};
// defines the size of the matrix 
int columns = 4;
int rows = 4;

//millisecond delay between displaying each row
int pause = 1;

void showPattern()
{
 for (int thisrow=0;thisrow<rows;thisrow++)
 {
 //turn everything off
 allOff();
 //turn on current row
 digitalWrite(row[thisrow], HIGH);
 // loop through columns of this row and light
 for (int thiscol=0;thiscol<columns;thiscol++)
 {
 if (bitRead(data[thisrow],columns-thiscol-1)==1)
 {
 digitalWrite(col[thiscol], LOW);
 }
 else
 {
 digitalWrite(col[thiscol], HIGH);
 }
 }
 delay(pause);
 }
}

 

Unfortunately I had available only a pressure sensor so this change a bit my final project. My goal was manage the led matrix according to the value of the pressure. Here the code that read the value of pressure:

void loop(){

 int sensorValue = analogRead(A0);
 // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
 voltage = sensorValue * (5.0 / 1023.0);
 
 // Print out the value you read:
 Serial.println(voltage);
 
 // define pattern
definePattern();
 
 delay(10);
}

If the pressure sensor perceives a high value the LEDs will be switch on all, If it perceives a less value only few LEDs will switch on and if there is no pressure the matrix will switch off.  

IMG_20160127_173203 IMG_20160127_173202

This is the snippet of the code that manages the matrix according to the value of the pressure:

void definePattern(){
if(voltage>=3){
 data[0] = B00001111;
 data[2] = B00001111;
 data[1] = B00001111;
 data[3] = B00001111;
 
 showPattern();
 }
 else if(voltage>=2){
 data[0] = B00001111;
 data[2] = B00001001;
 data[1] = B00001001;
 data[3] = B00001111;
 
 showPattern();
 } else if(voltage>=1){
 
 data[0] = B00000000;
 data[2] = B00000110;
 data[1] = B00000110;
 data[3] = B00000000;
 
 showPattern();
 } else if(voltage>0) {
 data[0] = B00000000;
 data[2] = B00000010;
 data[1] = B00000100;
 data[3] = B00000000;
 
 showPattern();
 }else if(voltage=0){
 
 allOff();
 
 }
 
}
void allOff()
{
 for (int i=0;i<4;i++)
 {
 digitalWrite(row[i], LOW);
 digitalWrite(col[i], HIGH);
 }
}

Conclusion

This gave me the opportunity to test different technologies that until now I had only heard about. In particular thanks to this project I was able to experience the Arduino technology, perhaps my main goal during this course. A special thanks to Romain and Joe our teacher for the support that they give to us.

IMG_20160127_172505

Publicités
Publié dans Uncategorized