0% found this document useful (0 votes)
8 views35 pages

Grade 8 Robotics Textbook GWH

The SE-2 Textbook for Grade 8 introduces the STEM Master Kit, which includes various components and sensors designed to engage students in Science, Technology, Engineering, and Mathematics (STEM) through hands-on learning. It also covers the Boffin ESP32 ArduBlock Software, a graphical programming tool that simplifies coding for beginners using a drag-and-drop interface. Additionally, it provides a lesson on controlling an LED with a sound sensor, demonstrating real-time applications and programming concepts.

Uploaded by

channel.aadit
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)
8 views35 pages

Grade 8 Robotics Textbook GWH

The SE-2 Textbook for Grade 8 introduces the STEM Master Kit, which includes various components and sensors designed to engage students in Science, Technology, Engineering, and Mathematics (STEM) through hands-on learning. It also covers the Boffin ESP32 ArduBlock Software, a graphical programming tool that simplifies coding for beginners using a drag-and-drop interface. Additionally, it provides a lesson on controlling an LED with a sound sensor, demonstrating real-time applications and programming concepts.

Uploaded by

channel.aadit
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
You are on page 1/ 35

SE-2 TEXTBOOK

GRADE 8

LESSON- 1
Introduction to STEM Master Kit
The STEM Master Kit is an educational resource designed to introduce students to the
fundamental concepts of Science, Technology, Engineering, and Mathematics (STEM). It
includes various hands-on materials and tools that allow learners to engage in interactive
experiments and projects. The kit aims to foster curiosity, creativity, and problem-solving
skills by providing practical experiences in different STEM areas.

Components:
 Microcontroller - ESP32
 DC Motors
 Servo Motor
 Motor Driver

Sensors:
 Buzzer (Actuator)
 Limit Switch (Actuator)
 LED (Actuator)
 Ultrasonic Sensor
 IR Sensor
 Sound Sensor
 Light Sensor
 Soil Moisture Sensor
 Temperature/Humidity Sensor
 Tilt Sensor
 Motion Sensor

COMPONENTS:
1. Microcontroller (ESP32):
The ESP32 is a small, affordable microcontroller.

It's popular for making smart devices and gadgets because it has a lot of useful features.
The ESP32 is a microcontroller that can connect to Wi-Fi and Bluetooth, making it great for
building smart devices.

Page | 1
Applications:
The ESP32 is widely used in various applications, including:

 Home automation
 Wearable electronics
 Wireless sensors
 Robotics
 Smart appliances

2. DC Motor:
The DC motor is an electric motor that runs on direct current (DC) electricity. It converts
electrical energy into mechanical energy, causing the motor to spin.
DC motor is a component that rotates 360 degrees.

3. Servo Motor:
A Servo motor is a component that can rotate its handle (between 0 degree to 180 degree).
It used to control the angular position of the object.
Servo motor can be used in Automated door lock - an automated door lock system where a
servo motor controls the locking mechanism, allowing you to lock and unlock doors remotely.

4. Motor Driver:
A motor driver sends the right amount of current and voltage to the motor to move the
motor shaft at the desired speed and in the desired direction.

📌 Important Note: Always remember, when using a DC motor in your model, a motor
driver is essential to integrate the motor with the microcontroller.

Page | 2
ACTUATORS:
An actuator is a device that converts energy (electric, hydraulic, or pneumatic) into
mechanical motion. It is used to control or move systems like motors, valves, or robotic arms.

1. Buzzer:
A buzzer is an audio signal device, often used to indicate an alarm, alert, or other notification.
It produces a sound, which can vary in tone, volume, and duration depending on its design.

2. Limit Switch:
A limit switch detects the position of a moving part and triggers actions like stopping or
reversing when it reaches a predefined limit.

3. LED (Light Emitting Diode):


An LED (Light Emitting Diode) is a semiconductor device that emits light when an electric
current flows through it.

SENSORS:
Sensors are used to detect environmental conditions or changes in the system, such as
movement, temperature, or light. They provide feedback to the robot, allowing it to make
decisions or adjustments based on the collected data, thus enabling automation.

