about button....

I have code on vb.net that will turn on led on my arduino but how can i turn it if i want to add button? how can i add button here in my code? #include int ledPin = 13; int buttonPin = 2;  // the number of the pushbutton pin      // the number of the LED pin int buttonState = 0;  // variables will change: LiquidCrystal lcd(12, 11, 5, 4, 3, 2); void setup() {   Serial.begin(9600); // set serial speed   pinMode(ledPin, OUTPUT); // set LED as output   digitalWrite(ledPin, LOW); //turn off LED      //   //         lcd.begin(16, 2);           lcd.setCursor(0,0);         lcd.print("     DaNeiL");          lcd.setCursor(0,1);         lcd.print("GASOLINE-STATION"); } void loop(){   while (Serial.available() == 0); // do nothing if nothing sent   int val = Serial.read() - '0'; // deduct ascii value of '0' to find numeric value of sent number     int buttonstate = Serial.read();       buttonState = digitalRead(buttonPin);   if (buttonState == HIGH) {         digitalWrite(ledPin, HIGH);     Serial.println("PLEASE WAIT WHILE REFUELING"); Serial.print('\n');     delay(9000); digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW     Serial.println("price 40");     Serial.print('\n');     Serial.print('\n');     Serial.println("liters 1");     }   else     // turn LED off:   if (val == 1) { // test for command 1 then turn on LED     Serial.println("P20.00                    1/2");     delay(10);     digitalWrite(ledPin, HIGH);// turn on LED      lcd.clear();      lcd.setCursor(0,0);      lcd.print("PRICE=  P20.00");      lcd.setCursor(0,1);      lcd.print("MILLILITERS=500");         }         {     Serial.println("P40.00                      1");     delay(10);     digitalWrite(ledPin, HIGH); // turn off LED      lcd.clear();      lcd.setCursor(0,0);      lcd.print("PRICE=  P40.00");      lcd.setCursor(0,1);      lcd.print("MILLILITERS=1000");       }   if (val == 3) { // test for command 1 then turn on LED     Serial.println("P80.00                      2");     delay(1000);     digitalWrite(ledPin, HIGH);// turn on LED      lcd.clear();      lcd.setCursor(0,0);      lcd.print("PRICE=  P80.00");      lcd.setCursor(0,1);      lcd.print("MILLILITERS=2000");       }   else if (val == 4) // test for command 0 then turn off LED   {     Serial.println("P120.00                      3");     delay(1000);     digitalWrite(ledPin, HIGH); // turn off LED      lcd.clear();      lcd.setCursor(0,0);      lcd.print("PRICE=  P120.00");      lcd.setCursor(0,1);      lcd.print("MILLILITERS=3000");       }       if (val == 5) { // test for command 1 then turn on LED       Serial.println("P160.00                      4 ");       delay(10);       digitalWrite(ledPin, HIGH);// turn on LED        lcd.clear();      lcd.setCursor(0,0);      lcd.print("PRICE=  P160.00");      lcd.setCursor(0,1);      lcd.print("MILLILITERS=4000");         }     else if (val == 6) // test for command 0 then turn off LED     {       Serial.println("P200.00                      5");       delay(10);       digitalWrite(ledPin, HIGH); // turn off LED        lcd.clear();      lcd.setCursor(0,0);      lcd.print("PRICE=  P200.00");      lcd.setCursor(0,1);      lcd.print("MILLILITERS=5000");         }       if (val == 8) { // test for command 1 then turn on LED     delay(10);     digitalWrite(ledPin, LOW);// turn on LED     lcd.clear();      lcd.print("     DaNeiL");          lcd.setCursor(0,1);         lcd.print("GASOLINE-STATION");       }           if (val == 9) { // test for command 1 then turn on LED     delay(10);     digitalWrite(ledPin, HIGH);// turn on LED     lcd.clear();      lcd.print("    FULL TANK");      lcd.setCursor(0,1);      lcd.print("PLEASE WAIT....");       }            if (val == 0) { // test for command 1 then turn on LED     delay(10);     digitalWrite(ledPin, LOW);// turn on LED                }   else if (val == 12) // test for command 0 then turn off LED   {     delay(10);     digitalWrite(ledPin, HIGH); // turn off LED           }   else {     }     }

Topic by NeilV2   |  last reply

Arduino Script Issue?

Hey world, I am making device that will automatically water my xmas tree: I am using the basic "button" script from the Arduino IDE examples. the only change I have made so far is instead of using an actual push button I am sticking 2 bare copper wires(the ground has a 10k resistor) into a jar.  When water is added to the jar the connection is made and the LED goes on. The problem is that it only stays on for like 7 seconds. I need it so as long as there is water in the cup the light stays on. any ideas? Below is a copy of the script. Thanks! const int buttonPin = 2;     // the number of the pushbutton pin const int ledPin =  13;      // the number of the LED pin // variables will change: int buttonState = 0;         // variable for reading the pushbutton status void setup() {   // initialize the LED pin as an output:   pinMode(ledPin, OUTPUT);   // initialize the pushbutton pin as an input:   pinMode(buttonPin, INPUT); } void loop() {   // read the state of the pushbutton value:   buttonState = digitalRead(buttonPin);   // check if the pushbutton is pressed. If it is, the buttonState is HIGH:   if (buttonState == HIGH) {     // turn LED on:     digitalWrite(ledPin, HIGH);   } else {     // turn LED off:     digitalWrite(ledPin, LOW);

Question by Mpc1055   |  last reply

Strongest 3V LED with pins?

I'd like to build a LED into an empty light bulb that can run on 3V (from button cells). So I can't use the normal screw-in leds that are sold because they are all 12V at least. I'm planning to build the LED into the lightbulb myself, and connect it manually to the batteries. I'd like my LED to be as omnidirectional as possible. So what LED would I be able to use for this, and would I need some sort of diffuser or something to make the light shine in all directions? Would I be able to get up to about similar lumens as a 40W incandescent bulb?

Question by reinhardtsmit   |  last reply

1 Button & 6 Neopixel Strips for an Explorers Map

Here is what I am attempting to make.... An interactive display where a user pushes a single button and 1 of the 6 strips lights in a slow sequence, showing the path an explorer took from point a to point b. There are 6 paths, each path will be its own neopixel strip. When the button is pressed a second time, the first strip goes off and the second strip sequentially lights, all the way through the 6 strips, ending at all strips off. I'd like to make the code work so I can use 6 PMW pins as wiring these as one large array is not practical, possible, just not practical. I am using the following: - 1 Arduino Mega 2560, - 1 momentary push button, and - 6 5v neopixel strips (currently with 19 pixels each, end product will be 60 each. - Windows PC and USB to power for testing I am attaching a code that works great with the button pushes for a single strip, and have a different color applied to each "case" so I'd know which one was active. Is a variable for the output pin number IE 3,4,5,6,7,8 the best way, or do I require a different type of condition? Thank you for any help here! Gary // This is a demonstration on how to use an input device to trigger changes on your neo pixels. // You should wire a momentary push button to connect from ground to a digital IO pin.  When you // press the button it will change to a new pixel animation.  Note that you need to press the // button once to start the first animation! #include #define BUTTON_PIN   3    // Digital IO pin connected to the button.  This will be                           // driven with a pull-up resistor so the switch should                           // pull the pin to ground momentarily.  On a high -> low                           // transition the button press logic will execute. #define PIXEL_PIN    6    // Digital IO pin connected to the NeoPixels. #define PIXEL_COUNT 19 // Parameter 1 = number of pixels in strip,  neopixel stick has 8 // Parameter 2 = pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: //   NEO_RGB     Pixels are wired for RGB bitstream //   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick //   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels) //   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800); bool oldState = HIGH; int showType = 0; void setup() {   pinMode(BUTTON_PIN, INPUT_PULLUP);   strip.begin();   strip.show(); // Initialize all pixels to 'off' } void loop() {   // Get current button state.   bool newState = digitalRead(BUTTON_PIN);     // Check if state changed from high to low (button press).   if (newState == LOW && oldState == HIGH) {     // Short delay to debounce button.     delay(20);     // Check if button is still low after debounce.     newState = digitalRead(BUTTON_PIN);     if (newState == LOW) {       showType++;       if (showType > 6)         showType=0;       startShow(showType);     }   }   // Set the last button state to the old state.   oldState = newState; } void startShow(int i) {   switch(i){     case 0: colorWipe(strip.Color(0, 0, 0), 0);    // Black/off             break;     case 1: colorWipe(strip.Color(255, 0, 0), 100);  // Red             break;     case 2: colorWipe(strip.Color(0, 255, 0), 100);  // Green             break;     case 3: colorWipe(strip.Color(0, 0, 255), 100);  // Blue             break;     case 4: colorWipe(strip.Color(127,127,127), 100);  // White             break;     case 5: colorWipe(strip.Color(255, 0, 0), 100);  // Red             break;     case 6: colorWipe(strip.Color(0, 0, 255), 100);  // Blue             break;   } } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) {   for(uint16_t i=0; i       strip.setPixelColor(i, c);       strip.show();       delay(wait);   } }

