Hi everyone,
I am trying to create a automatic bike light with the help of Arduino.
I want the bike light to turn on when I sit on the seat because of a force sensitive resistor embedded in the seat. However, if I'm riding in the daylight I want the light not to turn on - i think a photo resistor on the bike could achieve this. This means, the light will only turn on when I'm is seated and it is night time. Also, when I press the brake (i.e. a button) I want this to not only make the bike brake but also make the light flash, to let everyone know I am braking.
I have tried my code out on the Arduino simulator on 123D circuit, but it doesn't seem to work. I was working if anyone could have a look at my code and provide some feedback on what I might be doing wrong, as I think it is my code that is wrong and not my circuit. Thanks in advance to anyone who replies!
Here is my code and I have also attached an image of my circuit-
int ledpin = 11;
int sensePin1 = A0;
int sensePin2 = A1;
int sensePin3 = 7;
int senseReading;
int lightReading;
int pressureReading;
boolean buttonReading;
void setup()
{
pinMode(ledpin, OUTPUT);
pinMode(sensePin1, INPUT);
pinMode(sensePin2, INPUT);
pinMode(sensePin3, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
lightReading = analogRead(sensePin1);
pressureReading = analogRead(sensePin2);
buttonReading = digitalRead(sensePin3);
if (lightReading < 300 && pressureReading > 500) {
//it's dark and person on seat so turn light on
digitalWrite(ledpin, HIGH);
} else {
//it's light and no one is on bike so turn light off
digitalWrite(ledpin, LOW);
Serial.println(senseReading);
}
if (buttonReading == HIGH) {
//the brake button has been pushed and the light flashes/blinks
digitalWrite(ledpin, LOW); // turn LED OFF
delay (500);
digitalWrite(ledpin, HIGH); // turn LED ON
delay (500);
} else {
//it's light and no one is on bike so turn light off
digitalWrite(ledpin, LOW);
Serial.println(senseReading);
}
}