1. Ultrasonic Sensor:
An ultrasonic sensor is used to measure the distance to an object by emitting ultrasonic
waves and measuring the time it takes for the waves to return.
The maximum measurable distance for this sensor is 255 cm.

2. IR Sensor:
An IR (Infrared) sensor detects infrared light to sense motion or proximity.

It is commonly used in applications like motion detection, obstacle avoidance, and remote
controls.

3. Sound Sensor:
The sound sensor is capable of detecting the presence of sound in the surrounding.
It can be used sound –reactive project, such as clap activated light.

Page | 3
4. Light Sensor:
A light sensor detects and measures light intensity, converting it into an electrical signal to
adjust lighting, trigger alarms, or perform other actions.
It is commonly used in devices like smartphones, streetlights, and automatic brightness
controls.

5. Soil Moisture Sensor:


A soil moisture sensor is a device that measures the water content in soil.
It helps determine whether the soil is too dry, adequately moist, or too wet.
This information is often used in agriculture and gardening to optimize irrigation, ensuring
that plants receive the right amount of water.

6. Temperature Sensor/Humidity Sensor:


A temperature sensor is a device that measures temperature and converts the data into a
readable form, often an electrical signal.
These sensors can be used to monitor and control the temperature in various applications,
such as household appliances, industrial processes, HVAC systems, and electronic devices.

7. Tilt Sensor:
A tilt sensor is a device that detects the angle of tilt or inclination of an object relative to a
level surface.
Tilt sensors are commonly used in devices like smartphones, gaming controllers, and
machinery to detect orientation changes, trigger actions, or provide feedback.

8. Motion Sensor(PIR):
A motion sensor is a device that detects movement within a certain range.
It can sense the presence or movement of people, animals, or objects and typically triggers a
response, such as turning on lights, sounding an alarm, or activating a camera.
Motion sensors are commonly used in security systems, automated lighting, and smart home
devices.

Page | 4
LESSON- 2
Introduction to ArduBlock Software
Boffin ESP32 ArduBlock Software is a graphical programming tool designed
specifically for the ESP32 microcontroller. It provides a drag-and-drop interface to create
Arduino-based programs without requiring text based coding knowledge. Users can visually
create logic flows and functionalities by arranging blocks. This makes it an easy-to-use tool
for beginners and students, allowing them to quickly design projects, such as controlling
motors and sensors, without the need to learn complex coding.

📌 Important Note:
Before starting programming in the Boffin ESP32 ArduBlock software, make sure to choose
the correct board, as shown at the top in the figure above. From the "Board" menu at the
top, change the default setting to Boffin ESP32. This step is important to upload the code
correctly to your model.

Features of Boffin ESP32 ArduBlock Software:

1. Block-Based Programming
Allows users to program the ESP32 using drag-and-drop blocks (e.g., loops,
conditional statements, input/output), eliminating the need for complex coding.
2. Beginner-Friendly
Designed for students and beginners to easily create projects without prior
programming experience.
3. ESP32 Compatibility
Fully supports the ESP32 microcontroller, enabling seamless integration with its
features and peripherals.
4. Arduino-Compatible: It generates Arduino code in the background, which can be
uploaded directly to an Arduino-Compatible Arduino board.
5. Hardware Control
Simplifies the process of controlling motors, sensors, LEDs, and other hardware
components.
6. Interactive Logic Building
Enables users to visually construct logic flows and functionalities for their projects.
7. Quick Prototyping
Speeds up the development process, making it ideal for educational and prototype
projects.

Page | 5
8. Error-Free Programming
Reduces common syntax and coding errors through its graphical interface.
9. Customizable Blocks
Offers pre-built blocks for common functions and allows advanced users to extend
functionality.
10. STEM Education: Widely used in schools and workshops to teach programming
concepts in a hands-on way.

Pin Configuration Table for ESP32 Ports:

Overview of the ArduBlock software:


Boffin is an organization focused on creating educational tools for STEM learning,
specializing in robotics, electronics, and IoT. They customized ArduBlock to support their
hardware, such as Boffin ESP and Nano boards, by adding specialized block categories like
ESP_Server, WEB, and Flash Memory. These changes include pre-loaded libraries, improved
UI for beginners, and optimized code uploading for ESP32 boards, enabling easy use of
advanced features like Wi-Fi and Bluetooth.
The software offers multiple board categories, including Arduino Nano, Boffin Nano, Boffin
ESP, Arduino Nano (old), and ESP32. In general, we will be using the only Boffin ESP as the
microcontroller.
Boffin ESP likely refers to a specific software or hardware platform designed for working with
ESP microcontrollers, such as the ESP8266 or ESP32. Boffin ESP is aimed at developers with
ESP-based systems, possibly integrating sensors, actuators, and pre-built functionalities.
Page | 6
Reference to the visual layout of software.

Explanation of Each Block


1.Boffin Block: It refers to the blocks or modules in this platform that represent different
functions or commands, like controlling sensors, motors, or other components in a project.

2.Sensors Block: The Sensors Block in Boffin ESP is primarily used to read the input from
various sensors connected to the ESP32. It simplifies the process of gathering data from
sensors and using it in a project.

Page | 7
3.Actuators Block: An Actuator takes an input signal (like a sensor reading or a command)
and uses it to create a physical output (such as movement, light, or sound).

4.Logic Block: The Logic Block in Boffin ESP is used to implement conditional operations and
decision-making in projects. It allows users to create if/else statements, comparisons (e.g.,
greater than, equal to), and use logical operators (AND, OR, NOT) to control actions based on
sensor inputs. Key uses include:

 If/Else Blocks: To perform actions based on conditions (e.g., turn on a fan if the
temperature is above 30°C).
 Comparison Blocks: To compare sensor values (e.g., check if temperature > 25°C).
 Logical Operators: Combine multiple conditions (e.g., both temperature and humidity
must be high to activate the cooling system).
 Loops: Repeat actions until a condition is met

