Recent Posts

Pages: 1 2 [3] 4 5 ... 10
21
Hi,

Could I have some assistance with array.
So I have looked up arrays, i believe I need to do something like this.

Would the array below's min and max give me what I need?



Code: [Select]


// Find maximum and minimum element in an array.

int main ()
{
  int i;/*loop counter*/
  int tempall[6] = { temp, temp2, temp3, temp4, temp5, temp6 };/*array of ints*/
/*set values for comparison starting from the beginning of the array*/
  int max = tempall[0];
  int min = tempall[0];

/*step through the array*/
  for (i = 0; i < 6; i++)
 {
/*if anything is greater than the value of max, which  started as the int pointed to with a[0]*/
  if (tempall[i] > max)
 {
/*set the value found as the new max*/
  max = tempall[i];
 }
/*if anything is less than the value of min, which started as the int pointed to by a[0]*/
  else if (tempall[i] < min)
 {
/*set the value found as the new min*/
  min = tempall[i];
 }
 }
}


if (min > 6500){
   digitalWrite(29,LOW);
   digitalWrite(30,LOW);
   digitalWrite(31,LOW);}



Source
Code: [Select]
// Find maximum and minimum element in an arary.
#include<stdio.h>/*printf*/
int main ()
{
  int i;/*loop counter*/
  int a[10] = { 10, 55, 9, 4, 234, 20, 30, 40, 22, 34 };/*array of ints*/
/*set values for comparison starting from the beginning of the array*/
  int max = a[0];
  int min = a[0];

/*step through the array*/
  for (i = 0; i < 10; i++)
 {
/*if anything is greater than the value of max, which  started as the int pointed to with a[0]*/
  if (a[i] > max)
 {
/*set the value found as the new max*/
  max = a[i];
 }
/*if anything is less than the value of min, which started as the int pointed to by a[0]*/
  else if (a[i] < min)
 {
/*set the value found as the new min*/
  min = a[i];
 }
 }
/*after that loop is executed, we should have the minimum and maximum values*/
  printf ("Maximum element in an array : %d\n", max);
  printf ("Minimum element in an array : %d\n", min);

  return 0;
}

 
22
Programming Questions / Re: Unreliable debouncing in i...
Last post by LRAT - Today at 01:55 am
Hi outsider,

The program works to a certain extend.
It shows me the amount of accumulated tips and then prints the line "Just wasting time..."
However, it's restricted to adding one count per each five seconds.
In reality the rain bucket can make multiple tips during this five second period but these are not taken in account.
Eg:
On the serial monitor I can see something like this:

0
 wasting time...
0
Just wasting time...
0
Just wasting time...
1
Just wasting time...
2
Just wasting time...

However I made like four tips between the count from 1 to 2 and it only shows 1 extra tip.
Is there any chance that the code can be modified so that it can read every tip possible?

The TBRG is a slow moving counter. At maximum speed it probably makes one tip per second. (That would be equal to 720mm of rainfall per hour!!!!(Each tip is equal to 0.2mm of precipitation)).
Therefore I was looking for a reed switch de-bounce time of about 100 milliseconds. I probably can even bring that up to 500 milliseconds without any risk of losing future tip events.

The "Just wasting time..." is just there to fill up for the yet to be developed code.
The objective is to read the temperature and humidity sensor every 5 seconds or so. although most likely I will poll these sensors only once a minute.
I will also add an RTC so that every event will be time stamped.

I can't express enough how much I appreciate your time and effort; Thank you very much for helping out a noob like myself.
Cheers,

Luc
23
I'm trying to set up a little automation project. I have a wood doctor, a wood-fired water heater. It has a temperature controlled blower. I would like to use the blower turning on to turn the circulating pump off for a time interval. I have everything sorted for turning the circulating pump off and on, but not the input from the blower. Any suggestions would be appreciated.
24
Project Guidance / Re: Program freezing
Last post by groundFungus - Today at 01:39 am
I had a similar problem when i first used Grbl.  There was a g code in the header (written by a G code generator program) that stopped Grbl (G91.1 I think).   Check the header and footer of the G code file for unsupported codes.
25
Project Guidance / hc-05 cannot send/receive data...
Last post by subair - Today at 01:36 am
yoh!

