Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Sensor PIR + display seven leds counter on: November 12, 2012, 03:04:22 pm
Hi people!  smiley-cool
I need some help. I'm doing the arduino. I wanna use a sensor pir, and when every time that the sensor is active (sensorPir==HIGH) a counter plus one(+1). But the problem that i have is that the counter never stop. thnks.


Code:
int pirPin = 10;


int i =0;

void setup() {              
 
  Serial.begin(9600);
  pinMode(pirPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pirPin, LOW);
 pinMode(2, OUTPUT);  
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
 
}
void print_9(){
 // write '9'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
}

void print_8(){
 // write '8'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
}

void print_7(){
 // write '7'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 1);
 digitalWrite(8, 1);
}

void print_6(){
 // write '6'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
}

void print_5(){
 // write '5'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
}

void print_4(){
 // write '4'
 digitalWrite(2, 1);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
}

void print_3(){
 // write '3'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 1);
 digitalWrite(7, 1);
 digitalWrite(8, 0);
}

void print_2(){
 // write '2'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 1);
 digitalWrite(8, 0);
}

void print_1(){
 // write '1'
 digitalWrite(2, 1);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 1);
 digitalWrite(8, 1);
}

void print_0(){
 // write '0'
 digitalWrite(2, 0);
 digitalWrite(3, 0);
 digitalWrite(4, 0);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
}

  
void loop(){

     if(digitalRead(pirPin) == HIGH){
      
         print_1();   //the led visualizes the sensors output pin state
      
     }
       else
       print_0();
  }


2  Using Arduino / Programming Questions / Re: POV programming and temperature. Please help on: November 08, 2012, 07:44:29 pm
Thank you very much lidr. Everything its working perfect, repeat, thank very very much. smiley-grin
3  Using Arduino / Programming Questions / POV programming and temperature. Please help on: November 08, 2012, 08:00:35 am
hi, im making a project with POV , what im trying to do is to show trough the LEDs (POV) what a NTC temperature sensor is reading.
The problem is how can i put an integer value(int) to a char. Thanks.
PD. Each program works perfectly independent.

Code:
// defining the alphabet
#include "alphabet.h"
 
// define the Arduino LED pins in use
const int LEDpins[] = {1,2,3,4,5,6,7};
 
// number of LEDs character height and width
int charHeight = sizeof(LEDpins); //sizeof its value from arduino code
int charWidth = 5;

//Temperature
const float voltage = 5.00;       
const float B = 4100;
const float unodivr = 93.0;
const float resistor = 105000;     //Resistor
int sensorPin = A0;                // select the input pin for the potentiometer
int sensorValue = 0;
 
void setup()
{
   pinMode(1, OUTPUT);
   pinMode(2, OUTPUT);
   pinMode(3, OUTPUT);
   pinMode(4, OUTPUT);
   pinMode(5, OUTPUT);
   pinMode(6, OUTPUT);
   pinMode(7, OUTPUT);   
   Serial.begin(9600);
}
 
 void loop()
 {
   // Part 1:  Read the analog port 0 and convert the value to volts. 
   sensorValue = analogRead(sensorPin);//read analog 0
   float v2 = (voltage*float(sensorValue))/1024.0f;    // calculate volts in an awesome world
   // Part 2: Calculate the resistance with the volt value trough the voltage divider ecuation
   float r1a = (voltage*float(resistor))/v2; 
   float r1 =r1a - resistor;
   //Part 3: Calculate the temperature based on the Steinhart-Hart equation based on the B value equation. 
   float K = B/log(r1*unodivr);//Temperature in Kelvin
   int C=K-273;//Temperature in Celsius
   Serial.println(C);

   //PRoblem   
 }
 
//Function for print the letters 
void printLetter(char ch)
{  // make sure the character is within the alphabet bounds (defined by the alphabet.h file)
   // if it's not, make it a blank character
   if (ch < 32 || ch > 126){ch = 32;}
   ch -= 32;// subtract the space character (converts the ASCII number to the font index number)
   // step through each byte of the character array
   for(int i=0; i<charWidth; i++){byte b = font[ch][i];
       // bit shift through the byte and output it to the pin
       for(int j=0; j<charHeight; j++){digitalWrite(LEDpins[j], !!(b & (1 << j)));}
          // space between columns
          delayMicroseconds(3000);
   }
   
    //clear the LEDs
    digitalWrite(1 , LOW);   // set the LED on
    digitalWrite(2 , LOW);   // set the LED on
    digitalWrite(3 , LOW);   // set the LED on
    digitalWrite(4 , LOW);   // set the LED on
    digitalWrite(5 , LOW);   // set the LED on
    digitalWrite(6 , LOW);   // set the LED on
    digitalWrite(7 , LOW);   // set the LED on
   
    // space between letters
    delayMicroseconds(100);
   
       // printing every letter of the textString
   for (int k=0; k<sizeof(textString); k++){printLetter(textString[k]);}
}
Pages: [1]