How to make seed counter with arduino

I want to seed a number that counts the number of seeds. Also, the number of seeds counted, if the number entered by the kaypad was equal, then a relay would be illuminated.

Topic by hoosseina   |  last reply


Arduino Pish Button code Issue

Hey all, I am having a problem with my code and was hoping someone could help shed some light on how to fix it. Below is a code for an arduino push button counter. The concept is that there are 2 buttons, an "add" button and "subtract" button. Every time add is pressed it adds 1 to the count and vice versa when subtract is hit. The code works fine until we hit double digits. Once you subtract from 1 from 10 the LCD displays 90 not 9. Not sure how to fix this, any ideas?LiquidCrystal lcd(1, 2, 4, 5, 6, 7);int add=8;int sub=9; int valadd;int valsub;int count=000; int press;void setup() { lcd.begin(16,2); pinMode(add,INPUT); pinMode(sub,INPUT);}void loop() {valadd=digitalRead(add);valsub=digitalRead(sub);if(valadd==HIGH) {delay(100);press=count++;delay(250);}if(valsub==HIGH) {delay(100);press=count--;delay(250);}lcd.setCursor(0,0);lcd.print(press);}

Topic by Mpc1055   |  last reply


static int counter = 0; if ((++counter & 0x3f) == 0) Answered

I have not been ablle to find a laymans discription of what this is counting. Looks like it is counting 63 times from the 0x3f ASCII charactor. I bleave it is counting for the helper light, but what for? #include #include #include Password password = Password( "7457" ); //password to unlock door, can be changed const byte ROWS = 4; // Four rows const byte COLS = 3; // columns const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution // Define the Keymap char keys[ROWS][COLS] = { {'1','2','3',}, {'4','5','6',}, {'7','8','9',}, {'*','0','#',}, }; byte rowPins[ROWS] = { 5, 4, 3, 2 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins. byte colPins[COLS] = { 8, 7, 6,};// Connect keypad COL0, COL1 and COL2 to these Arduino pins. Stepper myStepper(stepsPerRevolution, 9,10,11,12); int enable_pin = 13; int button_pin = A0; int button_pinstate = 0; // variable to store current pir state //int lastpirstate = 0; // variable to store last pir state int lastbutton_pinstate = 0; int pos = 35; int pos2 = -35;  // Create the Keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); unsigned long offtime; boolean helper_light_is_on = false; // helper light off void setup(){ myStepper.setSpeed(60); // set the speed at 60 rpm: pinMode( button_pin, INPUT); digitalWrite(button_pin, HIGH); // pull-up Serial.begin(9600); Serial.write(254); Serial.write(0x01); delay(200); pinMode(15, OUTPUT); //Helper light pinMode(16, OUTPUT); //green light pinMode(17, OUTPUT); //red light pinMode(enable_pin, OUTPUT); digitalWrite(enable_pin,HIGH); keypad.addEventListener(keypadEvent); //add an event listener for this keypad } void loop() { button_pinstate = digitalRead(button_pin); if(button_pinstate != lastbutton_pinstate) { Serial.println(" Button Press"); if(button_pinstate == LOW)// { delay(10); digitalWrite(enable_pin,HIGH); myStepper.step(pos); Serial.print(" Open "); delay(2000); myStepper.step(pos2); Serial.print(" Close "); digitalWrite(enable_pin,LOW); delay(10); } static int counter = 0; if ((++counter & 0x3f) == 0) Serial.println(); delay(100); keypad.getKey(); myStepper.step(0); process_helper_light(); } void keypadEvent(KeypadEvent eKey) { switch (keypad.getState()) { case PRESSED: // a key is pressed so light the helper light helper_light_is_on = true; digitalWrite(15,HIGH); offtime = millis() + 5000; // set the offtime for 30 seconds in the future Serial.print(" enter: "); Serial.println(eKey); delay(10); Serial.write(254); switch (eKey) { case '*': checkPassword(); delay(1); break; case '#': password.reset(); delay(1); break; default: password.append(eKey); delay(1); } } } void checkPassword() { if (password.evaluate()) //if password is right unlock door { Serial.println(" Accepted"); Serial.write(254); delay(10); digitalWrite(enable_pin,HIGH); myStepper.step(pos); Serial.print(" open "); digitalWrite(16, HIGH);//turn on green led delay(2000); //wait 5 seconds digitalWrite(16, LOW);// turn offgreen led myStepper.step(pos2); digitalWrite(enable_pin,LOW); Serial.print(" Close "); } else { Serial.println(" Denied"); //if passwords wrong keep door locked Serial.write(254); delay(10); myStepper.step(0); Serial.println(" locked "); digitalWrite(17, HIGH); //turn on red led delay(2000); //wait 5 seconds digitalWrite(17, LOW);//turn off red led } }  void process_helper_light(void) { if (helper_light_is_on) { if (millis() >= offtime) { digitalWrite(15,LOW); //turn off the helper light helper_light_is_on = false; } } }

Question by WWC   |  last reply


Arduino hit counter - need ideas ? Answered

Good evening everyone  I need ideas about how to count number of hit using Arduino  for example an Arduino safely installed on kickboxing bag, and I need to count every time the kick-boxer hit the bag :)  please need ideas, its for senior project :)

Question by WardaA3   |  last reply


pwm arduino