I have followed this http://howtomechatronics.com/tutorials/arduino/how-to-configure-pair-two-hc-05-bluetooth-module-master-slave-commands/

They are now connected/network, but it not able to send or receive data from slave/master... :(
help plssss.....
This particular Bluetooth module uses a 3.3v level for its data pins, and thus there is supposed to be a voltage divider to lower the 5v from the Arduino's TX pin to 3.3v, but since transmission from Arduino to phone works, I thought perhaps the Bluetooth module can possibly work with 5v inputs instead of its specified 3.3v, and thus did not include the voltage divider.(c)
master(arduino mega+hc-05)
slave(arduino nano+hc-05)
26
Doesn't look good.   Here's a dump of the "big" pieces of code ("avr-nm -SC -t decimal --size-sort *.elf")
Code: [Select]

00005822 00000100 T __vector_18
00001736 00000108 t Adafruit_SSD1306::fastSPIwrite(unsigned char) [clone .constprop.19]
00006074 00000116 T delay
00011970 00000122 T __floatunsisf
00006986 00000136 T Adafruit_GFX::drawFastHLine(int, int, int, unsigned int)
00007122 00000138 T Adafruit_GFX::drawFastVLine(int, int, int, unsigned int)
00002606 00000142 T HardwareSerial::write(unsigned char)
00001906 00000146 t Adafruit_SSD1306::ssd1306_command(unsigned char) [clone .constprop.17]
00005132 00000146 t Print::printNumber(unsigned long, unsigned char)
00006190 00000148 T __vector_16
00005922 00000152 T digitalWrite
00006826 00000160 T Adafruit_GFX::fillRect(int, int, int, int, unsigned int)
00001550 00000186 t TwoWire::endTransmission(unsigned char) [clone .constprop.24]
00006338 00000190 T Adafruit_GFX::drawRect(int, int, int, int, unsigned int)
00009744 00000200 t global constructors keyed to 65535_0_sketch_dec17a.ino.cpp.o.2416
00011468 00000204 T __addsf3x
00012374 00000210 T __mulsf3x
00011688 00000220 T __divsf3x
00006528 00000238 T Adafruit_GFX::drawLine(int, int, int, int, unsigned int)
00002052 00000260 t Adafruit_SSD1306::display() [clone .constprop.16]
00004298 00000316 T Adafruit_SSD1306::drawPixel(int, int, unsigned int)
00007358 00000340 T Adafruit_GFX::writeLine(int, int, int, int, unsigned int)
00004662 00000428 T Adafruit_GFX::write(unsigned char)
00005278 00000468 T Print::printFloat(double, unsigned char)
00009140 00000604 T __vector_24
00002910 00000692 T Adafruit_SSD1306::drawFastVLine(int, int, int, unsigned int)
00003602 00000696 T Adafruit_SSD1306::drawFastHLine(int, int, int, unsigned int)
00008072 00001068 T Adafruit_GFX::drawChar(int, int, unsigned char, unsigned int, unsigned int, unsigned char)
00000184 00001280 t font
00009944 00001396 T main


There are a bunch of functions in there that it's not obvious why they're present (line drawing?), but I expect they're buried pretty deeply and hard to remove.  I was hoping that there would be several "font"-like tables you could eliminate by being more conservative with what you called, but I only see the one, and it's only about 1k...

27
Project Guidance / Re: 64 yr old newby would like...
Last post by larryd - Today at 01:35 am
We sometimes use R or K or M

4.7ohm   >>>- - - >  4R7

220Ω      >>>- - - >  220R

2,200 ohm     >>>- - - >  2.2K

2,200,000 ohm >>>- - - > 2.2M

28
You can buy 6V DC adapters on Ebay, I don't know what your mains AC power is, either 110V or 220V. but go to Ebay.com and do a search for either 110V to 6V DC or 220V to 6V DC. You will need to know how many Amps your power supply will have to provide, how much current your servos are gonna need. If they are small servos a few Amps will be ok.

Regarding your questions about wiring the servos, have a look here.

Servo Wire

You def do not need a 24Volt power supply.

You can find almost everything on Ebay or Amazon or other sites, everything possible is out there.
And the more info you share with us, the better we can help you. In this case we might even be possible to only use one power supply.

Have a look around on Ebay
29
This compiles, but I don't have the hardware to test, try it and let me know, good luck.
Code: [Select]
/*TBRG is connected between ground and pin 2 on UNO
Whenever the TBRG makes a tip an interrupt will override the main program
*/

volatile uint32_t currentMillis;
volatile uint16_t TBRGCOUNT;
volatile bool timing = false;
const byte dbTime = 100;

const byte tbrgPin = 2;
//volatile byte state = LOW;
//volatile int val = 0;            //Current value of reed switch
//int old_val = 0;                //Old value of reed switch
//int TBRGCOUNT = 0;              //This is the variable that hold the count of switching

void dbISR ()
{
  if (timing)
    return;
  else
  {
    timing = true;
    currentMillis = millis();
    ++TBRGCOUNT;
  }
}

void setup() {
  Serial.begin(9600);
  pinMode(tbrgPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(tbrgPin), dbISR, FALLING);
}

void loop() {
  if (millis() - currentMillis > dbTime)
    timing = false;
  Serial.println(TBRGCOUNT);
  Serial.println("Just wasting time...");
  delay(5000);
}
30
Displays / Re: 7 segment bubble display p...
Last post by rosscopicotrain - Today at 01:28 am
I've made some progress. It updates the display once per second now, but it quickly flashes then goes dark for the rest of the second.
Heres the current code:
Code: [Select]
/*
* created by Rui Santos, http://randomnerdtutorials.com
* modified by: Raphango
* Still more changes by: rccursach 2014
* Temperature Sensor Displayed on 4 Digit 7 segment common CATHODE
* 2013
* A Small portion from SparkFun's SevSeg Libray https://github.com/sparkfun/SevSeg
* SparkFun, Nathan Seidle, 2012 (Beerware license). Based on http://arduino.cc/playground/Main/SevenSegmentLibrary Dean Reading, 2012.
*/

#include <Thermistor4.h>

const int digitPins[4] = {9,10,11,12}; //4 common CATHODE pins of the display.
const int clockPin = 2;    //74HC595 Pin 2
const int latchPin = 3;    //74HC595 Pin 3
const int dataPin = 4;     //74HC595 Pin 44
const int tempPin = 3;     //thermistor temperature sensor pin

long ti = 0;
long tf = 0;

//As seen on SparkFun's SevSeg Library
const byte digit[10] =      //seven segment digits
{
  0b11111100, // 0
  0b01100000, // 1
  0b11011010, // 2
  0b11110010, // 3
  0b01100110, // 4
  0b10110110, // 5
  0b10111110, // 6
  0b11100000, // 7
  0b11111110, // 8
  0b11110110  // 9
};

#define THERMISTORPin 3

double tempRead; 
long tempTimeNow = 0;
long tempTimeLast = 0;

//Define Variables we'll be connecting to
double Setpoint, Input, Output;
//Specify the links and initial tuning parameters
double Kp = 100, Ki = 0.15, Kd = 1;

// instance of Thermistor Object
Thermistor4 Thermistor;
//various temp variables for testing.
unsigned int i, ADCAverage;

/////////////////////// used for measuring Vcc
long sum;
double average;
///////////////////

int digitBuffer[4] = {0};
int digitScan = 0;
float tempC;

void setup(){       
  Serial.begin(9600);       
  for(int i=0;i<4;i++)
  {
    pinMode(digitPins[i],OUTPUT);
  }
  pinMode(tempPin, INPUT);
  pinMode(latchPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(dataPin, OUTPUT);
  Serial.begin(9600);

  float vccValue = readVcc(); //measureVcc();
 
  printDisp(vccValue, 1000);

  Thermistor.Pin = THERMISTORPin; //Set the pin number.

  Thermistor.SetUp(); //Sets up the analog read pin for internal AVR.

  //pow() is used elsewhere so might as well be used here.
  Thermistor.BitResolution = pow(2, 10) - 1; //ATmega's have a 10bit ADC (2^10-1).

  //Thermistor.VoltageSupply = average;   //4.885;   //4.4481;  // Metered supply across voltage divider
  Thermistor.VoltageSupply = vccValue;   //4.885;   //4.4481;  // Metered supply across voltage divider
 
  Thermistor.ResistanceFixed = 8250;   ///Fixed resistor in the divider. Measured in ohms. Meter this for accuracy.

  Thermistor.Offset = 0.0; //adjust temperature in Kelvin up or down a little to account for unforseen variations.

  // Steinhart-Hart coefficients. Taken from datasheet provided from manufacturer
  Thermistor.SteinhartA1 = 5.99357907117746e-004;   // First Steinhart-Hart coefficient.
  Thermistor.SteinhartA2 = 2.31247850239102e-004;   // Second Steinhart-Hart coefficient.
  Thermistor.SteinhartA3 = 5.61924102167737e-008;   // Third Steinhart-Hart coefficient.
  Thermistor.SteinhartA4 = 3.23406799250025e-011;   // Fourth Steinhart-Hart coefficient.

}


void loop(){
  Thermistor.ReadCalculate(3);
 
  Thermistor.ReadADC(analogRead (Thermistor.Pin));
  tempRead = Thermistor.GetFarenheit();
  tempTimeNow = millis();
 
  printDisp(tempRead, 1000);
  if(tempTimeNow - tempTimeLast > 1000){
    Serial.println("Gets to here");
    updateDisp();
    tempTimeLast = tempTimeNow;
  }

 
  Thermistor.VoltageSupply = readVcc();
 
}




void printDisp(float value, int msec) {
  //tf = millis();
  clearDisp();
  //int digitThree, digitTwo, digitOne, digitZero;
  digitBuffer[3] = int(value / 100); // return hundreds value
  digitBuffer[2] = int(((value - (digitBuffer[3] * 100))) / 10);  // return tens value
  digitBuffer[1] = int ((value - (digitBuffer[3] * 100) - (digitBuffer[2] * 10))); // return units value
  digitBuffer[0] = int ((value - (digitBuffer[3] * 100) - (digitBuffer[2] * 10) - (digitBuffer[1])) * 10);  // return first decimal place value

}

//writes the temperature on display
void updateDisp() {
  for (int i = 0; i < 4; i++) {
    clearDisp();
    digitalWrite(digitPins[i], LOW); //Changed to LOW for turning the leds on.

    if (i == 1) //Add decimal dot
      shiftOut(dataPin, clockPin, LSBFIRST, digit[digitBuffer[i]] | 0b00000001);
    else
      shiftOut(dataPin, clockPin, LSBFIRST, digit[digitBuffer[i]]);

    digitalWrite(latchPin, HIGH);
    digitalWrite(latchPin, LOW);

    delay(5); //If not delayed, digits are seen brurry, if the value is 8 you migth see the display frickering.
  }
}

void clearDisp() {
  for (byte j = 0; j < 4; j++) {
    digitalWrite(digitPins[j], HIGH); // Turns the display off. Changed to HIGH
  }
}


long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA, ADSC));
  result = ADCL;
  result |= ADCH << 8;
  result = 1125300L / result; // Back-calculate AVcc in mV
  return result;
}

Pages: 1 2 [3] 4 5 ... 10