Skip to content

INPUT DEVICES

Welcome to week 11 assignment!

Key Learnings
This week I learned about input devices, I designed the circuit board I will be using in my machine including my input device.

Input Devices

Input devices allow humans to interact with their machine. some examples are motion sensors, distance sensors, touch screens and push buttons.

I will be using the HC-SR04 Ultrasonic Distance Sensor in my final project to measure distance between humans and my artwork to control the output.
sensor uses sonar to determine the distance to an object. This sensor reads from 2cm to 400cm (0.8inch to 157inch) with an accuracy of 0.3cm (0.1inches), which is good for most hobbyist projects. In addition, this particular module comes with ultrasonic transmitter and receiver modules.
Reference

Device

1- The ultrasound transmitter (trig pin) emits a high-frequency sound (40 kHz).
2- The sound travels through the air. If it finds an object, it bounces back to the module.
3- The ultrasound receiver (echo pin) receives the reflected sound (echo).

transmitter

Microcontroller

I will connect my sensor with XIAO-RP2040

microcontroller

Circuit Design

sketch

to design this sketch on eagle, Download EAGLE footprint of xiao RP-2040 microcontroller and for HC-SR04 Sensor.

You can add both footprints libraries into Eagle through the following: My documents > Eagle > Libraries > paste your footprint library.

Eagle CotrolPanel > File > Newproject.
A folder named “New project” will appear.
Right clink on “New Project” rename to sensor HC.
Right click on libraries > choose the library of the sensor and of the microcontroller > use.

control_panel

right click on your folder HC Sensor > New > Schematic
I added all components required and connected pins together.

schematic&Board

Testing my circuit on a breadboard. breadboard The footprint I used for my microcontroller was not long enough for the female connecter to be soldired, I should have modefied it, but since I didn’t modify the footprint I cut the pins from the connecter to become very short and soldered them.

PCB

connected_PCB

Arduino Code

The code I found on my favorite website (www.randomnerdtutorial.com), I modefied the pins numbers connected with the trigPin and echoPin.

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/esp32-hc-sr04-ultrasonic-arduino/

  Permission is hereby granted, free of charge, to any person obtaining a copy
  of this software and associated documentation files.

  The above copyright notice and this permission notice shall be included in all
  copies or substantial portions of the Software.
*********/

const int trigPin = D0;
const int echoPin = D10;

//define sound speed in cm/uS
#define SOUND_SPEED 0.034
#define CM_TO_INCH 0.393701

long duration;
float distanceCm;
float distanceInch;

void setup() {
  Serial.begin(115200); // Starts the serial communication
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}

void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

  // Calculate the distance
  distanceCm = duration * SOUND_SPEED/2;

  // Convert to inches
  distanceInch = distanceCm * CM_TO_INCH;

  // Prints the distance in the Serial Monitor
  Serial.print("Distance (cm): ");
  Serial.println(distanceCm);
  Serial.print("Distance (inch): ");
  Serial.println(distanceInch);

  delay(1000);
}

arduino

I was stuck debugging my circuit, I followed these steps:
1- first I checked with a multimeter if all the right pins were connected.
2- I tried different codes and installed multiple libraries but still not working.
3- I went back to the first code I tested because I was following a really good tutorial so I though it is better to check it. I found out the problem was that i was using the number of the pin without the symbol, so instead of 0 and 10, I used D0 & D10 and it worked.

Download Files

Eagle design file - Schematic & Board
PNG of PCB files

Group Assignment

We tested with two input devices 1-light sensor (Analog) and 2-Push Button (deigital), we monitored the voltage changes using a multimeter.

For the pushbutton circuit we connected the circuit with 5 volt and we used a 5k ohm resistor, when the button was pushed the circuit was closed and the voltage reading on the multimeter changed to 5.

video

For the (light sensor) LDR, when blocking the light from the sensor, the voltage at the LDR was decreasing. the value of the voltage at the multimeter decreased too but there wasn’t a fixed value like the pushbutton.

In conclusion; the digital signals have two-states; when reading is 0 that means 0V or low voltage, but if the multimeter reading was 1 that’s high voltage and that depends on the logic voltage on that system, while the analog values was ranging and the value of the voltage was changing over time when the amount of light directed to the LDR was changing.

follow group assignment page for further information, [link]

HC-SR04 ULTRASONIC ARDUINO


Last update: June 22, 2023
Back to top