wheel and axle prototype

albert_tjoeng's picture

Description:

Create a rotating axle that can rotate clockwise and counter clockwise. The FSR is acting like a gas pedal, the proximity sensor determine the direction of the wheel. If we put our hands blocking the proximity sensor, the wheel will rotate counter clockwise, if there is no blockage the wheel rotate clockwise. Two LEDs as an indicator, green:the wheel moving clockwise, red: the wheel moving counter clockwise.

Materials:

Proximity Sensor

FSR

DC motor

Wine cap

two LEDs

CODE:

 

int irPin = 5;
int potPin = 0;   // select the input pin for the potentiometer
int pwmPins[] = {6, 5};
int val = 0;      // variable to store the value coming from the sensor
int valIR = 0;
 
int speakerOut = 7;        
 
void setup() {
  Serial.begin(9600);
  for (int i = 0; i<=2; i++){
    pinMode (pwmPins[i], OUTPUT);
  }  
}
void loop() {
  val = analogRead(potPin);    // read the value from the sensor, between 0 - 1024
  val = map(val, 1, 1022, 0, 255);
  valIR = analogRead(irPin);
  Serial.println(valIR);
  analogWrite(pwmPins[0], 0); // analogWrite can be between 0-255
  analogWrite(pwmPins[1], val);
  digitalWrite(speakerOut, LOW);     
  
  if (valIR > 200){
    analogWrite(pwmPins[1], 0); 
    analogWrite(pwmPins[0], val);
  }  
}
photo.JPG
0
Your rating: None