Topic by grroane123   |  last reply

30-pin Car Media Controls

I'm looking to create a device to control my music while I'm in the car. I have the commands to control music here: http://web.student.tuwien.ac.at/~e0026607/ipod_remote/ipod_ap.html and the pinout for the 30-pin dock connector here: http://media.blackhat.com/bh-us-11/Esser/BH_US_11_Esser_Exploiting_The_iOS_Kernel_Slides.pdf But I need some help figuring out a way to have a button press trigger the command to be sent and received by my phone

Topic by BryanS1   |  last reply

Stop the light arcade game. Why is my ISR (interrupt Service Routine) not working?

I have written the following code in hopes of running an arcade style game. The idea of the code is that 2 cases will run the first being the lights tracking back and forth before the button has been used to stop them. The second case happens when the button is pressed, and flashes on the light stopped on untill the button is pressed again. Also, a potentiometer is employed to change the speed of the lights. The 4th light is the only red one the one you are trying to "catch" if caught "Winner" is printed... if not "try again" problems with code that i need help  on 1. the ISR isn't functioning 2. How can i have "winner" or "try again" print only once not with every blinking of the light 3. i think in case 2 its only using the case of light 4 even if it is not light 4... why is this? THANKS!! int Button=2; //button assigned to pin 2 just changed because of INT0 havent adjusted lights yet volatile int Buttonstate= LOW; int ledPins[] = { 2,3,4,5,6,7,8,9,10 }; // an array of pin numbers to which LEDs are attached int pinCount = 9; // the number of pins (i.e. the length of the array) int potpin=A1; int potscale=8; int oldpot=0; int var=1; void setup() {   pinMode(Button, INPUT);   pinMode(potpin,INPUT);   attachInterrupt(0,button,RISING);//INT0   Serial.begin(9600);   int thisPin;   // the array elements are numbered from 0 to (pinCount - 1).   // use a for loop to initialize each pin as an output:   for (int thisPin = 0; thisPin < pinCount; thisPin++) {     pinMode(ledPins[thisPin], OUTPUT);     }   } void loop() {   // reads pot for changing speed of the lights   int potvalue = analogRead(potpin);   int difficult= (1023- potvalue)/100;   // print the difficulty if it changes   if (difficult != difficult) {   Serial.print(" difficulty = " );   Serial.println(difficult);   oldpot = potvalue;   }   switch (var)     {     case 1:         //lights incrementing right to left          for (int thisPin = 0; thisPin < pinCount; thisPin++) {           digitalWrite(ledPins[thisPin], HIGH);           delay(potvalue/2);           digitalWrite(ledPins[thisPin], LOW);          }          //lights decrementing left to right         for (int thisPin = pinCount - 1; thisPin >= 0; thisPin--) {           digitalWrite(ledPins[thisPin], HIGH);           delay(potvalue/2);           digitalWrite(ledPins[thisPin], LOW);         }         break;      case 2:        //winner case if stopped on red light         if (int thisPin=4){           Serial.print("Winner!");           digitalWrite(ledPins[thisPin], HIGH);           delay(100);           digitalWrite(ledPins[thisPin], LOW);           delay(100);         }         //loser stopped on some other light         else{           Serial.print("try again");           digitalWrite(ledPins[thisPin],HIGH);           delay (100);           digitalWrite(ledPins[thisPin],LOW);           delay (100);        }         break;   } } //ISR-Button has gone HIGH void button() { //change buttonstate again   Buttonstate=digitalRead(Button);     if (var==1){var==2;}     else if (var==2){var==1;}   }

Question by vandygirl2013   |  last reply

Does anyone have an Iriver T10?

One that you wouldn't mind dissasembling to help me. My front button pad broke and I need to know the pinout, all I need are some front and back reference pics of the pad circuit(with the ribbon) with a reference mark as to what is what (like volume up or next track)

Question by The Ideanator 

How to alter the code in this LED chase

Hi,here is the code i have for a chase controlled by a button. When the button is engaged (held in) the chase runs. When the button is released the chase stops. My question is how can I make the LEDS appear to go haywire when the button is released and not simply go off. // A chase controlled by a button int Button=2; //button assigned to pin 2 int timer = 150; // The higher the number, the slower the timing. int ledPins[] = { 3,4,5,6,7,8,9,10 }; // an array of pin numbers to which LEDs are attached int pinCount = 8; // the number of pins (i.e. the length of the array) void setup() { Serial.begin(9600); pinMode(Button, INPUT); int thisPin; // the array elements are numbered from 0 to (pinCount - 1). // use a for loop to initialize each pin as an output: for (int thisPin = 0; thisPin < pinCount; thisPin++) { pinMode(ledPins[thisPin], OUTPUT); } } //turn LEDS on void loop() { while (digitalRead(Button)==HIGH); { //delay (10); Serial.println("LOW"); } while (digitalRead(Button)==LOW) { Serial.println("HIGH"); for (int thisPin = 0; thisPin < pinCount; thisPin++) { //turn leds on digitalWrite(ledPins[thisPin], HIGH); delay(timer); //turn leds off digitalWrite(ledPins[thisPin], LOW); } //turn leds on for (int thisPin = pinCount -1; thisPin >= 0; thisPin--) { //turn leds off digitalWrite(ledPins[thisPin], HIGH); delay(timer); digitalWrite(ledPins[thisPin], LOW); } } } many thanks, Frank

Topic by frankhiggins 

I would like to shift a logic 1 though pins 10, 11, 12 and 13 by a pulse at pin 2 from button inputs. please help.

On an Aduino no I would like to make pin 2 an input. Pin 10, 11, 12 and 13 out puts which will go high then low in turn on subsequent pulses on pin 2. I want to drive 4 LEDs one after the other on and off. If I press and release button at pin 2, led 10 comes on. when I press the button the second time, LED 10 goes off then LED 11 comes. on the next input pulse LED 11 goes off and LED 12 comes on. On the next pulse LED 12 goes off and LED 13 comes on.on the next pulse LED 13 goes off and LED 10 goes on again  Please help

Question by nyama   |  last reply

I have an old Iriver T10 1Gb player, how could I find the FCC id number? Answered

Ok, so I have an old MP3 player that I have decided to recommission. Unfortunately the problem that decommissioned it is still a problem, the front button pad does not work, the traces are so tiny that I cant easily test it by hand, and I cant find any information anywhere on the internals of the T10.I cant find the fcc id # anywhere on the body, I need it because it would allow me to get schematic diagrams for it (according to this I'ble)

Question by The Ideanator   |  last reply

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

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

Question by shooternash   |  last reply

Does PIC16F84A has TIMER0 interrupt? How to use with button?

I wanna connect my 8LEDs in the PORTB of the PIC then a button in any PORTA pins. I'll use the button to change the pattern of the blinking. How to do this in timer interrupt? Is it possible for the TMR0 to check the status of the button, if it was pressed then change the pattern? Say, I have four patterns. Cheers

Question by worthyrabbito 

Arduino score board code question

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

Question by spikepickstock   |  last reply

Arduino code not working. Super basic but I'm stuck. Help is appreciated. Answered

     So I have wrote an Arduino code for a simple Aquarium dosing pump controlled by Android and Arduino. I have a button on pin 8 and I want the button to just be a physical trigger for the dosing for calibration purposes. for whatever reason i cant seem to figure out how to do this and help would be greatly appreciated. Thanks a bunch (: (Warning: I'm far from an expert at Arduino I'm sure there is lots of ways this could be improved) //Objective: Dose aquarium with chemicals daily via bluetooth app. with the amount dosed set by potentiometer int pumpPin = 10; //to relay int ledpin = 13; //for test purposes int state = 0; int flag = 0; int Dtime = 0; //value for how long to dose int Mval = 0; //Variable that holds the value of dosing time int PumpCalPin = A0; //pin the potentiometer goes to int pumpTestPin = 8; //button to set off pump for calibration purposes int buttonPower = 9; //source of power for the button because I'm out of voltage pins void setup() {   pinMode(pumpPin, OUTPUT);   pinMode(buttonPower, OUTPUT);   digitalWrite(buttonPower, HIGH);   pinMode(pumpTestPin, INPUT);   pinMode(ledpin, OUTPUT);   digitalWrite(pumpPin, LOW);   digitalWrite(ledpin, LOW);   Serial.begin(9600); } void loop() {   int testPinVal = digitalRead(pumpTestPin);   if (testPinVal == 1) {     state = 1;     flag = 0;   }   if (Serial.available() > 0) {     state = Serial.read();     flag = 0;     Mval = analogRead(PumpCalPin);     Dtime = map(Mval, 0, 990, 1000, 5000); //map the potentiometer input from 1 to 5 seconds   }   if (state == '1') {     digitalWrite(pumpPin, HIGH);     digitalWrite(ledpin, HIGH);     delay(Dtime);     digitalWrite(pumpPin, LOW);     digitalWrite(ledpin, LOW);     if (flag == 0) {       state = 0;       flag = 1;     }   } }

Question by harry88   |  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

android app -> raspberry pi -> arduino !!!

Hey! I want to make a very simple android app with buttons... Each button has to be a "shortcut" for a specific command which will be sent from my phone to raspberry pi 3 with ssh.. These commands will simply power some arduino pins to give 5V ( like ser.write('3') which turns on pin 3 ). But I can't figure out the way to do what i describe with bold... Any help??

Topic by ΦώτηςΘ   |  last reply

I have various size button cells to power small projects, how can I make simple but small cell battery holders?

I have collected resistors, motors, LED's and switches from many small dismantled items. I want to use the recovered items along with other 1$ store button cell batteries to power projects. A clothes pin is great for testing, however I need simple strong cell holders to attach these to my projects. I would like to avoid super glue on the battery itself. I also know that the button cells will explode it I attempt to solder on them direct.

Question by Threeshirts 

Aduino Bluetooth code problem!

I am building a Morse Code machine with bluetooth functuonality.  It is in the early stages at the moment but I have hit a problem. My code uses a button to input Morse code which is displayed on an LCD and flashes an LED on pin 5, but also incorporates a bluetooth HC05 which controls an LED on pin 13. Seperately, they work fine but I wanted to merge the two sketches. I have succeeded but for one small problem. When pressing the LED 'ON' button on my android app, the LED only comes on after the Morse code button has been pressed. And it works the same way for the LED 'OFF' function on the app. Press it, then press the Morse code button and the LED switches off again. This repeats. I cannot figure out why this button is controlling the Bluetooth LED command signal. I have changed baud rates of the bluetooth but to no joy. I have attached my code. Can anyone help me solve this problem?!?

Topic by Satans Thong 

How do I use an Arduino to switch another IC's pin (reset) to ground?

I am trying to turn an IC's reset pin to ground with an Arduino.  It is a 5 LED array that has an IC controlling several flashing modes. I need to reset the IC to change modes and I want to use an Arduino Nano. I have seen an explanation setting an digital pin to input and then making it low and then setting the pin to output but I don't understand the process.  Supposedly it simulates a momentary push button switch using an Arduino. I guess I need a very thorough explanation for someone from the slide rule era. Thanks in advance. Murphy

Question by MurphySquint   |  last reply

Thrustmaster F22 Joystick to control servos

Hi there, I'm thinking about trying to use a microcontroller (AVRMega128) to read from an old Thrustmaster F22 port and then move some servos to eventually make some small "rocket turrer" for the office, like those that u can buy at thinkgeek. The fact is that I've searched for the specifications of a 15 pin joystick port and it says they were originally made to support two two-buttons joysticks, that means, two pins to control X and Y axis and other two for buttons, and the same for the eventual second joystick...funny, because mine is only one and it has 8 buttons, 4 ordinary and 4 to control the views...Do u know were to get the specifications of thrustmaster F22 joystick port? thanx

Topic by pingo wellman 

How to use Multiple mcp23017 chips with the adafruit mcp23017.h library?

I have been experimenting with I2C and the mcp23017 IO expander chip for my arduino ATMega2560 as I would rather use the IO on the arduino its self for other things I am just figuring out how to use the adafruit mcp23017.h library and cant figure out how to address multiple mcp23017 chips and how to use there pins individually this is the code from the button library that I editied. Here is the datesheet of mcp23017 I want to be able to address the individual chips and the pins I was not quite sure if in the setup that the pin modes for the IO go up sequentially from 0 past 15 if multiple chips are connected and addressed in code. For example if the first chip is addressed as 0x20 and the IO number count is from 0 - 15 if I added and addressed another chip as 0x21 will that count go from 0 - 15 to 0 - 31. ~ Edit if you could recommend or send a library that would be easier or could help please do. #include #include "Adafruit_MCP23017.h" //pin 1 and 0 are mcp pins not arduino IO pins Adafruit_MCP23017 mcp; void setup() {  mcp.begin();      // use default address 0 mcp.pinMode(0, INPUT); mcp.pinMode(1, OUTPUT); Serial.begin(9600); pinMode(13, OUTPUT);  // use the p13 LED as debugging } void loop() { // The LED will 'echo' the button digitalWrite(13, mcp.digitalRead(0)); //Writes pin 13 to the reading of pin    0 mcp.digitalWrite(1, mcp.digitalRead(0)); //Writes pin 1 to the reading of 0 if(mcp.digitalRead(1) == HIGH){ //if pin 1 == high serialprint led whent   high Serial.println("Led whent HIGH"); } }

Question by DELETED_MakiY2   |  last reply

How can i pun a real signal blinking handle from a car on a PC steering wheel?

I want to modify a PC steering wheel to be real. I want to put a signal blinker handle, by solder the pins on 2 buttons from the gamepad. Can i do without arduino or any PIC programmer a thing like the signal blinking from the car? I want on a PC steering wheel to put a handle for signal blinking. How? I solder the handle pins to the front panel (the buttons from the PC steering wheel, i suspend 2 buttons, like 2 and 4). Can i do a simple circuit when i commute the handle to right for exemple the signal goes once and when i commute back to none the signal goes none. I dont know how to explain. When the handle is on right position the semnal from him must go once, when the handle is switch, the signal from the handle to transmit the signal again, because i solder the pins to buttons command. Can it be done with something like in the photo? http://i60.tinypic.com/2crnf5j.png And here is something like my handle: http://i60.tinypic.com/sxd6cz.jpg

Question by danyelo   |  last reply

i have a fingerprint scanner from a old laptop, can i use it with a desktop pc or my new laptop? Answered

Its from an acer travelmate 5530, i still have the board it was attached to, but the piece itself has 10 pins sticking out of it, there is a chip on the board that the finger scanner was connected to that has a 8 pin chip, then the 2 mouse buttons, and a interface cable. is it even feasibly possible to reuse this fingerprint scanner?

Question by zack247   |  last reply

problem with my code

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

Question by font1135   |  last reply

4017 clock enable not working? Answered

Hi. I have a 4017 chip taking clock inputs from a de-bounce switch circuit. I have been trying to get the first two outputs on, one after another, with the second of these o-p's putting pin 13 (clock enable) high which I thought freezes the chip in effect. However this doesn't seem to be happening with my circuit. I know everything is in the right place. Reset is held low, I have one led on pin 2 and one on pin 4, both with appropriate resistors. I had the clock enable on o-p 4 and that worked. I repeatedly pressed the button and the led's didn't come on. But with clock enable on o-p 3, I presses the button and the first led came on after about 9 presses.  If someone could give me some pointers it would be greatly appreciated.  Many thanks 

Question by LED Maestro   |  last reply

Trying to figure out how ultrasonic humidifier detects low water level

Hello all, I'm currently working on a home automation system and have decided I want to throw my fragrance diffuser into the mix. What I'm trying to accomplish is I'd like the diffuser to come on whenever the unit has power so I can simply control it with a Sonoff SV. I was originally planning on just replacing the guts with an Arduino Nano or something until I tore into it and realized I have absolutely no clue how this thing detects when the water level is low! There's no sort of float switch or resistive fluid detection. In fact, the only part that has contact with the fluid is the ultrasonic transducer. I'm curious if anyone can look at the PCB and give me some more insight as to what's going on. On the far left the five pins coming into the board is the cable connector for the buttons and LEDs, the two large pins beneath that are the buzzer for making beeping noises when buttons are pressed, The SMD IC towards the middle is from what I can tell the brains of the operation. The three large pins (two with solder) near the top center are where 24vdc comes in. The two large pins on the upper right are for the fan and the two large pins on the bottom right are for the transducer. If anyone has any insight as to how this thing reads a low water level it'd be very much appreciated. Thank you!

Question by harry88   |  last reply

How do I choose an optocoupler/transistor? Answered

There are 2 circuits,one is a clap switch which provides output to ground voltage as 12 volts,and with a resistor,I managed to get an led to turn on each time I clap.I wanted to interface it with a clock which shows time when a button is pressed,but the problem is the button(marked as "show") isn't connected from microcontrollers  pin to vcc but from micro's pin to gnd (find attachment for reference).so I wanted to chose an optocoupler or transistor,but being a school student,I haven't  learnt about them,though I know how to connect them. also,please suggest some method (transistors or optocoupler & which one) to increase the number of output leds without overloading the micro Please help

Question by Suraj Grewal   |  last reply

How should i write this program (arduino)?

Hi,To whoever is reading this.I've been working with arduino for a few days and I don't knoiw how to make a program where if you press on button the arduino receives an input on some pin as HIGH  and then it increases the position of the servo clockwise and when you press another button and the arduino receives HIGH on some other pin and makes the servo tern anticlockwise.I've been trying to nail it but i just can't get it .I even tried this program and it did'nt work .Can anyone HELP me?.Thanks in advance.  #include Servo myservo;  int pos = 0; int up=13; int down=12; int a=0; void setup() {   myservo.attach(9);    pinMode(up,INPUT);   pinMode(down,INPUT); } void loop() { if(up==HIGH)      {       a=1;      }   if(down==HIGH)      {       a=0;      }      for(a=1; pos = 0; pos <= 180; pos += 1)     {                                     myservo.write(pos);                delay(15);                           }   for(a=0; pos = 180; pos>=0; pos-=1)         {                                    myservo.write(pos);                  delay(15);                   } }

Question by Strontium   |  last reply

A advanced Arduino calculator?

So I thought about a new project: make an "advanced" calculator since online there are plenty of tutorials of simple ones. I have done already the circuit and I have only some problems with the code since this is only my third project on Arduino and I don't  know programming in C. So basically: when I switch on the device it shows me a long text which I can scroll using a pair of pushbuttons(when the text can't scroll anymore a led switches on). When I push them contemporanealy the device switches to calculator. And this is the code I made (I know there are plenty of errors): #include #include long num1,num2 ; double total; char operation,button; const byte ROWS = 4; const byte COLS = 4; char keys[ROWS][COLS] = {   {'1','2','3','+'},   {'4','5','6','-'},   {'7','8','9','*'},   {'C','0','=','/'} }; byte rowPins[ROWS] = {A0,A1,A2,A3}; //connect to the row pinouts of the keypad byte colPins[COLS] = {A4,A5,0,1}; //connect to the column pinouts of the keypad Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS); // === CONSTANTS AND GLOBALS === // -- PINS -- const int PIN_LCD_LED = 6;  // analog const int PIN_ERR_LED = 7;  // digital const int PIN_BUTTON1 = 8;  // digital const int PIN_BUTTON2 = 9;  // digital // -- LCD -- // PIN 12   -> RS // PIN 11   -> Enable // PINS 2-5 -> D4-7 LiquidCrystal lcd(12, 11, 2, 3, 4, 5); // number of columns in the LCD const int LCD_COLS = 16; // LCD brightness [0, 255] const int LCD_BRIGHTNESS = 128; // LCD ON or OFF int state_lcd = LOW; // start position for text int lcd_start = 0; // -- LED -- // LOW -> LED is OFF - HIGH -> LED is ON int state_led = LOW; // stores time when turned LED on unsigned long t0_led; // timeout to turn the LED off const int LED_TIMEOUT = 500; // -- text to print -- // ASSUMPTION: text always longer than LCD_COLS, if not add a check in loop const char TEXT[] = "After trying Helloworld I made this more advanced version..."; const int TEXT_LEN = (sizeof(TEXT) / sizeof(char)) - 1; const int LCD_LIMIT = TEXT_LEN - LCD_COLS; // === CONSTANTS AND GLOBALS END === // === INITIALIZATION === void setup() {   // -- SET DIGITAL PINS --   pinMode(PIN_BUTTON1, INPUT);   pinMode(PIN_BUTTON2, INPUT);   pinMode(PIN_ERR_LED, OUTPUT);   // -- SET UP LCD --   lcd.begin(16,2);   lcd.noDisplay();   digitalWrite(PIN_LCD_LED, state_lcd);   // ERROR LED is off when starting   digitalWrite(PIN_ERR_LED, state_led);   // -- read buttons --   int state_button1 = digitalRead(PIN_BUTTON1);   int state_button2 = digitalRead(PIN_BUTTON2);     // pushed button 1 -> try to scroll left or turn LED on if can't     if(HIGH == state_button1)     {       if(lcd_start > 0)       {         lcd_start--;         state_led = LOW;         digitalWrite(PIN_ERR_LED, state_led);         delay(200);       }       else       {         state_led = HIGH;         digitalWrite(PIN_ERR_LED, state_led);         t0_led = millis();       }     }     // pushed button 2 -> try to scroll right or turn LED on if can't     if(HIGH == state_button2)     {       if(lcd_start < LCD_LIMIT)       {         lcd_start++;         state_led = LOW;         digitalWrite(PIN_ERR_LED, state_led);         delay(200);       }       else       {         state_led = HIGH;         digitalWrite(PIN_ERR_LED, state_led);         t0_led = millis();       }     }     // -- print text on the LCD --     for(int i = 0; i < LCD_COLS; i++)     {       lcd.setCursor(i, 0);       lcd.print(TEXT[lcd_start + i]);     }     // ERROR LED is ON     if(HIGH == state_led)     {       unsigned long td = millis() - t0_led;       // LED has been ON for more than LED_TIMEOUT ms. -> turn it OFF       if(td > LED_TIMEOUT)       {         state_led = LOW;         digitalWrite(PIN_ERR_LED, state_led);       }     }   }   // normally 20FPS   // === INITIALIZATION END === // === MAIN LOOP === void loop() {   // == LCD STILL OFF ==   if(HIGH == state_lcd)   {     // pushing both buttons -> turn LCD on     int state_button1 = digitalRead(PIN_BUTTON1);     int state_button2 = digitalRead(PIN_BUTTON2);         if(HIGH == state_button1 && HIGH == state_button2)     {       analogWrite(PIN_LCD_LED, LCD_BRIGHTNESS);       lcd.display();       state_lcd = HIGH;       delay(250);     }   }     else  // == LCD ON ==   {     // Loops are convenient for reading key press from keypad     while(1) // First loop. Here we read keypad and compose our first number. It does so untill we press operation button and break's out of loop or 'C' and it starts from beginning of this loop     {                 button = customKeypad.getKey(); // Button read         if (button=='C') // If user wants to resset while he is writing first number         {           num1=0;           num2=0;           total=0;           operation=0;           lcd.clear();         }                 if (button >='0' && button <='9') // If user pressed numeric value, 1 character at a time.         {           num1 = num1*10 + (button -'0'); // Our numeric values are 0-9 witch means they are in first decade, when we multiply with 10 we basicaly add zero after number,           // than we add a new number entered to that zero spot. As for (button -'0') this is simple ASCII table "trick" 0...9 in ASCII table are 48 ... 57,           // so by subtracting '0' from any of them we get their value in decade system ex. char '5' = 53 in decade numeric system minus 48 for zero char gives us value of actual 5,           // if our previous number was ex. 25 we get 250 by multiplying it with 10 and then we add 5 and we get 255 witch gets printed on LCD.           lcd.setCursor(0,0); // Select first row on lcd           lcd.print(num1); // Print current number1         }         if (num1 !=0 && (button=='-' || button=='+' || button=='*' || button=='/')) // If user is done inputing numbers         {           operation = button; // operation remembers what mathematical operation user wants on numbers           lcd.setCursor(0,1); // set cursor to row 2           lcd.print(operation); // print our operator           break;         }     }         while(1) // Second while loop, it loops untill user has pressed '=' or 'C'. so it either prints total or ressets program     {         if (button =='C'){break;} // This covers case where user pressed operator and still wants to reset         button = customKeypad.getKey();         if (button=='C') // Making sure user wants to reset at anytime         {           num1=0;           num2=0;           total=0;           operation=0;           lcd.clear();           break;         }         if (button >='0' && button <='9') // Getting chars from keypad for number 2         {           num2 = num2*10 + (button -'0');           lcd.setCursor(1,1);           lcd.print(num2);         }         if (button == '=' && num2 !=0)// If button pressed was '=' its the end of the road. Calls domath() subroutine does calculation and print our results         {           domath();                              break;          }     }     while(1)     {       // After all is done this loop waits for 'C' key to be pressed so it can reset program and start over.       if (button =='C'){break;} // This line is side effect of previous loop since if user pressed 'C' it breaks out of previous loop and continues here.So we need to break this one aswell or user would need to press 'C' 2 times       button = customKeypad.getKey();       if (button =='C')         {            lcd.clear();            lcd.setCursor(0,0);            num1=0;            num2=0;            total=0;            operation=0;            break;         }     } } void domath() // Simple switch case to pick what operation to do, based on button pressed by user. {   switch(operation)     {       case '+': // Addition           total = num1+num2;           break;             case '-': // Subtraction           total = num1-num2;           break;             case '/': // Division. Could add error for division by zero, or change line in second loop where it waits for '=' char to if (button == '=' && num2 != 0) this will halt program untill num2 is not zero and then continue           total = (float)num1/(float)num2;           break;             case '*': // Multiplication           total = num1*num2;           break;               }     // Based on case selected print our total and     lcd.setCursor(0,1);     lcd.print('=');     lcd.setCursor(1,1);     lcd.print(total);       } } // === MAIN LOOP END === Waiting your answers, Cristian

Question by IlirD2   |  last reply

Need help with arduino code for running motor with potentiometer and pushbutton.

I am running a motor in one direction for agricultural purposes. I am currently using some code I found to change the sporadic nature of the motor with a potentiometer and PWM. I found code which will use the potentiometer and this is successful and currently in use (built the whole 12v switch circuit using the Tip122). Now I want to be able to use a push button to retain the sporadic nature of the potentiometer when the push button is pushed once and have the motor be constant when the push button is pushed a second time.  I am stumped about how to do this, I am a beginner to the arduino code and trying to get better. I was wondering if someone might have an answer to how to program this. I've included the current code below. int potPin = 2;    // select the input pin for the potentiometer int ledPin = 13;   // select the pin for the LED int val = 0;       // variable to store the value coming from the sensor void setup() {   pinMode(ledPin, OUTPUT);  // declare the ledPin as an OUTPUT } void loop() {   val = analogRead(potPin);    // read the value from the sensor   digitalWrite(ledPin, HIGH);  // turn the ledPin on   delay(val);                  // stop the program for some time   digitalWrite(ledPin, LOW);   // turn the ledPin off   delay(val);                  // stop the program for some time }

Question by daleruisky   |  last reply

Require assistance building a circuit with sound and lights for the Aperture Science Handheld Portal Device.

Last week, I constructed a prop ASHPD for my cosplay outfit for the Tokyo Game Show- being a generic male test subject. Considering the time crunch I had, I was not able to put as much detail into it as I would have liked. None the less, it came out pretty good. Now, I want to improve upon it. One of the upgrades I want to apply, I have no experience with. The layout of the circuit that I want is as follows: On/Off toggle switch. This is simply to preserve battery life. The device will also have 2 single press buttons, one for the blue portal, and the other for the orange portal. Upon pressing the blue button, a blue light will illuminate, and play the sound file associated with the firing of a blue portal. Once the button is released, the blue light needs to stay on, however, upon pressing the button again, it will play the sound again, without chaning the state of the light. The same needs to happen with the orange button- it turns off the blue light and turns on the orange light simultaneously, while playing the sound file associated with the firing of the orange portal. Again, pressing this button again needs to play the sound file again, without changing the state of the illuminated orange light. I currently own the toggle switch and the 2 buttons, as well as 2 rod lights designed for placement in a computer. I don't know if I will be able to cut the motherboard pin connector off and just solder the wires to the circuit. I'm assuming so.

Question by tburton3 

What Code Should I use To Make a Single Pulse Trigger.

Hello World,I am currently making a circuit that will produce a single pulse using Arduino. I want that my circuit and code should produce a single pulse, after that the pin o which I am taking output becomes low until I switch off the button. the pulse should again be generated when the button is pressed.I have been using a series of codes. But, whenever I upload the sketch to the Arduino it works for once. after that when I switch the button off and turn it on again it doesn't work. If the switch is kept on after some time it again starts to generate a pulse.Please if anyone can help me out would be a great thing.Thankyou.

Question by shubhamnagla909   |  last reply

attiny85 tilt switch dc motor

Hello my project consists of an attiny85 with an led a dc motor a tilt switch and  a button. the button changes the pwm values and the led goes to the same values to know the strength of pwm.  the tilt switch will activate the dc motor at the corresponding pwm speed based on how many times the button is pressed. here is my code const int inPin = 3;         // tilt switch or button to trigger dc motor const int outPin = 1;       // dc motor const int buttonPin = 2; //button to change pwm const int ledPin = 0; // led to know the state of pwm int pwmvalue = 255; int buttonPushCounter = 0; int buttonState = 0; int lastButtonState =0; int LEDstate = HIGH;      // the current state of the output pin int reading;           // the current reading from the input pin int previous = LOW;    // the previous reading from the input pin // the follow variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long time = 0;         // the last time the output pin was toggled long debounce = 50;   // the debounce time, increase if the output flickers void setup() {   pinMode(buttonPin, INPUT);   pinMode(ledPin, OUTPUT);   pinMode(inPin, INPUT);   digitalWrite(inPin, HIGH);   // turn on the built in pull-up resistor   pinMode(outPin, OUTPUT); } void loop() { buttonState = digitalRead(buttonPin); if (buttonPushCounter == 1) {   (pwmvalue == 255);}   if (buttonPushCounter == 2) {   (pwmvalue == 180);}   if (buttonPushCounter == 3) {   (pwmvalue == 110);}   if (buttonPushCounter == 4) {   (pwmvalue == 70);}   // compare the buttonState to its previous state   if (buttonState != lastButtonState) {     // if the state has changed, increment the counter     if (buttonState == HIGH) {       // if the current state is HIGH then the button       // wend from off to on:       buttonPushCounter++;           } else {       // if the current state is LOW then the button       // wend from on to off:           }     // Delay a little bit to avoid bouncing     delay(50);   }   // save the current state as the last state,   //for next time through the loop   lastButtonState = buttonState;   // turns on the LED every four button pushes by   // checking the modulo of the button push counter.   // the modulo function gives you the remainder of   // the division of two numbers:   if (buttonPushCounter % 0 == 0) {     analogWrite(ledPin,pwmvalue);   }   if (buttonPushCounter % 1 == 0) {       analogWrite(ledPin,pwmvalue);   }   if (buttonPushCounter % 2 == 0) {       analogWrite(ledPin,pwmvalue);   }   if (buttonPushCounter % 3 == 0) {       analogWrite(ledPin,pwmvalue);   }       int switchstate;   reading = digitalRead(inPin);   // If the switch changed, due to bounce or pressing...   if (reading != previous) {     // reset the debouncing timer     time = millis();   }   if ((millis() - time) > debounce) {      // whatever the switch is at, its been there for a long time      // so lets settle on it!      switchstate = reading;      // Now invert the output on the pin13 LED     if (switchstate == HIGH)       LEDstate = LOW;     else       LEDstate = HIGH;   } LEDstate = HIGH == pwmvalue;     digitalWrite(outPin, pwmvalue);   // Save the last reading so we keep a running tally   previous = reading;   } is my code written correctly for my purpose is there anything i could have written better? its compiling without any problems andni havn't been able to upload because i ust back into arduino and im waiting for my attinys to come in. thank you guys for reading.

Question by wesm4   |  last reply

Virtualwire RF 433mhz Voltage problem

Hi, i am trying to have it switch a 5v relay on pin 8 receiver side only when pin 2 transmitter side in held down. I have set up a XY-MK 5v transmitter , Push button to pin 2 live when pushed 3.3v Data rf transmitter to pin 4 and 5v,gnd and receiver, data pin 2 5v and gnd led to pin 8 and gnd Here are the codes. Transmitter Code= #include const int button = 2; const int transmit_pin = 4; const int receive_pin = 2; const int transmit_en_pin = 3; void setup() {   // Initialise the IO and ISR   Serial.begin(9600);   vw_set_tx_pin(transmit_pin);   vw_set_rx_pin(receive_pin);   vw_set_ptt_pin(transmit_en_pin);   vw_set_ptt_inverted(true); // Required for DR3100   vw_setup(2000);  // Bits per sec } byte count = 1; void loop() {   char msg[7] = {'h','e','l','l','o',' ','#'};   if     (digitalRead(button) == HIGH)   {Serial.println("on its way");   msg[6] = count;   //digitalWrite(led_pin, HIGH); // Flash a light to show transmitting   vw_send((uint8_t *)msg, 7);   Serial.println("on its way");   vw_wait_tx(); // Wait until the whole message is gone   //digitalWrite(led_pin, LOW);   //delay(1000);   count = count + 1; } } And receiver code = #include const int led_pin = 8; const int transmit_pin = 12; const int receive_pin = 2; const int transmit_en_pin = 3; void setup() {     delay(1000);     Serial.begin(9600); // Debugging only     Serial.println("setup");     // Initialise the IO and ISR     vw_set_tx_pin(transmit_pin);     vw_set_rx_pin(receive_pin);     vw_set_ptt_pin(transmit_en_pin);     vw_set_ptt_inverted(true); // Required for DR3100     vw_setup(2000);  // Bits per sec     vw_rx_start();       // Start the receiver PLL running } void loop() {     uint8_t buf[VW_MAX_MESSAGE_LEN];     uint8_t buflen = VW_MAX_MESSAGE_LEN;     if (vw_get_message(buf, &buflen;)) // Non-blocking     { int i;         digitalWrite(led_pin, HIGH); // Flash a light to show received good message // Message with a good checksum received, print it. Serial.print("Got: "); for (i = 0; i < buflen; i++) {      Serial.print(buf[i], HEX);      Serial.print(' '); } Serial.println();         digitalWrite(led_pin, LOW);     } } I have tried many different codes i have found and this works the best but.........the voltage is only going from 0.20v to 0.40 on the receiver pin 8. i need this to be 5v any ideas?