5.Loops Block: They are the following comments in loops:

 Repeat Until: Repeats actions until a condition is true (e.g., "Repeat until temperature
> 30°C").
 Repeat for: Repeats actions a fixed number of times (e.g., "Repeat 5 times with a 1-
second delay").
 Forever: Repeats actions indefinitely (e.g., "Repeat turning on LED forever").
 Repeat While: Repeats actions while a condition is true (e.g., "Repeat while
temperature > 25°C").
 Break: Exits the loop before completing all iterations.
 Continue: Skips to the next iteration.

Page | 8
6.Math Block: Explanation of the blocks:

 Numbers: Basic inputs like 0, 90°.


 Arithmetic: Perform operations like R + 1 (addition, subtraction, etc.).
 Random Integers: Generate random numbers within a range (0 to 100).
 Mapping: Scale values (R from 0-1023 to 0-255).
 Conversion: Convert R to a specific data type (e.g., byte).
 Even/Odd Check: Verify if a number is even or odd.
 Modulo: Get the remainder of X ÷ Y.
 Limit Values: Restrict R to a range (10 to 20).
 Square Root: Calculate the square root of a number.
 π (Pi): Use the constant π for geometry or trigonometry

7.Text Block: This section handles text in ArduBlock. You can create text, combine it, convert
variables (like numbers) to text, find text length, and check if specific text exists in a variable.

Page | 9
8.Time Block: This section in ArduBlock manages delays, timers, durations, and pin states.

9.Structure Block: The primary structure consists of two main blocks:

 Setup Block:
1. Runs once at the start of the program.
2. Used to initialize pins, variables, or settings.
 Loop Block:
1. Runs continuously after the setup block finishes.
2. This is where the repetitive actions (like reading sensors or controlling outputs)
are placed.
 Background: The Background Block provides a way to manage tasks in parallel,
making program more efficient and responsive.

Page | 10
10.Variable Block: This block is used to create a variable on its own for user purpose.

11.Array Block: The Array Block in Ardublock is used to create and manage arrays, which
store multiple values in a single variable. This are the uses:

 Creating Arrays: You can define an array with a specific size and set initial values.
 Accessing Elements: You access array elements using their index (e.g., array[0] for the
first element).
 Modifying Values: You can change values in the array or use loops to work with all
elements.

Page | 11
13. Function Block: The Function Block in Ardublock is used to create custom functions for
reusable code. It allows you to group tasks into a function and call it multiple times, making
your program cleaner and more organized. Functions can also accept input parameters to
perform specific actions.

14.Serial Block: The Serial Block in Ardublock is used to send and receive data over the Serial
Port, allowing communication between the Arduino board and a computer or other devices.
It is commonly used for debugging, displaying information, or sending/receiving data. It is also
used to read, access and print the values. Most common used baud rate in serial monitoring
is 9600.

Baud Rate: Baud rate is the speed at which data is transmitted over a communication
channel, measured in bits per second (bps).

Page | 12
LESSON-3
LED control using Sound sensor
Definition:
A sound sensor is used to detect variations in sound levels and convert them into
electrical signals. By programming the sensor to monitor sound levels via serial
communication, it can be used in real-time applications such as a Clap-Activated Light, where
the sensor detects a clap and triggers an LED based on predefined sound intensity thresholds.

Serial Monitoring:
Serial Monitoring is the process of displaying real-time data from a microcontroller
to a computer via a serial communication interface.

Features of Serial Monitoring:


 Real-time Data Display: Shows sensor readings and program outputs as they occur.
 Debugging Tool: Helps identify errors in code by printing variables and program
states.
 Data Logging: Allows storing and reviewing sensor values over time.
 Bi-directional Communication: Enables sending data between the computer and
microcontroller for interactive control.
 Baud Rate Control: Allows adjusting the speed of data transfer between the
microcontroller and the computer. (The baud rate must be set to 9600, any other
value may cause communication issues).

Model:

Page | 13
Block Program:

“Setup”: Here set up is used to define all the components which


are attached to the controller, their port and their mode of
operation which is input or output.
“loop”: We add the instructions which we want to get executed in
the loop.

"If & Else block" - Conditional Statements


"if" and "else" are like the road signs of programming, guiding our code on
which path to take, based on certain conditions.

Imagine you're driving a car, and you approach a tunnel. Now, this tunnel has a
height limit, and there's a sign that reads, "If your car is taller than 7 feet, do
NOT enter. Else, proceed safely."

This program effectively creates a clap-activated light system, where the LED turns
on when a clap is detected and turns off otherwise.

Page | 14
Explanation:
Setup

1. Connect Sound Sensor Tagged S1 to Port 1:


 The sound sensor (S1) is connected to Port 1 of the microcontroller.
 This sensor detects sound levels and converts them into digital input signals.
2. Connect LED Tagged L1 to Port 2:
 The LED (L1) is connected to Port 2 of the microcontroller.
 This LED will be controlled based on the detected sound levels.
3. Port Monitor - Connection (Rx/Tx) Speed 9600:
 Serial communication is established with a baud rate of 9600.
 This allows real-time monitoring of the sensor values in the serial console.

Difference between print and println:

 print outputs data on the same line without moving to the next line.
 println outputs data and moves to the next line after printing.

Loop (Repeats the Actions Indefinitely)

1. Read and Print Digital Input Value of S1:


 The sound sensor’s digital input value is read and displayed on the serial
monitor.
 This helps track the detected sound levels.
2. If Sound is Detected (S1 = 1):
 When a sound is detected (e.g., a clap), the value of S1 becomes 1.
 The LED (L1) is turned ON (HIGH).
3. Else (No Sound Detected, S1 = 0):
 If no sound is detected, the value of S1 remains 0.
 The LED (L1) is turned OFF (LOW).

Page | 15
Lesson-4
Line Follower
Definition:
A line follower robot is a type of autonomous robot designed to follow a predefined
path or line on the ground. This line is usually a visible contrast, like black on white, that the
robot can detect using IR sensors. It continuously adjusts its movement based on sensor
feedback to stay on track.

Working:

Page | 16
Model:

Bottom View

Page | 17
Block Program:
This code controls a line follower robot that moves based on the input from two IR sensors
(IRL and IRR). The robot uses two DC motors (ML and MR) to navigate the path by following a black
line on a contrasting surface.

Explanation:

Setup

1. Connect IR sensor tagged IRL to Port 4:


• The left IR sensor (IRL) is connected to Port 4 on the microcontroller.
• This sensor detects whether the left side of the robot is on the black line or the
white surface.
2. Connect IR sensor tagged IRR to Port 5:
• The right IR sensor (IRR) is connected to Port 5 on the microcontroller.
Page | 18
• It detects whether the right side of the robot is on the black line or the white
surface.
3. Connect DC motor tagged ML to Port 6:
• The left motor (ML) is connected to Port 6 of the motor driver.
• This motor controls the movement on the left side of the robot.
4. Connect DC motor tagged MR to Port 7:
• The right motor (MR) is connected to Port 7 of the motor driver.
• This motor controls the movement on the right side of the robot.
5. Set DC motor ML to speed 0% in counter-clockwise direction:
• The left motor (ML) is initially set to 0% speed, meaning it is not moving.
6. Set DC motor MR to speed 0% in clockwise direction:
• The right motor (MR) is also set to 0% speed, keeping the robot stationary at the
start.

Loop (Repeats the actions indefinitely)

1. If both IR sensors detect the line (IRL = 1 and IRR = 1):


 The robot moves straight forward.
 ML: 80% speed in counter-clockwise.
 MR: 80% speed in clockwise.
2. If only the right sensor detects the line (IRL = 0 and IRR = 1):
 The robot turns right to correct its position.
 ML: 80% speed in counter-clockwise.
 MR: 0% (stopped).
3. If only the left sensor detects the line (IRL = 1 and IRR = 0):
 The robot turns left to stay on path.
 ML: 0% (stopped).
 MR: 80% speed in clockwise.
4. If neither sensor detects the line (IRL = 0 and IRR = 0):
 The robot stops completely to avoid going off-course.
 ML: 0% speed.
 MR: 0% speed.

Page | 19
Lesson-5
Automatic Toll Gate using Ultrasonic sensor and Servo Motor
Definition:
An Automatic Toll Gate system uses an ultrasonic sensor to detect approaching
vehicles. When a vehicle is detected, a servo motor opens the gate automatically. After the
vehicle passes, the gate closes, ensuring smooth traffic flow. This system enhances efficiency
by reducing manual toll operations.

Difference between DC motor and Servo motor:


DC motor Servo motor
 Rotates continuously (360° or more)  Moves to a specific angle (typically
in both directions. 0° to 180° for standard servos).
 Does not have built-in position  Has built-in feedback for accurate
control. positioning.
 Speed and direction are controlled  Controlled using PWM signals to
using voltage or PWM signals. maintain exact positions.

In short, a DC motor is for continuous rotation, while a servo motor is for precise angular
movement.

Model:

Page | 20
Block Program:
This code controls a servo motor based on the input from two ultrasonic sensors
(USEntry and USExit). The servo motor moves to different positions depending on whether
an object is detected at the entry or exit sensor. This setup can be used for an automatic gate
or barrier system.

Explanation:
Setup

1. Connect Ultrasonic sensor tagged USEntry to Port 5:


 The ultrasonic sensor labelled USEntry is connected to Port 5 of the
microcontroller.
 This sensor detects objects approaching the entry point.
2. Connect Ultrasonic sensor tagged USExit to Port 6:
 The ultrasonic sensor labelled USExit is connected to Port 6 of the
microcontroller.
 It detects objects leaving through the exit point.
3. Connect Servo motor tagged SM to Port 4:
 The servo motor SM is connected to Port 4 of the microcontroller.
 This motor controls the movement of a barrier or gate.
4. Turn Servo motor SM to 140°:
 The servo motor is initially set to 140°, which represents its starting position
(likely closed).

Page | 21
Loop (Repeats the actions indefinitely)

1. If the distance from the ultrasonic sensor USEntry is less than 10 cm:
 This means an object is detected at the entry point.
 The servo motor SM moves to 0°, likely opening the gate.
2. If the distance from the ultrasonic sensor USExit is less than 10 cm:
 This means an object is detected at the exit point.
 The servo motor SM moves back to 140°, likely closing the gate.

This program automates the movement of a barrier using ultrasonic sensors to detect
approaching and exiting objects.

Page | 22
Lesson-6
Conversion of Block code into C++ code
Definition:
Block Code to C++ Conversion involves translating visual programming (like Scratch
or Blockly) into text-based C++ code. This process helps in understanding core programming
concepts and provides greater control over hardware. It enables users to transition from drag-
and-drop coding to writing structured C++ programs.

Software used for converting Block code into C++ code

Steps to Convert Block code into C++ code and Upload the program to ESP32
using Arduino IDE software

Step 1: Open ArduBlock and Create the Program

 Launch ArduBlock and create the required program.


 In this case, we are using the Automatic Toll Gate program (In the examination you
should be prepared to convert all the three programs).

Step 2: Convert Block Code to C++ Code

 Click on the Arduino Code Preview icon.


 Your block-based code will automatically be converted into C++ code

Page | 23
Step 3: Copy the Generated C++ Code

 Once the code is generated, copy the C++ code.

Step 4: Open Arduino IDE and Paste the Code

 Open the Arduino IDE software.


 Paste the copied C++ code into the editor screen.

Page | 24
Step 5: Remove the Underscore in the First Line

 Ensure that the first line of the code does not contain any underscore (_).

Installing Required Libraries

Note: Since we are using the ESP32 microcontroller and a servo motor, we need to install
the necessary libraries before proceeding.

Step 6: Install the ESP32 Library

 Go to Tools > Boards > Board Manager. A Board Manager window will pop up.

 In the search bar, type ESP32 and press Enter.


 You will see multiple libraries; download only the one by Express if.

Page | 25
 Important: The latest version has some bugs, so download version 2.0.17 instead.

 Select the correct version and click Install.


 Wait for the library installation process to complete.

Step 7: Install the ESP32Servo Library

 Go to Tools > Manage Libraries. A Library Manager window will pop up.

 In the search bar, type ESP32Servo and press Enter.


 You will see multiple libraries; download only the one by Kevin Harrington.
 You can install the latest version of this library.

Page | 26
 Select the correct library and click Install.
 Wait for the library installation process to complete.

Uploading the Program to ESP32

Step 8: Connect the ESP32 Microcontroller

 Use a USB cable to connect the ESP32 microcontroller to the computer.


 Ensure that the microcontroller is properly recognized by your system.

Step 9: Select the Correct Board in Arduino IDE

 Go to Tools > Boards.


 If the ESP32 library is installed correctly, you will see an ESP32 option.
 Select "ESP32 Dev Module" as the board.

Step 10: Select the Correct Port

 Go to Tools > Ports.


 Since the ESP32 microcontroller is connected to your computer, the corresponding
port will be automatically detected.
 Select the correct port from the list.
 Ensure that both the board and port are selected properly.

Page | 27
Step 11: Verify the Code for Errors

 Click on the Verify button in Arduino IDE.


 This will check the code for any errors.
 If errors are found, refer to the error messages and fix them before proceeding.

Step 12: Upload the Code to ESP32

 Once there are no errors, click on the Upload button.


 The program will be uploaded to the ESP32 microcontroller.
 Wait for the process to complete.

Page | 28
Page | 29
Lesson-7
Conveyor Belt using two IR sensors
Definition:

A Conveyor Belt System uses two IR sensors placed on the left and right ends to detect
the presence of an object. When an object is detected by the left IR sensor, the conveyor belt
moves forward to transport it. Once the right IR sensor detects the object, the belt stops
automatically. This system ensures efficient material handling and precise control of
movement, reducing the need for manual intervention. In this model, a lever is used as the
object being detected and transported by the system.

Model:

Page | 30
Block Program:
This code controls a DC motor (conveyor belt) using two IR sensors placed on the left
and right sides. A lever is used as the object being detected and moved. Depending on where
the lever is placed, the motor rotates in a specific direction to move it. This setup can be used
in an automated system to shift a lever or similar object between two points.

Explanation:
Setup

1. Connect IR sensor tagged IRL to Port 4:


o The left IR sensor (IRL) is connected to Port 4 of the controller.
o It detects the lever placed on the left side of the conveyor.
2. Connect IR sensor tagged IRR to Port 5:
o The right IR sensor (IRR) is connected to Port 5.
o It detects the lever when it reaches the right side.
3. Connect DC motor tagged DCM to Port 6:
o The DC motor connected to Port 6 powers the conveyor belt.
o It moves the lever in both directions depending on sensor input.

Loop (Repeats the actions indefinitely)

1. If the lever is detected by the left IR sensor (IRL):


o The motor rotates clockwise at 80% speed.
o This moves the lever from left to right on the conveyor.

Page | 31
2. If the lever is detected by the right IR sensor (IRR):
o The motor rotates counter-clockwise at 80% speed.
o This moves the lever back from right to left.
3. If the lever is not detected by either sensor:
o Both sensors return LOW signals.
o The motor is stopped by setting its speed to 0%, halting the conveyor.

This system allows the conveyor to move a lever automatically in both directions based on its
position, making it suitable for tasks like sorting, object return systems, or interactive models.

Page | 32
Lesson-8
Counting Machine using IR sensor
Definition:
A Counting Machine System uses an IR sensor to detect and count the number of
rotations made by a rotating object, such as a wheel or gear. Each time a rotation is detected
by the IR sensor, the count is increased using a user-defined variable in the program. The
system continuously monitors the count, and once a preset rotation limit is reached, the
motor stops automatically. This setup ensures accurate rotation tracking and controlled
operation. In this model, custom variables are created to store and compare the count,
enabling precise control without manual intervention.

Model:

Page | 33
Block Program:
This code is used to create a Counting Machine that uses an IR sensor to count the
number of rotations made by a moving object. The count is stored in a variable, and once a
preset number of rotations is reached, the motor stops automatically. This system
demonstrates automatic control using IR detection and custom variables in the program.

Explanation:
Setup

1. Connect DC motor tagged DCM to Port 4


o The DC motor is connected to Port 4.
o It drives the rotating object (e.g., a wheel or disc with a reflective mark).
2. Connect IR sensor tagged IRS to Port 5
Page | 34
o The IR sensor is connected to Port 5.
o It detects a change in light (the reflective mark) once every rotation.
3. Initialize the DC motor to 0 % speed
o Ensures the motor is stopped at start-up.
4. ➤ CREATE YOUR OWN VARIABLE
1. Open the Variables palette in the block editor.
2. Click “Make a Variable…”.
3. Type the name Count and choose.
4. Press OK – the new variable block now appears and can be dragged into the
program.
(Repeat the same process to create Previous_IR_Value and Rides.)
5. Set variables
o Previous_IR_Value – stores the last IR reading.
o Rides – stores the desired number of rotations (set to 4).
o Count – starts at 0 and increments on each rotation.
6. Port Monitor setup
o Opens a serial/port monitor at 9600 baud for on-screen debugging.

Loop (Repeats the actions indefinitely)

1. Print the current Count on the Port Monitor.


2. Set motor speed to 100 % clockwise
o Keeps the wheel turning until the stop condition is met.
3. Rotation-detection logic
o IF Previous_IR_Value = 0 AND current IR reading = 1 → a marker has passed.
 Increment Count by 1.
 Set Previous_IR_Value to 1.
 Delay 100 ms to prevent double-counting.
4. Reset logic
o ELSE set Previous_IR_Value back to 0, ready for the next marker.
5. Stopping condition
o IF Count ≥ Rides → set motor speed to 0 %, stopping the machine.

This system automatically counts rotations using an IR sensor and a custom variable. It
demonstrates how logic and variables can be used in programming to monitor physical
actions and respond accordingly. It's useful for projects like gear counters, or controlled
rotating machines.

Page | 35

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy