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


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


sketch for a traffic light 4 way?

Sketch for a traffic light 4 way

Question by saleh alomari   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


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   |  last reply


Cone with rounded ends in Google Sketch Up?

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

Question by sparky123 


Uploading a single sketch to multiple arduino boards

Hi, I want to upload the same sketch to multiple arduino boards, say for eg 15 to 20 arduino uno boards. What could be the easiest way to do so? Thank You,

Topic by xshanky   |  last reply


Trying to get help with arduino photocell sketch... Answered

Not too familiarl with writing arduino sketches but I'd like to connect a photocell to arduino so that when  a shadow is casted upon a photocell nothing happens but when exposed to light again it triggers an action. Any help would be much appreciated. I've looked for any project like this but have been unable to find anything. 

Question by purpulhaze   |  last reply


Need help with changing arduino code for more servos Answered

This code makes a continuous rotation servo motor turn on and run until you let go of the button. I need to change this sketch so that there are 3 buttons, instead of 1, and if I press 1, a continuous rotation servo would turn for each button until I let go of the button. #include Servo myServo; int servoPin = 2; int buttonPin = 7; int buttonState = 0; void setup() {   // put your setup code here, to run once: pinMode(buttonPin, INPUT); myServo.attach(servoPin); } void loop() {   // put your main code here, to run repeatedly: buttonState = digitalRead(buttonPin); if (buttonState == HIGH) {   myServo.write(0); }else{   myServo.write(90); } delay(15); }

Question by Orange robot   |  last reply


How to get rid of decimals or add them? Answered

So here's my code. void loop() {   int pot = analogRead(A0);   float xval = pot * (10.0 / 1023.0);   Serial.println(xval); } When I open up serial monitor, I get a number (1-10 depending on my potentiometer) and two decimals. How do I make go in whole number increments? 1, 2, 3, etc? Can you show me the code and explain it? Also, here's another example centimeters = (xval * 2.54); Serial.print(centimeters); In this example, I only get a whole number. Can somebody show me some code to make it show decimals? Explain some code? Thanks!

Question by HavocRC   |  last reply


HELP! With Arduino coding.

Im working on a project to link 2 radios to make an em-comm repeater. I need the Arduino to preform the duty of the controller, and turn the transmitter on when a signal is received. I have all the sensors figured out, i just need help on the code, which il include at the end. if anyone can help, your name will be given kudos in the instructable, and will have my eternal gratitude! The entire project only takes up 4 digital pins, which are the receiver senseor(sensePin), the transmiter key(trigPin), the busy led(busyPin) and the ready led(readyPin). The idea is that when sensePin reads a HIGH state when a signal is received, it will set trigPin to HIGH, keying the transmitter, and set busyPin to HIGH, activating the BUSY indicator.At the end of this proccess, i would need a 3-5 second delay before the standby/ready sequence. When sensePin is read as LOW, trigPin & busyPin would be set LOW and readyPin would be set HIGH, activating the READY indicator. #define sensePin 13 #define trigPin 12 #define busyPin 11 #define readyPin 10 void setup() { pinMode(trigPin, OUTPUT); pinMode(busyPin, OUTPUT); pinMode(readyPin, OUTPUT); pinMode(sensePin, INPUT); } void loop() { if(sensePin, HIGH){digitalWrite(trigPin, HIGH); digitalWrite(busyPin, HIGH); digitalWrite(readyPin, LOW); delay(5000);} else {digitalWrite(trigPin, LOW); digitalWrite(busyPin, LOW); digitalWrite(readyPin, HIGH);} if(sensePin,LOW){digitalWrite(trigPin, LOW); digitalWrite(busyPin, LOW); digitalWrite(readyPin, HIGH);} else {digitalWrite(trigPin, HIGH); digitalWrite(busyPin, HIGH); digitalWrite(readyPin, LOW);}} If anyone can figure this out, like i said,i would be eternally greatful!

Topic by KJ4ZVQ   |  last reply


where can I get the cost of I Love Sketch software?www.ilovesketch.com?

Where can I get the cost of I Love Sketch software?www.ilovesketch.com? This software is designed for freehand sketching for product design.

Question by rmoffatt   |  last reply


How do I edit the sketch of a stl file that has Certificate Trust File error?

I am able to by-pass the error that says the file is Certificate Trust File, but in solidwirks I am unable to edit the sketch. I thought you just click on sketch and go from there, but that doesn't make the model go into sketch mode. Thanks

Question by ReharnaW   |  last reply


Making thermite. How do i open etch a sketch. Answered

I am trying to open my etch a sketch so i have aluminum powder for thermite. How do i get the sketch open???it has no screws whatsoever and i cant seem to pry it open with screw driver.

Question by The Red Button   |  last reply


Whi cant i use my Google sketch up 8 model on Google earth? Answered

I have recently been playing around on Google sketch up 8, i have successfully made a model of a school building, however i can not use it in Google earth like i should be able to. any idea whi i cant post this ? 

Question by knuckel   |  last reply


Adding Arduino Libraries Answered

This sketch requires 3 libraries; Password.h Keypad.h Servo.h. The servo.h is in red, i suspect that librarie is recognizes and being used by the main sketch. The other 2 are black and throw an error. The files are in the same place as the servo.h file but is not recognized by the main sketch. How to include them so the sketch compiles? 

Question by WWC   |  last reply


How do I make a cone in Google Sketch Up?

I have been working on a project in Google Sketch Up and I put it on hold because I don't know how to make a cone with rounded ends in Google Sketch Up. I'll post pictures when I'm done. Please help!

Question by sparky123 


Help with programming an arduino hexapod with 18 dof? Answered

I have just finished designing and building a hexapod with 18 DOF..  powered by arduino nano and a 32 channel servo controller. i need help with code.   So far, i have'nt even stroked a keyboard to start programming. truth is, i dnt know where to start, im new at  this. If someone is willing to help me start if of or send me sample Code that would be much appreciated. Thanks in advice.

Question by icey.hood   |  last reply


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


Uploading to ATmega328 with preloaded blink sketch through ArduinoISP doesnt work?

I'm using my Arduino Mega as an ISP and have successfully uploaded a blink sketch to an atmega on a breadboard, with the led @ D13. Thats the SCK pin, and now i cant upload another program to the atmega on the breadboard. I tried resetting both the boards JUST before uploading, but it didnt work. my connections are secure, reset pin is tested, auto-reset is off. im at a loss. Please HELP!!!

Topic by DangerousTim   |  last reply


Transfer my Licensed Google Sketch Up Pro from my Pc Desktop to my Pc laptop ?

 Can it be done? It would go from XP to 7.

Question by Chromatica   |  last reply


My code compiles, but doesn't work?? Answered

Hi, i'm doing a project based on the capacitive sensor method. the code will work fine as standard, but when its  with my added extras it doesnt work but it compiles. The other thing is that the its printing to the serial at 3.4 seconds, do you know why this might be. here's the code. #include #include Servo Mech; int pos = 0;   /*   * CapitiveSense Library Demo Sketc  * Paul Badger 2008 5.  * Uses a high value resistor e.g. 10M between send pin and receive pin 6  * Resistor effects sensitivity, experiment with values, 50K - 50M. Larger resistor values yield larger sensor values. 7.  * Receive pin is the sensor pin - try different amounts of foil/metal on this pin 8.  */     CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired CapacitiveSensor   cs_4_6 = CapacitiveSensor(4,6);        // dnt need this CapacitiveSensor   cs_4_8 = CapacitiveSensor(4,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil int light = 13; int yellow = 12; //dnt need this int power = 11; int fans = 5; boolean status_light = LOW, status_light_prev = LOW; boolean status_yellow = LOW, status_yellow_prev = LOW; // dnt need this boolean status_power = LOW, status_power_prev = LOW;    void setup()                    {     cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example     Serial.begin(9600);     Mech.attach(9);     pinMode(light, OUTPUT);     pinMode(yellow, OUTPUT); // dnt need this     pinMode(power, OUTPUT);     pinMode(fans, OUTPUT); }   void loop()                    {      long start = millis();      long total1 =  cs_4_2.capacitiveSensor(30); // to power pin 11      long total2 =  cs_4_6.capacitiveSensor(30); // dnt need this      long total3 =  cs_4_8.capacitiveSensor(30); // to light        Serial.print(millis() - start);        // check on performance in milliseconds      Serial.print("\t");                    // tab character for debug windown spacing        Serial.print(total1);                  // print sensor output 1      Serial.print("\t\t\t");      Serial.print(total2);                  // print sensor output 2      Serial.print("\t\t\t");      Serial.println(total3);                // print sensor output 3        delay(100);                             // arbitrary delay to limit data to serial port          if (total1 > 200)        status_light = !status_light;      Serial.print("\tstatus_light = ");      Serial.print(status_light);      Serial.print("\t");          if (status_light)        Mech.write(20);     else     Mech.write(160);     delay(600);          if (status_light)        digitalWrite(light, HIGH);      else      digitalWrite(light, LOW);                if (total2 > 200)                // dnt need this        status_yellow = !status_yellow;      Serial.print("status_yellow = ");      Serial.print(status_yellow);           Serial.print("\t");      if (status_yellow)        digitalWrite(yellow, HIGH);        else        digitalWrite(yellow, LOW);     if (total3 > 200)       status_power = !status_power;      Serial.print("status_power = ");      Serial.println(status_power);      if (status_power)        digitalWrite(power, HIGH);      else        digitalWrite(power, LOW);        if (status_power)               if (status_power)        digitalWrite(fans, HIGH);        else        digitalWrite(fans, LOW);     } thank you for your help thank you.

Question by icey.hood   |  last reply


can we use same arduino programmed sketch for different motor drivers ?

I am expecting to build a bluetooth controlled 2WD robot using arduino. i need to use a pulolu dual VNH motor driver to run the two motors. i have a programmed arduino sketch that made for L293D Motor Shield .can i use that programmed sketch on my new robot that using pulolu motor driver without making any changes to code? if i need changes, what are they.? your help will make my project possible http://www.apexelectrix.com/images/L293D_shield.JPG >> L293D MotorShield https://a.pololu-files.com/picture/0J3747.1200.jpg?c4b8922dc1a9b571b95eacb6eb43a616 >> pulolu VNH driver

Question by hardarknight   |  last reply


Im repurposing my atx power supply to be a bench Psu. I need help with code please?

In this project. I want to use an arduino mega, 2 lcds, and 6 acs712 current sensing modules and 2 Lm2596 dc step up/down module The set up I have in mind is like so; arduino is powered by ATX stand by power (IF possible) there is a push button which turns on the programing to start the monitoring and also grounds the ATX and GReen wire to supply power to all the rails. This set up will calculate Voltage and current printting them on the lcd's. The constant voltages will be printed on on lcd and the variable voltages on the other lcd. Ive written most of the code. I just want it to make sense. I've added a picture, which my project is based on.. the difference are, im not using I2c bus for lcd, im measuring current, and im printing info on two different lcds. thanks for the help. here is the code #include #define PWROK_PIN 4 // change to w.e pin i end up using connected to green? investigate #define PWRBTN 2 // closing push buttom connection makes it high #define PWRTRANS 6 /*-----( Declare objects )-----*/ // Variables will change: int PWRSTATE = HIGH;         // the current state of the output pin int buttonState;             // the current reading from the input pin int lastButtonState = LOW;   // the previous reading from the input pin // the following variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long lastDebounceTime = 0;  // the last time the output pin was toggled long debounceDelay = 50;    // the debounce time; increase if the output flickers // initialize the libr with the number of the intface pins double sensePinVthree = A0; double sensePinVfive = A1; double sensePinVfivesb = A2; double sensePinVtw = A3; double sensePinVrone = A4; double sensePinvrtwo = A5; //The current double sensePinIthree   = A6; double sensePinIfive   = A7; double sensePinIfivesb = A8; double sensePinItw  = A9; double sensePinIVrone = A10; double sensePinIVrtwo = A11; //setting up default or naming variables. double Voltsthree; double Voltsfive; double Voltsfivesb; double Voltstw; double VoltsVrone; double VoltsVrtwo; double Currentthree; double Currentfive; double Currentfivesb; double Currenttw; double CurrentVrone; double CurrentVrtwo; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); LiquidCrystal lcd2(12, 10, 5, 4, 3, 2); //remove this if not working or glitchy void checkPowerOK(){   // when green is grounded   if (digitalRead(PWROK_PIN) == HIGH) {     lcd.setCursor(4, 1);     lcd.print("ON ");     lcd.setCursor(9, 3);     lcd.print("hello");   }   else if (digitalRead(PWROK_PIN) == LOW) {     lcd.setCursor(8,1);     lcd.print("OFF");   } } void togglePower(){ static unsigned long last_interrupt_time = 0; unsigned long interrupt_time = millis(); // If interrupts come faster than 200ms, assume it's a bounce and ignore if (interrupt_time - last_interrupt_time > 500) {    // set the power:   digitalWrite(PWRTRANS, PWRSTATE); //trans is pin 6 } PWRSTATE = !PWRSTATE; last_interrupt_time = interrupt_time;  } void setup() { analogReference (DEFAULT); pinMode(PWRBTN, INPUT); pinMode(PWRTRANS, OUTPUT); attachInterrupt(0, togglePower, RISING); digitalWrite(PWRTRANS, PWRSTATE);     lcd.begin(16, 4);   lcd2.begin(16, 2); // Print a message to the LCD. lcd.setCursor(0,0); //take this out if monitor buggy lcd.print("Bench PSU");// this code be fine lcd.setCursor(0,1); lcd.print("Monitor  V1.0"); lcd.setCursor(0,2); lcd.print("ICE"); lcd.setCursor(4,3); lcd.print("ROBOTICS"); lcd2.begin(16, 2); // replace with the date_time function lcd2.setCursor(0,0); lcd2.print("Hope 4 the best"); lcd2.setCursor(0, 1); lcd2.print("prep 4 the worst"); delay(3000); lcd.clear(); // wipes old message lcd.setCursor(5,0);  lcd.print("Building the Future"); lcd.setCursor(0,1); lcd.print("since   2014"); //Inset the time function somewhere in here lcd.clear(); lcd2.clear(); //lcd.createChar(0, blockChar);     Voltsthree=0; //setting my variables to Zero   Voltsfive=0;   Voltsfivesb=0;   Voltstw=0;   Currentthree=0; //Setting current to Zero on this Lcd   Currentfive=0;   Currentfivesb=0;   Currenttw=0;       VoltsVrone=0; // doing the same but for second lcd   VoltsVrtwo=0;     CurrentVrone=0;// same for current   CurrentVrtwo=0; } void loop () {checkPowerOK(); // check to see if power ok   Voltsthree = ((analogRead(sensePinVthree)) /218.0) *5; // or 7 aalso the 218.0 value will chaange to mine specific   if(Voltsthree <0){     Voltsthree=0;   }   Currentthree =(((analogRead(sensePinIthree)) / 212.0) -2.55) / 0.6666667;// why 0.667   if(Currentthree <0) {     Currentthree=0;   }   Voltsfive = ((analogRead(sensePinVfive)) /218.0) *5;   if(Voltsfive <0){     Voltsfive=0);   }   Currentfive =(((analogRead(sensePinIfive)) / 212.0) -2.55) / 0.6666667;// why 0.667   if(Currentfive <0) {     Currentfive=0;   }   Voltsfivesb =((analogRead(sensePinVfivesb)) /218.0) *5;   if(Voltsfivesb <0){     Voltsfivesb=0;   }   Currentfivesb =(((analogRead(sensePinIfivesb)) / 212.0) -2.55) / 0.6666667;// why 0.667   if(Currentfivesb <0) {     Currentfivesb=0;   }   Voltstw =((analogRead(sensePinVtw)) /218.0) *5;   if(Voltstw <0){     Voltstw= 0;   }   Currenttw =((analogRead(sensePinItw)) / 212.0) -2.55) / 0.6666667;// why 0.667   if(Currenttw <0){     Currenttw=0;   }     VoltsVrone =((analogRead(sensePinVrone)) /218.0) *5;   if(VoltsVrone <0){     VoltsVrone=0;   }   CurrentVrone =(((analogRead(sensePinIVrone)) / 212.0) -2.55) / 0.6666667;// why 0.667   if(CurrentVrone <0) {     CurrentVrone=0;   }     VoltsVrtwo =((analogRead(sensePinVrtwo)) /218.0) *5;   if(VoltsVrtwo <0){     VoltsVrtwo = 0;   }   CurrentVrtwo =(((analogRead(sensePinIVrtwo)) / 212.0) -2.55) / 0.6666667;// why 0.667   if(CurrentVrtwo <0) {     CurrentVrtwo=0;   }   //1st line   lcd.setCursor(0,0);   lcd.print("                "); //clear the line 1st line   lcd.setCursor(0,0);   lcd.print(Voltsthree);   lcd.setCursor(5,0):   lcd.print("V");   lcd.setCursor(7,0);   lcd.print(Currentthree);   lcd.setCursor(14,0);   lcd.print("A");     //2nd line   lcd.setCursor(0,1);                  // clear and print second line   lcd.print("                ");   lcd.setCursor(0,1);   lcd.print(Voltsfive);     lcd.setCursor(5,1);   lcd.print("V");   lcd.setCursor(7,1);   lcd.print(Currentfive);   lcd.setCursor(14,1);   lcd.print("A");     //3rd line   lcd.setCursor(0,2);           // clear line 3   lcd.print("                ");   lcd.setCursor(0,2);   lcd.print(Voltsfivesb);     lcd.setCursor(5,2);   lcd.print("V");   lcd.setCursor(7,2);   lcd.print(Currentfivesb);   lcd.setCursor(14,2);   lcd.print("A");     //4th line   lcd.setCursor(0,3);           // clear line 4   lcd.print("                ");   lcd.setCursor(0,3);   lcd.print(Voltstw);     lcd.setCursor(5,3);   lcd.print("V");   lcd.setCursor(7,3);   lcd.print(Currenttw);   lcd.setCursor(14,3);   lcd.print("A");     //1st line   lcd.setCursor(0,0);   lcd.print("                "); //clear the line 1st line   lcd.setCursor(0,0);   lcd.print(VoltsVrone.);   lcd.setCursor(5,0);   lcd.print("V");   lcd.setCursor(7,0);   lcd.print(CurrentVrone);   lcd.setCursor(14,0);   lcd.print("A");     //2nd line   lcd2.setCursor(0,1);                   // clear and print second line   lcd.print("                ");   lcd.setCursor(0,1);   lcd.print(VoltsVrtwo);     lcd.setCursor(5,1);   lcd.print("V");   lcd.setCursor(7,1);   lcd.print(CurrentVrtwo);   lcd.setCursor(14,1);   lcd.print("A");   }

Question by icey.hood   |  last reply


need help writing Arduino sketch for Nano to Adafruit FX mini soundboard communications?

Hello everyone.  I am new here, and fairly new to arduino. Im an electrician/ communications tech by trade, but have only been working with code as a hobby for a few weeks (have wanted to learn this for a long time).  I am working on a project that would require an Motion sensor input to play an audio track at random, whilst illuminating a corresponding PWM LED. said LED should fade in sync with the audio file. ITs a robot of sorts that will detect movement and speak a random audio track.  Some nice (0-5) and some not so nice (6-12).  it will have a a diffused glow when on, blue when speaking nice, and red when speaking not so nice.  hence the audio input to act as an anologRead and output to the PWM's I know, a lot to take on for a noob.  but go big or go home.  I have put together what I thought was a good start sketch, but it doesnt even illuminate an LED, communicate with the soundboard, or serial link on the monitor. I think I am on the right track in regards to the parts and overall Idea.  And im pretty sure my sketch needs a lot of work, but i am trying. so here are the parts I had intended to use. (if im going down the wrong path, or you see another way, feel free to say so.  I expect some criticism, I can handle it) Arduino elegoo Nano V3.0, CH340/ATmega328p Adafruit Audio FX Mini soundboard w/o amp Adafruit Mono 2.5W Class D amplifier (PAM8302) Sodial mini IR motion sensor module, 3-pin LED's are undecided for finished product, but i was thinking RGB 6302's (5-7) speaker is an 8 ohm 2W power will be supplied by a small 3.7v lipo (thats the plan) My wiring idea should be easily discernible from the sketch, but i can draw my idea, and add it if need be. I did install the soundboard _library. but thats the only one (didnt think i needed others) Any and ALL help is greatly appreciated. the sketch... [code] /*   Menu driven control of a sound board over UART.   Connect UG to ground to have the sound board boot into UART mode */ #include #include #define SFX_TX 9      // Defines pin D9 as TX to FX Mini #define SFX_RX 10     // Defines pin 10 as RX to FX Mini #define PLAYING 11    // Connect to the ACT pin on the FX Mini #define SFX_RST 13   // Connect to the RST pin on the FX Mini SoftwareSerial ss = SoftwareSerial(SFX_TX, SFX_RX);  // Passes Software Serial to FX Mini SoftwareSerial mySerial(SFX_RX, SFX_TX); Adafruit_Soundboard sfx = Adafruit_Soundboard(&ss;, NULL, SFX_RST); // can also try hardware serial with // Adafruit_Soundboard sfx = Adafruit_Soundboard(&Serial1;, NULL, SFX_RST); int incomingAudio;            // Audio input assigned from FX Mini Right audio output int RedLED = 5;         // the PWM pin the Red LED is attached to int BlueLED = 3;        // the PWM pin the Blue LED is attached to int LED = 4;            // the output the normal state LED is attached to int Button = 12;        // pushbutton test play track pin int Track = random(0,13);     int inputPin = 2;       // choose the input pin (for PIR sensor) int pirState = LOW;           // we start, assuming no motion detected int val = 0;                  // variable for reading the pin status void setup() {   Serial.begin(115200);         // softwareserial at 115200 baud   Serial.println("Adafruit Sound Board!");   ss.begin(115200);      pinMode(LED, OUTPUT);           // assigning LED as an output   pinMode(RedLED, OUTPUT);        // assigning RedLED as an output   pinMode(BlueLED, OUTPUT);       // assigning BlueLED as an output   pinMode(incomingAudio, INPUT);  // assigning incomingAudion as an input   pinMode(Button, INPUT);         // assigning Button as an input   pinMode(inputPin, INPUT);       // declare sensor as input   if (!sfx.reset()) {     Serial.println("Not found");     while (1);   }   Serial.println("SFX board found"); } void loop(){   digitalWrite(LED, HIGH);        // assigning LED to start with +5V   incomingAudio = analogRead(A0);               //read voltage at A0   incomingAudio = (incomingAudio+1)/4 - 1;      //scale from 10 bit (0-1023) to 8 bit (0-255)   if (incomingAudio<0){                         //deal with negative numbers     incomingAudio = 0;   }   PORTD = incomingAudio;   Serial.println(PORTD);   val = digitalRead(inputPin);                 // read input value    if (val == HIGH) {                          // check if the input is HIGH       sfx.playTrack(Track);       Serial.println(Track);       if (pirState == LOW) {                   // we have just turned on       Serial.println("Motion detected!");      // We only want to print on the output change, not state       pirState = HIGH;       }     }    else {       if (pirState == HIGH){                   // we have just turned of       Serial.println("Motion ended!");         // We only want to print on the output change, not state       pirState = LOW;     }   }     if (Button=HIGH){                             // pin D12 to button, ground thru 10K res, and +5v       sfx.playTrack(Track);       Serial.println(Track);       }   if (incomingAudio>=128 &&Track;>=0 &&Track;<=6){      digitalWrite(RedLED, incomingAudio-128);      digitalWrite(LED, LOW);      }   else if (incomingAudio>=128 &&Track;>=7 &&Track;<=12){      digitalWrite(BlueLED, incomingAudio-128);      digitalWrite(LED, LOW);      }   else{      digitalWrite(LED, HIGH);      digitalWrite(RedLED, LOW);      digitalWrite(BlueLED, LOW);      delay(15000);   } } [/code]

Question by supramp 


interface arduino with MLX90620?

Does anyone know of an arduino sketch or library that can drive a 16x4 array of LEDs from the input from a MLX90620 sensor?  I want to make a basic thermal viewer, that doesn't need to read exact temperature, just dim them according to the input.   

Question by jduffy54   |  last reply


Linkit One not working

I have a Linkit One that keeps disappearing from my ports when I try to upload a sketch. I was doing some testing of a sketch I had made and I keep getting the message that there was not board on the port I had selected. I have successfully uploaded sketches with this setup before. This was on a Macbook Pro running Yosemite 10.10.5. After several attempts to fix the problem I moved my setup to my Windows 7 machine. The issue is similar. I cannot get the board to remain visible on the port for any amount of time. I plug it in and it shows up for a few second before disappearing again. I fear my board's usb port has gone bad. I can upload to my arduino uno with no problems.   If it is a bad usb port is there anything I can do? Can I upload sketches another way? I would hate to lose the use of this board. Thanks for your time.

Topic by ehudwill   |  last reply


Does Arduino IDE1.0 save compiled hex files after it loaded the sketch? Where to?

I'd love to have the hex file that the compiler creates so I can load it later with avrdude. No further editing will be done, so I don't really need the IDE - can do it from command string. I've looked and looked and can't find the hex files. How come? Does IDE delete them after they're uploaded? Thanks!

Question by elabz   |  last reply


Arduino motor shield, do the shields not use the same stepper motor sketches or commands? Answered

Ok, I have an arduino uno and arduino motorshield. My stepper is a 1.8 degree 75 ohm motor, i can get it to run in one direction, or the other, but what I'm having trouble with is the code really, all the examples Ive been messing with don't seem compatible with the shield, all i want to do is make the stepper go one direction for "x" amount of steps then reverse the same number back, at a set rpm/speed, however when i try to give it step commands it does nothing, seems like i have to use the digital pins to control speed. but that's not exactly working for me. I'm sure this is an easy code for anyone who has used an arduino , but Ive only had this for 4 days and spent the last 2 researching and learning code, I'm getting frustrated. I thought getting the motor shield would make this easier...but it seems to over complicate, maybe not .maybe Ive just over analyzed this. if anyone has a code or recommendation for the arduino motor shield it would be greatly appreciated. here is an example of something similar to what im trying to do, but im trying to get it to work on an arduino motor shield.(example from Tom Igoe) /* Stepper Motor Controller language: Wiring/Arduino This program drives a unipolar or bipolar stepper motor. The motor is attached to digital pins 8 and 9 of the Arduino.  //motor shield pins 8,9 are the motor brake, use other pins or is this //correct? The motor moves 100 steps in one direction, then 100 in the other. Created 11 Mar. 2007 Modified 7 Apr. 2007 by Tom Igoe */ // define the pins that the motor is attached to. You can use // any digital I/O pins. #include #define motorSteps 200     // change this depending on the number of steps                            // per revolution of your motor #define motorPin1 8 #define motorPin2 9 #define ledPin 13 // initialize of the Stepper library: Stepper myStepper(motorSteps, motorPin1,motorPin2); void setup() {   // set the motor speed at 60 RPMS:   myStepper.setSpeed(60);   // Initialize the Serial port:   Serial.begin(9600);   // set up the LED pin:   pinMode(ledPin, OUTPUT);   // blink the LED:   blink(3); } void loop() {   // Step forward 100 steps:   Serial.println("Forward");   myStepper.step(100);   delay(500);   // Step backward 100 steps:   Serial.println("Backward");   myStepper.step(-100);   delay(500); } // Blink the reset LED: void blink(int howManyTimes) {   int i;   for (i=0; i< howManyTimes; i++) {     digitalWrite(ledPin, HIGH);     delay(200);     digitalWrite(ledPin, LOW);     delay(200);   } }

Question by thedanger   |  last reply