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 6 years ago  |  last reply 6 years ago


A little sketch.

Just drew a picture and thought it was neat. One of my first using my new arm. Critique my style.

Topic by 8bit 10 years ago  |  last reply 10 years ago


Etch-a-Sketch clock

The Etch-a-Sketch gets a cool new hack with this clock that automatically draws in the time every minute and shakes it up in between. Slick.via Neatorama

Topic by fungus amungus 11 years ago  |  last reply 9 years ago


coMBINING ARDUINO SKETCHES

Every thing is okay except line follow command ,,,when i say line follow it only goes forward but does not follow line my code is String voice; int LS=10; int RS=9; int LED=13; char getstr; int in1=3; int in2=4; int in3=5; int in4=6; int ENA=2; int ENB=7; long duration, distance; int trigPin=A0; int echoPin=A1; int buzzer=8; void forward() {   digitalWrite(ENA,HIGH);   digitalWrite(ENB,HIGH);   digitalWrite(in1,HIGH);   digitalWrite(in2,LOW);   digitalWrite(in3,LOW);   digitalWrite(in4,HIGH);   } void back() {   digitalWrite(ENA,HIGH);   digitalWrite(ENB,HIGH);   digitalWrite(in1,LOW);   digitalWrite(in2,HIGH);   digitalWrite(in3,HIGH);   digitalWrite(in4,LOW);   } void left() {   digitalWrite(ENA,HIGH);   digitalWrite(ENB,HIGH);   digitalWrite(in1,LOW);   digitalWrite(in2,HIGH);   digitalWrite(in3,LOW);   digitalWrite(in4,HIGH);   } void right() {   digitalWrite(ENA,HIGH);   digitalWrite(ENB,HIGH);   digitalWrite(in1,HIGH);   digitalWrite(in2,LOW);   digitalWrite(in3,HIGH);   digitalWrite(in4,LOW);   } void stop() {   digitalWrite(ENA,LOW);   digitalWrite(ENB,LOW);   } void on() {   digitalWrite(LED,HIGH); } void off() {   digitalWrite(LED,LOW); } void line(){ if(digitalRead(LS) && digitalRead(RS))     // Stop   { stop();   }     if(!(digitalRead(LS)) && digitalRead(RS))     // right   { right();   }     if(digitalRead(LS) && !(digitalRead(RS)))     // Turn left   { left();   }     if(!(digitalRead(LS)) && !(digitalRead(RS)))     // Forward   {     forward();   } } void setup() {   pinMode(LED, OUTPUT);   Serial.begin(9600); pinMode(LS, INPUT);   pinMode(RS, INPUT);   pinMode(in1,OUTPUT);   pinMode(in2,OUTPUT); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT);   pinMode(in3,OUTPUT);   pinMode(in4,OUTPUT);   pinMode(ENA,OUTPUT);   pinMode(ENB,OUTPUT); pinMode(buzzer, OUTPUT); } void loop() {   while (Serial.available()){ //Check if there is an available byte to read      delay(10); //Delay added to make thing stable     char c = Serial.read(); //Conduct a serial read     if (c == '#') {break;} //Exit the loop when the # is detected after the word     voice += c; //Shorthand for voice = voice + c   }   if (voice.length() > 0){     if(voice == "*go ahead"){       forward();       }     else if(voice == "*go back"){       back();       }     else if(voice == "*turn right") {       right();     }     else if(voice == "*turn left") {       left();     }     else if(voice == "*light on") {       on();     }     else if(voice == "*light off") {       off();     }         else if(voice == "*stop") {       stop();     } else if(voice == "*line follow") { line();           }       voice=""; //Reset the variable after initiating   } }

Topic by BibekP4 1 year ago  |  last reply 1 year ago


Favorite Medium for sketching?

I've been a pretty-much strictly pen-and-paper sketch artist for most of my life but I've been looking into new canvas materials to doodle/create pieces on. Cardboard is a favorite right now. What do you dabble with?

Topic by fireatlions 10 years ago  |  last reply 9 years ago


blending sketch and photo

I saw an instructable on how to change part of a photo to sketch art and it was done with a motorcycle. I have searched and can not find it again. Anyone know where it is? Thank you

Topic by tryan1211 12 years ago  |  last reply 12 years ago


Compiling the Blink Sketch? Answered

When i compile the Blink sketch on a 328 it verifies OK. Compile the same blink sketch on a ATtiny85 verifies OK. Compile the same blink sketch on a ATtiny2313 it troughs an error every time. These are the same" family " of processor. When you download the 85 board files the 2313 board files come with it.  Same results from 23, 1 and 1.01 IDE's. I used an LPT programmer and can read the READ ALL files from the 2313 using Pony Prog. So there is a connection there. I just can not write the blink sketch to the 2313 cuz of the compile error. There is a lot of tutorials on how to program using this method, that i have read everyone i could, but to resolve the compile error i have not found an answer to. I would switch to an 85 but not available locally. Anybody come across this error before?   

Question by WWC 6 years ago  |  last reply 6 years ago


20$ for Arduino sketch

I will pay 20$ for Arduino sketch. please if you can do; reply here and I will send the flowchart. Flowchart steps: Arduino has one PIR sensor input. when sensor detects a surface at distance 25 cm or closer; it triggers 2 DC motors and 3 servo motors to move randomly. the 3 servos move back or forth at range 0- 60 degrees. Direction is random and amount of movement is also random. but speed is fixed 20 degrees per second. the 3 servos should move same time but independently. the 2 DC motors move forward only for 250ms at full speed. but the interval between on move and another is random between 1-3 seconds. they both independent from each other. you are free to choose which pins you use for input/output. use arduino Nano. Thanks for reading

Topic by goldenshuttle 4 years ago


Whats wrong with the sketch??

This arduino robo, there is no servo, this runs only with 2 geared motors, i made the sketch according to the needs bt it doent seem to making those turns even after sensing the obstacle. The ping sensor is functional and connected properly and thel293d ic is also functional..Pls tell me whats wrong with dis sketch..........  #include #define LeftMotorForward 11 #define LeftMotorBackward 10 #define RightMotorForward 9 #define RightMotorBackward 8 #define USTrigger 4 #define USEcho 5 #define MaxDistance 100 NewPing sonar(USTrigger, USEcho, MaxDistance); unsigned int duration; unsigned int distance; unsigned int FrontDistance; unsigned int LeftDistance; unsigned int RightDistance; void setup()  {     pinMode(LeftMotorForward, OUTPUT);   pinMode(LeftMotorBackward, OUTPUT);   pinMode(RightMotorForward, OUTPUT);   pinMode(RightMotorBackward, OUTPUT); }      void loop()                                           {                                            FrontDistance = distance;                               if(FrontDistance > 40 || FrontDistance == 0)          {    moveForward();                                      }   else                                                  {     moveBackward();         moveStop();                                           navigate();   } } void moveForward()                                    {   digitalWrite(LeftMotorBackward, LOW);   digitalWrite(LeftMotorForward, HIGH);   digitalWrite(RightMotorBackward, LOW);   digitalWrite(RightMotorForward, HIGH); } void moveBackward()                                 {     digitalWrite(LeftMotorForward, LOW);   digitalWrite(LeftMotorBackward, HIGH);   digitalWrite(RightMotorForward, LOW);   digitalWrite(RightMotorBackward, HIGH); } void moveLeft()                                     {     digitalWrite(LeftMotorForward, LOW);   digitalWrite(LeftMotorBackward, HIGH);   digitalWrite(RightMotorBackward, LOW);   digitalWrite(RightMotorForward, HIGH);   } void moveRight()                                   {     digitalWrite(LeftMotorBackward, LOW);   digitalWrite(LeftMotorForward, HIGH);   digitalWrite(RightMotorForward, LOW);   digitalWrite(RightMotorBackward, HIGH); } void moveStop()                                    {   digitalWrite(LeftMotorBackward, LOW);   digitalWrite(LeftMotorForward, LOW);   digitalWrite(RightMotorForward, LOW);   digitalWrite(RightMotorBackward, LOW); } void scan()                                       {     distance = sonar.ping_cm();   delay(500); } void navigate() {     moveLeft();     delay(1000);     scan();                                               LeftDistance = distance;                                moveRight();                                      delay(1000);     scan();       RightDistance = distance;                                    if(RightDistance < LeftDistance)                      {      moveLeft();                                           delay(200);                                          }     else if(LeftDistance < RightDistance)                 {      moveRight();                                          delay(200);                                          } }

Question by Ankan Nayak 4 years ago  |  last reply 4 years ago


Combing Arduino Sketches

Hello, I have a question. I need to combine my code for my Arduino Webserver with the code for my Parallax card reader. When I combine them only the RFID card part works? Can someone help me debunk this. I orginally wanted it to be when someone swiped a valid RFID card, that it would launch the webserver? I don't think that's possible though. Here's my code: #define RFID_ENABLE 2   //to RFID ENABLE #define CODE_LEN 10      //Max length of RFID tag #define VALIDATE_TAG 1  //should we validate tag? #define VALIDATE_LENGTH  200 //maximum reads b/w tag read and validate #define ITERATION_LENGTH 200 //time, in ms, given to the user to move hand away #define START_BYTE 0x0A #define STOP_BYTE 0x0D #include #include char ssid[] = "*******";      //  your network SSID (name) char pass[] = "*********";   // your network password char tag[CODE_LEN];  int readLed = 4; int invalidCardled = 5; int validCardled = 6; int ipCam = 7; int doorLock = 8; int alarm    = 9; int status = WL_IDLE_STATUS; WiFiServer server(1025); void setup() {   Serial.begin(2400);    Serial.println("Please Swipe Your Card.");   pinMode(RFID_ENABLE,OUTPUT);    pinMode(readLed, OUTPUT);   pinMode(validCardled , OUTPUT);   pinMode(invalidCardled, OUTPUT);   pinMode(ipCam, OUTPUT);   pinMode(doorLock, OUTPUT);   pinMode(alarm, OUTPUT);       if (WiFi.status() == WL_NO_SHIELD) {// check for the presence of the shield:     Serial.println("WiFi shield not present");     while(true);        // don't continue    // attempt to connect to Wifi network:   while ( status != WL_CONNECTED) {     Serial.print("Attempting to connect to Network named: ");     Serial.println(ssid);                   // print the network name (SSID);     // Connect to WPA/WPA2 network. Change this line if using open or WEP network:        status = WiFi.begin(ssid, pass);     // wait 10 seconds for connection:     delay(10000);   }   server.begin();                           // start the web server on port 80   printWifiStatus();                        // you're connected now, so print out the status   } }   void loop() {   //Start our main Arduino Loop   enableRFID();   //Enable the RFID card   getRFIDTag();   //Reads the tag   if(isCodeValid()) {  //Validates that the tag is good     disableRFID();  //Puts the RFID reader in to low power mode     sendCode();     //Sends the code read to the serial port     delay(ITERATION_LENGTH);  //Debounce?   } else {     disableRFID();  //Got a incomplete code..   }   Serial.flush();   clearCode();       WiFiClient client = server.available();   // listen for incoming clients   if (client) {                             // if you get a client,     Serial.println("new client");           // print a message out the serial port     String currentLine = "";                // make a String to hold incoming data from the client     while (client.connected()) {            // loop while the client's connected       if (client.available()) {             // if there's bytes to read from the client,         char c = client.read();             // read a byte, then         Serial.write(c);                    // print it out the serial monitor         if (c == '\n') {                    // if the byte is a newline character           // if the current line is blank, you got two newline characters in a row.           // that's the end of the client HTTP request, so send a response:           if (currentLine.length() == 0) {              // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)             // and a content-type so the client knows what's coming, then a blank line:                client.println("HTTP/1.1 200 OK");             client.println("Content-type:text/html");             client.println();                         client.println("");             client.println("");             client.println("Remote Security Solutions");             client.println("");                                     client.println("");             client.println("");                         client.println("");             client.println("");             client.println("Remote Door Control");             client.println("");             client.println("ATTENTION!!! SOMEONE IS TRYING TO ACCESS A SECURED DOOR!!!");                                                             // the content of the HTTP response follows the header:             client.println("");             client.print("PLEASE CHOOSE FROM ONE OF THE FOLLOWING OPTIONS BELOW.");             client.print("Unlock The Door:");             client.print("");             client.print("");             client.print("");             client.print("Lock The Door:");             client.print("");             client.print("");             client.print("");             client.print("Sound The Alarm:");             client.print("");             client.print("");             client.print("");                                               // The HTTP response ends with another blank line:             client.println();             // break out of the while loop:             break;                   }           else {      // if you got a newline, then clear currentLine:             currentLine = "";           }         }             else if (c != '\r') {    // if you got anything else but a carriage return character,           currentLine += c;      // add it to the end of the currentLine         }                 if (currentLine.endsWith("GET /1")) {           digitalWrite(ipCam, HIGH);                       }         if (currentLine.endsWith("GET /2")) {           digitalWrite(ipCam, LOW);                        }          if (currentLine.endsWith("GET /3")) {           digitalWrite(doorLock, HIGH);                       }         if (currentLine.endsWith("GET /4")) {           digitalWrite(doorLock, LOW);                       }          if (currentLine.endsWith("GET /5")) {           digitalWrite(alarm, HIGH);                       }         if (currentLine.endsWith("GET /6")) {           digitalWrite(alarm, LOW);                        }                        }     }     // close the connection:     client.stop();     Serial.println("client disonnected");   } }   /**  * Clears out the memory space for the tag to 0s.  */ void clearCode() {   for(int i=0; i     tag[i] = 0;   } }   /**  * Sends the tag to the computer.  */ void sendCode() {   //This is where I would add a return value (the code) to "validiate" or whatever at.     Serial.print("Valid Card ID Scanned:");      char full_tag[10];     for(int i=0; i       if (i == 9)  //Edits by riley porter         Serial.println(tag[i]);  //This checks to see if its the last byte       else                       //If it is it will print a "new line" so that the codes to jumble together         Serial.print(tag[i]);         } }   /**************************************************************/ /********************   RFID Functions  ***********************/ /**************************************************************/   void enableRFID() {    digitalWrite(RFID_ENABLE, LOW);    digitalWrite(validCardled, HIGH); }   void disableRFID() {    digitalWrite(RFID_ENABLE, HIGH); }   /**  * Blocking function, waits for and gets the RFID tag.  */ void getRFIDTag() {      byte next_byte;   while(Serial.available() <= 0) {}   if((next_byte = Serial.read()) == START_BYTE) {          byte bytesread = 0;     while(bytesread < CODE_LEN) {       if(Serial.available() > 0) { //wait for the next byte           if((next_byte = Serial.read()) == STOP_BYTE) break;                 tag[bytesread++] = next_byte;       digitalWrite(readLed, HIGH);       delay(25);       digitalWrite(validCardled, HIGH);       delay(25);       digitalWrite(invalidCardled, HIGH);       delay(25);       digitalWrite(readLed, LOW);       delay(25);       digitalWrite(validCardled, LOW);       delay(25);       digitalWrite(invalidCardled, LOW);       delay(25);       digitalWrite(validCardled, HIGH);       delay(25);       digitalWrite(validCardled, LOW);       delay(25);       digitalWrite(readLed, HIGH);           }     }                  }    }   /**  * Waits for the next incoming tag to see if it matches  * the current tag.  */ boolean isCodeValid() {   byte next_byte;   int count = 0;   while (Serial.available() < 2) {  //there is already a STOP_BYTE in buffer     delay(1); //probably not a very pure millisecond     if(count++ > VALIDATE_LENGTH) return false;   }   Serial.read(); //throw away extra STOP_BYTE   if ((next_byte = Serial.read()) == START_BYTE) {      byte bytes_read = 0;     while (bytes_read < CODE_LEN) {       if (Serial.available() > 0) { //wait for the next byte                if ((next_byte = Serial.read()) == STOP_BYTE) break;           if (tag[bytes_read++] != next_byte) return false;          digitalWrite(invalidCardled, HIGH);          delay(10);          digitalWrite(invalidCardled, LOW);                       }     }                  }   return true;     }   void printWifiStatus() {   // print the SSID of the network you're attached to:   Serial.print("SSID: ");   Serial.println(WiFi.SSID());   // print your WiFi shield's IP address:   IPAddress ip = WiFi.localIP();   Serial.print("IP Address: ");   Serial.println(ip);   // print the received signal strength:   long rssi = WiFi.RSSI();   Serial.print("signal strength (RSSI):");   Serial.print(rssi);   Serial.println(" dBm");   // print where to go in a browser:   Serial.print("To see this page in action, open a browser to http://");   Serial.println(ip); }

Topic by lonto81 6 years ago  |  last reply 6 years ago


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 6 years ago  |  last reply 6 years ago


Remove a sketch from ATmega328

Is It possible to remove a sketch from an Arduino with a 328 using the Arduino IDE? I have deleted the sketch from my PC. The program is running now but no more sketch in the Arduino files. Or is rewriting it the only way?   

Question by WWC 6 years ago  |  last reply 4 years ago


Knife's Edge- Sketch Up

This is a design I came up with and drew (i guess is the term) into sketch up. The Wings swivel up (shown in second Set of pics). This took about 10-15 hrs of drawing and about 2 hrs of rendering. The wings swivel to maneuver and when landing inside atmosphere. I haven't added weaponry and such so it's still a WIP. But suggestions are welcomed. Tech Specs: - Engines:             10 engines (4 small  large) -Take Off type:       VTOL - Class:                  Frigate - Operation zone: Space/ Atmosphere And for you sketch Up and rendering junkies...  used 40 passes in each render.

Topic by ry25920 8 years ago  |  last reply 8 years ago


My Sketch Up Ships

     I started working with sketch up about 3 months ago, since then, I've been converting my 2 designs into 3D models. www.conceptships.org/viewtopic.php  This the link to Concept Ships.com, where I have my 2D and some of my 3D designs posted. Other link: www.conceptships.org/viewtopic.php  . List: -- 1.) Convoy front isometric -- 2.) Convoy close one- General Frigate -- 3.) Convoy close two- Heron II with container -- 4.)  Convoy close three- side -- 5.) Convoy rear -- 6.) Heron Front iso (the thing below is the container) -- 7.) Heron Back iso -- 8.) Heron front -- 9.) Transport front iso -- 10.) Transport back iso -- 11.) Transport bottom -- 12.) Transport turret -- 13.) Dropship front -- 14.) Dropship Weaponry -- 15.)  Dropship rear -- 16.) Life support pod front -- 17.) Life Support pod back -- 18.) OH SANP!!! Instructables HQ is under attack!!! Ship explainations:: -- CCM-21b "Heron II" - UH-60 of this faction - Can be used as a gunship, APC, fighter - bomber, transport, or ECM/ Support, depending on the module. - The cargo module (below craft) can be load with anything from missles, to bombs, to twin 30mm gating guns (personal favorite). - Carries two (pilot, co-pilot/ gunner). - VTOL - Basically my spin on the Pelican from Halo (hopefully it doesn't get shot down as much) LSPS II "Messiah" (life Support pod) - This is the generic life support pod. Similar to halo, but no re-entry... we all saw how reliable that was. - Holds 6 people (pilot, 5 auxillery) - supports 6 for up to 2.5 weeks. - Has a powerful SOS beacon. - Used by military and civilian. - Launch method: launched from ship by air rushing from the pod's chamber and conventional thrust (Fuel + oxidizer). All ships were designed and 3D- ified by me... google earth was used in the ibles HQ screenshot

Topic by ry25920 9 years ago  |  last reply 9 years ago


Help with this Arduino sketch please... Answered

I got this sketch for flashing LED's off a site the other day and have been playing with it to try and have a couple of the LED's on all the time but I have failed, can someone please give me some help. int sensorValue = 0;    //make a variable where you can store incoming                         //analog values void setup(){   pinMode(12, OUTPUT);  //tell arduino what you'll be using these pins   pinMode(11, OUTPUT);  // for (output).   pinMode(10, OUTPUT);   pinMode(9, OUTPUT);   pinMode(8, OUTPUT);   Serial.begin(9600);  //initialize serial } void loop(){      //we put the code we want executed in a loop Serial.print("sensor = " );  //sends what's in quotes via serial Serial.println(sensorValue); //sends our variable (sensorValue)                              //via serial     digitalWrite(12,HIGH);       // lights the led   sensorValue = analogRead(0); // reads pin 0   delay(sensorValue + 25);     // sensorValue used for delay   digitalWrite(12,LOW);        //turns off the led   delay(15);                   //delay before moving to next output pin                                //the + 25 keeps delay from reaching zero            //code below is for remaining 4 LEDs   digitalWrite(11,HIGH);   sensorValue = analogRead(0);   delay(sensorValue + 25);   digitalWrite(11,LOW); delay(15);   digitalWrite(10,HIGH);   sensorValue = analogRead(0);   delay(sensorValue + 25);   digitalWrite(10,LOW); delay(15);   digitalWrite(9,HIGH);   sensorValue = analogRead(0);   delay(sensorValue + 25);   digitalWrite(9,LOW); delay(15);   digitalWrite(8, HIGH);   sensorValue = analogRead(0);   delay(sensorValue + 25);   digitalWrite(8, LOW); delay(15);   digitalWrite(9,HIGH);   sensorValue = analogRead(0);   delay(sensorValue + 25);   digitalWrite(9,LOW); delay(15);   digitalWrite(10,HIGH);   sensorValue = analogRead(0);   delay(sensorValue + 25);   digitalWrite(10,LOW); delay(15);   digitalWrite(11,HIGH);   sensorValue = analogRead(0);   delay(sensorValue + 25);   digitalWrite(11,LOW); delay(15); }