I have a couple questions about driving motors from the arduino (I have a boarduino) - First off, these motors are from various walkmans and I think each one is rated for 1.7 volts. - If I need a transistor, can i use a 2n3904 (since these arn't giant motors) - How do I protect against the emf? The motors need to work going either way (clockwise or counter clockwise) - How would you program it so that the motor can go either forward or backwards?

Topic by guyfrom7up   |  last reply


BB Gun, shot counter? Answered

I am planning on using an Arduino nano (clone or similar) but am struggling to figure out how I can use a proximity sensor or other method to count shots fired... Am not sure if I could use IR, as don't know if it will detect a break at the velocity the BB's will be getting fired at.. When I get something put together am planning on mounting a nokia 5110/3210 in the butt so is visible, maybe a laser range finder etc.. Any ideas would be much appreciated

Question by sparks_vfr   |  last reply


Where to buy tobacco seeds

Hi everyone hates the rising prices of our luxurys so i have done some research and found out that growing your own tobacco IS NOT ILEGAL my question is can you buy tobacco seeds over the counter anywhere in the south west ??? someone please help me lol Cheers Darren

Topic by dazzer730   |  last reply


Is there a way to count button pushes on an arduino and have the led blink after pressed the button 4 time?

I would like to make if the button pressed 4 time.. led will start blinking for 5 second and if button pressed 8 time.. led will start blinking for 10 second... Can anyone help me with an example code or a tutorial somewhere? Greatly Appreciated!

Question by AzamJ   |  last reply


Looking for help with a simple enough idea?

I say simple enough, but obviously not simple enough for me.  But for someone out there this is probably something you could do in your sleep.... Looking for a setup that has two buttons. When button 1 is pushed, button 2 must then be pushed to register a count of "1" on a display.  And then button 1 and 2 must be pushed again (in that order) to register a count of "2" - and so on.... It would be nice then if a target figure could be set to trigger an action when the target number is reached. The application is for exercise - for example burpees. Button 1 is on the ground and button 2 is above the head. Triggering both buttons gives a count of 1. And when a target such as 30 is reached an alarm or light can be activated to show completion of exercise. It is important that two pushes of either button in a row doesn't give a count of "1" - a count is only valid if the buttons are pushed in sequence. I'm guessing an Arduino board of some sort would be required, but its all new to me and I'm guessing its a simple enough programme if you have the know how. But I don't even know what board to purchase to get started. And while I'm purchasing the board I may as well know what else I'll need for the entire project and order all that at the  same time. So can anyone help?

Question by ajamesr   |  last reply


Newby needs some help with arduino code for kids party

OK, I'm kinda new at the programming part for my projects. I was wondering if anyone can help me with (what I assume will be a simple code for a veteran) a code for arduino and maybe with a little explanation of the code. Project is simple. I have a toy laser gun shooting at a target with a photocell attached and connected to a relay. What I would like is that every time the relay switches, a counter adds the shot so I can keep score. It's for my son's 9th birthday party and I've already built the targeting range (with  Lego Movie theme) and even some servos to knock back guys down.  I just need a way to keep score.  I have some Arduino Uno's, some nanos, some trinkets, some LCDs (2X16 and 4X8) and 4X 7segment displays so I have some options for parts,but at the moment I do not have a lot of time to go through a self-learning curve to get the coding to work.  Can anyone please help?  It would be greatly appreciated. Thanks. .  

Topic by jedii72   |  last reply


Arduino BUTTON_PIN?

I am having trouble with the BUTTON_PIN to work the servo. If i use the BUTTON_PIN sketch as a stand alone it will operate the servo. When i try to incorporate the button sketch into the keypad sketch i can not get the servo to operate. The button is supposed to bypass the keypad and operate the servo. How could i get this to operate correctly? I will post the library files if needed.   Thanks W #include #include #include //tells to use servo library Servo myservo; //declares servo Password password = Password( "4444" ); //password to unlock door, can be changed const byte ROWS = 4; // Four rows const byte COLS = 3; // columns // Define the Keymap char keys[ROWS][COLS] = { {'1','2','3',}, {'4','5','6',}, {'7','8','9',}, {'*','0','#',}, }; byte rowPins[ROWS] = { 5, 4, 3, 2 };// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins. byte colPins[COLS] = { 8, 7, 6,};// Connect keypad COL0, COL1 and COL2 to these Arduino pins. // Create the Keypad Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS ); unsigned long offtime; boolean  helper_light_is_on = false; // helper light off #define BUTTON_PIN        A0  // Button #define DELAY            20  // Delay per loop in ms boolean handle_button() {   int button_pressed = !digitalRead(BUTTON_PIN); // pin low -> pressed   return button_pressed; } void setup() {   pinMode(BUTTON_PIN, INPUT);   digitalWrite(BUTTON_PIN, HIGH); // pull-up   Serial.begin(9600);   Serial.print(254, BYTE);   Serial.print(0x01, BYTE);   delay(200);   pinMode(10, OUTPUT);  //Helper light   pinMode(11, OUTPUT);  //green light   pinMode(12, OUTPUT);  //red light   myservo.attach(9); //servo on digital pin 9 //servo   keypad.addEventListener(keypadEvent); //add an event listener for this keypad } void loop() {   // handle button   boolean button_pressed = handle_button();   // do other things   Serial.print(button_pressed ? "^" : ".");   // add newline sometimes   static int counter = 0;   if ((++counter & 0x3f) == 0)     Serial.println();   delay(DELAY);   keypad.getKey();   myservo.write(0);   process_helper_light(); } //take care of some special events void keypadEvent(KeypadEvent eKey) {   switch (keypad.getState())   {     case PRESSED:       // a key is pressed so light the helper light       helper_light_is_on = true;       digitalWrite(10,HIGH);       offtime = millis() + 5000;  // set the offtime for 30 seconds in the future             Serial.print(" enter: ");       Serial.println(eKey);       delay(DELAY);       Serial.print(254, BYTE);       switch (eKey)       {         case '*':           checkPassword();           delay(1);           break;         case '#':           password.reset();           delay(1);           break;         default:           password.append(eKey);           delay(1);            }   } } void checkPassword() {   if (password.evaluate())  //if password is right unlock door   {      Serial.println(" Accepted");     Serial.print(254, BYTE);     delay(DELAY);     //Add code to run if it works     myservo.write(90); //160deg     digitalWrite(11, HIGH);//turn on     delay(2000); //wait 5 seconds     digitalWrite(11, LOW);// turn off   }   else   {     Serial.println(" Denied"); //if passwords wrong keep door locked     Serial.print(254, BYTE);     delay(DELAY);     //add code to run if it did not work     myservo.write(0);     digitalWrite(12, HIGH); //turn on     delay(2000); //wait 5 seconds     digitalWrite(12, LOW);//turn off   }    if (handle_button == LOW)   {     myservo.write(90); //160deg     delay(DELAY); //wait 5 seconds      }   else   {     myservo.write(0);     delay(DELAY); //wait 5 seconds    } } // this routine turns off the light when the timer expires void process_helper_light(void) {   if (helper_light_is_on)   {     if (millis() >= offtime)     {       digitalWrite(10,LOW);  //turn off the helper light       helper_light_is_on = false;     }   } }

Question by WWC   |  last reply


ARDUINO OSCILLOSCOPE?

Hey there, I have been working on a recent project to build an Arduino Oscilloscope interfaced with a 4X4 keypad membrane with Nokia 5110 LCD display.I have successful individual code fragments/portions which 1)Generate waves interfaced with the keyboard  2)Display the same on the Nokia LCD 5110 i am using the Arduino Due and the 1st part of my code generates waves on DAC1 with the code as follows:- #include "Waveforms.h" #include #include //Set the desired duty cycle in percentage double dc,t,a,d; long d_milli,d_micro,a_milli,a_micro,m,n; int stage =0; int sample_delay1; LiquidCrystal lcd(A2, A3, A4, A5, A6, A7); float sample_delay; String num1,num2; int wave1; String wave_name; double duty_cycle,k; const byte ROWS = 4; //four rows const byte COLS = 4; //four columns //define the cymbols on the buttons of the keypads char hexaKeys[ROWS][COLS] = {   {'1','2','3','A'},   {'4','5','6','B'},   {'7','8','9','C'},   {'.','0','#','D'} }; byte rowPins[ROWS] = {23,25,27,29}; //connect to the row pinouts of the keypad byte colPins[COLS] = {31,33,35,37}; //connect to the column pinouts of the keypad int i = 0; int sample; //initialize an instance of class NewKeypad Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); boolean in_setup = true; void setup() {   Serial.begin(9600);   analogWriteResolution(12);  // set the analog output resolution to 12 bit (4096 levels)   analogReadResolution(12);   lcd.begin(20,4);   char key = customKeypad.getKey();   lcd.setCursor(0, 0);   lcd.print("choose wave: ");   lcd.setCursor(0, 1);   lcd.print("A=Sine");   lcd.setCursor(8, 1);   lcd.print("B=Triangular");   lcd.setCursor(0, 2);   lcd.print("C=Sawtooth");   lcd.setCursor(11, 2);   lcd.print("D=Square");   while( true)   {         char key = customKeypad.getKey();         if(stage == 0)         {               Serial.println("in stage 0");               if(key == 'A' )               {                 wave1 = 0;                 lcd.clear();                 lcd.setCursor(0,0);                 lcd.print(" Sine?      ");                 wave_name ="Sinusoidal";                 Serial.println(wave_name);               }               else if(key == 'B')               {                 wave1 = 1;                 lcd.clear();                 lcd.setCursor(0,0);                 lcd.print("Triangular?");                 wave_name ="Triangular";                 Serial.println(wave_name);               }               else if(key == 'C')               {                 wave1 = 2;                 lcd.clear();                 lcd.setCursor(0,0);                 lcd.print("Sawtooth?  ");                 wave_name ="Sawtooth";                 Serial.println(wave_name);               }               else if(key == 'D')               {                 wave1 = 3;                 lcd.clear();                 lcd.setCursor(0,0);                 lcd.print("Square?    ");                 wave_name ="Square";                 Serial.println(wave_name);                               }               else if(key == '#')               {                 stage++;                 //lcd.clear();                 lcd.setCursor(0,1);                 lcd.print("Frequency=");                 Serial.println("Frequency=");               }         }        else if(stage == 1)         {               if(key != NO_KEY &&(key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9'||key=='0'))               {                 num1 = num1 + key;                 //int numLength = num1.length();                 //to adjust one whitespace for operator                 lcd.setCursor(10,1);                 lcd.print(num1);               }                             else if(key == '#')               {                     k = num1.toInt();                     Serial.print(k);                                                                                        int sample_delay_int = 1000000/(k*120);                           float sample_delay_float = 1000000/(k*120);                           float difference= sample_delay_float-sample_delay_int;                           sample_delay1 = sample_delay_int - 6;                           if(difference > 0.5)                           {                             sample_delay1++;                           }                                                                               Serial.println(sample_delay1);                           lcd.clear();                           lcd.print(wave_name);                           lcd.setCursor(0,1);                           lcd.print("Frequency=");                           lcd.print(num1);                           lcd.print(" Hz");                                         break;                                       }                   }                                                 }       } void loop()   {   analogWrite(DAC1, waveformsTable[wave1][i] );    i++;   if(i == maxSamplesNum)  // Reset the counter to repeat the wave     i = 0;   else delayMicroseconds(sample_delay1);                   } Next, I input these waves from DAC1 into analog input A0 to display on the LCD with code as below:- #include #include #include #define DISPLAY_WIDTH 84 #define DISPLAY_HEIGHT 48 #define ARDUINO_PRECISION 1023.0 Adafruit_PCD8544 display = Adafruit_PCD8544(8,9,10,12,11); //Analog Pins int channelAI = A0;      // probe #define DELAY_POTENTIMETER //disabled it I don't have it connected #ifdef DELAY_POTENTIMETER int delayAI = A1;       // delay potentiometer #endif float delayVariable = 0; float scale = 0; int xCounter = 0; int yPosition = 0; int readings[DISPLAY_WIDTH+1]; int counter = 0; unsigned long drawtime = 0; unsigned long lastdraw = 0; int frames = 0; void setup(void) {   display.begin();   display.setContrast(30);// you might have a slightly different display so it might not be the optimal value for you   display.clearDisplay(); } void loop() {    #ifdef DELAY_POTENTIMETER   delayVariable = analogRead(delayAI);   delayVariable = (delayVariable/100);   #endif   scale = (float)(DISPLAY_HEIGHT-1)/ARDUINO_PRECISION;     //record readings   for(xCounter = 0; xCounter <= DISPLAY_WIDTH; xCounter++)   {                                     yPosition = analogRead(channelAI);     readings[xCounter] = (yPosition*scale);     #ifdef DELAY_POTENTIMETER     delay (delayVariable);     #endif   }     display.clearDisplay();   //Draw Voltage Ref Lines   display.drawLine( 10, 0, 10, DISPLAY_HEIGHT-1, BLACK);   display.drawLine( 5, (DISPLAY_HEIGHT-1)-(.2 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.2 *ARDUINO_PRECISION * scale), BLACK);   display.drawLine( 0, (DISPLAY_HEIGHT-1)-(.4 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.4 *ARDUINO_PRECISION * scale), BLACK);   display.drawLine( 5, (DISPLAY_HEIGHT-1)-(.6 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.6 *ARDUINO_PRECISION * scale), BLACK);   display.drawLine( 0, (DISPLAY_HEIGHT-1)-(.8 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.8 *ARDUINO_PRECISION * scale), BLACK);   //display.drawLine( 5, (DISPLAY_HEIGHT-1)-(.84 *ARDUINO_PRECISION * scale), 10, (DISPLAY_HEIGHT-1)-(.84 *ARDUINO_PRECISION * scale), BLACK);     //Draw Voltage Ref Numbers   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.2 *ARDUINO_PRECISION * scale))-3);   display.print((int)(5.0*0.2));   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.4 *ARDUINO_PRECISION * scale))-3);   display.print((int)(5.0*0.4));   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.6 *ARDUINO_PRECISION * scale))-3);   display.print((int)(5.0*0.6));   display.setCursor(0,((DISPLAY_HEIGHT-1)-(.8 *ARDUINO_PRECISION * scale))-3);   display.print((int)(5.0*0.8));     for(xCounter = 0; xCounter <= DISPLAY_WIDTH; xCounter++)   {     display.drawPixel(xCounter, (DISPLAY_HEIGHT-1)-readings[xCounter], BLACK);     if(xCounter>1){       display.drawLine(xCounter-1, (DISPLAY_HEIGHT-1)-readings[xCounter-1], xCounter, (DISPLAY_HEIGHT-1)-readings[xCounter], BLACK);     }   }   //Draw FPS   display.setCursor((DISPLAY_WIDTH-1)-11,0);   display.print(frames);     //Draw Voltage   display.setCursor(((DISPLAY_WIDTH-1)/2),0);   display.print(analogRead(channelAI)/ARDUINO_PRECISION*5.0);     display.display();     //Calculate FPS   drawtime = micros();   frames=1000000/*a second*//(drawtime-lastdraw);   lastdraw = drawtime; } Now the problem arises when i try doing the 2 things on d same arduino due board. I got perfect results when i used arduino due and arduino uno simultaneously but have not been able to generate waves on the LCD using the same board. Is it possible to do the same. Can some1 help me incorporate the 2 programs into 1..Thanxx

Question by ranjana_1   |  last reply


How can i make an up/down counter with arduino?

I would like some help making a 2 digit up/down counter with arduino that resets to a preset-able number and how to connect it to a 2 digit 7-segment display, all responses are appreciated.

Question by BBru62   |  last reply



Arduino LDR tachometer (RPM counter)- not sensitive enough ?!?

Ladies & Gentlemans  ... I would like to ask you, what I'm doing wrong, in this RPM counter ??? As mentioned in my previous questions, I 've got an ARDUINO and I started with my first part - of my project. To count RPM / or speed. I'm using a LDR (light dependant resistor) and green laser as light source. The scheme is like this: + 5V ------- LDR -------------Analog pin 1                                     \                                       \--------resistor (220kOhm) --------- GND The code for this project looks like this : int LDR=1; // LDR is on analog port 1 int val=0; // this is the value, I get from the LRD void sextup(){  Serial.begin(9600); } void loop() {  val = analogRead(LDR); // read the value getting from LDR Serial.println(val); if (val<1018) {delay(4000);} } To explain the value 1018 in the IF condition ... when pointed the laser on the LDR,I get value from 1019-1020. So my idea was, when the value decrease just by one or more ... let me know, that the laser beam has been interrupt. But I realised, that I can cross the laser beam very quickly, and the LDR/Arduino will not notice it. I really don't know, where I'm going wrong. My few suggestions are : 1. wrong method - to use LDR ... should I use something else ??? 2. wrong RESISTOR value ??? ... should I change to different value to make it more sensitive ??? (I tried 2 different values = 220kOhm, 46kOhm ... that's what my voltmeter said :) ... but with both of them I have the same result ) 3. should I use different code ??? Any ideas ??? Thank you in advance for your answers. Zholy

Question by zholy   |  last reply


Help making laser trip wire with LED counter

I have seen a few different laser trip wire instructables here, but they are usually for triggering a nerf device or other projectiles. I am interested in a laser trip wire that would count objects as the laser beam was broken, and display the count on an LED screen. I was wondering if someone would be kind enough to create an instructable for this. This has real world applications, such as counting cases moving along a conveyor line. I would like to use an arduino with a shield for this, and be able to plug it into an outlet. I am a complete Noob when it comes to arduinos. This is a project that I would like to get my feet wet with. I learn best by working on something that interest me. I know it isn't as much fun as a nerf Gatling gun, but it would get plenty of use every day.

Topic by babycody   |  last reply


Touch Sensitive counter project question

Hi everyone, Great to be part of this community. I am trying to make a touch sensitive counter, the sensor has to be as flat as possible, something like a thick cardboard, or I can put a flat sensor in between two sheets. It needs to handle about 10-20lbs of weight. It will go under fabric like carpet, so it cannot be super sensitive, clickable is fine. It will be connected to a very simple 1 or 2 digit counter. Any suggestions? PS: Eventually I'd like to upgrade this with a system that can instruct something else, for example 5 counters, display etc. Or be able to use bluetooth or wifi or arduino, and be able to count back. For example input 10 and it will count 1/10, 2/10, 3/10, etc..