Topic by Senken   |  last reply

Analog and Digital Inputs for Teensy 3.2 MIDI Programming within Arduino

Been having some trouble with programming my custom potentiometers for my midi controller. I have 12 buttons and 6 knobs. I have it wired correctly and have the sanwa arcade buttons working fine. I'm just having a huge problem adding analog code to my digital code. I'm not sure where to go from here, I have tried over 20 different types of analog code and I'm not sure what I'm doing wrong. Just need a basic potentiometer for reading MIDI. I have the first 1-12 digital inputs on my teensy soldered in for my arcade buttons. For the analog potentiometers I have them soldered on inputs 18-23 or (A4 thru A9) on the Teensy 3.2. I am using Arduino software along with the Teensy loader. Any help would be greatly appreciated, thank you. Here is the code I have thus far. I only have the 19 and 23 analog inputs written in this one at the very end, because I removed the others.  ******** /* Buttons to USB MIDI Example    You must select MIDI from the "Tools > USB Type" menu    To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"    This example code is in the public domain. */ #include // the MIDI channel number to send messages const int channel = 1; // Create Bounce objects for each button.  The Bounce object // automatically deals with contact chatter or "bounce", and // it makes detecting changes very simple. Bounce button1 = Bounce(1, 5);  // 5 = 5 ms debounce time Bounce button2 = Bounce(2, 5);  // which is appropriate for good Bounce button3 = Bounce(3, 5);  // quality mechanical pushbuttons Bounce button4 = Bounce(4, 5); Bounce button5 = Bounce(5, 5);  // if a button is too "sensitive" Bounce button6 = Bounce(6, 5);  // to rapid touch, you can Bounce button7 = Bounce(7, 5);  // increase this time. Bounce button8 = Bounce(8, 5); Bounce button9 = Bounce(9, 5); Bounce button10 = Bounce(10, 5); Bounce button11 = Bounce(11, 5); Bounce button12 = Bounce(12, 5); void setup() {   // Configure the pins for input mode with pullup resistors.   // The pushbuttons connect from each pin to ground.  When   // the button is pressed, the pin reads LOW because the button   // shorts it to ground.  When released, the pin reads HIGH   // because the pullup resistor connects to +5 volts inside   // the chip.  LOW for "on", and HIGH for "off" may seem   // backwards, but using the on-chip pullup resistors is very   // convenient.  The scheme is called "active low", and it's   // very commonly used in electronics... so much that the chip   // has built-in pullup resistors!   pinMode(1, INPUT_PULLUP);   pinMode(2, INPUT_PULLUP);   pinMode(3, INPUT_PULLUP);   pinMode(4, INPUT_PULLUP);   pinMode(5, INPUT_PULLUP);   pinMode(6, INPUT_PULLUP);  // Teensy++ 2.0 LED, may need 1k resistor pullup   pinMode(7, INPUT_PULLUP);   pinMode(8, INPUT_PULLUP);   pinMode(9, INPUT_PULLUP);   pinMode(10, INPUT_PULLUP);   pinMode(11, INPUT_PULLUP);   pinMode(12, INPUT_PULLUP);// Teensy 2.0 LED, may need 1k resistor pullup } void loop() {   // Update all the buttons.  There should not be any long   // delays in loop(), so this runs repetitively at a rate   // faster than the buttons could be pressed and released.   button1.update();   button2.update();   button3.update();   button4.update();   button5.update();   button6.update();   button7.update();   button8.update();   button9.update();   button10.update();   button11.update();   button12.update();   // Check each button for "falling" edge.   // Send a MIDI Note On message when each button presses   // Update the Joystick buttons only upon changes.   // falling = high (not pressed - voltage from pullup resistor)   //           to low (pressed - button connects pin to ground)   if (button1.fallingEdge()) {     usbMIDI.sendNoteOn(61, 99, channel);  // 61 = C#4   }   if (button2.fallingEdge()) {     usbMIDI.sendNoteOn(62, 99, channel);  // 62 = D4   }   if (button3.fallingEdge()) {     usbMIDI.sendNoteOn(63, 99, channel);  // 63 = D#4   }   if (button4.fallingEdge()) {     usbMIDI.sendNoteOn(64, 99, channel);  // 64 = E4   }   if (button5.fallingEdge()) {     usbMIDI.sendNoteOn(65, 99, channel);  // 65 = F4   }   if (button6.fallingEdge()) {     usbMIDI.sendNoteOn(66, 99, channel);  // 66 = F#4   }   if (button7.fallingEdge()) {     usbMIDI.sendNoteOn(67, 99, channel);  // 67 = G4   }   if (button8.fallingEdge()) {     usbMIDI.sendNoteOn(68, 99, channel);  // 68 = G#4   }   if (button9.fallingEdge()) {     usbMIDI.sendNoteOn(69, 99, channel);  // 69 = A5   }   if (button10.fallingEdge()) {     usbMIDI.sendNoteOn(70, 99, channel);  // 70 = A#5   }   if (button11.fallingEdge()) {     usbMIDI.sendNoteOn(71, 99, channel);  // 71 = B5   }   if (button12.fallingEdge()) {     usbMIDI.sendNoteOn(72, 99, channel);  // 72 = C4   // Check each button for "rising" edge   // Send a MIDI Note Off message when each button releases   // For many types of projects, you only care when the button   // is pressed and the release isn't needed.   // rising = low (pressed - button connects pin to ground)   //          to high (not pressed - voltage from pullup resistor)    }   if (button1.risingEdge()) {     usbMIDI.sendNoteOff(61, 0, channel);  // 61 = C#4   }   if (button2.risingEdge()) {     usbMIDI.sendNoteOff(62, 0, channel);  // 62 = D4   }   if (button3.risingEdge()) {     usbMIDI.sendNoteOff(63, 0, channel);  // 63 = D#4   }   if (button4.risingEdge()) {     usbMIDI.sendNoteOff(64, 0, channel);  // 64 = E4   }   if (button5.risingEdge()) {     usbMIDI.sendNoteOff(65, 0, channel);  // 65 = F4   }   if (button6.risingEdge()) {     usbMIDI.sendNoteOff(66, 0, channel);  // 66 = F#4   }   if (button7.risingEdge()) {     usbMIDI.sendNoteOff(67, 0, channel);  // 67 = G4   }   if (button8.risingEdge()) {     usbMIDI.sendNoteOff(68, 0, channel);  // 68 = G#4   }   if (button9.risingEdge()) {     usbMIDI.sendNoteOff(69, 0, channel);  // 69 = A5   }   if (button10.risingEdge()) {     usbMIDI.sendNoteOff(70, 0, channel);  // 70 = A#5   }   if (button11.risingEdge()) {     usbMIDI.sendNoteOff(71, 0, channel);  // 71 = B5   }   if (button12.risingEdge()) {     usbMIDI.sendNoteOff(72, 0, channel);  // 72 = C4   // MIDI Controllers should discard incoming MIDI messages.   // http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash   while (usbMIDI.read()) {     // ignore incoming messages   } } // read the input on analog pin 19:   int sensorValue = analogRead(A5);   // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):   float voltage = sensorValue * (5.0 / 1023.0);   // print out the value you read:   Serial.println(voltage); } // read the input on analog pin 23:   int sensorValue = analogRead(A9);   // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):   float voltage = sensorValue * (5.0 / 1023.0);   // print out the value you read:

Topic by abissmusic   |  last reply

can anyone help me with Opto-isolator and Arduino problems