Question by lifeofB 4 years ago  |  last reply 4 years ago


Help with sketch, and a safety question? Answered

The model I'm building calls for 13 LED's and fiber optics running from about 6 more LED's. I have managed to get them all running on one arduino and breadboard, will this be safe? The arduino will run on a mains adapter and has a pot for flashing speed, a pot for brightness, and an on/off switch. After lots of trial an error and a lot of luck I have the other LED's acting just as I want. But I am having trouble getting 11 and 12 to stop flashing, any ideas? int sensorValue = 0; //make a variable where you can store incoming //analog values void setup(){ pinMode(12, OUTPUT); //tell arduino what you'll be using these pins pinMode(11, OUTPUT); // for (output). pinMode(10, OUTPUT); pinMode(9, OUTPUT); pinMode(8, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT); pinMode(5, OUTPUT); pinMode(4, OUTPUT); Serial.begin(9600); //initialize serial } void loop(){ //we put the code we want executed in a loop Serial.print("sensor = " ); //sends what's in quotes via serial Serial.println(sensorValue); //sends our variable (sensorValue) //via serial digitalWrite(12,HIGH); // lights the led digitalWrite(11,HIGH); digitalWrite(8,HIGH); digitalWrite(4, HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(4, LOW); delay(15); digitalWrite(6, HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(6, LOW); delay(15); digitalWrite(5, HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(5, LOW); delay(15); digitalWrite(7, HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(7, LOW); delay(15); digitalWrite(5, HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(5, LOW); delay(15); digitalWrite(10,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(10,LOW); delay(15); digitalWrite(9,HIGH); sensorValue = analogRead(0); delay(sensorValue + 25); digitalWrite(9,LOW); delay(15); }

Question by lifeofB 4 years ago  |  last reply 4 years ago


sketch for a traffic light 4 way?

Sketch for a traffic light 4 way

Question by saleh alomari 6 years ago  |  last reply 6 years ago


How to upload a sketch on an Atmega 8 IC?

Hey frnds! we r working on a simple persistence of vision project. for that i'v bought a cheap Atmega 8 From here: Robomart Atmega 8 Project Board With Controller V 1.0 I think it have arduino bootloader by before but i dont know how to upload a sketch to it. I have an arduino uno by before. Can it help in some way?

Question by DELETED_Snehil1101 3 years ago  |  last reply 3 years ago


Arduino sketch not working how i want it.

Hi everyone, I've got a short sketch that doesn't behave how I expected to, just want to know what I did wrong. What i want it to do.push button 1 and led 13 lights uppush button 2 and no leds light uppush button 1 and 2 and Led 12 lights upWhat it actually does is push button 1 and led 13 lights uppush button 2 and no leds light up push button 1 and 2 and Led 12 and 13 lights up.Iv tried a few things, but it doesn't make any difference, any IdeasthanksNow how do I get the code on here without making a mess? heres a screen shot thankfully it a short sketch

Question by liquidhandwash 8 months ago


I am stuck on one part of my sketch, handle button stepper(50) issue?