Topic by tees_deney   |  last reply


Arduino coloured ball counter PLEASE HELP FOR SCHOOL PROJECT!!

I have a school project where i have to make a colour sorter with a arduino i got it far enough that it sorts it phisically but I also have to sort is digitally This is how it's supposed to work:1) the laptop where the arduino is connected to has to show "press button to start colour sorter" 2) you put in the balls and it sorts it 3) then the laptop shows "press button to stop sorting"4) you press the button again the machine stops and shows-total amount of balls -the amount of red balls,blue balls and white balls (only colours I need to sort)-and show "press button to restart again"this is what it's supposed to look likehttps://www.youtube.com/watch?v=g3i51hdfLaw

Question by lukekat 


sketch for arduino obstacle robot using seed motor shield v2.0?

Hi everybody, im barely started writing sletch so i need help, i build a obstacle robot and i used  arduino uno r3 seeed motor shield v2.0 one servo tamiya twin motor gear box hc-sr04 sensor  so i dont really know how to start writind the sketch.....

Question by salvador.lopez1   |  last reply


Can I reverse servo direction in Arduino?

On my robot, both servos move clockwise. Is there any way in the  Arduino Environment to reverse the direction of one, to make it move counter-clockwise? 

Question by DELETED_afw11   |  last reply


Slot Car Lap Counter using Hall Effect Sensor & Arduino

Hi guys, For a university project I am using a hall effect sensor to count laps of a slot car. I am hoping to count the laps and output the number to a 7 segment LED display. However I am very new to coding and arduinos themselves. I was wondering if anyone had any similar projects or knows of any code I could use or any ideas people may have for a potential solution. Any response would be greatly appreciated. Thanks.

Topic by TomR77   |  last reply


Two arduino nano with oled check please help

Hi friends, I connected 2 arduino with i2c data, I'm doing the classic Led flashing, my question is, the master card in the project, counting from 1 to 100 counters, and initially the green LED is lit, when the counter is 80 yellow Led lights up green and 95 when yellow turns off and turns red, the system turns off. And this whole process is being copied to the sd card, the energy is cut off and the counter continues to be nosed when it is given again. Due to lack of memory the need for the second card was born. Now the Master is also on the slave card connected to the slave when it comes to burning operations (when the green LED is lit, the "system is running" while the yellow LED is running "maintenance approached" as the "service time", etc.) did the research but did not get a result. please help

Question by ErolT3 


Arduino with flow sensor and relay

Hello. I'm needing help on a project with a water flow sensor. Basically, I'm trying to activate a relay (to turn on a motor) when the Arduino board senses any water flow present for 15 seconds or more. I was expecting the relay to turn on after the flow sensor picked up water flow for 15 seconds. After I ran the code, I had water flowing through the flow sensor for 5 seconds and then I shut off the water. The relay still turned on 10 seconds later. I didn't want this to happen. Instead, I would like to have the relay turn on only after there is water flow for at least 15 seconds. Please review my code below. I would appreciate any help. Thank you!!!byte sensorInterrupt = 0; byte statusLed = 13;byte sensorPin = 2;const int threshold = 15000; // thresholdfloat calibrationFactor = 4.5;volatile byte pulseCount; float flowRate;unsigned int flowMilliLitres;unsigned long totalMilliLitres;unsigned long oldTime;unsigned int countstart = 0;unsigned long starttime;unsigned long endtime;unsigned long elapsedtime;void setup(){ Serial.begin(9600); pinMode(statusLed, OUTPUT); digitalWrite(statusLed, HIGH); // We have an active-low LED attached pinMode(sensorPin, INPUT); digitalWrite(sensorPin, HIGH); pinMode(7, OUTPUT);// connected to relay pulseCount = 0; flowRate = 0.0; flowMilliLitres = 0; totalMilliLitres = 0; oldTime = 0; attachInterrupt(sensorInterrupt, pulseCounter, FALLING);}void loop(){ while (1){ if((millis() - oldTime) > 1000) // Only process counters once per second { detachInterrupt(sensorInterrupt); flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor; oldTime = millis(); flowMilliLitres = (flowRate / 60) * 1000; totalMilliLitres += flowMilliLitres; unsigned int frac; Serial.print("Flow rate: "); Serial.print(int(flowRate)); // Print the integer part of the variable Serial.print("L/min"); Serial.print("\t"); // Print tab space Serial.print("Output Liquid Quantity: "); Serial.print(totalMilliLitres); Serial.println("mL"); Serial.print("\t"); // Print tab space Serial.print(totalMilliLitres/1000); Serial.print("L"); pulseCount = 0; attachInterrupt(sensorInterrupt, pulseCounter, FALLING); } if( totalMilliLitres > 0 && countstart == 0) { starttime = millis(); countstart = 1; } if ( totalMilliLitres > 0 ) { endtime = millis(); elapsedtime = endtime - starttime; } if (elapsedtime >= threshold){ digitalWrite(7,HIGH); // Activate relay to turn on motor delay(10000); digitalWrite(7,LOW); // Deactivate relay to turn on motor totalMilliLitres = 0; countstart = 0; elapsedtime = 0; break; } else{ digitalWrite(statusLed, LOW); // Turn the LED off digitalWrite(7, LOW);// turn relay OFF } }}void pulseCounter(){ // Increment the pulse counter pulseCount++;}

Topic by Eric-soberano   |  last reply


Arduino score board code question

Hi all. Ive been trying to work this out for a week and I'm guessing its a simple answer. Im building a score board, just LED modules (lights) instead of a 7 segment display There are two buttons, one for when each player scores a point. The led will work similar to a chaser but manually, each time the button is pressed the light advances one space and when the opposite players button is pushed the light goes towards the other player.  I tried using a button counter code, but because its counting the tines it touched it works in multiples. and just messes things up. can anyone help? thanks The schematic doesn't show the full thing, nor does the code. Im only working with one player at the moment to simply things a bit. // this constant won't change: const int  buttonPin1 = 6;    // the pin that pushbutton 1 is attached to const int  buttonPin2 = 7;    // the pin that pushbutton 2 is attached to const int ledPin1 = 2;       // the pin that the LED 1 is attached to const int ledPin2 = 3;       // the pin that the LED 2 is attached to const int ledPin3 = 4;       // the pin that the LED 3 is attached to const int ledPin4 = 5;       // the pin that the LED 4 is attached to const int ledPin4 = 8;       // the pin that the LED 5 is attached to // Variables will change: int buttonPushCounter = 0;   // counter for the number of button presses int buttonState = 0;         // current state of the button int lastButtonState = 0;     // previous state of the button void setup() {   // initialize the button pin as a input:   pinMode(buttonPin1, INPUT);   pinMode(buttonPin2, INPUT);   // initialize the LED as an output:   pinMode(ledPin1, OUTPUT);   pinMode(ledPin2, OUTPUT);   pinMode(ledPin3, OUTPUT);   pinMode(ledPin4, OUTPUT);   // initialize serial communication:   Serial.begin(9600); } void loop() {   // read the pushbutton input pin:   buttonState = digitalRead(buttonPin1);   // compare the buttonState to its previous state   if (buttonState != lastButtonState) {     // if the state has changed, increment the counter     if (buttonState == HIGH) {       // if the current state is HIGH then the button       // wend from off to on:       buttonPushCounter++;       Serial.println("on");       Serial.print("number of button pushes:  ");       Serial.println(buttonPushCounter);     } else {       // if the current state is LOW then the button       // wend from on to off:       Serial.println("off");     }     // Delay a little bit to avoid bouncing     delay(50);   }   // save the current state as the last state,   //for next time through the loop   lastButtonState = buttonState;   // turns on the LED every four button pushes by   // checking the modulo of the button push counter.   // the modulo function gives you the remainder of   // the division of two numbers:   if (buttonPushCounter % 1 == 0) {     digitalWrite(ledPin1, HIGH);     digitalWrite(ledPin2, LOW);     digitalWrite(ledPin3, LOW);     digitalWrite(ledPin4, LOW);   } else {     digitalWrite(ledPin1, LOW);   }   if (buttonPushCounter % 2 == 0) {     digitalWrite(ledPin2, HIGH);     digitalWrite(ledPin1, LOW);     digitalWrite(ledPin4, LOW);     digitalWrite(ledPin3, LOW);}           {if (buttonPushCounter % 3 == 0) {     digitalWrite(ledPin3, HIGH);     digitalWrite(ledPin4, LOW);     digitalWrite(ledPin2, LOW);     digitalWrite(ledPin1, LOW);}           if (buttonPushCounter % 4 == 0) {     digitalWrite(ledPin4, HIGH);     digitalWrite(ledPin1, LOW);     digitalWrite(ledPin2, LOW);     digitalWrite(ledPin3, LOW); }       } }

Question by spikepickstock   |  last reply


LED status

Is there a way you can read the status of an LED using an arduino code? That is,to read whether an LED is high or low

Question by chikarito   |  last reply


How to make Flip Clock Numbers and build a "like"-counter around it?

Hey All So I've got this client, who's absolutely crazy about the "FLIKE" (A physical like counter.). But he can't have it for another couple of months, and he'd like it to be a little more custom... Long story short, I might end up making a similar product in a few weeks. it will probably consist out of 5 digits and if it's up to me (not sure what the client wants) I'd stuff them behind a long picture frame. Something like this but actually mechanical and not just a picture of it:  http://www.notonthehighstreet.com/thedriftingbear/product/personalised-framed-vintage-flip-clock-print So I started googling every hardware piece I needed and it turns out it's a huge pain to find Flip Clock Numbers / Flip Board Numbers... whatever you want to call them. (What's the right name btw?) You can't just buy these things, let alone in a custom size. So the idea is to build them myself. I found this on wikipedia, which gives a clue about the inside: http://en.wikipedia.org/wiki/File:Analog_clock_with_digital_display.png So I'm figuring out what needs to go in it to make this work. (I'll end up making an instructable about it) The numbers themselves are going to be made out of vinyl stickers. You can easily buy those from ebay in about any size if you look for them. The stickers will be put on to plastic boards. But I'm not totally sure what kind I should get. They should be thin and must be able to stand up straight, yet "easy" to fold. I'll probably get them lasercut, but you should be able to cut them by hand as well. Currently I'm thinking about gluing small metal or carbon rods on the back of those letters. Although I'm not sure if that would be strong enough. Would it be enough to file one side of the rods to get a bigger contact surface? (What do you guys think?) I'm planning of putting the half letters in a drum of ABS or PLA. it should be shaped like this:  |--------| I'm thinking about 3D printing this. But no idea how it'll do... One side of the drum will be connected to a small stepper motor (5.625° with 1/64 reduction). I don't have real experience with stepper motors, but this resolution seems more than sufficient. The other side will be connected to a metal or plastic positioner. Each digit might end up with it's own "unit" so I can swap them separately if they'd break. I've got great experience with lasercut plexi, so I might use that because it's more accurate than wood and I might have some lying around. I was first thinking about 1 stepper motor and a set of gears. I decided not to do that in the end because I don't have good experience with making gears and I can never find the right sizes online. Also, it'll make everything way more complex. So each motor will have it's own controller connected to it. Those controllers would have to talk to an ATMega or something. (I'm planning on using an arduino to prototype, but then just swap the chip and make a stand-alone version without usb etc) The ATMega has to be connected to the internet of course to get the current number of likes, so I'd connect it to a raspberry pi via I²C. I'm not familiar with the GPIO pins on the pi so I figured this would be a save and convenient way to handle this. The ATMega is robust, and I love the Arduino bootloader. A sketch is written in no time, but I have no idea how to start writhing this code for the GPIO pins. So why the Raspberry Pi? First off, this thing might end up being wireless, and since a wifi module for the arduino costs as much as a Pi, I figured this would be easier. The plan is to make the pi run python script that could ask the number of likes from the facebook API. Once returned, it'll send +1 or +5 or +10 over I²C. The arduino shifts the numbers to the correct position and replies with the total number it's displaying (3012 for instance). The PI can then recheck if everything is in sync. As for the set up. Since we have Pi, we can put on a LAMP stack (I know, this is overkill, but it wouldn't hurt either). So for initial set-up, we'd connect the counter to ethernet, browse to it on a different computer via "http://counter.local". And we'd be presented with a web interface. You'll be able to set the URL of the page u want to get the likes from, set and reset the number that is displayed on the counter, and the WIFI settings. The WIFI settings can be saved in the wpa_supplicant.conf file and on reboot it'll automatically connect to this network. From now on the whole system is manageable over wifi via a html interface. For debugging I might enable ssh though. So I guess you've got the whole outline now. I'd like to get your feedback on this! And this for the mechanics, electronics, and software side of things! 

