Digital Inputs on Arduino

Digital signals must have a finite set of possible values. The number of values in the set can be anywhere between two and a-very-large-number-that's-not-infinity. Most commonly digital signals will be one of two values -- like either 0V or 5V. This can also be defined as on or off, or 1's and 0's in binary- the language of computing. Timing graphs of these signals look like square waves.

Here we see an example of PWM, or Pulse Width Modulation. PWM modulates the frequency of a fixed voltage square wave to simulate a new average reading of voltage. For example, an 80% high pulse with of 5V will simulate a 4V output.

A digital signal can also be a discrete representation of an analog waveform. Viewed from afar, the wave function below may seem smooth and analog, but when you look closely there are tiny discrete steps as the signal tries to approximate values:

That's the big difference between analog and digital waves. Analog waves are smooth and continuous, digital waves are stepping, square, and discrete. However, digital waves can simulate analog, but analog cannot simulate digital. 

Digital Sensor Examples

Button or Switch

The simplest digital sensor is a button or switch. As stated above, the most basic definition of digital inputs or outputs mean that the signal is high voltage or low voltage, on or off, 1's or 0's in binary. Since most of the time, the function of a button or switch is simply turn something on or off, these devices are digital signal creators. By plugging a button or switch into an Arduino, you have given your project the simplest way to communicate digitally with the external world. 

Disclaimer from TinkerCAD:

"The switch isn’t exactly like an actual switch (i.e. completely off or completely on). Our simulator needs the whole circuit to be connected all of the time. Instead, the switch is treated like a variable resistor with two states: very small (on), or very large (off). For the ‘off’ state, the internal resistance used is 10 GOhms (10^10 Ohms).

The multimeter has internal resistance as well. This is true for actual multimeters. For ours in the simulator, it is 100 MOhms (10^8 Ohms).

The main voltage drop is across the internal resistance of the switch and the multimeter. Since the switch resistance is 100 times as large as the multimeter resistance, the Voltage at the multimeter input is roughly 5V x 1 / (100 + 1) = 49.5 mV."

This means while simulating using TinkerCAD, a switch will never apply a LOW input to an Arduino. This means you will have to get creative with a button if you want to achieve similar results as a switch in the TinkerCAD simulation- See our Serial Monitor Page on how to do this with button inputs. If all you are using TinkerCAD for is to generate C++ script from block coding to input into the IDE, then you can still continue use a switch- if everything else is correct, the code will still function in real life the way it is supposed to with a switch. 

Ultrasonic Proximity Sensor 

Ultrasonic proximity sensors operate by emitting and receiving high-frequency sound waves. The frequency is usually in the order of 200 kHz, which is too high for the human ear to hear. Ultrasonic proximity sensors use reflected or transmitted ultrasonic waves to detect the presence or absence of a target component.

There are two basic modes of operation: opposed mode and diffuse (echo) mode. In opposed mode, one sensor emits the sound wave, and another, mounted opposite the emitter, receives the sound wave. In diffuse mode, the same sensor emits the sound wave and then listens for the echo that bounces off an object.

Ultrasonic Sensor HC-SR04 is a sensor that can measure distance. It emits ultrasound at 40 000 Hz (40kHz) which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate the distance.

For example, if the object is 20 cm away from the sensor, and the speed of the sound is 340 m/s or 0.034 cm/µs the sound wave will need to travel about 588 microseconds. But what you will get from the Echo pin will be double that number because the sound wave needs to travel forward and bounce backward. So in order to get the distance in cm, we need to multiply the received travel time value from the echo pin by 0.034 and divide it by 2.

While some sensors use a separate sound emitter and receiver, it’s also possible to combine these into one package device, having an ultrasonic element alternate between emitting and receiving signals. This type of sensor can be manufactured in a smaller package than with separate elements, which is convenient for applications where size is at a premium.

Depending on which proximity sensor you choose to use, you will have the option in TinkerCAD to read the trigger and echo on the same pin or have them on separate pins like the two examples below. Really, the main difference just depends on which proximity sensor you have. They are within comparable sensitivity ranges.