I originally had this sketch working with a servo, but i over stressed it and it failed. So i changed it to a stepper. Everything is working correctly, keypad will operate the stepper and helper lights ect except the handle button does not operate the stepper. Button press shows in the serial monitor and i put a serial.write very close to the end that says -  last line -  and it shows in the serial monitor . But for some reason the sketch seams to skip over the if statement for the handle button operation.  What did i not do correctly?  #include #include #include //Stepper myStepper; Password password = Password( "4444" ); //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. // 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            100  // Delay per loop in ms Stepper myStepper(stepsPerRevolution, 9,10,11,12);            boolean handle_button() {   int button_pressed = !digitalRead(BUTTON_PIN); // pin low -> pressed   return button_pressed; } 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      keypad.addEventListener(keypadEvent); //add an event listener for this keypad } void loop() {    //handle button   boolean button_pressed = handle_button();   // do other things   Serial.println(button_pressed ? " button press" : ".");     static int counter = 0;   if ((++counter & 0x3f) == 0)    Serial.println();   delay(DELAY);   keypad.getKey();   myStepper.step(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(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);     myStepper.step(50);     Serial.print(" open ");     digitalWrite(16, HIGH);//turn on green led     delay(2000); //wait 5 seconds     digitalWrite(16, LOW);// turn offgreen led     myStepper.step(-50);   }  //Closes if password.evalute   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       }  //Closes first else   if (handle_button == LOW)   {              Serial.write (" pressed ");         myStepper.step(50);      Serial.write(" clockwise ");           digitalWrite(15, HIGH);//turn on helper light     delay(2000); //wait 5 seconds     myStepper.step(-50);     digitalWrite(15, LOW);// turn off helper light   //}   //Closes if handle button low   //else // {        //myStepper.step(0);     //digitalWrite(15, LOW); //turn on     //delay(2000); //wait 5 seconds     //digitalWrite(15, LOW);//turn off      Serial.println(" last line");           delay(50); //wait 5 seconds        }  // Closes second else }  //Closes Check password // this routine turns off the light when the timer expires 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 6 years ago  |  last reply 6 years ago


How to draw people?

Anyone know any good instructable for drawing people? Like the shapes and techniques and stuff?

Question by Catherine12345 8 years ago  |  last reply 8 years ago


How to draw storyboards in a quick observation setting?

I'm looking for the techniques of drawing basic shapes to record objects and actions in a field setting. A simple storyboard with outline figures would be my end goal.

Question by 10 years ago  |  last reply 10 years ago


Rate my art

Hey, I recently drew a portrait of Lady Gaga, and I have then added some colour to it using photoshop. I would love if you guys could give me any critques or positives about it, so that I can improve it! And then I can start working on other drawings I have done too. Thanks :)

