Skip to content

7. Input & Output device

This week I worked on Input & Output devices.

Inputs

there is many things can be an input devices and one of them the one I did use here is the line tracking sensor, this website help me to program it and wiring it in my Adafruit Feather nRF52840 microcontroller. KY-033 Line tracking sensor– A line tracking sensor and it does exactly what the name suggests it tracks black lines against white background or white lines against black background whatever you would like to do and it’s a pretty simple device. This sensor is also known as hunt sensor or line following sensor.

Specification

  • Working voltage: DC 3.3V-5V
  • Working current: ≥ 20mA
  • Operating temperature: -10℃~+50℃
  • Detection distance: 2-40cm
  • IO Interface:3-wire interfaces
  • Output signal: TTL level (low level there is an obstacle, no obstacle high)
  • Adjustment: adjust multi-turn resistance
  • Effective angle: 35°

  • and inside the line tracking sensor

now time for wiring everything this photo helped me to do it I did the same wiring just instead of pin 8 I used A1 for analog read

and this is the code I used

void setup()
{
Serial.begin(9600); // activates Serial Communication
}

void loop()
{
Serial.print(analogRead(A1)); // Line Tracking sensor is connected with pin A1 of the Adafruit
delay(500);
}
  • Serial begin code for establish serial communication between the Adafruit and the PC.
  • Serial print for reading the analog data that we get from the tracking sensor
  • The delay is the time between each read (each loop)

final result

Output

A servomotor (or servo motor) is a rotary actuator or linear actuator that allows for precise control of angular or linear position, velocity and acceleration. It consists of a suitable motor coupled to a sensor for position feedback. It also requires a relatively sophisticated controller, often a dedicated module designed specifically for use with servomotors. read more

Here I used the servo motor SM-S2309s - micro analog servo

Now I started wiring it’s almost the same as the input device I used above this helped to do it

  • after the wiring I used this code
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

The for loop here in the code establish a variable pos initialized with integer 0 and increases each time with the step of +1 until it reaches 180 afterward we use this variable inside the loop to move the servomotor 180 degrees in the second for loop is reverse of the first on we start with pos equal 180 and decrease each time with a step of -1.

  • from this wbesite and did the sweep

Overall

everything worked fine and perfectly as it should just I couldn’t make a code that use the line tracking sensor to control the output the servomotor.


Last update: August 18, 2022