Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Calculating Percentages yields 0% or 100%- never between on: September 01, 2014, 09:51:49 am
@BulldogLowell, your fix worked! Thank you!

@westfw, your code didn't exactly work.. it did change to nonzero, but the math was off. I think BulldogLowell's fix is the most accurate. I added in (int) to the whole thing to get a nice round number smiley
2  Using Arduino / Programming Questions / Calculating Percentages yields 0% or 100%- never between on: August 31, 2014, 09:47:27 pm
Hello! I'm trying to calculate the percentage of something in Arduino. More specifically, I have a fan that I'm reading the RPM from. I know it's maximum RPM, so I would like to be able to display both its RPM and its % speed (0%-100%). I have no problem reading the RPM, but for some reason, I can't get the % to calculate!

Is there something I'm missing? Full code below:

Code:

//Calculate RPM from fan tachometer:


int fanRPM= 0;
int maxfanRPM= 1380;
float fanRPM_percentage= 0;
unsigned long lastmillis= 0;
int half_revolutions= 0;


 //--------------------------------------------------------------------------------------
 
 void RPM_fan()  // this code will be executed every time the interrupt 0 (pin 2) gets low.
 {
  half_revolutions= half_revolutions + 1;
 }

//--------------------------------------------------------------------------------------

void setup()
{
 Serial.begin(9600);
 attachInterrupt(0, RPM_fan, FALLING);
 }
 
//--------------------------------------------------------------------------------------
 
 void loop()
 {
   if (millis() - lastmillis == 1000) //Update every second
   {
     detachInterrupt(0); //Disable interrupt when calculating
     fanRPM= half_revolutions * 30; //Convert frecuency to RPM, note: this works for one interruption per full rotation. For two interrups per full rotation use half_revolutions * 30.
     fanRPM_percentage= (fanRPM / maxfanRPM) * 100;
     Serial.print("Fan Speed: ");
     Serial.print(fanRPM);
     Serial.print(" (");
     Serial.print(fanRPM_percentage);
     Serial.println("%)");
     half_revolutions = 0;
     fanRPM= 0;
     fanRPM_percentage= 0;
     lastmillis = millis();
     attachInterrupt(0, RPM_fan, FALLING); //Enable interrupt
  }
 }
 

//--------------------------------END OF PROGRAM------------------------------------------