Topic by rebeccah18 3 years ago  |  last reply 1 year ago


github!

I just learned that codebender is closing up shop. Sometimes my arduino folder feels like it's a mess so I was using codebender for my final code. I guess I should be using github though. I'd like some guidance about how to better use github. I'm familiar with other people's github pages but I'm not sure about how to use my own. Can the instructables community help me out? Thanks!!

Topic by _Amelia_ 2 years ago  |  last reply 2 years ago


Arduino code help input binary to pin 4?

Unsigned char APin=4; unsigned char BPin=5; unsigned char CPin=6; unsigned char PinState; unsigned char LastPinState=B111;  // As in High, High, High for random mode pinMode(APin, INPUT);   pinMode(BPin, INPUT);   pinMode(CPin, INPUT);   digitalWrite(APin, HIGH);   digitalWrite(BPin, HIGH);   digitalWrite(CPin, HIGH); this code im using is outdated for me now and im using an iphone to send binary commands to atmel328 chip witch tells sends the binary code out a pin to my arduino can i recieve a b101 or b111 on pin 4 or any other pin. how do i change what i have right now it reads the state of pins 4,5,6 aka a,b,c and displays different messages. so if i ground b and c it plays one of the messages and so on i dont want this i want to take the b001 being sent from my other boards and use it on pin 4 aka a void loop(){   PinState = B111;       // Read ABC and assign to a 3 bit number   if(digitalRead(CPin)==LOW){        // A if Gnd -1 to make B??0     PinState = PinState - 1;                     }   if(digitalRead(BPin)==LOW){        // B if Gnd -2 to make B?0?     PinState = PinState - 2;      }   if(digitalRead(APin)==LOW){        // C if Gnd -4 to make B0??     PinState = PinState - 4;      }   if (PinState != LastPinState){     LastPinState = PinState;     switch (PinState){       case B000:{    // B000  HPs all on random on/off         if((FrontHPStateDefault==0) && (RearHPStateDefault==0) && (TopHPStateDefault==0)){           FrontHPStateDefault=3;           RearHPStateDefault=3;           TopHPStateDefault=3;         } else {           FrontHPStateDefault=0;           RearHPStateDefault=0;           TopHPStateDefault=0;         }         break;       }       case B001:{    // B001 Cantina MP3         FeedString    (1, FrontHPStateDefault, RearHPStateDefault, TopHPStateDefault, 1,0, 0, "<<<<<<<<<");         break;       }       case B010:{    // B010 Han Shot First         FeedString    (8, 3,3,3, 1,1, 1, " HAN SHOT FIRST! ");         break;       }       case B011:{    // B011 Short Circuit         Failure       (7, 5,5,5, 8);         LogicOffDelay (6, 0,0,0, 1, 20);         FailureReverse(8, 4,4,4, 2);         break;       }

Question by slipnots 5 years ago  |  last reply 5 years ago


Arduino - Trigger only Section of sketch

Hi. My sketch is to run 3 different relays over a different periods. I am new to arduino, and what i Know up untill know I've learned from reading it up. Please help me how to use an input to trigger certain parts of the sketch(the different periods) Thanks!

Topic by Rookie89 2 years ago  |  last reply 2 years ago


Multiple "void setup" in Arduino sketch? Answered