Question by woutervddn   |  last reply


Robotic Planting

Peter Sands shows off his latest arduino-based creation over at adafruit industries. The giant robot creates a garden, plants seeds, waters them and lovingly tends to it. Check out the sweet video!via: Hack-A-Day

Topic by scoochmaroo   |  last reply


Arduino Coding Question: How do I blink one LED 8 times and then another LED 8 times then repeat?

I'm using two 4017 decade counters to count to 16 and I figure two Arduino outputs would be a good way to go. I want one 4017 to receive 9 pulses then and then wait while the other 4017 receives 9 pulses. (one pulse is a holding position) For the moment I'm just trying to blink one LED 9 times and then another 9 times to represent two separate clock outputs. Here is a diagram: pin 13    1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, pin 12    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, Start      ------------------------------------------------------------------------------------------------------------ then loop. This is for multiplexing a 16x16 led screen so I don't think I should use the  delay(1000);  command. Each counter needs 9 pulses with the last pulse to the first counter happening simultaneously with the first pulse to the second counter. And similarly the first counter getting its first pulse at the same time as the second counter gets its 9th pulse. Get it?

Question by snotty   |  last reply


Simple Quadcopter using Arduino Uno?

Hello guys I am making a quadcopter using Arduino uno. My first simple aim is to lift and hover the quadcopter.  To achieve this aim  I have connected the signal Wire of all the ESC's to arduino Pin 9 and giving throttle via node server using bluetooth module and johnny five library.  My quadcopter lifts from 2 sides (flips) and sometimes little bit from 3rd side also.  Can anyone suggest me anything ? The thing which I am doing giving equal throttle to all motor, Is it right ? or  should I give more throttle to clockwise and little less throttle to counter clock wise motors. I will be very thankful, if you guys help me to lift my quadcopter

Question by nishanksingla   |  last reply


Neotech NT7086 display and arduino?