Basically i have tried to connect a Remote control to an opto-isolator via positive and negative wires running from the sides of a button, and then connected the opto - isolator to the arduino via ground and digital pin. I am a programmer and have written a home automation program to control this digital pin on the arduino, and when the pin is set to high the button is pressed on the remote control. Now here is the tricky part. I know that the pos/neg wires are correctly soldered on because you touch them and they make the connection and turn the Remote controlled socket( which is controlled by the remote control) on and everything is lovely. But when the opto-isolator is involved you get the nice blinking LED on the remote control to signal it is sending, but the socket does nothing. Again i have tried the output circuit on the end of the opto-isolator with a 9v batteries and an LED and they are fine.  Working nicely. Another thing to note is that te multimeter showsthat when using the opto-isolator and the remote control the power is the same as if you pressed the button.   I seem to be tearing my hair out here, so anyone who can give me an answer would be on my lifesavers list for life! Before anyone suggests using anything else like a transistor,Relay etc, it must be an opto-isolator as this is a project i want to do centering around opto-isolators. Cheers Mark 

Question by MarkFW   |  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 sensor and moving wheel with encoder help with code

I'm still new at this but I been trying to figure this out for awhile now and can't seem to get it to work how I want it to. If  anyone can help or give advice on how I can go about doing this would be great. Thanks #include       const int BUTTON = A5;              // push button for starting       const int RIGHT_SERVO = 10;       const int LEFT_SERVO = 11;       Servo leftServo;       Servo rightServo;       int valButton;       int turnOnOff=0;             // the val of the pull up button is set to zero to start with             volatile int Lindex = 0;             void setup()       {         attachInterrupt(0,ltEncoderInterrupt,RISING);         Serial.begin(9600);         leftServo.attach(LEFT_SERVO);         rightServo.attach(RIGHT_SERVO);         leftServo.write(1500);         rightServo.write(1500);       }       void loop()       { Serial.println(turnOnOff);         turnOnOff=readButton();      // calls the function readButton to see if the button has been pressed(1)         int sensorValue = analogRead(A0);         if(turnOnOff==1)         {           if (sensorValue <300) //This robot moves on a white background           {           delay(500);                  leftServo.write(1700);           rightServo.write(1300);                              }           else if (sensorValue >300)           {                     // It stop when it detect a black electrical tape.           leftServo.write(1500);           rightServo.write(1500);            Lindex = 0;           delay(500);             }                                // can't seem to get it to work it keep moving backward           {                     }           leftServo.write(1300);           rightServo.write(1700);                     while (Lindex < 50) // this is how many tick i want it to move back with the encoder           {                     }           turnOnOff = 0;           Lindex = 0;         }                 else         {           leftServo.write(1500);           rightServo.write(1500);                  }        }             /************* Subroutine for reading the button switch********************/       int readButton()       {         unsigned long contactTime;               //local variable; contactTime declared         valButton=analogRead(BUTTON);            // Read the pushbutton on an analog pin         if(valButton>512)                        // Since 5V will produce a value of 1023, < 512 means button not pushed          return turnOnOff;                       // return the value of turnOnOff without changing it         contactTime=millis();                    // set contactTime = to the millis() clock value         while(valButton<=512)         {                   // while the pushbutton is pushed           valButton=analogRead(BUTTON);           // read the button value again and keep reading until valButton is less than 512         }         if(millis()-contactTime<20)               // If the button is held for less than 20 ms          return turnOnOff;                       // return the turnOnOff value unchanged          return(1-turnOnOff);                      // if the button is held longer than 20 ms then change the turnOnOff                                                  // to the opposite value to what it was       }       /////////////////////////////////////////////////////////////////////////////             /******************ISR for wheel count**************************************/       void ltEncoderInterrupt()       {                Lindex++;       }       ///////////////////////////////////////////////////////////////////////////////

Topic by al2tistic   |  last reply

Is this a hidden microphone or some kind of power supply? Answered

The button on the left clicks in like a pen and an internal lever locks it into place.  It will not ever release unless the unit is disassembled.  After pressing the end, the internal pin makes contact with the metal can on the right.  The can was broken open open during extraction and has a core of an unknown material.  There is also a single wire protruding from the side.  The insulation originally covered the wire.  Markings on the plastic housing are NB and under the NB, a lower case letter "a".  It is about an inch long.  A larger, milder spring and internal pin that looked like a tiny nail that was in the square housing are not in the image.

Question by spacetime   |  last reply

How to tell what current-limiting resistor to use Answered

I'm having my Arduino Leonardo substitute a few buttons in a device. In the buttons, one pin connects to ground with the other going to a microcontroller. I figured I could connect an NPN transistor in parallel, with the emitter to ground, the collector to the microcontroller, and the base to a resistor and my Arduino. How do I choose this resistor? Every guide I found involves getting the current load, and I don't know how to do that. I'm thinking I can just put in a 10k resistor and be fine, but I want to make sure. Thanks for any help

Question by 4lifenerdfighter   |  last reply

555 monostable sensitivity?

Has anyone built a 555 monostable circuit that was extremely sensitive for no apparent reason? I'm trying to use one in a rube-goldburg machine, and for some reason it's extremely sensitive to any sort of touch! The circuit sometimes comes on for no apparent reason, other times it will stay on for longer than the expected duration after the button is pushed. I'm using non-CMOS 555 on about 5 volts to run a small LED. The capacitor I used was a 0.01 uF on pin 1 to 5, and a 1 uF electrolytic on pin 1 to 6. I used a 1M resistor on pin 7 to 8.  I'm simply baffled by it. I've tried using different breadboards, different PSUs, brand new components, and correct gauge wire, but despite everything being seemingly fine, it's still shows the sensitivity. Anyone have any advice?

Question by tylervitale   |  last reply

Analog to Digital not correct for set trigger value Answered

I am trying to remedy false hits. I have a remote operated light that uses a 38MHz 3 leg IR sensor and a  TV remote for on/off, but it can have false hits, IE light may come on when ever.  I decided it needed a  long button press or in this case a long IR input. Because the IR sensor doesn't go from 0 to 5 volts i have set a threshold of 600. IR voltage values are, low is 1.8v and high is 3.6v. So i decided 2.75V could be a reasonable threshold value. that ROUGHLY translated to 600 if going from 0 to 1023. This sketch works good for a button but trying to use the IR sensor does not. I have tried to map the sensor and put a trigger value but something is a miss with my work. Any suggestions?  /* *  Press & Hold Switch LED program */ // Parameters int HOLD_DELAY = 500;    // Sets the hold delay of switch for LED state change int ledPin     = 9;      // LED is connected to pin x int switchPin  = A0;      // Switch is connected to pin x int val = 0; int statePin = LOW; int THRESHOLD = 600; // In-Program Variables unsigned long start_hold; boolean allow = false; int sw_state; int sw_laststate = LOW; int led_state = LOW; // Setup void setup() {   Serial.begin(9600);   pinMode(ledPin, OUTPUT);      // Set the LED pin as output   pinMode(switchPin, INPUT);    // Set the switch pin as input } // Loop void loop(){   int val = analogRead(switchPin);    val = map(val, 0, 1023, 0, 255);    if (val >= THRESHOLD) {     statePin = !statePin;         digitalWrite(ledPin, statePin);     Serial.print(val);     Serial.println("Triggered!");     delay(80);   sw_state = digitalRead(switchPin);             // read input value     if (sw_state == HIGH && sw_laststate == LOW){  // for button pressing     start_hold = millis();                       // mark the time     allow = true;                                // allow LED state changes   }        if (allow == true && sw_state == HIGH && sw_laststate == HIGH){  // if button remains pressed       if ((millis() - start_hold) >= HOLD_DELAY){                   // for longer than x/1000 sec(s)          led_state = !led_state;                                   // change state of LED          allow = false;                                            // prevent multiple state changes       }   }   sw_laststate = sw_state;     digitalWrite(ledPin, led_state);    } }  

Question by WWC   |  last reply


Hello, I recently acquired this clock (photos attached), after googling around, i think it is some type of network synced clock.. It has a green plastic cover with a transparent front side, the cover has no buttons at all ( it s not a radio clock). the only input output are those 4 pins in the 4th photo. I think it can be a good project,  maybe box it in wood, but i have no idea how to make it work. can you help :)? thanks

Topic by Kreat0r   |  last reply

Arduino Coding help? Answered

