You should know my steampunk robot is going along fine with a minor setback. A few days ago I accidently shorted out an arduino uno for a simple mistake. I didn't know how to use a limit switch. Guys you should know I am using whisker type limit switches and arduino uno and I don't know what to do. I am trying to ask you is how do you wire the switch and how do you program the switch with my code. Thanks.
From: Noah
#include <Servo.h>
Servo myServoLeft;
Servo myServoRight;
int IRpin = A0;
int myLeftWhisker = A1;
int myRightWhisker = A2;
void setup()
{
Serial.begin(9600);
pinMode(myLeftWhisker, INPUT);
pinMode(myRightWhisker, INPUT);
}
void loop()
{
// boolean Signal = digitalRead(IRpin);
// Serial.println(Signal);
int myLeftWhiskerVal = digitalRead(myLeftWhisker);
int myRightWhiskerVal = digitalRead(myRightWhisker);
You specified that the switches are inputs. Now you need to supply the signals without killing the CPU. I would suggest a 4.7K resistor with one end wired to +5 and the other end to the CPU I/O pin and the normally open contact on the switch. Wire the commom contact on the switch to ground. While not closed you will see a high (1) on the input pin, when closed you will get a low (0). Like Ossipee said, with luck you can get a replacement CPU. You probably want to make sure it has the bootloader installed!!!
I am not very falimiar with which chip is used on which Arduino. Some (perhaps all) support internal pullups on some or all digital I/O lines. SparkFun has a tutorial on pullups.
You use pull up resisters You use pull up resisters for a couple of reasons.
First, if you just connect the switch between an input pin and ground, then what is read when the switch is open? In that state, there is nothing: not a high or a low being read. With the built in pull-ups enabled, then when the switch is open, it reads high, and when closed it reads low.
Second, I can’t really think of a second reason right now.
I’d suggest buying a cheap clone of the Arduino on eBay to replace it. And pick up the proper chip to hopefully fix yours, then you’ll have two.
I would avoid using the analog inputs for purely digital data. If you continue developing this robot with this software, you may find yourself having to move inputs around to make use of one or more of those analog inputs. I would also avoid the pwm pins, as you may need them later on.
You see guys first of all it turns out that the uno I thought got shorted wan’t shorted. It had too many wires and too little power. Next you should know that the COM pin should be connected to power while the other pin which is NC which I originally thought stood for No Connection turns out it means that the sensor has been in contact. Also last but not least I was using analog pins not digital pins which resulted in the board being confused. Thanks for all your help this won’t be the last you’ll hear from me.