7. Input & Output device¶
in this assignment i was required to work on input and output deviceses
Assesment(1):A Line tracking sensor¶
Research¶
The Line Tracking Sensor based on TCRT5000 is an type of infrared reflectance sensor, and is commonly used in line following robots, it is mounted at the bottom of the robot chassis. The line tracking sensor works by detecting reflected light coming from its own infrared LED and by measuring the amount of reflected infrared light, it can detect transitions from light to dark (lines) or even objects directly in front of it.
STEPS:¶
1- the sensor i used is tracking sensor HW-511
2- after that using jumping wires, i connected the positive in the sensor with the “5v” in the micrcontroller and the the ‘G’ in the sensor which represent ground with “GND”in the micrcontroller and the last one which is analog in the sensor with “DCA/A0 ” in the microcontroler
3- i connected the mictro controller to voltage source(my laptop) using USB to run it
4-Finally i uploaded a code to read the change in voltage and conver it to number between 0 and 1023 code:
#define sensor 2
#define buzzer 3
#define red 4
#define green 5
void setup() {
Serial.begin(9600);
pinMode(sensor,INPUT);
//pinMode(buzzer,OUTPUT);
//pinMode(green,OUTPUT);
//pinMode(red,OUTPUT);
}
void loop() {
bool value = digitalRead(sensor);
int sensorValue = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue);
delay(1);
}
Hero shot video¶
Assesment(2): Servo motor¶
Research¶
A servo motor is an electromechanical device that produces torque and velocity based on the supplied current and voltage. A servo motor works as part of a closed loop system providing torque and velocity as commanded from a servo controller utilizing a feedback device to close the loop. The feedback device supplies information such as current, velocity, or position to the servo controller, which adjusts the motor action depending on the commanded parameters.
MG90S is a micro servo motor with metal gear. This small and lightweight servo comes with high output power, thus ideal for RC Airplane, Quadcopter or Robotic Arms.
its uses as actuators in many robots like Biped Robot, Hexapod, robotic arm etc.. also Commonly used for steering system in RC toys Robots where position control is required without feedback Less weight hence used in multi DOF robots like humanoid robots.
Code:
#include <Servo.h>
Servo myservo;
Define the servo pin:
#define servoPin 9
Create a variable to store the servo position:
int angle = 0;
void setup() {
Attach the Servo variable to a pin:
myservo.attach(servoPin);
}
void loop() {
// Tell the servo to go to a particular angle:
myservo.write(90);
delay(1000);
myservo.write(180);
delay(1000);
myservo.write(0);
delay(1000);
// Sweep from 0 to 180 degrees:
for (angle = 0; angle <= 180; angle += 1) {
myservo.write(angle);
delay(15);
}
// And back from 180 to 0 degrees:
for (angle = 180; angle >= 0; angle -= 1) {
myservo.write(angle);
delay(30);
}
delay(1000);
}