Hello ! Can I use more than one '''void setups' simultaneously in one arduino sketch. Something like that - void setup() { code  } void setup1() { code 2  } void setup2() { code 3 } I saw in here that I can run multiple "void loops" simultaneously in sketch.

Question by Konstantin Dimitrov 3 years ago  |  last reply 2 years ago


Sketch Furniture - 3D designed and printed

The four FRONT members have developed a method to materialise free hand sketches. They make it possible by using a unique method where two advanced techniques are combined. Pen strokes made in the air are recorded with Motion Capture and become 3D digital files; these are then materialised through Rapid Prototyping into real pieces of furniture.Trendwatching's analysis:Swedish design group FRONT has launched Sketch Furniture, which is a method to materialize freehand sketches. Pen strokes made in the air are recorded with Motion Capture, and the resulting 3-D patterns are output digitally to a laser sintering machine. Over several days, the machine produces the object by shaping and hardening 0.1-mm layers of liquid plastic. Sketch Furniture is on view and on sale (about USD 10,500 per piece) at the Barry Friedman Gallery in New York.

Topic by ewilhelm 11 years ago  |  last reply 11 years ago


Using GoogleSketchup

Hi I'am new to Sketchup Does anyone know where to get a tutorial or have any tips for Sketchup????

Topic by Mattrox 9 years ago  |  last reply 9 years ago


Drawing Instructables

Just to let you guys know (you guys being members of the group PWMMOP) I am working on another drawing instructable that I'm hoping to publish soon. So their will be more instructables in the group soon. Hopefully, new ones will start coming as new members are added also. I'm hoping to make more drawing instructables after I finish the one I'm working on but I need ideas. So...if you have any ideas please let me know!!!

Topic by LoneWolf 9 years ago


Arduino Code Help

Hello! for(int i=0; i<5; ++i) I know this little bit of code is probably very simple but for some reason I'm having a hard time understanding it. It seems like 'i' would be reset to 0 ever time it was done with the statement in brackets. How can you put multiple test statements inside of a if statement? When I try to add another one  like this for(int i=0; i<10; i>3; ++i), it doesn't work. Why can't I add another one? Why is it ++i? I thought it was supposed to be i++. Could someone please explain it? Thanks! for(int i=0; i<5; ++i)  {    repeat something in here    delay(100);  }

Topic by HavocRC 5 years ago  |  last reply 5 years ago


Arduino programming help: Do two things at once!

So I'm making a new project but I ran up into a little problem with the code. So this is what I want: Arduino check to see if A0 is HIGH, If so, turn on LED for 5 minutes. If, during any period within the 5 minutes, if pin A0 goes HIGH again, then start the 5 minutes all over again.  So basically every time pin A0 is HIGH no matter when always start a new 5 min timer. This is what I had. . . void loop() {     pirstate = digitalRead(pir);     if (pirstate == HIGH)   {     digitalWrite(LED, HIGH);     digitalWrite(relay, HIGH);     delay(pulse);   }    else   {     digitalWrite(LED, LOW);     digitalWrite(relay, LOW);   }   } The only problem with the above code is that it doesn't do anything while waiting the 'pulse' time. I need it to be able to within 'pulse' time check again to see if the pin is HIGH, and if it is, start all over again with 'pulse' seconds. Thanks guys! Your help is invaluable!

Topic by HavocRC 6 years ago  |  last reply 3 years ago


if/else Arduino code

So I need a little help building some if/else statements. I went to the Arduino website but there wasn't a whole lot of information there. I need some help with reading analog input and reacting to them. I'm not totally sure how to use the == either, I know it means do something if one thing is equal to, but. . . Also, with the if/else, I need some help with using >= => (i think??) as well as true and false. I also think you can like use two different if statements and only one else. Could I get a little assistance from you guys!? Here's an example: if(analog_in (is less than) 5) {  do something here  } else {  do another thing here } Here's another example: if(analog_in (is equal to, I think ==) 5); {   analogWrite(LED, 100); } if(analog_in (is greater than) 5); { analogWrite(LED, 255); } if(analog_in (is less than 3, but greater than 1); {  analogWrite(LED, 50); } and if none of that is true, then do this else {  digitalWrite(LED, LOW); } So you can see I need some help!  Thanks!

Topic by HavocRC 6 years ago  |  last reply 3 years ago


Change sketch got invalid operation!

I want to change the sketch dimension but I got invalid operation when i try to change it. Also why somes lines are in green? what does that mean?

Question by cwl123d 5 years ago  |  last reply 5 years ago


Debounce arduino push button sketch

Hi, I have done the following sketch and wiring, i have tried all sorts of Debounce code in the sketch but can't get it to stop. Most of the sketches i have read and tried switch the led on with one push and off with the second. i just want it to stay on while being pushed and go off while not being pushed, i am working towards RF or Bluetooth but not until i stop this bounce!

Topic by Senken 4 years ago  |  last reply 4 years ago


How to upload a sketch to a barebones arduino? Answered

Hey friends! After seeing a few instructables on making a barebones arduino i decided to make one. But there is a problem. I cannot find and FTDI serial to USB cable around. Also i read that a duemilanove can be used to upload the sketch. I have an UNO. Can it be used to upload sketch without taking off the ic because i think that i will be damaged while snapping off. Plz help.

Question by DELETED_Snehil1101 3 years ago  |  last reply 3 years ago


bi-color LED sketch will not work?

I have downloaded the BiColorLED.pde sketch but I cannot get it to work and I cannot figure out what I am missing? I am trying to follow the Basic exercises on a Mac using Arduino, but I cannot get this one to work.

Question by atlas2 6 years ago  |  last reply 6 years ago


URGENT!!!sketch for arduino robot with ping?

I am making an arduino obstacle avoiding robot for my science project.. But i am not getting a suitable sketch for a ping to use with it. I am only getting that of sharp ir sensor. Please help me out with a sketch..its urgent..below i have linked the site where there is the sketch and the project dat i want to make..... http://communityofrobots.com/tutorial/kawal/how-make-your-first-robot-using-arduino

Question by Ankan Nayak 4 years ago  |  last reply 4 years ago


Help with basic arduino sketch for Halloween

Hello all, I'm very new to Arduino programming, and was trying to write a basic sketch to flash some LEDs in a jack o lantern for halloween, but I'm struggling with the code. Essentially what I wanted to accomplish was blinking a LED from pin 13 x times, followed by fading (pulsing) another LED from pin 9 x times and then repeat.   If anyone would be so kind as to help me accomplish this, I would be very grateful. Thanks in advance.

Topic by SubEclipse 6 years ago  |  last reply 5 years ago


My Sketch Up designs (rendered)

 These were made in Sketch Up over the past 2-4 months. Most of them are almost finished, they just need texturing. Index: List of ships: - 3300mm anti-capital gun - CCM-21b "Heron 2" - Battleship and it's render /w/ editing - XUAP Medium Assault Craft (Atomosphere model, space version coming soon) - Missile Cruiser (based on missile frigate in halo) - MGV (Modular Ground vehicle) And I had an issue on another forum... If you don't like it so much that you have to start flaming... just click the little x in the top right (or the red button on the top left for Mac users) or click the back button. Please, if you wanna use this, give me credit for what I did. I spent about 4 months almost

Topic by ry25920 8 years ago  |  last reply 8 years ago


Help with an arduino 16x2 LCD sketch?

Hey all. Im new to arduino and have bought a 16x2 lcd to learn more about the ide. I was able to write the simple text. Then i also scrolled it. But now i want that the upper line should be static and the lower line should move. How can i achieve this effect. Also when scrolling a piece of sentence (lets say right to left), when the sentence goes completely toward left, it doesn't appear from the right until the whole sentence has not disappeared. This leaves a lot of space in between. I want that the moment text touches the left, it starts coming back from the right ( like what was there in the old snakes game that came with all primitive phones).  Plz reply fast......Thanks a lot! :)

Question by SnehilSensei 3 years ago  |  last reply 3 years ago


help with my sketch anyone please....

const int TxPin = 6;       //lcd pin const int buttonPin1 = 2;  //pins that are for const int buttonPin2 = 3;  //buttons to open valves const int buttonPin3  =  4;                       // and pumps const int buttonPin4 = 5;    const int pumpPin = 9;        //pin that turns on the pump    const int valvePin1 = 13;        //pins that run valves const int valvePin2 = 12;       const int valvePin3 = 11; const int valvePin4 = 10; int buttonState1 = LOW;           //setting the button state to low int buttonState2 = LOW; int buttonState3 = LOW; int buttonState4 = LOW; const int PROBE1=A0, PROBE2=A1, PROBE3=A2, PROBE4=A3; int MOISTURE_LEVEL = 250;                              //the value after the valves and pump goes ON #include SoftwareSerial mySerial = SoftwareSerial(255, TxPin); void setup() {        pinMode(pumpPin,OUTPUT);    // sets pumpPin to output    pinMode(valvePin1,OUTPUT);    // sets valvePins to output    pinMode(valvePin2,OUTPUT);    pinMode(valvePin3,OUTPUT);    pinMode(valvePin4,OUTPUT);    pinMode(TxPin, OUTPUT);          //lcd pin to output    digitalWrite(TxPin, HIGH);            digitalWrite(pumpPin, LOW);         digitalWrite  (valvePin1,LOW);    digitalWrite(valvePin2,LOW);    digitalWrite(valvePin3,LOW);    digitalWrite(valvePin4,LOW);    mySerial.begin(9600);    mySerial.write(22);                // turns display on    mySerial.write(17);                // turn on lcd back light      mySerial.write(12);                 // Clear  LCD    delay(5);                          //required delay after clear Lcd                                    } void loop(){    mySerial.write(128);        // sets sets lcd cursor to line 0 space 0   mySerial.print("S1-");      mySerial.write(148);           // sets lcd cursor to line 1 space 0   mySerial.print( "S2-");      mySerial.write(168);              //sets lcd cursor to line 2 space 0   mySerial.print("S3-");      mySerial.write(188);              //sets lcd cursor to line3 space 0   mySerial.print( "S4-");      mySerial.write(132);               //sets lcd cursor to line 0 space 4   mySerial.print (analogRead(A0));    mySerial.write(152);               //sets lcd cursor to line 1 space 4   mySerial.print (analogRead(A1));    mySerial.write(172);                //sets lcd cursor to line 2 space 4   mySerial.print (analogRead(A2));     mySerial.write(192);               //sets lcd cursor to line 3 space 4   mySerial.print (analogRead(A3));                if (analogRead(A3) < MOISTURE_LEVEL) {     digitalWrite(pumpPin, HIGH);     digitalWrite(valvePin1, HIGH); }    else   {     digitalWrite(pumpPin, LOW);     digitalWrite(valvePin4, LOW); }   if (analogRead(A1) < MOISTURE_LEVEL)   {     digitalWrite(pumpPin, HIGH);     digitalWrite(valvePin2, HIGH); }   else   {     digitalWrite(pumpPin, LOW);     digitalWrite(valvePin2, LOW); }       if (analogRead(A2) < MOISTURE_LEVEL)   {     digitalWrite(pumpPin, HIGH);     digitalWrite(valvePin3, HIGH); }   else   {     digitalWrite(pumpPin, LOW);     digitalWrite(valvePin3, LOW); }    if (analogRead(A0) < MOISTURE_LEVEL)   {     digitalWrite(pumpPin,HIGH );     digitalWrite(valvePin1, HIGH); }   else {     digitalWrite(pumpPin, LOW);     digitalWrite(valvePin1, LOW); }

Topic by s1im 6 years ago  |  last reply 6 years ago


Is it possible to upload a new Arduino, already compiled sketch with VB or C?

Hello everyone, so my question is: Is it possible to upload already compiled sketch with the Arduino IDE (.ini file) with a program created in VB or C?

Question by mart225 3 years ago  |  last reply 3 years ago


Problems copy/pasting arduino sketch code into my instructable

Hi there, as I type this in the text box, I see  a source button at the far right of the formatting line, but when I edit my instructable I dont have this option, I have a much more basic range of options. I have recently upgraded to pro membership and was wondering if I need to do something  to get this option to have nicely formatted source code in my instructable

Topic by break_it_fix_it 3 years ago  |  last reply 3 years ago


Arduino true and false statements

So I'm having the worst trouble tying to figure out how to use true and false statements. Can anyone explain how to define something as true and how to use it! An example sketch maybe? Thanks!

Topic by HavocRC 6 years ago  |  last reply 6 years ago


how do i get knex pieces with google sketch up?

Title explains it.

Topic by the dawg 11 years ago  |  last reply 10 years ago


What Do You Like To Draw?

What type of art do you do? (i.e. painting, sculpting, pastels, graphite, charcoal etc.) What do you like to draw? (i.e. landscapes, animals, people etc.) 

Topic by LoneWolf 9 years ago  |  last reply 3 years ago


Is there anywhere that sells moleskine sketchbooks on the cheap?

I want to find moleskine sketchbooks that are cheaper than usual. I can't find them for a descent enough price to get them.

Question by techgeek13 9 years ago  |  last reply 9 years ago


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 9 years ago  |  last reply 1 year ago


Cone with rounded ends in Google Sketch Up?

How do you make a cone with rounded ends in Google Sketch Up?

Question by sparky123 7 years ago