I found a couple of these older looking dot matrix LCDs in some electronic logbooks that didnt work. it was a 14 pin connector, so i figured why not try it out. i found the pinout of each pin using the chips that were on board, but i don`t know where to go from here, or if i should even bother. the display was made by or for hantronix, and they have a touch layer that could be used as well. each display has 7 of the NT7086PQ chips on it, a 74HC74D, a 74HC40103D, and an LM324. it was originally connected via a flat flex cable, but it had a convenient place for headers to plug it into a breadboard. the 74HC40103D is an 8-bit synchronous binary down counter: http://www.nxp.com/documents/data_sheet/74HC40103.pdf the 74HC74D is a Dual D-type flip-flop: http://www.mouser.com/ds/2/302/74HC_HCT74-225071.pdf the Neotech chips are LCD display drivers: http://www.crystalfontz.com/controllers/NT7086.pdf upon inspecting the physical properties of the display I can see there are the rubber/carbon edge contacts on two sides and a ribbon on one end. The pinout i figured out is: 14 is GND 13 is base on SOT23 transistor     (connected to 12 on parent board) 12 collector on a SOT23 transistor 11 gets pulled low at some point (pulled low on parent board) 10 is power 9 is cl2          (unactive high?) (on one set of neotech chips, assuming the edge contact drivers) 8 Clock input (74HC40103D) 7 does nothing 6 is d4 on one chip? 5 is display off  (active low) 4 is d4 3 is d3 2 is d2 1 is d1 So i would appreciate any input people have. I would ideally like to drive this using an arduino/atmega, and although i have not read the neotech datasheet to much depth it would appear to work similar to the popular parallel displays, but maybe with different syntaxes. so is this a possible thing, or is it a fruitless endeavor? thanks in advance.

Question by zack247   |  last reply


Arduino + RF to create item/finder?

IDEA 1. I've got the idea to create this kind of project where people nowadays being careless and misplace their item. So to counter this problem, i want to create a device which can detect the object/item within an area/radius of the receiver and transmitter. 2. This is not only for item/object but also can be placed on your children just in case they are away from you thus this device can alert you in sound, sight ( blinking LED ) , and vibration. PROBLEM 1. Is it possible to only use 1 transmitter and receiver? 2. Just in case for future uses, can compass be implanted in this device where it will always shows to the transmitter? 3. Currently programming are very hard for me, where can i get reference for programming this kind of device?

Question by Isaace11   |  last reply


Clock signal from Arduino crystal input pins? Answered

I'm interfacing an Arduino to a chip that needs a 1 MHz clock signal. Can I take one of the Arduino's clock input pins an input it into a 74169 (4 bit cascading counter) to generate a 1 MHz signal?  If not how do I create a 1 MHz 50% duty cycle signal?  Thanks in advance.

Question by maewert   |  last reply


Chords With An Arduino Microcontroller?

Does anyone have any idea as to how I could make more than just one tone with the Arduino Uno? I would like to make chords. I had an idea that you could make octaves with a binary counter that would half the frequency, but you still only get one key at a time (i.e. A, G#, Db, etc...)

Question by jensenr30   |  last reply


Can Someone Modify an Arduino Sketch For Me? Answered

I recently got into Arduino, and my first long term project is an autonomous roaming robot. Now, I've been in electronics for a while, so the actual building of the thing was not a problem....but the programming is. I've found a couple examples of codes online, but they all use Sharp IR sensors, whereas I have a Ping))) Ultrasonic sensor. I was wondering if there were any Arduino experts out there that could modify a sketch that I found to only use the Ping))) instead of the IR sensor(s). This sketch actually uses both, and would be perfect if the Ping))) was used in place of the IR sensors, rather than with them. If anybody could modify the sketch below to do as I said, your help would be greatly appreciated. Thanks. Code: int micVal; int cdsVal; int irLval;  // Left IR int irCval;  // Center IR int irRval;  // Right IR int i;   // Generic Counter int x;  // Generic Counter int PLval;  // Pulse Width for Left Servo int PRval;  // Pulse Width for Right Servo int cntr;  // Generic Counter Used for Determining amt. of Object Detections int counter; // Generic Counter int clrpth;  // amt. of Milliseconds Of Unobstructed Path int objdet;  // Time an Object was Detected int task;  // Routine to Follow for Clearest Path int pwm;  // Pulse Width for Pan Servo boolean add;  // Whether to Increment or Decrement PW Value for Pan Servo int distance;  // Distance to Object Detected via Ultrasonic Ranger int oldDistance;  // Previous Distance Value Read from Ultrasonic Ranger float scale = 1.9866666666666666666666666666667;  // *Not Currently Used* int LeftPin = 6;  // Left Servo int RightPin = 9;  // Right Servo int PiezoPin = 11;  // Piezo int PingServoPin = 5;  // Pan Servo int irLPin = 0;            // Analog 0; Left IR int irCPin = 1;            // Analog 1; Center IR int irRPin = 2;            // Analog 2; Right IR int ultraSoundSignal = 7; // Ultrasound signal pin int val = 0;              // Used for Ultrasonic Ranger int ultrasoundValue = 0;  // Raw Distance Val int oldUltrasoundValue;  // *Not used* int pulseCount;        // Generic Counter int timecount = 0; // Echo counter int ledPin = 13; // LED connected to digital pin 13 #define BAUD 9600 #define CmConstant 1/29.034 void setup() {   Serial.begin(9600);   pinMode(PiezoPin, OUTPUT);   pinMode(ledPin, OUTPUT);   pinMode(LeftPin, OUTPUT);   pinMode(RightPin, OUTPUT);   pinMode(PingServoPin, OUTPUT);   pinMode(irLPin, INPUT);   pinMode(irCPin, INPUT);   pinMode(irRPin, INPUT);   for(i = 0; i < 500; i++) {     digitalWrite(PiezoPin, HIGH);     delayMicroseconds(1000);     digitalWrite(PiezoPin, LOW);     delayMicroseconds(1000);   }   for(i = 0; i < 20; i++) {   digitalWrite(PingServoPin, HIGH);   delayMicroseconds(655 * 2);   digitalWrite(PingServoPin, LOW);   delay(20);   }   ultrasoundValue = 600;   i = 0; } void loop() {   //Scan();   Look();   Go(); } void Look() {   irLval = analogRead(irLPin);   irCval = analogRead(irCPin);   irRval = analogRead(irRPin);   //if(counter > 10) {     //counter = 0;     //readPing();   //}   if(irLval > 200) {     PLval = 820;     PRval = 850;     x = 5;     cntr = cntr + 1;     clrpth = 0;     objdet = millis();   }   else if(irCval > 200) {     PLval = 820;     PRval = 850;     x = 10;     cntr = cntr + 1;     clrpth = 0;     objdet = millis();   }   else if(irRval > 200) {     PLval = 620;     PRval = 650;     x = 5;     cntr = cntr + 1;     clrpth = 0;     objdet = millis();   }   else {     x = 1;     PLval = 620;     PRval = 850;     counter = counter + 1;     clrpth = (millis() - objdet);     if(add == true) {       pwm = pwm + 50;     }     else if(add == false) {       pwm = pwm - 50;     }     if(pwm < 400) {       pwm = 400;       add = true;     }     if(pwm > 950) {       pwm = 950;       add = false;     }     digitalWrite(PingServoPin, HIGH);     delayMicroseconds(pwm * 2);     digitalWrite(PingServoPin, LOW);     delay(20);     readPing();     if(ultrasoundValue < 500) {       cntr = cntr + 1;       switch(pwm) {         case 400:           x = 7;           PLval = 650;           PRval = 650;           Go();           break;         case 500:           x = 10;           PLval = 650;           PRval = 650;           Go();           break;         case 600:           x = 14;           PLval = 850;           PRval = 850;           Go();           break;         case 700:           x = 10;           PLval = 850;           PRval = 850;           Go();           break;         case 950:           x = 7;           PLval = 850;           PRval = 850;           Go();           break;       }     }   }   //Serial.print("clrpth: ");   //Serial.println(clrpth);   //Serial.print("objdet: ");   //Serial.println(objdet);   //Serial.print("cntr: ");   //Serial.println(cntr);   if(cntr > 25 && clrpth < 2000) {     clrpth = 0;     cntr = 0;     Scan();   } } void Go() {   for(i = 0; i < x; i++) {     digitalWrite(LeftPin, HIGH);     delayMicroseconds(PLval * 2);     digitalWrite(LeftPin, LOW);     digitalWrite(RightPin, HIGH);     delayMicroseconds(PRval * 2);     digitalWrite(RightPin, LOW);     delay(20);   } } void readPing() {  // Get Distance from Ultrasonic Ranger timecount = 0; val = 0; pinMode(ultraSoundSignal, OUTPUT); // Switch signalpin to output /* Send low-high-low pulse to activate the trigger pulse of the sensor * ------------------------------------------------------------------- */ digitalWrite(ultraSoundSignal, LOW); // Send low pulse delayMicroseconds(2); // Wait for 2 microseconds digitalWrite(ultraSoundSignal, HIGH); // Send high pulse delayMicroseconds(5); // Wait for 5 microseconds digitalWrite(ultraSoundSignal, LOW); // Holdoff /* Listening for echo pulse * ------------------------------------------------------------------- */ pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input val = digitalRead(ultraSoundSignal); // Append signal value to val while(val == LOW) { // Loop until pin reads a high value   val = digitalRead(ultraSoundSignal); } while(val == HIGH) { // Loop until pin reads a high value   val = digitalRead(ultraSoundSignal);   timecount = timecount +1;            // Count echo pulse time } /* Writing out values to the serial port * ------------------------------------------------------------------- */ ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue //serialWrite('A'); // Example identifier for the sensor //printInteger(ultrasoundValue); //serialWrite(10); //serialWrite(13); /* Lite up LED if any value is passed by the echo pulse * ------------------------------------------------------------------- */ if(timecount > 0){   digitalWrite(ledPin, HIGH); } } void Scan() {   // Scan for the Clearest Path   oldDistance = 30;   task = 0;   for(i = 1; i < 5; i++) {     switch(i) {       case 1:         //Serial.println("Pos. 1");         pwm = 1125;    ///  incr. by 100 from 1085         break;       case 2:         //Serial.println("Pos. 2");         pwm = 850; //// increased by 100 from 850         break;       case 3:         //Serial.println("Pos. 3");         pwm = 400;         break;       case 4:         //Serial.println("Pos. 4");         pwm = 235;         break;     }     for(pulseCount = 0; pulseCount < 20; pulseCount++) {  // Adjust Pan Servo and Read USR       digitalWrite(PingServoPin, HIGH);       delayMicroseconds(pwm * 2);       digitalWrite(PingServoPin, LOW);       readPing();       delay(20);     }     distance = ((float)ultrasoundValue * CmConstant);   // Calculate Distance in Cm     if(distance > oldDistance) {  // If the Newest distance is longer, replace previous reading with it       oldDistance = distance;       task = i;   // Set task equal to Pan Servo Position     }   }   //Serial.print("Task: ");   //Serial.println(task);   //Serial.print("distance: ");   //Serial.println(distance);   //Serial.print("oldDistance: ");   //Serial.println(oldDistance);   distance = 50;  // Prevents Scan from Looping   switch(task) {   // Determine which task should be carried out     case 0:  // Center was clearest       x = 28;       PLval = (850);       PRval = (850);       Go();       break;     case 1:  // 90 degrees Left was Clearest       x = 14;       PLval = (650);       PRval = (650);       Go();       break;     case 2:  // 45 degrees left       x = 7;       PLval = (650);       PRval = (650);       Go();       break;     case 3:  // 45 degrees right       x = 7;       PLval = (850);       PRval = (850);       Go();       break;     case 4:  // 90 degrees right       x = 14;       PLval = (850);       PRval = (850);       Go();       break;   } }    

Question by punkhead58   |  last reply


What is a normal current draw for an arduino ATMega168 with nothing connected? Answered

I'm building a handheld geiger counter using an ATMega168 microcontroller with the arduino bootloader. I was planning on using a 9v battery with a 7805 to power the circuit since the geiger counter power supply only draws 3ma and I did not think an arduino would draw much current. however, after building it on protoboard I found that the total current draw on the battery was in the neighborhood of 170ma and drained a fresh 9v in a few minutes flat. The rest of the circuit continues to work without the arduino, and draws only 20ma when the micro has been removed. is it normal for an ATMega168 or 328 to draw 150ma when loaded with a minimal program and none of its I/O pins are sinking/sourcing any current? It is possible this chip has been mistreated somewhat, would it being slightly damaged cause it to use more power than usual? maybe using sleep mode aggressively in my code to save power would work? also, does anyone know of a 5v regulator chip like the 7805 that does not use so much current? the 7805 burns up about 10ma by itself which is not so great when the geiger counter itself uses only a few ma.

Question by hivoltage   |  last reply


how to control servo motor(analog or digital servo) with ps2 remote and Arduino Uno r3?

Hello, I just want to control my servo Pan tilt with my ps2 remote and arduino uno R3. It means when i press the Triangle(Green) button it will move clock wise, and when i press X(Blue) button it will move counter clock wise. and this condition will true when button will press. unless it stop at current position.

Question by vrushank26   |  last reply


Arduino output multiplier: What's a good way to get more pins on my Arduino?

I want more outputs for my Arduino Duemilanove. I want to run a simple 16x16 LED matrix but I'd need more pins. Most instructions I find use one of several chips such as the 7442 1 of 10 decoder IC, another option might be a couple of 4017 decade counters. Can anybody recommend a method that is widely used and well documented?

Question by snotty   |  last reply


I need a way of measuring a 0-1000kHz signal (50% duty cycle square wave from a TSL237) with an arduino. Answered

I'm willing to use external hardware if it is cheap.I've tried using an interrupt base pulse accumulator but when the frequency becomes high the counter increments so fast that it stops the arduino from doing anything else (like stopping counting). Does anyone know of a nice easy solution to count frequency? Perhaps a fancy 8 pin DIP that talks i2c? I need to be senstive to the very low end of the frequency scale too, so just throwing a prescaler on will not solve this (afaik). Thanks.

Question by quatch   |  last reply


problem with Arduino ): i don't want to use it ???

Hi all  i want anyone help me in my project first i want explain the idea of my project :-) this project will show you how to build a quite fancy 8 by 10 L.E.D matrix(with scrolling text and animations) using the Arduino and 4017 decade counter. T you can see the details of project from : http://sohilp.blogspot.com/2011/10/tutorial-10x8-led-matrix-arduino.html my problem::-( i don't want to use Arduino Can I use parallel port Instead ArduinoØ�Ø�Ø� if you tell yes how i:|? and how to make the new circle plz help me or give me any like about this thank you :oops: i am waiting for all [/LEFT]

Question by a7la nono   |  last reply


Ball counter or weight sensor with relay to sound alarm or trigger 9v confetti cannon

Anyone interested in a bit of work...I could also run it as a competition. Apologies in advance if what I am doing in not allowed on instructables, but I couldn't find a place to offer this work. Peoplehour does not specialise in tech gadgets! I am a one man band training business in the UK. I am trying to find someone to make this gadget to work with my Gravity Ball Game. Gravity Ball is a two hour team building activity. Gravity Ball requires teams to design and build a construction capable of transporting a ball from one zone to another; the ball must roll freely along the construction using gravity only. There will be a shared zone that will require team collaboration, co­operation and coordination. Everyone needs to contribute to the overall team objective whilst ensuring their own structure functions to a specific brief and works correctly. All teams will release their designated ball (tennis ball, golf ball, cricket ball, squash ball. Etc.) at the same time. Each team ball will roll freely along the team structure, into the shared area and the fall into a collection container. When all the balls are in the container (and a specific weight achieved) then the Weight sensitive relay switch will detonate a electronic confetti cannon. Alternatively, an infra red or sensor can count the number of balls that pass at a particular point and when the designated number is reached, the confetti cannon will detonate The detonation will give a wow factor to the team activity. Considerations: I need a gadget, Arduino, raspberry pi or beaglebone that can measure or count the number of ball and then detonate a confetti cannon or sound an alarm • Programmable weight or ball counter setting • Maximum weight 300g-400g or Maximum number of passing balls is 10 • Work with standard electronic confetti cannon from Confetti Masters, alarm or Siren (http://www.confettimaster.com/streamer.electric.confetti.cannons.html) or Showtec electric cannons (http://www.sblite.co.uk/598-80cm-multicolour-electric-confetti-cannon.html) Message me if you are interested! Kind regards Canute

Topic by GreenflashUK 


How to reset arduino after pressing the pushbutton 16 times?

Good afternoon, I'm trying to reset my Arduino after pressing the pushbutton 16 times. What I'm currently experiencing is that it is not resetting. I'm trying to achieve this using the StateChangeDetection example. Could anyone give me tips on how to achieve this? I'm working on this using an Multi Function Shield or MFS. My code is: // this constant won't change: const int  buttonPin = A1;    // the pin that the pushbutton is attached to const int ledPin = 13;       // the pin that the LED is attached to // Variables will change: int buttonPushCounter = 0;   // counter for the number of button presses int buttonState = 0;         // current state of the button int lastButtonState = 0;     // previous state of the button int count = 0; void setup() {   // initialize the button pin as a input:   pinMode(buttonPin, INPUT);   // initialize the LED as an output:   pinMode(ledPin, OUTPUT);   // initialize serial communication:   Serial.begin(9600); } void loop() {   // read the pushbutton input pin:   buttonState = !digitalRead(buttonPin);   // compare the buttonState to its previous state   if (buttonState != lastButtonState) {     // if the state has changed, increment the counter     if (buttonState == LOW) {       // if the current state is HIGH then the button went from off to on:       buttonPushCounter++;       Serial.println("on");       Serial.print("number of button pushes: ");       Serial.println(buttonPushCounter);     } else {       // if the current state is LOW then the button went from on to off:       Serial.println("off");     }     // Delay a little bit to avoid bouncing     delay(50);   }   // save the current state as the last state, for next time through the loop   lastButtonState = buttonState;   // read the state of the pushbutton value:   buttonState = digitalRead(buttonPin); //Source: https://www.instructables.com/answers/Is-there-a-way-to-count-button-pushes-on-an-arduin/ if (buttonState == HIGH) {        // turn LED on:       digitalWrite(ledPin, HIGH);     count++;               // add 1 to the count     if (count >= 8) {       count = 0;     }   }   else {     // turn LED off:     digitalWrite(ledPin, LOW);   } }

Question by DanielB804   |  last reply


Controlling degree of multiple Stepper motors using one push button as a counter Answered

Hello everyone,I am having 3x 28BYJ48 stepper motors and ULN2003 driver equally.I want to control the stepper motors to a pre-defined degree based on the number of pushbutton has been pressed.For an example,i have motor x, y and z.1) When the button is pressed zero time, all the motors need to be in zero degree.2) when the button is pressed for the first time, motor x need to move to 90 degree, motor y to 120 degree and motor z to 180 degree.3) when the button is pressed for the second time, motor x need to move to 110 degree, motor y to 150 degree and motor z move to 210 degree.4) when the button is pressed for the third and last time, all the motors need to move back to zero degrees.Can anyone guide me on this control?Advance thanks to all

Question by JaiJ11   |  last reply


Arduino or Teensy coil winder - any code already out there?

I am in the process of deciding on a normal 8bit Arduino platform or a Teensy for my coil winder project.A found some interesting projects online, some with the code available too.But I was wondering if someone already implemented more than just winding a coil in such a project?At Krux.org is a nice winder based on a normal Arduino while the Alba winder uses a Teensy already to gain more precision and speed I guess.Misusing some printer or CNC code to be able to generate coils by G-code sounded nice at first but turned out to be more complex than actually required.My goal is actually rather simple despite the size and all, so let me try to explain what I want to be able to do:Have a modular winder setup so basically any winding task can be done with just two stepper motors.One for the spin, one to position the wire.Additions like limit switches and external counters are nice but usually not required for such a task if the the code is properly done.As a basic winder like all the examples out there it should be possible to just enter the wire diamter and number of turns and then push a button to wait for the finnished coil.In theory things like pitch or spacing can be calculated externally and then entered as a fictive wire diameter but of course this would be not user friendly enough ;)For special RF coils it is often required to keep an even turn spacing as well as creating a coil with many layers.So far I have been unable to find any usable code for this purpose that does not require glue, guides or at least waxing the wire.Although this seems to be simple enough, when adding things like a display and counters it soon starts to get messy with timings and steps.Is there anything out there that works properly on a 8bit processor with reasonable speed?Originally I wanted to use an OLED with touchscreen.This turned out to be too much for the timing on a Mega.Without messing around with timers and interrupts it seem a 20x4 LCD is the only option.Even then the refresh must be in sync with the tart of a new turn as otherwise the motors miss some steps here and there.These things run a 3D printer or little laser cutter with ease, so I am definately doing something wong with my approach here LOL

Topic by Downunder35m 


problem with my code

This is the top of the code where i am getting the error. "Tone speakerpin" is the line that it is talking about. The error says "Tone" does not name a type. Please help #include Tone speakerpin; int starttune[] = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_E4, NOTE_F4, NOTE_G4}; int duration2[] = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100, 200, 100, 500}; int note[] = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5}; int duration[] = {100, 100, 100, 300, 100, 300}; boolean button[] = {2, 3, 4, 5}; //The four button input pins boolean ledpin[] = {8, 9, 10, 11};  // LED pins int turn = 0;  // turn counter int buttonstate = 0;  // button state checker int randomArray[100]; //Intentionally long to store up to 100 inputs (doubtful anyone will get this far) int inputArray[100];

Question by font1135   |  last reply


how way profit count coin joined by LCD display and notification through audio system using arduino?

Ok, Im have a little project about coin counter joined by LCD display and notify through audio system using arduino. Im using LDR sensor because it just a cheap project. Im not using a coin acceptor sensor as it difficult to be acquired. Is that any kind of program that is applicable to calculate coin instantly display coin total through LCD and can notify through audio system? or suggestion to use any other sensor? I hope anybody can help me.. thanks ^_^

Question by MohdFirdaus   |  last reply


Connect a Sketch Answered

This is a People counter, well hope to be if working.ha. Lazer across a doorway hitting a LDR. The 4 digit 7 seg display counting up 1 each time a person breaks the beam.  As of now i  have a counting sketch from the Sparkfun example. It is counting up 0 to 999 and at the same time i have an LDR reading to the serial monitor and blinking the LED on pin 13. But they are not "interacting". I am trying to get the beam breakes from the LDR to advance the count by 1 every time it is broken. In the loop function is the mills that was advancing the counting. I have changed it to   displayNumber(counter).  Among other things.But i haven't been successful in having the LDR advance the count. The sketch is still missing some "stuff". What could i change to have the counter advance by 1 every time the lazer beam is broken?    Thanks W /* 6-13-2011 Spark Fun Electronics 2011 Nathan Seidle This code is public domain but you buy me a beer if you use this and we meet someday (Beerware license). 4 digit 7 segment display: http://www.sparkfun.com/products/9483 Datasheet: http://www.sparkfun.com/datasheets/Components/LED/7-Segment/YSD-439AR6B-35.pdf This is an example of how to drive a 7 segment LED display from an ATmega without the use of current limiting resistors. This technique is very common but requires some knowledge of electronics - you do run the risk of dumping too much current through the segments and burning out parts of the display. If you use the stock code you should be ok, but be careful editing the brightness values. This code should work with all colors (red, blue, yellow, green) but the brightness will vary from one color to the next because the forward voltage drop of each color is different. This code was written and calibrated for the red color. This code will work with most Arduinos but you may want to re-route some of the pins. 7 segments 4 digits 1 colon = 12 pins required for full control */ #define ldrPin A2    // pin used for input (analog)    int digit1 = 11; //PWM Display pin 1 int digit2 = 10; //PWM Display pin 2 int digit3 = 9; //PWM Display pin 6 int digit4 = 6; //PWM Display pin 8 //Pin mapping from Arduino to the ATmega DIP28 if you need it //http://www.arduino.cc/en/Hacking/PinMapping //int ldrPin = A2; int segA = A1; //Display pin 14 int segB = 3; //Display pin 16 int segC = 4; //Display pin 13 int segD = 5; //Display pin 3 int segE = A0; //Display pin 5 int segF = 7; //Display pin 11 int segG = 8; //Display pin 15 int ldr_pinValue; int counter; int currState; int then; //int ldrpread; //int digit[4]; //int leftover; int LDR = A2;                                //analog pin to which LDR is connected, here we set it to 0 so it means A0 int LDRValue = 0;                    //that’s a variable to store LDR values int light_sensitivity = 500;  //This is the approx value of light surrounding your LDR //int digit_to_show = 0; int ldr_Pin = 0;  // LED status (0 = low, 1 = high) int inVal = 0;    // variable used to store state of input int switchOn = 725;   // value at which we switch LED on int switchOff = 550;  // value at which we switch LED off void setup() {         {     Serial.begin(9600);            //start the serial monitor with 9600 buad     pinMode(13, OUTPUT);     //we mostly use13 because there is already a built in yellow LED in arduino which shows output when 13 pin is enabled   }       pinMode(ldr_Pin, INPUT );    pinMode(segA, OUTPUT);   pinMode(segB, OUTPUT);   pinMode(segC, OUTPUT);   pinMode(segD, OUTPUT);   pinMode(segE, OUTPUT);   pinMode(segF, OUTPUT);   pinMode(segG, OUTPUT);   pinMode(digit1, OUTPUT);   pinMode(digit2, OUTPUT);   pinMode(digit3, OUTPUT);   pinMode(digit4, OUTPUT);     pinMode(13, OUTPUT); } void loop(){ {     LDRValue = analogRead(LDR);          //reads the ldr’s value through LDR which we have set to Analog input 0 “A0″     Serial.println(LDRValue);                  //prints the LDR values to serial monitor     delay(5);                                                //This is the speed by which LDR sends value to arduino     if (LDRValue < light_sensitivity)       {         digitalWrite(13, HIGH);       }     else       {         digitalWrite(13, LOW); {    if (currState() >  300) then         currState = HIGH    } else     currState = LOW //endif if currState != prevState and currState == LOW then // LOW or HIGH depending on the circuit     counter++     prevState = currState endif      //long startTime = millis();   displayNumber(counter);     //while( (millis() - startTime) < 2000) {   //displayNumber(1217);   //}   //delay(1000);    } //Given a number, we display 10:22 //After running through the 4 numbers, the display is left turned off //Display brightness //Each digit is on for a certain amount of microseconds //Then it is off until we have reached a total of 20ms for the function call //Let's assume each digit is on for 1000us //Each digit is on for 1ms, there are 4 digits, so the display is off for 16ms. //That's a ratio of 1ms to 16ms or 6.25% on time (PWM). //Let's define a variable called brightness that varies from: //5000 blindingly bright (15.7mA current draw per digit) //2000 shockingly bright (11.4mA current draw per digit) //1000 pretty bright (5.9mA) //500 normal (3mA) //200 dim but readable (1.4mA) //50 dim but readable (0.56mA) //5 dim but readable (0.31mA) //1 dim but readable in dark (0.28mA) void displayNumber(int toDisplay) { #define DISPLAY_BRIGHTNESS  500 #define DIGIT_ON  HIGH #define DIGIT_OFF  LOW   long beginTime = millis();   for(int digit = 4 ; digit > 0 ; digit--) {     //Turn on a digit for a short amount of time     switch(digit) {     case 1:       digitalWrite(digit1, DIGIT_ON);       break;     case 2:       digitalWrite(digit2, DIGIT_ON);       break;     case 3:       digitalWrite(digit3, DIGIT_ON);       break;     case 4:       digitalWrite(digit4, DIGIT_ON);       break;     }     //Turn on the right segments for this digit     lightNumber(toDisplay % 10);     toDisplay /= 10;     delayMicroseconds(DISPLAY_BRIGHTNESS);     //Display digit for fraction of a second (1us to 5000us, 500 is pretty good)     //Turn off all segments     lightNumber(10);     //Turn off all digits     digitalWrite(digit1, DIGIT_OFF);     digitalWrite(digit2, DIGIT_OFF);     digitalWrite(digit3, DIGIT_OFF);     digitalWrite(digit4, DIGIT_OFF);   }   while( (millis() - beginTime) < 10) ;   //Wait for 20ms to pass before we paint the display again } //Given a number, turns on those segments //If number == 10, then turn off number void lightNumber(int numberToDisplay) { #define SEGMENT_ON  LOW #define SEGMENT_OFF HIGH   switch (numberToDisplay){   case 0:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_OFF);     break;   case 1:     digitalWrite(segA, SEGMENT_OFF);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_OFF);     break;   case 2:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_OFF);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_ON);     break;   case 3:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_ON);     break;   case 4:     digitalWrite(segA, SEGMENT_OFF);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 5:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_OFF);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 6:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_OFF);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 7:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_OFF);     break;   case 8:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_ON);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 9:     digitalWrite(segA, SEGMENT_ON);     digitalWrite(segB, SEGMENT_ON);     digitalWrite(segC, SEGMENT_ON);     digitalWrite(segD, SEGMENT_ON);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_ON);     digitalWrite(segG, SEGMENT_ON);     break;   case 10:     digitalWrite(segA, SEGMENT_OFF);     digitalWrite(segB, SEGMENT_OFF);     digitalWrite(segC, SEGMENT_OFF);     digitalWrite(segD, SEGMENT_OFF);     digitalWrite(segE, SEGMENT_OFF);     digitalWrite(segF, SEGMENT_OFF);     digitalWrite(segG, SEGMENT_OFF);     break;   } }

Question by WWC   |  last reply


Arduino coding help! Buttons, switches, and servos are not agreeing.

Hi my name is Nash and I've been playing with Arduino Duemilanove for about a year and just touching a little bit of everything. Right now I'm have the Arduino powering basically a pan/tilt device that rotates horizontally 360 degrees and vertically 90 degrees. Using a specific code containing one button, I can have the Arduino run a sequence of the two servos. I would like to add a second button and have a switch to choose "modes." If the switch is OFF, then pushing one button will run the sequence- simple enough. When the switch is ON, I would like the same button as before as well as an additional button control rotation of the horizontal servo. I have the code using only one button and no switch to run the sequence and the device runs flawlessly. Once I add the "switching" part to the code, the servos freak out and fidget constantly without a positive result. I am fairly new to the servo library in Arduino and am open to any kind of instruction or changes to my code below. Thanks for your help! #include Servo servo; //we think this will make the Cont-Rot servo to sit still Servo iservo; //set second servo #define button 3 //attaches button to pin 3 int ibutton = 0; //ibutton is used to store state of input #define button2 2 //second button attached to pin 2 int qbutton = 0; //qbutton stores input #define button7 7 //switch connected to pin 7 int sbutton = 0; //switch stores input void setup() {   servo.attach(5); //attaches servo to pin 5   iservo.attach(6); //attaches second servo to pin 6   pinMode(button, INPUT); //sets button as input   pinMode(button2, INPUT); //sets button2 as input   pinMode(button7, INPUT); //sets switch as input } void loop() {   ibutton = digitalRead(button); //reads state of button   qbutton = digitalRead(button2); //reads state of second button   Switch = digitalRead(button7); //reads state of switch   if (Switch == LOW) { //if switch is off   if (ibutton == HIGH) { //and ibutton is pressed     iservo.write(0); //run this servo sequence     servo.write(100);     delay(2000);     iservo.write(0);     servo.write(80);     delay(4000);     iservo.write(0);     servo.write(100);     delay(2000);   }   if (ibutton == LOW) { //ibutton is not pressed     servo.write(90); //do nothing     iservo.write(50);   } }   if (Switch == HIGH) { //switch is on     if ((ibutton == HIGH) && (qbutton == LOW)) { //ibutton is pressed and qbutton is not       servo.write(80); //servo spin counter-clockwise     }     if ((ibutton == LOW) && (qbutton == HIGH)) { //ibutton is not pressed and qbutton is       servo.write(100); //servo spin clockwise     }     if ((ibutton == LOW) && (qbutton == LOW)) { //neither button is pressed       servo.write(90); //do nothing     }   } }

Question by shooternash   |  last reply


How do you code an arduino to count and display on LCD each number every time a relay triggers? Answered

OK, I'm kinda new at the programming part for my projects. I was wondering if anyone can help me with (what I assume will be a simple code for a veteran) a code for arduino and maybe with a little explanation of the code. Project is simple. I have a toy laser gun shooting at a target with a photocell attached and connected to a relay. What I would like is that every time the relay switches, a counter adds the shot so I can keep score. It's for my son's 9th birthday party and I've already built the targeting range (with  Lego Movie theme) and even some servos to knock back guys down.  I just need a way to keep score. I have some Arduino Uno's, some nanos, some trinkets, some LCDs (2X16 and 4X8) and 4X 7segment displays so I have some options for parts,but at the moment I do not have a lot of time to go through a self-learning curve to get the coding to work.  Can anyone please help?  It would be greatly appreciated. Thanks.

Question by jedii72   |  last reply


new to arduino, want to run a dual display for 2 sensors

I'm new to the Arduino community.  wanting to set up a dual radar setup with 2 ultrasonic sensors,  (Ultrasonic Sensor Module HC-SR04), and outputting to a pair of 7 segment displays ( two 7 segment displays each).  I've found a code to do a single could use a lot of help to output two at the same time, basically 2 lanes without 2 units.  im using an arduino mega, ordered a unor3 and hopefully it can be made to run on one or the other. code is as follows: /* HC-SR04 Sensor    The circuit:     * VCC connection of the sensor attached to +5V     * GND connection of the sensor attached to ground     * TRIG connection of the sensor attached to digital pin 2     * ECHO connection of the sensor attached to digital pin 4  */    /*  This is a radar ping sensor that calcultates the speed of an  object traveling away or towards the sensor. I took some of this  code for the HC-SR04 Sensor implementation by Tautvidas Sipavicius. The rest  is original code from me. I know that the seven segment display  code is not the best to look at or the most optimized but it  serves its purpose just fine and is easy to understand.    Written by Matthew Ladd  */   const int trigPin = 2; const int echoPin = 4;   void setup() {   // initialize serial communication:   Serial.begin(9600);   //First 7 segment (ones place)   pinMode(30,OUTPUT);//F   pinMode(31,OUTPUT);//G   pinMode(32,OUTPUT);//E   pinMode(33,OUTPUT);//D   pinMode(34,OUTPUT);//C   pinMode(35,OUTPUT);//B   pinMode(36,OUTPUT);//A   //Second 7 segment (tens place)   pinMode(37,OUTPUT);//F   pinMode(38,OUTPUT);//G   pinMode(39,OUTPUT);//E   pinMode(40,OUTPUT);//D   pinMode(41,OUTPUT);//C   pinMode(42,OUTPUT);//B   pinMode(43,OUTPUT);//A } void zerofirst(){   digitalWrite(30,LOW);   digitalWrite(31,HIGH);   digitalWrite(32,LOW);   digitalWrite(33,LOW);   digitalWrite(34,LOW);   digitalWrite(35,LOW);   digitalWrite(36,LOW); } void onefirst(){   digitalWrite(30,HIGH);   digitalWrite(31,HIGH);   digitalWrite(32,HIGH);   digitalWrite(33,HIGH);   digitalWrite(34,LOW);   digitalWrite(35,LOW);   digitalWrite(36,HIGH); } void twofirst(){   digitalWrite(30,HIGH);//F   digitalWrite(31,LOW);//G   digitalWrite(32,LOW);//E   digitalWrite(33,LOW);//D   digitalWrite(34,HIGH);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void threefirst(){   digitalWrite(30,HIGH);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void fourfirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,HIGH);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,HIGH);//A } void fivefirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,HIGH);//B   digitalWrite(36,LOW);//A } void sixfirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,LOW);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,HIGH);//B   digitalWrite(36,LOW);//A } void sevenfirst(){   digitalWrite(30,HIGH);//F   digitalWrite(31,HIGH);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,HIGH);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void eightfirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,LOW);//E   digitalWrite(33,LOW);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void ninefirst(){   digitalWrite(30,LOW);//F   digitalWrite(31,LOW);//G   digitalWrite(32,HIGH);//E   digitalWrite(33,HIGH);//D   digitalWrite(34,LOW);//C   digitalWrite(35,LOW);//B   digitalWrite(36,LOW);//A } void zerosecond(){   digitalWrite(37,LOW);   digitalWrite(38,HIGH);   digitalWrite(39,LOW);   digitalWrite(40,LOW);   digitalWrite(41,LOW);   digitalWrite(42,LOW);   digitalWrite(43,LOW); } void onesecond(){   digitalWrite(37,HIGH);   digitalWrite(38,HIGH);   digitalWrite(39,HIGH);   digitalWrite(40,HIGH);   digitalWrite(41,LOW);   digitalWrite(42,LOW);   digitalWrite(43,HIGH); } void twosecond(){   digitalWrite(37,HIGH);//F   digitalWrite(38,LOW);//G   digitalWrite(39,LOW);//E   digitalWrite(40,LOW);//D   digitalWrite(41,HIGH);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void threesecond(){   digitalWrite(37,HIGH);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void foursecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,HIGH);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,HIGH);//A } void fivesecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,HIGH);//B   digitalWrite(43,LOW);//A } void sixsecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,LOW);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,HIGH);//B   digitalWrite(43,LOW);//A } void sevensecond(){   digitalWrite(37,HIGH);//F   digitalWrite(38,HIGH);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,HIGH);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void eightsecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,LOW);//E   digitalWrite(40,LOW);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } void ninesecond(){   digitalWrite(37,LOW);//F   digitalWrite(38,LOW);//G   digitalWrite(39,HIGH);//E   digitalWrite(40,HIGH);//D   digitalWrite(41,LOW);//C   digitalWrite(42,LOW);//B   digitalWrite(43,LOW);//A } long distanceOverTime(long first,long second){  return ((first-second)/.1)*.0223693629;//taking cm/s to mph } long holder;//store the cm from last time through loop. long temp;//used to store the speed value after changes int counter; void loop() {   // establish variables for duration of the ping,   // and the distance result in inches and centimeters:   long duration, inches, cm;   int tens;   int ones;   long Speed;   // The sensor is triggered by a HIGH pulse of 10 or more microseconds.   // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:   pinMode(trigPin, OUTPUT);   digitalWrite(trigPin, LOW);   delayMicroseconds(2);   digitalWrite(trigPin, HIGH);   delayMicroseconds(10);   digitalWrite(trigPin, LOW);     // Read the signal from the sensor: a HIGH pulse whose   // duration is the time (in microseconds) from the sending   // of the ping to the reception of its echo off of an object.   pinMode(echoPin, INPUT);   duration = pulseIn(echoPin, HIGH);     // convert the time into a distance   inches = microsecondsToInches(duration);   cm = microsecondsToCentimeters(duration);   Speed=distanceOverTime(holder,cm);   holder=cm;//after speed caclulation so take the cm value for another calculation   Speed=abs(Speed);   if(Speed!=0 || counter==10){     temp=Speed;     counter=0;   }else{     counter++;   }   if(temp>=100){    zerofirst();    zerosecond();   }else{     ones=temp%10;     tens=temp/10;   }   if(ones == 0){     zerofirst();   }else if(ones==1){     onefirst();   }else if(ones==2){     twofirst();   }else if(ones==3){     threefirst();   }else if(ones==4){     fourfirst();   }else if(ones==5){     fivefirst();   }else if(ones==6){     sixfirst();   }else if(ones==7){     sevenfirst();   }else if(ones==8){     eightfirst();   }else if(ones==9){     ninefirst();   }   if(tens == 0){     zerosecond();   }else if(tens==1){     onesecond();   }else if(tens==2){     twosecond();   }else if(tens==3){     threesecond();   }else if(tens==4){     foursecond();   }else if(tens==5){     fivesecond();   }else if(tens==6){     sixsecond();   }else if(tens==7){     sevensecond();   }else if(tens==8){     eightsecond();   }else if(tens==9){     ninesecond();   }       Serial.print(inches);   Serial.print(" in, ");   Serial.print(cm);   Serial.print(" cm, ");   Serial.print(Speed);   Serial.print(" mph");   Serial.println();     delay(100); }   long microsecondsToInches(long microseconds) {   // According to Parallax's datasheet for the PING))), there are   // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per   // second).  This gives the distance travelled by the ping, outbound   // and return, so we divide by 2 to get the distance of the obstacle.   // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf   return microseconds / 74 / 2; }   long microsecondsToCentimeters(long microseconds) {   // The speed of sound is 340 m/s or 29 microseconds per centimeter.   // The ping travels out and back, so to find the distance of the   // object we take half of the distance travelled.   return microseconds / 29 / 2; } again, all your help and thought are appricated

Topic by herb1977   |  last reply


Problem in arduino code... you'll have to run this one to understand - Word Clock? Answered

I have been writing this code for the Word clock. I am trying to customize the code to fit into an atmega8, and use DS1307 RTC. Both of these is fine, but what is wrong is that when I upload my code and try to set the time by using the buttons, the time is not setting properly. I can increment minutes with the minutes button to 16, but not further. Hours works fine, but if, lets say the time is 6:36 on the arduino, then If I press the hour button, I find that time changes to 7:31. Five minutes less than what I expected. What am I overlooking here?  I advise to run the code and understand the problem. On the other hand Binary sketch size: 7164 bytes (of a 7168 byte maximum), this is just 4 bytes short of max. Can that be a part of the problem Code: #include // Display output pin assignments #define MTEN  Display1=Display1 | (1<<0)  #define HALF Display1=Display1 | (1<<1) #define QUARTER Display1=Display1 | (1<<2) #define TWENTY Display1=Display1 | (1<<3) #define MFIVE Display1=Display1 | (1<<4) #define MINUTES Display1=Display1 | (1<<5) #define PAST Display1=Display1 | (1<<6) #define UNUSED1 Display1=Display1 | (1<<7) #define TO Display2=Display2 | (1<<0) #define ONE Display2=Display2 | (1<<1) #define TWO Display2=Display2 | (1<<2) #define THREE Display2=Display2 | (1<<3) #define FOUR Display2=Display2 | (1<<4) #define HFIVE Display2=Display2 | (1<<5) #define SIX Display2=Display2 | (1<<6) #define UNUSED2 Display2=Display2 | (1<<7) #define SEVEN Display3=Display3 | (1<<0) #define EIGHT Display3=Display3 | (1<<1) #define NINE Display3=Display3 | (1<<2) #define HTEN Display3=Display3 | (1<<3) #define ELEVEN Display3=Display3 | (1<<4) #define TWELVE Display3=Display3 | (1<<5) #define OCLOCK  Display3=Display3 | (1<<6) #define UNUSED3 Display3=Display3 | (1<<7) #define DS1307_I2C_ADDRESS 0x68  // This is the I2C address #if defined(ARDUINO) && ARDUINO >= 100   // Arduino v1.0 and newer   #define I2C_WRITE Wire.write   #define I2C_READ Wire.read #else                                   // Arduino Prior to v1.0   #define I2C_WRITE Wire.send   #define I2C_READ Wire.receive #endif int  hr=12, mn=00, scnd=0; static unsigned long msTick =0;  // the number of Millisecond Ticks since we last                                  // incremented the second counter int  count; boolean selftestmode; boolean  DS1307Present=false;       // flag to indicate that the 1307 is there..    1 = present char Display1=0, Display2=0, Display3=0; // hardware constants static unsigned int LEDClockPin=5;    //11 d5 ok static unsigned int LEDDataPin=3;    //5 d3 static unsigned int LEDStrobePin=4;   //6 d4 static unsigned int MinuteButtonPin=6;  //d6 12 static unsigned int HourButtonPin=7;    //d7 13 static unsigned int PWMPin = 11; char buf[50]; // time output string for debugging byte decToBcd(byte b) {  return ( ((b/10) << 4) + (b%10) );} // Convert binary coded decimal to normal decimal numbers byte bcdToDec(byte b) {  return ( ((b >> 4)*10) + (b%16) );} void getTime() {   //read from chip and store in hr, mn, scnd   Wire.beginTransmission(DS1307_I2C_ADDRESS);   I2C_WRITE((uint8_t) 0x00);   Wire.endTransmission();     Wire.requestFrom(DS1307_I2C_ADDRESS, 3);   scnd = bcdToDec(I2C_READ());   mn =  bcdToDec(I2C_READ());   hr =  bcdToDec(I2C_READ()); } void setTime() {   //to be paranoid, we're going to first stop the clock   //to ensure we don't have rollovers while we're   //writing:   writeRTCreg(0,0x80);   //now, we'll write everything *except* the second   Wire.beginTransmission(DS1307_I2C_ADDRESS);   I2C_WRITE((uint8_t) 0x01);   I2C_WRITE(mn);   I2C_WRITE(hr);   Wire.endTransmission();   //now, we'll write the seconds; we didn't have to keep   //track of whether the clock was already running, because   //scnd already knows what we want it to be. This   //will restart the clock as it writes the new seconds value.   writeRTCreg(0,scnd); } byte readRTCreg(byte adr) {    if(adr > 0x3F) { return 0xff; }   Wire.beginTransmission(DS1307_I2C_ADDRESS);   I2C_WRITE(adr);   Wire.endTransmission();   Wire.requestFrom(DS1307_I2C_ADDRESS, 1);   return I2C_READ(); } void writeRTCreg(byte adr, byte val) { if(adr > 0x3F) { return; }    Wire.beginTransmission(DS1307_I2C_ADDRESS);    I2C_WRITE(adr);    I2C_WRITE(val);    Wire.endTransmission(); } void print_DS1307time() {   /* Format the time and date and insert into the temporary buffer */   snprintf(buf, sizeof(buf), "RTC time: %02d:%02d:%02d",   hr, mn, scnd);   /* Print the formatted string to serial so we can see the time */   Serial.println(buf); } void setup() {   // initialise the hardware   // initialize the appropriate pins as outputs:   pinMode(LEDClockPin, OUTPUT);   pinMode(LEDDataPin, OUTPUT);   pinMode(LEDStrobePin, OUTPUT);       //pinMode(BrightnessPin, INPUT);   pinMode(MinuteButtonPin, INPUT);   pinMode(HourButtonPin, INPUT);   digitalWrite(MinuteButtonPin, HIGH);  //set internal pullup   digitalWrite(HourButtonPin, HIGH); //set internal pullup   pinMode(PWMPin, OUTPUT);     Serial.begin(9600);   Wire.begin();    // test whether the DS1302 is there   Serial.print("Verifying DS1307 ");   // start by verifying that the chip has a valid signature   if (readRTCreg(0x20) == 0x55) {     // Signature is there - set the present flag and mmove on     DS1307Present=true;     Serial.println("Valid Signature");   }   else   {     // Signature isnt there - may be a new chip -     //   do a write to see if it will hold the signature     writeRTCreg(0x20,0x55);     if (readRTCreg(0x20) == 0x55) {       // We can store data - assume that it is a new chip that needs initialisation /*      // Start by clearing the clock halt flag.           //"Bit 7 of register 0 is the clock halt (CH) bit.           //When this bit is set to a 1, the oscillator is disabled."             byte _reg0_sec = decToBcd(scnd);             _reg0_sec = _reg0_sec & ~0x80;             writeRTCreg(0,_reg0_sec); */       // Set the time and date on the chip       scnd = 0;       mn = 0;       hr = 12;       setTime();       // set the DS1302 present flag       DS1307Present=true;       Serial.println("present - new chip initialised.");     }     else  Serial.println("absent");   }    msTick=millis();      // Initialise the msTick counter     selftest();   selftestmode=false;   if (DS1307Present) {     // Get the current time and date from the chip    getTime();     }     displaytime();        // display the current time } void ledsoff(void) { Display1=0; Display2=0; Display3=0; } void WriteLEDs(void) { // Now we write the actual values to the hardware shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display3); shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display2); shiftOut(LEDDataPin, LEDClockPin, MSBFIRST, Display1); digitalWrite(LEDStrobePin,HIGH); delay(2); digitalWrite(LEDStrobePin,LOW); } void selftest(void){   Serial.print("TEST");   analogWrite(PWMPin, 255);     ledsoff(); MTEN; WriteLEDs(); delay(500);   ledsoff(); HALF; WriteLEDs(); delay(500);   ledsoff(); QUARTER; WriteLEDs(); delay(500);   ledsoff(); TWENTY; WriteLEDs(); delay(500);   ledsoff(); MFIVE; WriteLEDs(); delay(500);   ledsoff(); MINUTES; WriteLEDs(); delay(500);   ledsoff(); PAST; WriteLEDs(); delay(500);   ledsoff(); TO; WriteLEDs(); delay(500);   ledsoff(); ONE; WriteLEDs(); delay(500);   ledsoff(); TWO; WriteLEDs(); delay(500);   ledsoff(); THREE; WriteLEDs(); delay(500);   ledsoff(); FOUR; WriteLEDs(); delay(500);   ledsoff(); HFIVE; WriteLEDs(); delay(500);   ledsoff(); SIX; WriteLEDs(); delay(500);   ledsoff(); SEVEN; WriteLEDs(); delay(500);   ledsoff(); EIGHT; WriteLEDs(); delay(500);   ledsoff(); NINE; WriteLEDs(); delay(500);   ledsoff(); HTEN; WriteLEDs(); delay(500);   ledsoff(); ELEVEN; WriteLEDs(); delay(500);   ledsoff(); TWELVE; WriteLEDs(); delay(500);   ledsoff(); OCLOCK; WriteLEDs(); delay(500); } void displaytime(void){   // start by clearing the display to a known state   ledsoff();     Serial.print("It is ");   // now we display the appropriate minute counter   if ((mn>4) && (mn<10)) {     MFIVE;     MINUTES;     Serial.print("Five Minutes ");   }   if ((mn>9) && (mn<15)) {     MTEN;     MINUTES;     Serial.print("Ten Minutes ");   }   if ((mn>14) && (mn<20)) {     QUARTER;       Serial.print("Quarter ");   }   if ((mn>19) && (mn<25)) {     TWENTY;     MINUTES;     Serial.print("Twenty Minutes ");   }   if ((mn>24) && (mn<30)) {     TWENTY;     MFIVE;     MINUTES;     Serial.print("Twenty Five Minutes ");   }    if ((mn>29) && (mn<35)) {     HALF;     Serial.print("Half ");   }   if ((mn>34) && (mn<40)) {     TWENTY;     MFIVE;     MINUTES;     Serial.print("Twenty Five Minutes ");   }    if ((mn>39) && (mn<45)) {     TWENTY;     MINUTES;     Serial.print("Twenty Minutes ");   }   if ((mn>44) && (mn<50)) {     QUARTER;     Serial.print("Quarter ");   }   if ((mn>49) && (mn<55)) {     MTEN;     MINUTES;     Serial.print("Ten Minutes ");   }   if (mn>54) {     MFIVE;     MINUTES;     Serial.print("Five Minutes ");   }   if ((mn <5))   {     switch (hr) {     case 1:       ONE;       Serial.print("One ");       break;     case 2:       TWO;       Serial.print("Two ");       break;     case 3:       THREE;       Serial.print("Three ");       break;     case 4:       FOUR;       Serial.print("Four ");       break;     case 5:       HFIVE;       Serial.print("Five ");       break;     case 6:       SIX;       Serial.print("Six ");       break;     case 7:       SEVEN;       Serial.print("Seven ");       break;     case 8:       EIGHT;       Serial.print("Eight ");       break;     case 9:       NINE;       Serial.print("Nine ");       break;     case 10:       HTEN;       Serial.print("Ten ");       break;     case 11:       ELEVEN;       Serial.print("Eleven ");       break;     case 12:       TWELVE;       Serial.print("Twelve ");       break;     }   OCLOCK;   Serial.println("O'Clock");   }   else     if ((mn < 35) && (mn >4))     {       PAST;       Serial.print("Past ");       switch (hr) {     case 1:       ONE;       Serial.println("One ");       break;     case 2:       TWO;       Serial.println("Two ");       break;     case 3:       THREE;       Serial.println("Three ");       break;     case 4:       FOUR;       Serial.println("Four ");       break;     case 5:       HFIVE;       Serial.println("Five ");       break;     case 6:       SIX;       Serial.println("Six ");       break;     case 7:       SEVEN;       Serial.println("Seven ");       break;     case 8:       EIGHT;       Serial.println("Eight ");       break;     case 9:       NINE;       Serial.println("Nine ");       break;     case 10:       HTEN;       Serial.println("Ten ");       break;     case 11:       ELEVEN;       Serial.println("Eleven ");       break;     case 12:       TWELVE;       Serial.println("Twelve ");       break;       }     }     else     {       // if we are greater than 34 minutes past the hour then display       // the next hour, as we will be displaying a 'to' sign       TO;       Serial.print("To ");       switch (hr) {       case 1:         TWO;        Serial.println("Two ");        break;       case 2:         THREE;       Serial.println("Three ");         break;       case 3:         FOUR;       Serial.println("Four ");         break;       case 4:         HFIVE;       Serial.println("Five ");         break;       case 5:         SIX;       Serial.println("Six ");         break;       case 6:         SEVEN;       Serial.println("Seven ");         break;       case 7:         EIGHT;       Serial.println("Eight ");         break;       case 8:         NINE;       Serial.println("Nine ");         break;       case 9:         HTEN;       Serial.println("Ten ");         break;       case 10:         ELEVEN;       Serial.println("Eleven ");         break;       case 11:         TWELVE;       Serial.println("Twelve ");         break;       case 12:         ONE;       Serial.println("One ");         break;       }     }    WriteLEDs();    } void incrementtime(void){   // increment the time counters keeping care to rollover as required   scnd=0;   if (++mn >= 60) {     mn=0;     if (++hr == 13) {       hr=1;      }   }    // debug outputs   Serial.println(); //  if (DS1307Present) //  print_DS1307time(); //  else{ //  Serial.print("Arduino Time: " );   Serial.print(hr);   Serial.print(":");   Serial.print(mn);   Serial.print(":");   Serial.println(scnd); //  } } void loop(void) {     //selftest(); int aread = sq(analogRead(3)/4)+3;   //Uncomment the following line and comment the next one in order to   //  enable dimming via a potentiometer connected to pin 0:   analogWrite(PWMPin, aread>255 ? 255:aread);   //analogWrite(PWMPin, 255);       // heart of the timer - keep looking at the millisecond timer on the Arduino     // and increment the seconds counter every 1000 ms     if ( millis() - msTick >999) {         msTick=millis();         scnd++; /*        // Flash the onboard Pin13 Led so we know something is hapening!         digitalWrite(13,HIGH);         delay(100);         digitalWrite(13,LOW);    */    }                 //test to see if we need to increment the time counters     if (scnd==60)     {       incrementtime();       displaytime();     } if (DS1307Present) {     // Get the current time and date from the chip      getTime();     }     // test to see if a forward button is being held down     // for time setting     if ( (digitalRead(MinuteButtonPin) ==0 ) && scnd!=1)       // the forward button is down       // and it has been more than one second since we       // last looked     {       mn=(((mn/5)*5) +5);       scnd=0;       incrementtime();       scnd++;  // Increment the second counter to ensure that the name       // flash doesnt happen when setting time       if (DS1307Present) {       // Set the time on the chip       setTime();     }     delay(100);       displaytime();     }     // test to see if the back button is being held down     // for time setting     if ((digitalRead(HourButtonPin)==0 ) && scnd!=1)     {       /*       minute=(((minute/5)*5) -5);       second=0; // decrement the minute counter       if (minute<0) {         minute=55;         if (--hour <0) hour=12;       }       */             mn = (mn/5)*5;  //round minute down to previous 5 min interval       if (++hr == 13) {         hr=1;        }       incrementtime();       scnd++;  // Increment the second counter to ensure that the name       // flash doesnt happen when setting time        if (DS1307Present) {       // Set the time and date on the chip       setTime();     }     delay(100);       displaytime();     } }

Question by pro2xy   |  last reply