Ford Cardboard Truck

Description:

Get information from at least one analog sensor and at least one digital sensor (switch), and use this information to control at least two LEDs, one in a digital fashion and the other in an analog fashion, in some creative way.

Process:

I first started this process, just by completing the circuit and finishing the requirements of the assignment, that is, to use a sensor (analog), button (digital switch )

I used 4 LEDs, 6 resistors ( 4 – 330 v and 2- 10k), jumper cables, LDR (Light-dependent resistor) resistors, breadboard, and Arduino board.

I used the LDR in a way in which if the surroundings are bright (more than 400 (LDR sensor status)), blue LED would light up, and if the surroundings are dark(less than 400 (LDR sensor status)), green LED would light up. By bending the lights a little and using the cardboard, I made it look like a car.

So, I used the LEDs as the front light of the truck. Then, I had to use a switch, so I did that by using the back of the truck.

So, if I closed the back of the truck, one red LED would light up, if I opened it, the other would light up.

This is what the breadboard and Arduino looked like:

This is how the LDR resistor looked like when it worked:

Overall, it was fun to use my creativity to learn how to use these tools.

The code for this is given below:

const int ledPin = 10;
const int ledPin2 = 9;
const int knobPin = A1;

const int ledRed = 13;
const int switch1 = 7;
const int ledBlue = 12;
bool currentState = false;
bool switchState = LOW;



void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(knobPin, INPUT);

  pinMode(ledRed, OUTPUT);
  pinMode(ledBlue, OUTPUT);
  pinMode(switch1, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  int ldrStatus = analogRead(knobPin);

  if(ldrStatus <= 400){
    digitalWrite(ledPin, HIGH);
    digitalWrite(ledPin2, LOW);
    
    }
    else{
      digitalWrite(ledPin, LOW);
      digitalWrite(ledPin2, HIGH);
      
      
      }

    switchState = digitalRead(switch1);
    if (currentState != switchState ){
      digitalWrite(ledBlue, LOW);
      digitalWrite(ledRed, HIGH);
     } else {
      digitalWrite(ledBlue, HIGH);
      digitalWrite(ledRed, LOW);
    }
}

 

 

Leave a Reply