Recent Posts

Pages: 1 ... 7 8 [9] 10
will this work on your atTiny167?

Code: [Select]

const byte statusLedPin = 1;

void setup()



void loop()

void prettyFade(void)
  float val = (exp(sin(millis()/2000.0*PI)) - 0.36787944)*108.0;
  analogWrite(statusLedPin, val);
Audio / Reading A Frequency
Last post by sigilwig444 - Today at 03:15 am
Hi there! I've been working on this project for a little while now and can seem to get it to work... I can't determine if my problem is in my wiring or my code... I normally would give up at this point but it's a pretty important project... Anyhow, I'll add what I'm using for wiring and post my code here also, you guys can take a look and see if you can see any problems... Basically I'm trying to get a frequency just as some type of tuner would from a microphone... Whenever I try to run the code it reads in the serial monitor "0.00 hz"

Find Wiring Here:

Code: [Select]

boolean clipping = 0;

//data storage variables
byte newData = 0;
byte prevData = 0;

//freq variables
unsigned int timer = 0;//counts period of wave
unsigned int period;
int frequency;

void setup(){
  pinMode(13,OUTPUT);//led indicator pin
  cli();//diable interrupts
  //set up continuous sampling of analog pin 0
  //clear ADCSRA and ADCSRB registers
  ADCSRA = 0;
  ADCSRB = 0;
  ADMUX |= (1 << REFS0); //set reference voltage
  ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
  ADCSRA |= (1 << ADPS2) | (1 << ADPS0); //set ADC clock with 32 prescaler- 16mHz/32=500kHz
  ADCSRA |= (1 << ADATE); //enabble auto trigger
  ADCSRA |= (1 << ADIE); //enable interrupts when measurement complete
  ADCSRA |= (1 << ADEN); //enable ADC
  ADCSRA |= (1 << ADSC); //start ADC measurements
  sei();//enable interrupts

ISR(ADC_vect) {//when new ADC value ready

  prevData = newData;//store previous value
  newData = ADCH;//get value from A0
  if (prevData < 127 && newData >=127){//if increasing and crossing midpoint
    period = timer;//get period
    timer = 0;//reset timer
  if (newData == 0 || newData == 1023){//if clipping
    PORTB |= B00100000;//set pin 13 high- turn on clipping indicator led
    clipping = 1;//currently clipping
  timer++;//increment timer at rate of 38.5kHz

void loop(){
  if (clipping){//if currently clipping
    PORTB &= B11011111;//turn off clippng indicator led
    clipping = 0;

  frequency = 38462/period;//timer rate/period
  //print results
  Serial.println(" hz");
Glad it worked for you, Maria.
Programming Questions / RFID buffer keeping old UID a ...
Last post by Bkid - Today at 03:07 am
I'm new to this whole c++/arduino thing, so please bare with me! I'm trying to can RFID cards, which is working properly, however when trying to scan a new card after scanning a previous one, the old card's UID shows up a few more times before the new one starts appearing, and I'm not sure why.

I'm sure it's something simple that I'm overlooking, but I'm stumped. Thanks for any help! haha..

Code: [Select]
int readpin = 20;    //pin that is being read from
boolean gtisent = false; //if tag info has been sent or not
unsigned long timesent;
byte buffer[256];
byte uid[8];
byte olduid[8];
byte a = 0;
byte card;

void PrintHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes
       for (int i=0; i<length; i++) {
         if (data[i]<0x10) {Serial.print("0");}

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  pinMode(13, OUTPUT); //LED pin for testing
  pinMode(20, INPUT);
  Serial.println("Waiting for card...");

// the loop routine runs over and over again forever:
void loop() {
  if(digitalRead(readpin)==HIGH) {
    digitalWrite(13, LOW);
    digitalWrite(13, HIGH);

    if(!gtisent) {
      Serial1.write(0xBA ^ 0x02 ^ 0x31);
      gtisent = true;
      timesent = millis();
    } else {
      if(Serial1.available()>0) {
        buffer[a] =;
      if(buffer[0] != 0xBD)
        a = 0;
      if(a>2) {
        byte length = buffer[1];
        if(a >= length + 2)
          byte chk = 0x00; //checksum checking below
          for(int i=0;i < length+1; i++)
            chk ^= buffer[a];
          if(chk != buffer[length+1]) {
            gtisent = false; //checksum error
          } else {
            if(buffer[3] != 0x00) { //failed (0x00 is success)
              gtisent = false;
            } else {
              for(int i=0;i<8;i++) {
                uid[i] = buffer[11-i]; //copy the UID into the uid array
          if(memcmp_P(uid,olduid,8 == 0)) { //uid comparison thingy to try and prevent duplicates
           memset(buffer,0,sizeof(buffer));// many memsets here and below may not even be needed, I was just gettind desperate :/
        if(uid[0] == 0xE0 && uid[1] == 0x04) //check specific card UID beginning
          PrintHex8(uid,8); //print the UID
   } else {
       if(millis() - timesent >500) {         // if last command was sent more than 500ms ago, send a new one
         gtisent = false;
    else // if no tag in range
     card = 0;
     gtisent = false;
Project Guidance / Re: Help figuring out what com...
Last post by jembol747 - Today at 03:03 am
Im new to this forum. i want to upgrade my overhead tank system with arduino. i want to control a ultra sonic sensor, lcd module, 2 ac motors(15-20amps each), smoke alarm and water detecting sensor and receiving and sending messages to the board. what arduino module can be used and what components should i purchase.

if further if i  want to log the data to the device what other module or component is needed. like a memory card.

Project Guidance / Re: Drinks can dispenser??
Last post by dave-in-nj - Today at 02:57 am
at my work, we are basically honest and anyone would toss in the diffference to make up.

if I was to devise such a thing I would buy a couple of those soda slides that you put in the frighe and one soda at a time becomes availalbe.

add a simple lever with s stepper or solenoid or servo.

use a keypad, punch in yoru code, gain access.  count how many you owe.

alternatly, a coin slot.  available for use with an arduino.

alterntly, a wine fridge, you know half size.  with solenoid on the latch so you put in money or your code and gain access.

mechancis shoudl be pretty simple if you are mechancially inclined. 

there are lots of arduino soda machines on the net. you might find one that suits yours needs.

Sensors / Re: outside the box way of usi...
Last post by Fredric58 - Today at 02:56 am
the time is set to 5 seconds and 10 seconds so I don't have to wait a half hour........

Code: [Select]
const byte LDRPwrPin =  3;      //Timer declare pin 3 power to LDR
unsigned long previousMillis = 0;   //Timer
unsigned long interval;            //Timer
int LdrSignal = A0;    //LDR analog input A0 reads LDR
int PwrPIR = 2;        //LDR digital pin 2 Pwr PIR
int threshold = 812;   //LDR nominal threshold
int hyst = 50;         //LDR on when input above threshold + hyst, off when below threshold - hyst

void setup() {
  pinMode(PwrPIR, OUTPUT);   //LDR initializes pin 2 Pwr PIR
  pinMode(LDRPwrPin, OUTPUT);   //output power to LDR
  pinMode(LdrSignal, INPUT);   ///read LDR signal


void loop()

  unsigned long currentMillis = millis();          //get current value of millsecond counter
  if (currentMillis - previousMillis >= interval)  //if the time period has elapsed (method of comparison is rollover safe)
    byte currentState = digitalRead(LDRPwrPin);
    if (currentState)
      interval = 5000;
      interval = 10000;
    digitalWrite(LDRPwrPin, !currentState);         //change state of the LDR
    previousMillis = currentMillis;                //save the time of change

  int v;                           //LDR declare read value

  v = analogRead(LdrSignal);           //LDR read the value

  if (v > (threshold + hyst)) {   //LDR if it's higher than the on-threshold
    digitalWrite(PwrPIR, HIGH);     //LDR turn the output high

  else if (v < (threshold - hyst)) {   //LDR if it's lower than the off-threshold
    digitalWrite(PwrPIR, LOW);           //turn the output low

Thanks guys!

The text only OLED library worked a peach! Down to the right size now. I will try using the NeoGPS library too some time, I left it out just now because the examples were a bit confusing.
Project Guidance / Re: Full adder help with bread...
Last post by Whandall - Today at 02:53 am
The code does not care about any leds, it just exercises the adder.
(and it does that in a very fast way, it is only slowed down by the serial prints)

So define two more outputs,
 attach leds via resistors,
 shadow the read states of sum and carry to the corresponding leds
 and slow down the loop so you can see it step through the states.

Move the for into loop to run the test over and over.
"EncodermyEnc(5, 6);" in your supplied code

Maybe try separating into  Encoder myEnc(5,6);

If this is correct in your code, why supply code that is not being used?

In your diagram, please use D5 and D6 rather than pin 5 and 6, for clarity.

 As you have not told us, can we assume the encoder supply and ground are connected and the grounds are all connected?


Pages: 1 ... 7 8 [9] 10