Thanks in advance!!
3  Using Arduino / Sensors / Re: Parallax RFID Read/Write Module 28440 on: May 31, 2013, 06:29:22 pm
I'm trying to get this to work with an Arduino Mega 2560. I'm also working with the Blue Fob tags sold by Parallax (https://www.parallax.com/StoreSearchResults/tabid/768/List/0/SortField/4/ProductID/503/Default.aspx?txtSearch=blue+fob) which work on the EM-4100 tech, which I suppose we are referring to as 'legacy'.

I cannot for the life of me get a read. In addition, the LED on the RFID reader is always GREEN, not red as I believe it should be, correct? According to Arduino's SoftwareSerial example, though: "Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69" (http://arduino.cc/en/Tutorial/SoftwareSerialExample so I use 10 typically for RX and anything else for TX, but that really shouldn't matter since I only want to read.

Can anyone give me any pointers?
4  Using Arduino / Sensors / Re: Parallax RFID Read/Write Module 28440 on: May 31, 2013, 06:18:43 pm
Thank you all for doing all of this work. I'm working on a Mega 2560 and cannot get this to work at all. I tried many examples, including the ones on this page. If it makes any difference, I'm using the "Blue Eye Key Fob Tag" from Parallax that uses the EM-4100 tech.

According to Arduino's SofwareSerial example, (http://arduino.cc/en/Tutorial/SoftwareSerialExample) "Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX:  10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69"

So I naturally just changed the RX pin to any one of the above. I only want to read tags, not write them, so I suppose TX doesn't really matter, but I hook it up anyway. Still nothing.


Can anyone give me any pointers for a Mega 2560?
5  Using Arduino / LEDs and Multiplexing / Re: General U8glib Question on: January 04, 2013, 09:09:24 pm
I actually can't post my entire code because it's too long!  smiley-sad-blue
6  Using Arduino / LEDs and Multiplexing / General U8glib Question on: January 04, 2013, 09:07:34 pm
Hello,

I'm trying to create a system with a bit of pizazz, making a sort of boot screen. My setup includes (among other things), an IR motion sensor (link) and a display being driven by the U8glib. The IR motion sensor requires a calibration time. Instead of the LCD being blank, I want to do a countdown. But this is unfortunately not in the loop() section, but in the setup() section. Any attempt to do

Code:
u8g.setFont(u8g_font_fur14);
u8g.drawStr( 10, 35, "HAMMOND");

in that section just gets ignored by the display. Any ideas on how to do this? I really appreciate your help, and here is my full code if you want to take a look:

[EDIT: code in next post because it's too long!]

(I know it's really long, that's because it includes a LOT of other things, but I tried to keep it as neat and labeled as I could!)
7  Using Arduino / Programming Questions / 8-button pinpad wiring/programming on: November 14, 2012, 10:29:12 am
Hello all,

I am the proud owner of an 8-button pin pad, as seen in the link below:

http://dx.com/p/8-push-buttons-keypad-module-blue-150367?item=10

In my code, I commented out all the other buttons other than 0 and 1 for my sanity for the time being. The first time I tried this I had the G pin wired to GND and K0-K7 wired to a digital pin on my Mega 2560. That was giving me random results all the time so I tried something someone in another thread suggested:

http://arduino.cc/forum/index.php/topic,42198.0.html

I had the same problem as him, so I figured it must work. I figure now that the G pin on the keypad must be connected to a voltage source, so I plugged it into 5V. Still constantly on. Back to GND. Still constantly on. I am at wits end. I'm hoping someone else will see something I'm not?

Here is my code:

Code:

//Define keypad pins:
  const int BUTTON0= 53; //input pin for button 0 on keypad
  //button 0: Chandelier
  int valBUT0=0;
 
  const int BUTTON1= 52; //input pin for button 1 on keypad
  //button 1: Desk Lamp
  int valBUT1=0;
  /*
  const int BUTTON2= 23; //input pin for button 2 on keypad
  //button 2: Speakers
  int valBUT2=0;
  const int BUTTON3= 24; //input pin for button 3 on keypad
  //button 3: SELECT
  int valBUT3=0;
  const int BUTTON4= 25; //input pin for button 4 on keypad
  //button 4: Blinds
  int valBUT4=0;
  const int BUTTON5= 26; //input pin for button 5 on keypad
  //button 5: Floor Lamp
  int valBUT5=0;
  const int BUTTON6= 27; //input pin for button 6 on keypad
  //button 6: Emery Lamp
  int valBUT6=0;
  const int BUTTON7= 28; //input pin for button 7 on keypad
  //button 7: MENU
  int valBUT7=0;
*/

//---------------------------------------------------------------------


void setup()
{
 
  //Setup for keypad:
    pinMode(BUTTON0, INPUT); //BUTTON0 is an input (on pin 53)
    digitalWrite(BUTTON0, HIGH); //connects internal pullup resistor //write HIGH to input pin
    pinMode(BUTTON1, INPUT); //BUTTON1 is an input (on pin 52)
    digitalWrite(BUTTON0, HIGH);
    /*
    pinMode(BUTTON2, INPUT); //BUTTON2 is an input (on pin 23)
    pinMode(BUTTON3, INPUT); //BUTTON3 is an input (on pin 24)
    pinMode(BUTTON4, INPUT); //BUTTON4 is an input (on pin 25)
    pinMode(BUTTON5, INPUT); //BUTTON5 is an input (on pin 26)
    pinMode(BUTTON6, INPUT); //BUTTON6 is an input (on pin 27)
    pinMode(BUTTON7, INPUT); //BUTTON7 is an input (on pin 28)
    */
   
  // open the serial port at 9600 bps:
    Serial.begin(9600);

 
}


//----------------------------------------------------------------------------


void loop()
{
   
    //Check for input from Keypad:
      valBUT0= digitalRead(BUTTON0); //read input from Button 0 and store it
      //Button0: Chandelier
      valBUT1= digitalRead(BUTTON1); //read input from Button 1 and store it
      //Button1: Desk Lamp
      /*
      valBUT2= digitalRead(BUTTON2); //read input from Button 2 and store it
      //Button2: Speaker
      valBUT3= digitalRead(BUTTON3); //read input from Button 3 and store it
      //Button3: SELECT
      valBUT4= digitalRead(BUTTON4); //read input from Button 4 and store it
      //Button4: Blinds
      valBUT5= digitalRead(BUTTON5); //read input from Button 5 and store it
      //Button5: Floor Lamp
      valBUT6= digitalRead(BUTTON6); //read input from Button 6 and store it
      //Button6: Emery Lamp
      valBUT7= digitalRead(BUTTON7); //read input from Button 7 and store it
      //Button7: MENU
      */
      //check whether in input is HIGH (button pressed):
     
      if(digitalRead(BUTTON0 == LOW))
      {
        //switch is closed
        Serial.println("Chandelier");
        Serial.println(" ");
        delay(300);
      }
      else
      {
        //switch is open
        //do nothing
      }
     
      if(digitalRead(BUTTON1==LOW))
      {
        //switch is closed
        Serial.println("Desk Lamp");
        Serial.println(" ");
        delay(300);
      }
      else
      {
        //switch is open
        //do nothing
      }
      /*
      if(valBUT2==HIGH)
      {
        Serial.println("Speaker");
        Serial.println(" ");
        delay(300);
      }
      else
      {
       //do nothing
      }
      if(valBUT3==HIGH)
      {
       Serial.println("SELECT");
       Serial.println(" ");
       delay(300);
      }
      else
      {
       //do nothing
      }
      if(valBUT4==HIGH)
      {
       Serial.println("Blinds");
       Serial.println(" ");
       delay(300);
      }
      else
      {
       //do nothing
      }
      if(valBUT5==HIGH)
      {
       Serial.println("Floor Lamp");
       Serial.println(" ");
       delay(300);
      }
      else
      {
       //do nothing
      }
      if(valBUT6==HIGH)
      {
       Serial.println("Emery Lamp");
       Serial.println(" ");
       delay(300);
      }
      else
      {
       //do nothing
      }
      if(valBUT7==HIGH)
      {
       Serial.println("MENU");
       Serial.println(" ");
       delay(300);
      }
 
 */
 
} //END OF PROGRAM



I am getting so much rando
8  Using Arduino / Motors, Mechanics, and Power / DC/Stepper Motor Driver on: November 07, 2012, 09:26:05 pm
Hello All,

I'm new to Arduino but not that new to electronics, electricity and coding, so I've started myself off on a bit of an ambitious project. I ordered the following product on DealExtreme:

http://dx.com/p/l9110-dc-stepper-motor-driver-controller-board-for-arduino-153951?item=20

I was under the impression that this was an H-bridge circuit that could allow me to control on/off and motor direction of a DC motor. My motor draws 12V, so I have an external voltage source but I cannot figure out the wiring for this module. I am assuming that VCC and GND are for the external power but have no clue as to what A-IB and A-IA could be!
9  Using Arduino / Programming Questions / Two Serial Devices Simultaneously (Arduino MEGA) on: November 06, 2012, 05:33:42 pm
Hello all,

I am embarking on a rather ambitious project with Arduino. I am new to Arduino but I have decent experience with C++ in programming classes I took in school.

Basically what I am trying to do is use both the TSOP1838 IR Infrared Receiver and the One Wire Digital Temperature (DS18B20) at the same time to make a DIY digital thermostat (Arduino will turn a relay on/off for a fan to regulate temperature) and IR to receive remote control for lights in the room from an Apple remote. I borrowed heavily from other demos available online. Both work great separately, but when combined, wonky things happen.

I believe that this is due to both codes I am using making the IR receiver and digital temperature as serial devices on 3600?

Here are my two codes:


IR Code:

Code:

#include <IRremote.h>

int RECV_PIN = 22;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
 
}

void loop()
{
  if (irrecv.decode(&results))
  {
    Serial.println(results.value);   //, HEX <- took this out, values were initially passed in HEX
   
        if(results.value==2011242612)
        {
        Serial.println("Center Button");
        }
        if(results.value==4294967295)
        {
          Serial.println("Down Button");
        }
   
    irrecv.resume(); // Receive the next value
  }
 
 
 
}



Temperature code:

Code:

#include <OneWire.h>

int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2

void setup()
{
 Serial.begin(9600);
}

void loop()
{
 float temperature = getTemp();
 /*
 Serial.print(temperature);
 Serial.print(" C");
 Serial.println(" ");
 */
 float temperatureF=0;
 temperatureF=(temperature*(9/5)+32);
 Serial.println(" ");
 Serial.print(temperatureF);
 Serial.print(" F");
 Serial.println(" ");
 
 delay(5000); //just here to slow down the output so it is easier to read
 
}


float getTemp(){
 //returns the temperature from one DS18S20 in DEG Celsius

 byte data[12];
 byte addr[8];

 if ( !ds.search(addr)) {
   //no more sensors on chain, reset search
   ds.reset_search();
   return -1000;
 }

 if ( OneWire::crc8( addr, 7) != addr[7]) {
   Serial.println("CRC is not valid!");
   return -1000;
 }

 if ( addr[0] != 0x10 && addr[0] != 0x28) {
   Serial.print("Device is not recognized");
   return -1000;
 }

 ds.reset();
 ds.select(addr);
 ds.write(0x44,1); // start conversion, with parasite power on at the end

 byte present = ds.reset();
 ds.select(addr); 
 ds.write(0xBE); // Read Scratchpad

 
 for (int i = 0; i < 9; i++) { // we need 9 bytes
  data[i] = ds.read();
 }
 
 ds.reset_search();
 
 byte MSB = data[1];
 byte LSB = data[0];

 float tempRead = ((MSB << 8) | LSB); //using two's compliment
 float TemperatureSum = tempRead / 16;
 
 return TemperatureSum;
 
}


I really appreciate all of your help. I intend to make my project available online with as much documentation as I could give, so I promise I will give back!



Paul
Pages: [1]