I need some guidance on how to write some Arduino code. The physical side is an Arduino mega ADK connected to some buttons and leds. On the code side, I modified the button sketch. I am stuck on how to add multiple buttons. in the void loop. I just need someont to show me how to add 1 after that i can figure out how to add the rest. Thanks,  Kaden const int button1 = 24;     // the number of the pushbutton pin const int button2 = 25; const int button3 = 26; const int button4 = 27; const int button5 = 28; const int Bucket1 = 2; const int Bucket2 = 3; const int Bucket3 = 4; const int Bucket4 = 5; const int Bucket5 = 6; const int Bucket6 = 7; const int Bucket7 = 8; const int Bucket8 = 9; const int Bucket9 = 10; const int Bucket10 = 11; const int Bucket11 = 12; const int Bucket12 = 13; int buttonState1 = 0;         // variable for reading the pushbutton status int buttonState2 = 0; int buttonState3 = 0; int buttonState4 = 0; int buttonState5 = 0; void setup() {   // initialize the LED pin as an output:   pinMode(Bucket1, OUTPUT);   // declare LED strip pin as output   pinMode(Bucket2, OUTPUT);   pinMode(Bucket3, OUTPUT);   pinMode(Bucket4, OUTPUT);   pinMode(Bucket5, OUTPUT);   pinMode(Bucket6, OUTPUT);   pinMode(Bucket7, OUTPUT);   pinMode(Bucket8, OUTPUT);   pinMode(Bucket9, OUTPUT);   pinMode(Bucket10, OUTPUT);   pinMode(Bucket11, OUTPUT);   pinMode(Bucket12, OUTPUT);   // initialize the pushbutton pin as an input:   pinMode(button1, INPUT);   pinMode(button2, INPUT);   pinMode(button3, INPUT);   pinMode(button4, INPUT);   pinMode(button5, INPUT); } void loop() {     buttonState1 = digitalRead(button1);   buttonState2 = digitalRead(button2);   buttonState3 = digitalRead(button3);   buttonState4 = digitalRead(button4);   buttonState5 = digitalRead(button5);   // check if the pushbutton is pressed.   // if it is, the buttonState is HIGH:   if (buttonState1 == HIGH) {     // turn LED on:   digitalWrite(Bucket1, HIGH);  // turn LED strip on when button is pressed   digitalWrite(Bucket2, HIGH);   digitalWrite(Bucket3, HIGH);   digitalWrite(Bucket4, HIGH);   digitalWrite(Bucket5, HIGH);   digitalWrite(Bucket6, HIGH);   digitalWrite(Bucket7, HIGH);   digitalWrite(Bucket8, HIGH);   digitalWrite(Bucket9, HIGH);   digitalWrite(Bucket10, HIGH);   digitalWrite(Bucket11, HIGH);   digitalWrite(Bucket12, HIGH);   }   else {     // turn LED off:   digitalWrite(Bucket1, LOW);  // turn LED strip on when button is pressed   digitalWrite(Bucket2, LOW);   digitalWrite(Bucket3, LOW);   digitalWrite(Bucket4, LOW);   digitalWrite(Bucket5, LOW);   digitalWrite(Bucket6, LOW);   digitalWrite(Bucket7, LOW);   digitalWrite(Bucket8, LOW);   digitalWrite(Bucket9, LOW);   digitalWrite(Bucket10, LOW);   digitalWrite(Bucket11, LOW);   digitalWrite(Bucket12, LOW);   } }

Question by FarmerKJS   |  last reply

Microcontroller inputs in C language?

I'm having problems finding and figuring how to do inputs with mirocontrollers VIA button press >> led goes on.(I have a ATTINY2313)Outputs are as simple as PORTB = 0x10 (being hex for pin 16). Keep in mind I'm very new to micros and C. The most I've done was fast-slow blink patterns. How can i do inputs though? SIMPLE code sample is welcomed!

Topic by Killa-X   |  last reply

floppy bipolar stepper motor driver? Answered

hi i wanted to salvage my old floppy drive , and take the small bipolar motor from it after i removed it , i looked around and i found small ic (  LB1838M  ) its data-sheet is here http://www.datasheetcatalog.org/datasheet/sanyo/ds_pdf_e/LB1838M.pdf i found somethings (pins configuration) in the data-sheet that i don't understand like :  IN1 ,  IN2  ,  ENA1 , ENA2 so , what this pins represent for ? and , can i remove this ic from the board , and make a circuit like this one in the data-sheet and use it to control the stepper ( independently ) ? if yes , i need to know how to make controlling buttons or something . English in not my 1st language btw , so ... thank you :)

Question by lu2a   |  last reply

Buzzer and LED interfering with each other on an arduino? Answered

Hi, I recently got an arduino for Christmas and am experiencing a problem.  I am practicing using it with a piezo buzzer, push button, and a RGB LED.  I programmed it so that whenever the button was pushed, the LED turned green, and when it wasn't pushed, the LED turned RED.  It worked fine until I added the buzzer.  I modified the program so that the buzzer was on when the button was not pushed.  Once I did this, the buzzer turned on and green and red pin of the LED came on dimly making the LED orange when the button was not pushed, and when the button was pushed, the buzzer turned off and the LED lit up green like it was supposed to.  I wan't to know why the LED is orange instead of solid red.  Any help would be appreciated.  If you need more information let me know. Here is my sketch //#include const int RED_PIN = 9; const int GREEN_PIN = 10; const int BUTTON_PIN = 7; const int BUZZER_PIN = 6; //const int TRIGGER_PIN = 12, ECHO_PIN = 11; //NewPing sonar(TRIGGER_PIN, ECHO_PIN); void setup() {   pinMode (RED_PIN, OUTPUT);   pinMode (GREEN_PIN, OUTPUT);   pinMode (BUTTON_PIN, INPUT);   pinMode (BUZZER_PIN, OUTPUT); } void loop() {   if (digitalRead(BUTTON_PIN) == HIGH)   {     digitalWrite(GREEN_PIN, LOW);     digitalWrite(RED_PIN, HIGH);     analogWrite(BUZZER_PIN, 100);   }   else if (digitalRead(BUTTON_PIN) == LOW)   {     digitalWrite(RED_PIN, LOW);     digitalWrite(GREEN_PIN, HIGH);     analogWrite(BUZZER_PIN,0);   } }

Question by roboticarrow   |  last reply

Making a gamepad with the HC05 bluetooth module.

Hi guys! this is my first post here at Instructables :D I really hope someone will be able to help me! Basically the problem is described in the attached image. To be short, we have: - 1x smartphone (Android) - 1x bluetooth module (HC05 with breakout board GW-040 4 pin SPI) - some buttons and arrows... I've already managed to get the HC05 recognized by Windows as a gamepad (modifying the tag using AT commands). The real problem is that i'm stuck with that. I would like to understand how i can connect some buttons (let's say four) that will actually behave like arrows while playing. As far as i understood i need to use the PIO pins but unfortunately my knowledge stops here. Theoretically the code behind this is simple: when the button is pressed the circuit is close and a signal is received by the HC05 who sends the corresponding command via bluetooth. So if the up arrow is pressed, that pin will receive 1 (closed circuit) and the HC05 will send "UP_Arrow" as an instruction to the smartphone. The problem is how do i write down this code and put it into the HC05? since the gamepad tag is "universal" i guess there is some default code for things like this. I think it's the same thing they did with the MOGA... I also read that i could need a SPI-USB Download (something like this ) to use the BlueSuite, that seems like the software needed for this operation. Thanks for any advice!! P.S.: Some useful links i found while searching.. http://dextersstory.tistory.com/3 http://dextersstory.tistory.com/10 http://dextersstory.tistory.com/11 http://dextersstory.tistory.com/16 http://www.martyncurrey.com/arduino-with-hc-05-bluetooth-module-at-mode/ https://developer.mbed.org/users/edodm85/notebook/HC-05-bluetooth/ https://www.sparkfun.com/datasheets/Wireless/Bluetooth/rn-42-ds.pdf http://cdn.sparkfun.com/datasheets/Wireless/Bluetooth/RN-HID-User-Guide-v1.0r.pdf http://ww1.microchip.com/downloads/en/DeviceDoc/bluetooth_cr_UG-v1.0r.pdf

Topic by HarryValenti   |  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 

FT232RL+breadboard arduino programming problems

I am trying to program a breadboard arduino with an ft232rl programming adaptor that I found online. I made the 'duino using a atmega 328 preloaded with arduino uno optiboot from sparkfun. I attached 5volts power, 16mhz crystal, reset button, and an led to pin 13. When power is supplied, the led pulses then stopps suggesting that the bootloader is working correctly. I then connected a ft232rl to the arduino with rx to tx and tx to rx as well as the DTS pin to a 0.1 UF cap and to reset. Then i connected it to my computer via usb and installed the VCP drivers. It shows up as a com port in the IDE and I selected the board as an uno and tried to flash the blink sketch. The lights on the breakout blink, but i keep getting the avrdude not in sync message. I have tried switching cables, usb ports, pressing the reset button while programming, i have gotten rig of the 0.1 uf cap and jumped directly to DTS, i have tried both sets of drivers and have restarted the board, my computer, and the IDE as well as feeding a separate 5 volt source to the chip. How can I fix this? I am using windows vista SP1 with ide version 1.0.1 and a cheap programmer from ebay. 

Topic by qquuiinn   |  last reply