I hooked up my arudino with a bike speedometer so every time the magnet from my wheel made contact with the switch, it would supposedly tell my arduino that it was on.
The way I verified it working was I hooked it up to an LED to power it on to see if the LED would turn on every time the magnet passed the switch and it worked so I wanted to make a program on my arduino.
The program was to take the input from pin 12 and everytime it was on, it would set pin 13 (where the LED was hooked up to) to HIGH so it would turn on, else it would set it to LOW.
I have it simultaneously hooked up with another LED with the setup I described above to make sure the bike switch combo is working and it turns on whenever the switch is active but my program does not work. I'm not sure how to troubleshoot since I do not know why my code does not print anything out even though I have the lines in there.
Please help!!!!!!
/*
turns on an LED hooked up to pin 13 when the magnet touches the bike wheel
at pin 12
*/
// constants won't change. They're used here to
// set pin numbers:
const int bikeinput = 12; // the number of the bike pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
//int bikeinput = 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(bikeinput, INPUT);
Serial.begin(9600);
}
/*
turns on an LED hooked up to pin 13 when the magnet touches the bike wheel
at pin 12
*/
// constants won't change. They're used here to
// set pin numbers:
const int bikeinput = 12; // the number of the bike pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
//int bikeinput = 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(bikeinput, INPUT);
Serial.begin(9600);
}
void loop(){
Serial.println("hi");
if (bikeinput == HIGH)
{
//turn the ledpin to on
digitalWrite(ledPin,HIGH);
Serial.println("hello");
}
else {
//turn it off
digitalWrite(ledPin,LOW);
Serial.println(bikeinput);
}
}
It seems you forgot digitalRead for the bikeinput pin.
I tried your code, but it does not seem to still wanna work. Any other suggestions on how I can do this? I don't get why it wouldn't work this way? I know my circuit is correct and I've verified everything is plugged in and working.
Thanks
And the print thing still wouldn't work so I can't check the values that are being sent into the Arduino
If you want a variable to hold the state of the bikeinput pin the last time you looked at it, you need to give that variable a different name, e.g. "inputWas"
Instead of....
if (bikeinput == HIGH)
.... you want...
if (digitalRead(bikeinput) == HIGH)
... or...
inputWas=digitalRead(bikeinput);
if (inputWas == HIGH);
(Also, the line "Serial.println(bikeinput);" won't work as you seem to be expecting. It will just keep printing 12. Getting what I think you want is possible, though... it just needs more code than I can be bothered with this late at night!)
is that all i would need to change? Just those couple lines? Is there any tutorials I can read that would help me understand how to take those inputs and make them turn into other functions?
speed means distance per time. you'll need the wheel circumference--something like 2.136 meters depending on your wheel and tire. one revolution will be that much distance. then you'll need time--you can use millis() to get the passage of time; you'll want to save what millis() was at one click and then subtract that from the millis() at the next click and figure out how to convert that time and distance to speed in the units of your choice.