0% found this document useful (0 votes)
4 views4 pages

Simulation 2

The document outlines a simulation project using three IR sensors connected to an Arduino, with pushbuttons used to mimic sensor readings. It provides a step-by-step guide for wiring, coding, and testing the setup in Tinkercad, including the use of a pull-down resistor to ensure accurate readings. The expected outcomes for various button combinations are detailed, demonstrating the Left-Hand Rule for decision-making in robot navigation.

Uploaded by

hamilton8002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views4 pages

Simulation 2

The document outlines a simulation project using three IR sensors connected to an Arduino, with pushbuttons used to mimic sensor readings. It provides a step-by-step guide for wiring, coding, and testing the setup in Tinkercad, including the use of a pull-down resistor to ensure accurate readings. The expected outcomes for various button combinations are detailed, demonstrating the Left-Hand Rule for decision-making in robot navigation.

Uploaded by

hamilton8002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Simulation 2 — IR sensor readings

Here's what we're building. Three IR sensors — left, front, right — each
connected to the Arduino. We'll simulate walls using pushbuttons in Tinkercad
since Tinkercad doesn't have an IR sensor component.

A pushbutton perfectly mimics an IR sensor for logic testing:

 Button not pressed = no wall detected = HIGH


 Button pressed = wall detected = LOW

The logic your code sees is identical either way.

Wiring diagram

Why the 10kΩ resistor?


This is called a pull-down resistor — a concept you'll have seen in your ECE
classes. Without it, the Arduino pin floats between HIGH and LOW randomly
when the button isn't pressed, giving you garbage readings. The resistor pulls
the pin firmly to GND (LOW) when the button is open. When pressed, 5V
overrides it and the pin reads HIGH.

Real IR sensor modules have this resistor built in — so on the actual robot you
don't need to add one manually.

Step by step in Tinkercad


Step 1 — Place components

From the components panel, drag onto canvas:


 Arduino Uno R3
 Pushbutton × 3
 Resistor × 3 — set each to 10kΩ (click the resistor → change value to
10000Ω)

Step 2 — Wire each button identically

For each of the three buttons repeat this pattern:

 One leg of button → Arduino 5V


 Other leg of button → Arduino signal pin (7, 8, 4)
 Same signal leg → one end of 10kΩ resistor
 Other end of resistor → Arduino GND

Step 3 — Enter the code

Click Code → Text → paste this:

cpp
#define IR_LEFT 7
#define IR_FRONT 8
#define IR_RIGHT 4

void setup() {
pinMode(IR_LEFT, INPUT);
pinMode(IR_FRONT, INPUT);
pinMode(IR_RIGHT, INPUT);
[Link](9600);
}

void loop() {
int left = digitalRead(IR_LEFT);
int front = digitalRead(IR_FRONT);
int right = digitalRead(IR_RIGHT);

// Print raw values


[Link]("LEFT: "); [Link](left == LOW ? "WALL" : "open");
[Link](" FRONT: "); [Link](front == LOW ? "WALL" : "open");
[Link](" RIGHT: "); [Link](right == LOW ? "WALL" :
"open");

// Print what the robot would decide


[Link]("Decision: ");
if (left == LOW) [Link]("→ turn LEFT");
else if (front == LOW) [Link]("→ go FORWARD");
else if (right == LOW) [Link]("→ turn RIGHT");
else [Link]("→ U-TURN");

[Link]("---");
delay(500);
}

Step 4 — Test all 8 wall combinations


Start simulation and open the Serial Monitor. Then press button combinations
and verify the decision printed is correct. There are 8 possible combinations —
here's what each should print:

Left button Front button Right button Expected decision


Not pressed Not pressed Not pressed U-TURN
Pressed Not pressed Not pressed turn LEFT
Not pressed Pressed Not pressed go FORWARD
Not pressed Not pressed Pressed turn RIGHT
Pressed Pressed Not pressed turn LEFT
Pressed Not pressed Pressed turn LEFT
Not pressed Pressed Pressed go FORWARD
Pressed Pressed Pressed turn LEFT

Notice the last three rows — when multiple walls are present, left always wins
because of the if/else priority order. That's the Left-Hand Rule working
exactly as designed.

What to verify
 ✅ No buttons pressed → Serial Monitor says "U-TURN"
 ✅ Left button pressed alone → "turn LEFT" regardless of others
 ✅ Only front pressed → "go FORWARD"
 ✅ Only right pressed → "turn RIGHT"
 ✅ All 8 combinations match the table above

Once all 8 pass, come back and we'll move to Simulation 3 — combining
sensors and motors together into the full Left-Hand Rule logic. That's where
it all comes together!

You might also like